- attributestodocument_src.zip
- Palladino.DocGen
- Palla.DocGen.App
- Palla.DocGen.Library
- Palladino.DocGen
- SampleAssembly1
- SampleBins
- SampleAssembly1.dll
- SampleAssembly2.dll
- SampleAssembly3.dll
- SampleAssembly4.dll
- SampleAssembly5.dll
|
using System;
using System.Xml;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Xml.Serialization;
using System.Globalization;
using Palla.DocGen.Library;
namespace Palla.DocGen.App
{
/// <summary>
/// User process for "frmDocGen"
/// </summary>
public class UserProcessfrmDocGen
{
private DateTime initialDate = DateTime.Now;
private DateTime finalDate = DateTime.Now;
private string targetPath = String.Empty;
private string[] assemblieList = null;
protected AssemblyInformationCollection ic = new AssemblyInformationCollection();
public event NoticeFaultsEventHandler NoticeFaults = null;
public event NoticeStartProcessEventHandler NoticeStartProcess = null;
public event EventHandler NoticeProgress = null;
public event EventHandler NoticeEndProcess = null;
#region Constructors
public UserProcessfrmDocGen()
{
}
#endregion
#region Virtuals
protected virtual void OnNoticeFaults(ArrayList messages)
{
if(this.NoticeFaults != null)
this.NoticeFaults(this,new NoticeFaultsEventArgs(messages));
}
protected virtual void OnNoticeStartProcess(int limit)
{
if(this.NoticeStartProcess != null)
this.NoticeStartProcess(this,new NoticeStartProcessEventArgs(limit));
}
protected virtual void OnNoticeProgress()
{
if(this.NoticeProgress != null)
this.NoticeProgress(this, EventArgs.Empty);
}
protected virtual void OnNoticeEndProcess()
{
if(this.NoticeEndProcess != null)
this.NoticeEndProcess(this, EventArgs.Empty);
}
protected virtual bool ValidateInstance()
{
ArrayList returnErrors = new ArrayList();
if (!Directory.Exists(Path.GetDirectoryName(this.targetPath)))
returnErrors.Add(String.Format("Path '{0}' no exists.", this.targetPath));
if (this.initialDate > this.finalDate)
returnErrors.Add("Selected period is not valid.");
if (this.assemblieList==null || this.assemblieList.Length==0)
returnErrors.Add("There are not selected assemblies.");
if (returnErrors.Count>0)
{
this.OnNoticeFaults(returnErrors);
return false;
}
else
return true;
}
protected virtual void LoadAssembliesInformations()
{
try
{
foreach(string assembly in this.assemblieList)
{
Assembly asm = Assembly.LoadFrom(assembly);
if (asm!=null)
{
object[] attributeList = asm.GetCustomAttributes(typeof(UpdateDocumentationAttribute), false);
foreach(Attribute attrib in attributeList)
{
if (attrib!=null)
{
DateTime dtAtr = Convert.ToDateTime(((UpdateDocumentationAttribute)attrib).DateChange, CultureInfo.CurrentCulture);
if (attrib != null &&
(dtAtr >= this.initialDate && dtAtr <= this.finalDate))
{
this.ic.Add(new AssemblyInformation(Path.GetFileName(assembly),
((UpdateDocumentationAttribute)attrib).Version,
dtAtr.ToString("d", CultureInfo.CurrentCulture),
((UpdateDocumentationAttribute)attrib).Priority,
((UpdateDocumentationAttribute)attrib).ChangesSummary,
((UpdateDocumentationAttribute)attrib).ChangesSummaryCommonUser));
}
}
}
}
this.OnNoticeProgress();
}
}
catch
{
throw;
}
}
protected virtual void SaveXmlFile()
{
try
{
XmlSerializer s = new XmlSerializer(typeof(AssemblyInformationCollection));
TextWriter writer = new StreamWriter(this.XmlFileName);
s.Serialize(writer, this.ic);
writer.Close();
}
catch
{
throw;
}
}
protected virtual void DoTransform()
{
try
{
System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform();
xslt.Load(this.XslFileName);
System.Xml.XPath.XPathDocument xDoc = new System.Xml.XPath.XPathDocument(this.XmlFileName);
XmlWriter writer = new XmlTextWriter(this.targetPath,System.Text.Encoding.UTF8);
xslt.Transform(xDoc, null, writer);
writer.Close();
}
catch
{
throw;
}
}
#endregion
#region Methods
public virtual bool GenerateIt(string[] assemblieList, string targetPath, DateTime initialDate, DateTime finalDate)
{
try
{
this.assemblieList = assemblieList;
this.initialDate = initialDate;
this.finalDate = finalDate;
this.targetPath = targetPath;
if (this.ValidateInstance() &&
DocGenHelpers.SaveImageFile(targetPath) &&
DocGenHelpers.SaveXslFile(targetPath))
{
//Notify start process
this.OnNoticeStartProcess(this.assemblieList.Length);
//Loading the informations
this.LoadAssembliesInformations();
//Save xml file
this.SaveXmlFile();
//Transformation
this.DoTransform();
//Notify end process
this.OnNoticeEndProcess();
return true;
}
else
return false;
}
catch
{
throw;
}
}
#endregion
#region Internal Properties
private string XmlFileName
{
get{return Path.GetDirectoryName(this.targetPath) + @"\doc.xml";}
}
private string XslFileName
{
get{return Path.GetDirectoryName(this.targetPath) + @"\docstyle.xsl";}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.