TdoSolutionClass.cs :  » Database » TDO » TdoCodeGenerator » TdoGeneratorDom » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Database » TDO 
TDO » TdoCodeGenerator » TdoGeneratorDom » TdoSolutionClass.cs
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Data;
using System.Collections;
using System.Text;
using System.IO;
using System.Runtime.Serialization;

namespace TdoCodeGenerator.TdoGeneratorDom{
  [Serializable()]
  public class TdoSolutionClass : IXmlSerializable
  {
    #region Fields
    [NonSerialized()]
    private string fName;
    [NonSerialized()]
    private string fPath;
    [NonSerialized()]
    internal string fOldPath;
    [NonSerialized()]
    private TdoProjectCollection fTdoProjects;
    internal bool fModified;
    #endregion Fields
    #region Constructors
    public TdoSolutionClass()
    {
      this.fName = String.Empty;
      this.fPath = String.Empty;
      this.fTdoProjects = new TdoProjectCollection();
      this.fModified = false;
    }
    #endregion Constructors
    #region Properties
    public string Name
    {
      get 
      {
        return this.fName;
      }
      set
      {
        if (this.fName != value)
        {
          this.fModified = true;
          this.fName = value;
          this.Path = String.Empty;
        }
      }  
    }
    [XmlIgnore()]
    public TdoProjectCollection TdoProjects
    {
      get 
      {
        return this.fTdoProjects; 
      }
      set 
      {
        if (this.fTdoProjects != value) this.fModified = true;
        this.fTdoProjects = value; 
      }
    }
    public bool Modified
    {
      get
      {
        bool modified = this.fModified;
        modified |= this.TdoProjects.Modified;
        return modified;
      }
    }
    [XmlIgnore()]
    public string Path
    {
      get
      {
        return this.fPath;
      }
      set
      {
        if (this.fPath != value)
        {
          this.fModified = true;
          this.fOldPath = this.fPath;
          this.fPath = value;
        }
      }
    }
    #endregion Properties
    #region Methods
    public void Rename(string newName)
    {
      this.Name = newName;
    }

        public void Save()
        {
            if (!this.Modified) return;
            //Make all TdoProject path relative
            foreach (TdoProjectClass prj in this.TdoProjects)
            {
                string absPath = prj.Settings.Destination.OutputFolder;
                prj.Settings.Destination.OutputFolder = TdoCodeGenerator.Generator.TdoDiscovery.getRelativePath(System.IO.Path.GetDirectoryName(prj.Path), absPath);
                prj.Path = TdoCodeGenerator.Generator.TdoDiscovery.getRelativePath(this.Path, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.Path), prj.Path));
            }
            XmlSerializer ser = new XmlSerializer(typeof(TdoSolutionClass));
            StreamWriter streamWriter = new StreamWriter(this.fPath);
            ser.Serialize(streamWriter, this);
            streamWriter.Close();
            this.fModified = false;
            foreach (TdoProjectClass prj in this.TdoProjects)
            {
                prj.Path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.fPath), prj.Path);
                prj.Settings.Destination.OutputFolder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(prj.Path), prj.Settings.Destination.OutputFolder);
                if (prj.Settings.Destination.OutputFolder.EndsWith("\\.\\"))
                    prj.Settings.Destination.OutputFolder = prj.Settings.Destination.OutputFolder.Substring(0, prj.Settings.Destination.OutputFolder.Length - 3);
                prj.fModified = false;
                prj.Data.fModified = false;
                prj.Settings.fModified = false;
                prj.Data.Tables.fModified = false;
                prj.Data.Views.fModified = false;
                prj.Data.StoredProcedures.fModified = false;
                prj.Data.TableValuedFunctions.fModified = false;
                prj.Data.ScalarValuedFunctions.fModified = false;
                prj.Settings.Destination.fModified = false;
                prj.Settings.Source.fModified = false;
            }
            this.fModified = false;
            this.TdoProjects.fModified = false;
        }
    #endregion Methods
        #region Static Fields
        internal static string basePath;
        #endregion Static Fields
        #region Static Methods
        public static TdoSolutionClass Open(string path)
        {
            XmlSerializer ser = new XmlSerializer(typeof(TdoSolutionClass));
            StreamReader streamReader = new StreamReader(path);
            TdoSolutionClass.basePath = System.IO.Path.GetDirectoryName(path);
            TdoSolutionClass result = (TdoSolutionClass)ser.Deserialize(streamReader);
            streamReader.Close();
            result.Path = path;
            foreach (TdoProjectClass prj in result.TdoProjects)
            {
                prj.Path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), prj.Path);
                prj.Settings.Destination.OutputFolder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(prj.Path), prj.Settings.Destination.OutputFolder);
                if (prj.Settings.Destination.OutputFolder.EndsWith("\\.\\"))
                    prj.Settings.Destination.OutputFolder = prj.Settings.Destination.OutputFolder.Substring(0, prj.Settings.Destination.OutputFolder.Length - 3);
                prj.fModified = false;
                prj.Data.fModified = false;
                prj.Settings.fModified = false;
                prj.Data.Tables.fModified = false;
                prj.Data.Views.fModified = false;
                prj.Data.StoredProcedures.fModified = false;
                prj.Data.TableValuedFunctions.fModified = false;
                prj.Data.ScalarValuedFunctions.fModified = false;
                prj.Settings.Destination.fModified = false;
                prj.Settings.Source.fModified = false;
            }
            result.fModified = false;
            result.TdoProjects.fModified = false;
            return result;
        }
    #endregion Static Methods
    #region IXmlSerializable Members
    public System.Xml.Schema.XmlSchema GetSchema()
    {
      return null;
    }
    public void ReadXml(XmlReader reader)
    {
      reader.ReadStartElement();
      reader.ReadStartElement("Name"); this.fName = reader.ReadString(); reader.ReadEndElement();
      XmlDocument xmlTdoProjects = new XmlDocument();
      xmlTdoProjects.LoadXml(reader.ReadOuterXml());
      XmlNodeList xmlTdoProject = xmlTdoProjects.GetElementsByTagName("TdoProject");
      XmlSerializer ser=new XmlSerializer(typeof(TdoProjectClass));
      foreach (XmlNode xmlprj in xmlTdoProject)
      {
        string path = xmlprj["Path"].InnerText;
        TdoProjectClass prj = (TdoProjectClass)ser.Deserialize(new StreamReader(System.IO.Path.Combine(TdoSolutionClass.basePath, path)));
        prj.Path = path;
        prj.fModified = false;
        this.fTdoProjects.Add(prj);

      }
      reader.ReadEndElement();
    }
    public void WriteXml(XmlWriter writer)
    {
      writer.WriteStartElement("Name"); writer.WriteString(this.fName); writer.WriteEndElement();
      writer.WriteStartElement("TdoProjects");
      foreach (TdoProjectClass prj in this.fTdoProjects)
      {
        writer.WriteStartElement("TdoProject");
        writer.WriteStartElement("Path"); writer.WriteString(prj.Path); writer.WriteEndElement();
        writer.WriteEndElement();
      }
      writer.WriteEndElement();
    }

    [OnDeserialized()]
    internal void OnDeserializedMethod(StreamingContext context)
    {
      this.fModified = false;
    }

    #endregion
}

  [Serializable()]
  public class TdoProjectCollection : System.Collections.Generic.List<TdoProjectClass>
  {
    #region Fields
    [NonSerialized()]
    internal bool fModified;
    #endregion Fields
    #region Constructors
    public TdoProjectCollection()
    {
      this.fModified = false;
    }
    #endregion Constructors
    #region Properties
    #region Indexers

    public new TdoProjectClass this[int index]
    {
      get
      {
        return base[index];
      }
      set
      {
        base[index] = value;
      }
    }
    public TdoProjectClass this[string name]
    {
      get
      {
        for (int i = 0; i < this.Count; i++)
        {
          if (this[i].Name == name)
            return this[i];
        }
        return null;
      }
      set
      {
        for (int i = 0; i < this.Count; i++)
        {
          if (this[i].Name == name)
          {
            this[i] = value;
          }
        }
      }
    }
    #endregion Indexers
    public bool Modified
    {
      get
      {
        return this.fModified;
      }
    }
    #endregion Properties
    #region Methods
    public new void Add(TdoProjectClass item)
    {
      base.Add(item);
      this.fModified = true;
    }
    public new bool Remove(TdoProjectClass item)
    {
      if (base.Contains(item))
      {
        this.fModified = true;
        return base.Remove(item);
      }
      else
      {
        return false;
      }
    }
    public bool Contains(string tdoProjectName)
    {
      for (int i=0;i<this.Count;i++)
      {
        if (base[i].Name == tdoProjectName)
          return true;
      }
      return false;
    }

    #endregion Methods

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.