Recycle Bin.. Continued
/*=====================================================================
File: EventSinkData.cs
Summary: Class to collect data for the event sink.
---------------------------------------------------------------------
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections;
namespace RecycleBin.SharePoint.Configuration
{
[XmlRoot("Data",Namespace="")]
/// <summary>
/// Summary description for EventSinkData.
/// </summary>
public class EventSinkData
{
private string _strMirrorLib;
private string _strRecycleBinLib;
private string _strMainLib;
private string _strUserName;
private string _strDomain;
private string _strPassword;
private string _strFileType;
private string _strFileSize;
# region Properties for Configuration
public string MirrorLib{get{return _strMirrorLib;}set{_strMirrorLib= value;}}
public string RecycleBinLib{get{return _strRecycleBinLib;}set{_strRecycleBinLib= value;}}
public string MainLib{get{return _strMainLib;}set{_strMainLib= value;}}
public string Domain {get{return _strDomain;}set{_strDomain= value;}}
public string UserName{get{return _strUserName;}set{_strUserName= value;}}
public string Password{get{return _strPassword;}set{_strPassword= value;}}
public string FileType{get{ return _strFileType;}set{_strFileType= value;}}
public string FileSize{get{ return _strFileSize;}set{_strFileSize= value;}}
# endregion
/// <summary>
/// Static Methods creates an instance of the object from XML string
/// </summary>
/// <param name="text">XML String passed from SinkData property of the SPEventList object</param>
/// <returns></returns>
public static EventSinkData GetInstance(string text)
{
XmlSerializer objXmlSer = new XmlSerializer(typeof(EventSinkData));
using(MemoryStream objMemStr = new MemoryStream())
{
try
{
if (text!= "")
{
//return array of bytes
byte[] input = Encoding.UTF8.GetBytes(text);
//load array of bytes to memory stream
objMemStr.Write(input,0,(int)input.Length);
objMemStr.Seek(0,0);
EventSinkData e = null;
e = (EventSinkData)objXmlSer.Deserialize(objMemStr);
return e;}
else
{
XmlNodeList nl;
string xmlPath ="C:\\sharepoint\\configuration.xml";
XmlDocument objDoc = new XmlDocument();
objDoc.Load(xmlPath);
nl = objDoc.GetElementsByTagName("Data");
EventSinkData e = new EventSinkData();
e.MirrorLib = nl.Item(0).ChildNodes.Item(0).InnerText;
e.RecycleBinLib = nl.Item(0).ChildNodes.Item(1).InnerText;
e.MainLib = nl.Item(0).ChildNodes.Item(2).InnerText;
e.UserName = nl.Item(0).ChildNodes.Item(4).InnerText;
e.Password= nl.Item(0).ChildNodes.Item(5).InnerText;
e.FileSize = nl.Item(0).ChildNodes.Item(7).InnerText;
e.FileType = nl.Item(0).ChildNodes.Item(6).InnerText;
e.Domain = nl.Item(0).ChildNodes.Item(3).InnerText;
return e;
}
}
catch (Exception ex)
{
throw ex;
}
}
}
/// <summary>
/// Save Object structure into XML
/// </summary>
/// <returns>String in XML format</returns>
public string Persist()
{
XmlSerializer ser = new XmlSerializer(typeof(EventSinkData));
using(MemoryStream mstr =new MemoryStream())
{
try
{
ser.Serialize(mstr, this);
return Encoding.UTF8.GetString(mstr.ToArray());
}
catch (Exception ex)
{
throw ex;
}
}
}
}
}
Continued again...