internal void UpdateInfo(DanuComponent d)
 {
     this.SourceComponent    = d;
     this.textBlockName.Text = d.Name;
     foreach (DanuInterfaceObject i in d.Interfaces)
     {
         ComponentControlInterface newInterface = new ComponentControlInterface();
         newInterface.ParentControl     = d;
         newInterface.Interface         = i;
         newInterface.MouseDoubleClick += new MouseButtonEventHandler(newInterface_MouseDoubleClick);
         this.stackPanelInterfaces.Children.Add(newInterface);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Generates an interface's code.
        /// CURRENT: Working fairly well, surprisingly.
        /// </summary>
        /// <param name="io">Interface to be generated.</param>
        /// <param name="path">Where to write it.</param>
        /// <param name="parent">What component it belongs to.</param>
        public static void GenerateInterface(DanuInterfaceObject io, string path, DanuComponent parent)
        {
            // NOTE: This is probably the tidiest method in this class. Best not tamper much with it, lest we wake some dragons.

            #region OBSOLETE
            //string currentExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(currentExecutingAssemblyLocation);
            //System.Environment.CurrentDirectory = f.Directory.FullName;
            #endregion

            // Setting up the filewriter.
            string filename = io.Name + ".cs";
            //TODO Fishy tampering. I wonder how he's creating these files beforehand.
            //File.Create(filename).Close();
            TextWriter writer = new StreamWriter(path + filename);

            // Basic "using" clauses.
            writer.WriteLine("using System;");
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("using System.Linq;");
            writer.WriteLine("using System.Text;");

            writer.WriteLine("");

            writer.WriteLine("namespace " + parent.Name);
            writer.WriteLine("{");
            writer.WriteLine("\tpublic interface " + io.Name);
            writer.WriteLine("\t{");

            // Declaration of the methods this interface signature defines.
            foreach (EshuMethod method in io.Eshu.Signature)
            {
                writer.Write("\t\t" + method.ReturnType + " " + method.Name + "(");
                foreach (EshuProperty parameter in method.Parameters)
                {
                    if (!parameter.Equals(method.Parameters.First()))
                    {
                        writer.Write(", ");
                    }
                    writer.Write(parameter.Type + " " + parameter.Name);
                }
                writer.Write(");\n");
            }

            writer.WriteLine("\t\t");
            writer.WriteLine("\t}");
            writer.WriteLine("}");

            writer.Close();
        }
        public static void GenerateMainClass(DanuComponent comp)
        {
            string filename = comp.Name + ".cs";

            File.Create(filename).Close();
            TextWriter writer = new StreamWriter(filename);

            writer.WriteLine("using System;");
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("using System.Linq;");
            writer.WriteLine("using System.Text;");

            writer.WriteLine("");

            writer.WriteLine("namespace " + comp.Name);
            writer.WriteLine("{");
            writer.WriteLine("\t// This is the core class of the " + comp.Name + " component.");
            writer.Write("\tpublic class " + comp.Name);

            if (comp.Sockets.Count != 0)
            {
                writer.Write(" : ");
                foreach (DanuSocket so in comp.Sockets)
                {
                    writer.Write(so.InterfaceUsed.Name + ", ");
                }
                writer.Write("\n");
            }

            writer.WriteLine("\t{");

            foreach (DanuInterfaceObject io in comp.Interfaces)
            {
                writer.WriteLine("\t\tpublic " + io.Name);
            }

            writer.WriteLine("\t\t");
            writer.WriteLine("\t}");
            writer.WriteLine("}");
        }
Esempio n. 4
0
        /// <summary>
        /// Generates the assemblyinfo file for a component.
        /// CURRENT: Pretty useless, not to mention broken.
        /// </summary>
        /// <param name="comp">Component in question.</param>
        public static void GenerateAssemblyInfo(DanuComponent comp)
        {
            #region OBSOLETE
            //string currentExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(currentExecutingAssemblyLocation);
            //System.Environment.CurrentDirectory = f.Directory.FullName;
            #endregion

            // Creates the file writer.
            string filename = "AssemblyInfo.cs";
            //TODO Tampering
            //File.Create(filename).Close();
            TextWriter writer = new StreamWriter("./Source/" + comp.Name + "/Properties/" + filename);

            //TODO Hm? What are these?
            writer.WriteLine("using System.Reflection;");
            writer.WriteLine("using System.Runtime.CompilerServices;");
            writer.WriteLine("using System.Runtime.InteropServices;");

            //TODO I wonder if we shouldn't auto-fill these somehow. Maybe get some information from the user's computer?
            writer.WriteLine("[assembly: AssemblyTitle(\"" + comp.Name + "\")]");
            writer.WriteLine("[assembly: AssemblyDescription(\"\")]");
            writer.WriteLine("[assembly: AssemblyConfiguration(\"\")]");
            writer.WriteLine("[assembly: AssemblyCompany(\"\")]");
            writer.WriteLine("[assembly: AssemblyProduct(\"" + comp.Name + "\")]");
            writer.WriteLine("[assembly: AssemblyCopyright(\"\")]");
            writer.WriteLine("[assembly: AssemblyTrademark(\"\")]");
            writer.WriteLine("[assembly: AssemblyCulture(\"\")]");
            writer.WriteLine("[assembly: ComVisible(false)]");

            /* TODO My goodness, this is old code. Gotta take the GUID from the component's attribute, otherwise it'll be impossible
             * to ever compile these libraries on their own.
             */
            writer.WriteLine("[assembly: Guid(\"0fe9c50c-c8b9-4798-9ed4-a764e0615052\")]");
            writer.WriteLine("[assembly: AssemblyVersion(\"1.0.0.0\")]");
            writer.WriteLine("[assembly: AssemblyFileVersion(\"1.0.0.0\")]");

            writer.Close();
        }
Esempio n. 5
0
        /// <summary>
        /// Generates the project file (.csproj) for a component.
        /// CURRENT: The current status is that all projects generated will become libraries. Unknown whether that is to be modified.
        /// </summary>
        /// <param name="comp">The component that is to be written.</param>
        public static void GenerateProjectFile(DanuComponent comp)
        {
            #region OBSOLETE
            //string currentExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(currentExecutingAssemblyLocation);
            //System.Environment.CurrentDirectory = f.Directory.FullName;
            #endregion

            // Creation of the file.
            //TODO Check whether at this point the folder is already created or not.
            string    filename = comp.Name + ".csproj";
            XmlWriter writer   = XmlWriter.Create("./Source/" + comp.Name + "/" + filename);

            #region Stable as of 3.0
            // This section need only be changed if ever we desire to change the versions with which to compile.
            writer.WriteStartElement("Project", "http://schemas.microsoft.com/developer/msbuild/2003");
            writer.WriteAttributeString("ToolsVersion", "4.0");
            writer.WriteAttributeString("DefaultTargets", "Build");
            writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
            #endregion

            #region Hardcoded
            writer.WriteStartElement("PropertyGroup");

            writer.WriteStartElement("Configuration");
            writer.WriteAttributeString("Condition", " '$(Configuration)' == '' ");
            writer.WriteValue("Debug");
            writer.WriteEndElement();

            writer.WriteStartElement("Platform");
            writer.WriteAttributeString("Condition", " '$(Platform)' == '' ");
            writer.WriteValue("AnyCPU");
            writer.WriteEndElement();
            #endregion

            //TODO Figure out what these are.
            writer.WriteElementString("ProductVersion", "8.0.30703");
            writer.WriteElementString("SchemaVersion", "2.0");

            // Gets the GUID from the structure, which should already have been generated prior to call.
            writer.WriteElementString("ProjectGuid", comp.Specification.GUID);

            // "Library" must become some sort of variable if the OutputType ever has to change.
            writer.WriteElementString("OutputType", "Library");

            #region Hardcoded
            writer.WriteElementString("AppDesignerFolder", "Properties");
            writer.WriteElementString("RootNamespace", comp.Name);
            writer.WriteElementString("AssemblyName", comp.Name);
            #endregion

            //TODO Figure out what these are.
            writer.WriteElementString("TargetFrameworkVersion", "v4.0");
            writer.WriteElementString("FileAlignment", "512");

            writer.WriteEndElement();

            #region Compile Parameters

            /* TODO Turn these into variables so that the output path can be picked, the constants can be defined, the compile parameters
             * can be defined, etc.
             */
            writer.WriteStartElement("PropertyGroup");
            writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ");
            writer.WriteElementString("DebugSymbols", "true");
            writer.WriteElementString("DebugType", "full");
            writer.WriteElementString("Optimize", "false");
            writer.WriteElementString("OutputPath", "bin\\Debug\\");
            writer.WriteElementString("DefineConstants", "DEBUG;TRACE");
            writer.WriteElementString("ErrorReport", "prompt");
            writer.WriteElementString("WarningLevel", "4");
            writer.WriteEndElement();

            writer.WriteStartElement("PropertyGroup");
            writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ");
            writer.WriteElementString("DebugType", "pdbonly");
            writer.WriteElementString("Optimize", "true");
            writer.WriteElementString("OutputPath", "bin\\Release\\");
            writer.WriteElementString("DefineConstants", "TRACE");
            writer.WriteElementString("ErrorReport", "prompt");
            writer.WriteElementString("WarningLevel", "4");
            writer.WriteEndElement();
            #endregion

            #region References
            //TODO Figure these out, whether they're references, includes or what.
            writer.WriteStartElement("ItemGroup");
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Core");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Xml.Linq");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Data.DataSetExtensions");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "Microsoft.CSharp");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Data");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Xml");
            writer.WriteEndElement();
            writer.WriteEndElement();
            #endregion

            #region Project Classes?
            //TODO Are these the classes that will be compiled? Gotta check on that.
            writer.WriteStartElement("ItemGroup");
            writer.WriteStartElement("Compile");
            writer.WriteAttributeString("Include", comp.Name + ".cs");
            writer.WriteEndElement();

            //TODO Need to check on whether this stuff is affected by optional or not.
            foreach (EshuInterface io in comp.Specification.Interfaces)
            {
                writer.WriteStartElement("Compile");
                writer.WriteAttributeString("Include", io.Name + ".cs");
                writer.WriteEndElement();
            }

            writer.WriteStartElement("Compile");
            writer.WriteAttributeString("Include", "Properties\\AssemblyInfo.cs");
            writer.WriteEndElement();
            writer.WriteEndElement();
            #endregion

            #region Direct Refenreces?
            //TODO Check if these are the references to the classes from other projects or what. If not, well damn.
            if (comp.Sockets.Count != 0)
            {
                writer.WriteStartElement("ItemGroup");

                foreach (DanuSocket so in comp.Sockets)
                {
                    writer.WriteStartElement("ProjectReference");
                    DanuInterfaceObject io = so.InterfaceUsed;
                    writer.WriteAttributeString("Include", "..\\" + io.Eshu.ImplementingParents.First().Name + "\\" + io.Eshu.ImplementingParents.First().Name + ".csproj");
                    writer.WriteElementString("Project", io.Eshu.Parent.Parent.GUID);
                    writer.WriteElementString("Name", io.Eshu.Parent.Name);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
            #endregion

            //TODO Figure this out.
            writer.WriteStartElement("Import");
            writer.WriteAttributeString("Project", "$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
            writer.WriteEndElement();

            writer.WriteEndElement();

            writer.Close();
        }
Esempio n. 6
0
        /// <summary>
        /// Generates the so-called "main class" of a component.
        /// CURRENT: Unsure whether this method is quite what we need.
        /// </summary>
        /// <param name="comp">Component to which the class belongs.</param>
        public static void GenerateMainClass(DanuComponent comp)
        {
            #region OBSOLETE
            //string currentExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(currentExecutingAssemblyLocation);
            //System.Environment.CurrentDirectory = f.Directory.FullName;
            #endregion

            string filename = comp.Name + ".cs";

            /* TODO Tamper tamper tamper... Is there any certainty this file exists beforehand? And if there is, why not check?
             * Must examine.
             */
            //if(!File.Exists(filename))
            //    File.Create(filename).Close();

            // Initializing the class writer.
            TextWriter writer = new StreamWriter("./Source/" + comp.Name + "/" + filename);

            // "Using" section of the cs code.
            writer.WriteLine("using System;");
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("using System.Linq;");
            writer.WriteLine("using System.Text;");

            /* Adds "using" clauses for any sockets this component uses. Theoretically, it will allow this class to implement the
             * interfaces of which this is a specialization.
             */
            //TODO Must check on the logic of this part, as well as its usefulness with optional.
            foreach (DanuSocket so in comp.Sockets)
            {
                DanuInterfaceObject io = so.InterfaceUsed;
                writer.WriteLine("using " + io.Eshu.Parent.Name + ";");
            }

            //Hardcode
            writer.WriteLine("");

            writer.WriteLine("namespace " + comp.Name);
            writer.WriteLine("{");
            writer.WriteLine("\t// This is the core class of the " + comp.Name + " component.");
            writer.Write("\tpublic class " + comp.Name);

            // Analyses the class for specialization requirements and adds implementations to the interfaces in question.

            /* TODO I'm still unsure as to whether it is possible for a class to implement more than one interface through diagram
             * manipulation. It seems illogical to me, as that would create a dependency we do not really foresee.
             */
            if (comp.Sockets.Count != 0)
            {
                writer.Write(" : ");
                foreach (DanuSocket so in comp.Sockets)
                {
                    if (!so.Equals(comp.Sockets.First()))
                    {
                        writer.Write(", ");
                    }
                    writer.Write(so.InterfaceUsed.Name);
                }
                writer.Write("\n");
            }

            writer.WriteLine("\t{");

            // Declaration of the interface instances for use within the code. This bit is tricksy with optionals.
            foreach (DanuInterfaceObject io in comp.Interfaces)
            {
                writer.WriteLine("\t\t//REPLACE");
                writer.WriteLine("\t\tpublic " + io.Name + " instance" + io.Name + " = " + "null;");
                writer.WriteLine("\t\t//REPLACE");
            }

            writer.WriteLine("\t\t");

            //TODO Should anything go in here? How will we check if the programmer did the ifdefs correctly?
            if (comp.Sockets.Count == 0)
            {
                writer.WriteLine("\t\tpublic static void Main(string[] args)");
                writer.WriteLine("\t\t{");
                writer.WriteLine("\t\t\t");
                writer.WriteLine("\t\t}");
                writer.WriteLine("\t\t");
            }

            // Implementation of the methods, if this class implements interfaces.
            //TODO I wonder, if it has a return type, should we write some sort of auto-code to throw an exception or return null?
            foreach (DanuSocket so in comp.Sockets)
            {
                foreach (EshuMethod method in so.InterfaceUsed.Eshu.Signature)
                {
                    writer.Write("\t\t" + "public " + method.ReturnType + " " + method.Name + "(");
                    foreach (EshuProperty parameter in method.Parameters)
                    {
                        if (!parameter.Equals(method.Parameters.First()))
                        {
                            writer.Write(", ");
                        }
                        writer.Write(parameter.Type + " " + parameter.Name);
                    }
                    writer.Write(")\n");
                    writer.WriteLine("\t\t{");
                    writer.WriteLine("\t\t\t");
                    writer.WriteLine("\t\t}");
                    writer.WriteLine("\t\t");
                }
            }

            writer.WriteLine("\t}");
            writer.WriteLine("}");

            writer.Close();
        }
        public static void GenerateProjectFile(DanuComponent comp)
        {
            string    filename = comp.Name + ".csproj";
            XmlWriter writer   = XmlWriter.Create(filename);

            writer.WriteStartElement("Project");
            writer.WriteAttributeString("ToolsVersion", "4.0");
            writer.WriteAttributeString("DefaultTargets", "Build");
            writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");

            writer.WriteStartElement("PropertyGroup");

            writer.WriteStartElement("Configuration");
            writer.WriteAttributeString("Condition", " '$(Configuration)' == '' ");
            writer.WriteValue("Debug");
            writer.WriteEndElement();

            writer.WriteStartElement("Platform");
            writer.WriteAttributeString("Condition", " '$(Platform)' == '' ");
            writer.WriteValue("AnyCPU");
            writer.WriteEndElement();

            writer.WriteElementString("ProductVersion", "8.0.30703");
            writer.WriteElementString("SchemaVersion", "2.0");
            writer.WriteElementString("ProjectGuid", "{24279181-0EF3-4F9D-8810-7ECEB097158E}");
            writer.WriteElementString("OutputType", "Library");
            writer.WriteElementString("AppDesignerFolder", "Properties");
            writer.WriteElementString("RootNamespace", comp.Name);
            writer.WriteElementString("AssemblyName", comp.Name);
            writer.WriteElementString("TargetFrameworkVersion", "v4.0");
            writer.WriteElementString("FileAlignment", "512");

            writer.WriteEndElement();

            writer.WriteStartElement("PropertyGroup");
            writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ");
            writer.WriteElementString("DebugSymbols", "true");
            writer.WriteElementString("DebugType", "full");
            writer.WriteElementString("Optimize", "false");
            writer.WriteElementString("OutputPath", "bin\\Debug\\");
            writer.WriteElementString("DefineConstants", "DEBUG;TRACE");
            writer.WriteElementString("ErrorReport", "prompt");
            writer.WriteElementString("WarningLevel", "4");
            writer.WriteEndElement();

            writer.WriteStartElement("PropertyGroup");
            writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ");
            writer.WriteElementString("DebugType", "pdbonly");
            writer.WriteElementString("Optimize", "true");
            writer.WriteElementString("OutputPath", "bin\\Release\\");
            writer.WriteElementString("DefineConstants", "TRACE");
            writer.WriteElementString("ErrorReport", "prompt");
            writer.WriteElementString("WarningLevel", "4");
            writer.WriteEndElement();

            writer.WriteStartElement("ItemGroup");
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Core");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Xml.Linq");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Data.DataSetExtensions");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "Microsoft.CSharp");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Data");
            writer.WriteEndElement();
            writer.WriteStartElement("Reference");
            writer.WriteAttributeString("Include", "System.Xml");
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement("ItemGroup");
            writer.WriteStartElement("Compile");
            writer.WriteAttributeString("Include", comp.Name + ".cs");
            writer.WriteEndElement();
            writer.WriteStartElement("Compile");
            writer.WriteAttributeString("Include", "Properties\\AssemblyInfo.cs");
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement("Import");
            writer.WriteAttributeString("Project", "$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
            writer.WriteEndElement();

            writer.WriteEndElement();
        }