Saturday 30 October 2010

Week-08-CRM

29 Oct 2010
Total 6 hours
  1. <Group Meeting> 2 hours We discussed about the table layout. In this time we haven't done normalization. So there are many tables, which have duplicated information, for example, status, category and so on.
  2. <Coding for Reminder function> 4 hours Honestly, I want to finish up the reminder function today, however I could not finish. So I will continue that on weekend. This weekend I have an appointment, so I don't know I can finish or not. Anyway I will do my best:)

28 Oct 2010
Total 6 hours
  1. <Coding for mail> 1hours I created to display part of the recent e-mail address. I checked the recent e-mail and I could get result, which I expected.
  2. <Coding for Reminder function > 5hours Now I make the programming for the reminder function. I realized one page has many functions, so I have to coding many things. And also I need to send e-mail to the using smtp, however sending e-mail function has already done at the last semester, so I can do.

27 Oct 2010
Total 8 hours
  1. <Coding for mail> 3hours I searched internet and I found the C# console application can create exe file. So I can make exe file and I create schedule to do this execute file every 5 min.
  2. <Coding for Reminder function > 5hours I make the reminder function, however I need to take a time using ASP.net, because I don't know many functions, and also sometimes working is different from my expectation. So I need time. 
To create exe file
Tool bar > Build > Batch build > select release and then press Build button. You can fine bin file in the release folder, there is exe file.
I create record using control panel in side scheduler.


26 Oct 2010
Total 5 hours
  1. <Coding for mail> 3hours I thought the web application is not suitable for getting e-mail, because someone must go to this web site. So I need to create bat file or some kind of executable file. This programming can get e-mail automatically, which means no one action to get e-mail. Therefore, system can do to get data automatically.
  2. <Presentation meeting> 2hours We attend the meeting.This time only two group made a presentation, so we have a time to do.
25 Oct 2010
Total 4 hours
  1. <Coding for mail> 4hours Today is Labor day, which is New Zealand National holiday. New Zealand's holidays are less than Japanese ones. So I got a little rest. Today, I could get to read Google mail using ATOM Feed. Finally, I understood C# XML classes. Actually, there are many similar naming classes, so I need to research one by one. I can already read some ATOM feed, but I could not get attribute of the link, for example "href=". So if someone may try to do same thing, I will write down coding.  

GmailHandler Class
I downloaded this class form http://fci-h.blogspot.com
using System;
using System.Data;
using System.Xml;
using System.Net;
using System.IO;
/*
 * this code made by Ahmed Essawy
 * AhmedEssawy@gmail.com
 * http://fci-h.blogspot.com
 */
/// 
/// Summary description for Class1
/// 
public class GmailHandler
{
    private string username;
    private string password;
    private string gmailAtomUrl;

    public string GmailAtomUrl
    {
        get { return gmailAtomUrl; }
        set { gmailAtomUrl = value; }
    }

    public string Password
    {
        get { return password; }
        set { password = value; }
    }

    public string Username
    {
        get { return username; }
        set { username = value; }
    }

    public GmailHandler(string _Username, string _Password, string _GmailAtomUrl)
    {
        Username = _Username;
        Password = _Password;
        GmailAtomUrl = _GmailAtomUrl;
    }

    public GmailHandler(string _Username, string _Password)
    {
        Username = _Username;
        Password = _Password;
        GmailAtomUrl = "https://mail.google.com/mail/feed/atom";
    }
    public XmlDocument GetGmailAtom()
    {
        byte[] buffer = new byte[8192];
        int byteCount = 0;
        XmlDocument _feedXml = null;
        try
        {
            System.Text.StringBuilder sBuilder = new System.Text.StringBuilder();
            WebRequest webRequest = WebRequest.Create(GmailAtomUrl);

            webRequest.PreAuthenticate = true;

            System.Net.NetworkCredential credentials = new NetworkCredential(this.Username, this.Password);
            webRequest.Credentials = credentials;

            WebResponse webResponse = webRequest.GetResponse();
            Stream stream = webResponse.GetResponseStream();

            while ((byteCount = stream.Read(buffer, 0, buffer.Length)) > 0)
                sBuilder.Append(System.Text.Encoding.ASCII.GetString(buffer, 0, byteCount));


            _feedXml = new XmlDocument();
            _feedXml.LoadXml(sBuilder.ToString());


        }
        catch (Exception ex)
        {
            //add error handling
            throw ex;
        }
        return _feedXml;
    }
}

Default.aspx.cs
This page calls Google mail Atom feed and displays result.
I was struggling "if (entrychild.Name == "link")" part, because Atom feed uses link for attribute. If it was <link> URL </link>, there would be no problem:)
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Net.Security;
using System.Text.RegularExpressions;
using System.Xml.XPath;

public partial class _Default : System.Web.UI.Page
{
    public string r = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        //Create the object from GmailHandler class 
        GmailHandler gmailFeed = new GmailHandler("your username", "password");
        //Get the feed :) 
        XmlDocument myXml = gmailFeed.GetGmailAtom();

        //For to get Name and Innner Text From Atom Feed
        XmlElement root = myXml.DocumentElement;
        XmlNodeList xmlnode = myXml.GetElementsByTagName("entry");

        foreach (XmlElement entry in xmlnode)
        {
            foreach (XmlElement entrychild in entry)
            {
                if (entrychild.Name == "author")
                {
                    foreach (XmlElement entry2ndchild in entrychild)
                    {
                        Response.Write(entry2ndchild.Name);
                        Response.Write(":\t" + entry2ndchild.InnerText + " \n
");                   
                    
                    }
                }

                Response.Write(entrychild.Name);
                Response.Write(":\t" + entrychild.InnerText + " \n
");
                if (entrychild.Name == "link")
                {
                    string target = entrychild.OuterXml;
                    Match match = Regex.Match(target,
                    @"href=""([^""]+)""");
                    if (match.Success)
                    {
                        string href = match.Groups[1].Value;
                        Response.Write(href + " \n
");
                    }
                }
            }
            Response.Write("\r\n\r\n
");
        }
    }
}

No comments:

Post a Comment