public void ImportStructure()
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "PlugSPL Component Metadata (*.plugcm) | *.plugcm";

            if (open.ShowDialog() != true)
            {
                return;
            }

            //change directory. must to be fixed.
            string oldLocation   = Environment.CurrentDirectory;
            string lowerFileName = open.FileName.Split('\\').Last().Split('.').First();
            string appPath       = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Environment.CurrentDirectory = System.IO.Path.Combine(appPath, "./Projects/" + lowerFileName);

            StreamReader reader = new StreamReader(open.FileName);

            this.textBoxRed.Text = open.FileName;
            XmlSerializer serializer = new XmlSerializer(typeof(PlugSpl.DataStructs.ProductConfigurator.DanuProductConfigurator));

            danu = (PlugSpl.DataStructs.ProductConfigurator.DanuProductConfigurator)serializer.Deserialize(reader);

            //change current dir to old location
            Environment.CurrentDirectory = oldLocation;
            path = oldLocation;
        }
        /// <summary>
        /// Load a danu.xml file.
        /// </summary>
        private void buttonOpenConfig_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter = "PlugSPL Component Metadata (*.plugcm)|*.plugcm";

                if (dialog.ShowDialog() == true)
                {
                    using (TextReader reader = new StreamReader(dialog.FileName))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(DanuProductConfigurator));

                        string projectLowerDirectory = dialog.FileName.Split('\\').Last().Split('.').First();
                        string oldDirectory          = Environment.CurrentDirectory;
                        Environment.CurrentDirectory = oldDirectory + "/Projects/" + projectLowerDirectory;

                        DanuProductConfigurator productConfigurator = null;
                        try
                        {
                            productConfigurator = (DanuProductConfigurator)serializer.Deserialize(reader);
                        }
                        catch (Exception ex)
                        {
                            productConfigurator = null;
                            MessageBox.Show(ex.Message, "PlugSPL Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                        if (productConfigurator != null)
                        {
                            this.danu = productConfigurator;
                            this.loadDanuIntoGui();
                        }
                        else
                        {
                            this.textBlockStatus.Text = "Unable to parser [" + dialog.FileName + "] file.";
                        }

                        reader.Close();

                        Environment.CurrentDirectory = oldDirectory;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "PlugSPL Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#3
0
        public void GenerateCode(DanuProductConfigurator danu)
        {
            string projectLowerName = danu.Root.Name;


            string currentLocation = Assembly.GetExecutingAssembly().Location;

            foreach (DanuComponent comp in danu.Components)
            {
                Directory.CreateDirectory("./Source/" + comp.Name);
                GenerateMainClass(comp);
                GenerateProjectFile(comp);
                Directory.CreateDirectory("./Source/" + comp.Name + "/Properties");
                GenerateAssemblyInfo(comp);
                foreach (DanuInterfaceObject io in comp.Interfaces)
                {
                    GenerateInterface(io, "./Source/" + comp.Name + "/", comp);
                }
            }
        }
        /// <summary>
        /// Import bragi file and builds an Danu struct with it.
        /// </summary>
        private void buttonLoadDanu_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "UML Component Diagram / Smarty (*.plugcd)|*.plugcd";

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            ComponentDiagramBragi plugcd     = null;
            XmlSerializer         serializer = new XmlSerializer(typeof(ComponentDiagramBragi));

            using (TextReader reader = new StreamReader(dialog.FileName))
            {
                try
                {
                    plugcd = (ComponentDiagramBragi)serializer.Deserialize(reader);
                }
                catch (Exception)
                {
                    MessageBox.Show("Wrong data format. Given file has no valid structure inside it.",
                                    "PlugSPL Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            if (plugcd == null)
            {
                return;
            }

            lastPlugCD = dialog.FileName;
            lastPlugCD = lastPlugCD.Split('\\').Last().Split('.')[0];

            this.danu = new DanuProductConfigurator(plugcd);
            this.loadDanuIntoGui();
        }
示例#5
0
        /// <summary>
        /// Generates the project file (.csproj) for compiling the final product.
        /// CURRENT: This thing's a mess. It probably shouldn't even exist. Gotta check on it.
        /// </summary>
        /// <param name="pool">The entire pool with every single component. This thingamajig causes trouble.</param>
        /// <param name="pathname">The path to the config file, which is a glorified txt.</param>
        /// <param name="extraFiles">A list containing extra files to be added to the project file</param>
        /// <returns>No idea why it has to return anything...</returns>
        public static List <DanuComponent> GenerateProductProject(DanuProductConfigurator pool, string pathname, List <string> extraFiles)
        {
            #region OBSOLETE
            //string currentExecutingAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(currentExecutingAssemblyLocation);
            //System.Environment.CurrentDirectory = f.Directory.FullName;
            #endregion

            // List of components that have been chosen in the config.
            List <DanuComponent> chosenOnes = new List <DanuComponent>();
            // Frankenstein list of classes to be compiled.
            List <string> classNames = new List <string>();
            // Frankenstein list of references for the executable project.
            List <string> referenceNames = new List <string>();
            //TODO No idea.
            List <string> embeddedResource = new List <string>();
            // Reader for the config.
            XmlTextReader reader = new XmlTextReader(pathname);

            #region Finding correct components
            // Fills in the chosenOnes list with the correct components.

            /* TODO IMPORTANT: This does NOT remove the connections with unused interfaces which MAY (probably do) cause the entire
             * project to be compiled every single time. Which would be bad.
             */
            while (reader.Read())
            {
                if (!reader.Name.Equals("Component") && !reader.Name.Equals("Root"))
                {
                    chosenOnes.Add(pool.GetComponent(reader.ReadContentAsString()));
                }
            }
            #endregion

            #region Reading Component .csproj
            // Reader for each component's .csproj.
            //TODO This here code reeks some'in foul. I gotta see if this can't be eliminated.
            XmlReader compReader;

            /* TODO This entire thing is used to read the .csproj of a single component, going through all of the chosen components
             * and picking out their references, includes and all that, in order to create a gigantic Frankenstein csproj. This thing
             * is monstruous and hurts my eyes, as well as the pride of humanity.
             */
            foreach (DanuComponent comp in chosenOnes)
            {
                compReader = new XmlTextReader("./Source/" + comp.Name + "/" + comp.Name + ".csproj");

                while (compReader.Read())
                {
                    if (compReader.Name.Equals("Reference") && !referenceNames.Contains(compReader["Include"]))
                    {
                        if (compReader["Include"].Contains(".cs"))
                        {
                            referenceNames.Add(comp.Name + "\\" + compReader["Include"]);
                        }
                        else
                        {
                            referenceNames.Add(compReader["Include"]);
                        }
                    }
                    if (compReader.Name.Equals("Compile") && !compReader["Include"].Equals("Properties\\AssemblyInfo.cs"))
                    {
                        if (compReader["Include"].Contains(".cs"))
                        {
                            classNames.Add(comp.Name + "\\" + compReader["Include"]);
                        }
                        else
                        {
                            classNames.Add(compReader["Include"]);
                        }
                    }
                    if (compReader.Name.Equals("EmbeddedResource") && !compReader["Include"].Equals("Properties\\AssemblyInfo.cs"))
                    {
                        //TODO Why has this been tampered with? Must examine more carefully if Frankenstein.csproj continues to exist.
                        //if (compReader["Include"].Contains(".cs"))
                        //{
                        embeddedResource.Add(comp.Name + "\\" + compReader["Include"]);
                        //}
                        //else
                        //{
                        //    classNames.Add(compReader["Include"]);
                        //}
                    }
                }

                compReader.Close();
            }

            //adding extraFiles to theirs right place
            foreach (string ext in extraFiles)
            {
                if (!ext.Contains("AssemblyInfo.cs"))
                {
                    if (ext.EndsWith(".cs"))
                    {
                        if (classNames.FindIndex(x => x.Equals(ext, StringComparison.OrdinalIgnoreCase)) <= -1)
                        {
                            classNames.Add(ext);
                            System.Diagnostics.Debug.WriteLine("cs " + ext);
                        }
                    }
                    else //if (ext.EndsWith(".xml"))
                    {
                        if (embeddedResource.FindIndex(x => x.Equals(ext, StringComparison.OrdinalIgnoreCase)) <= -1)
                        {
                            embeddedResource.Add(ext);
                            System.Diagnostics.Debug.WriteLine("etc " + ext);
                        }
                    }
                }
            }
            #endregion

            // Beginning of Frankenstein.csproj writing.
            string filename = "PlugSPLCompileProject.csproj";

            /* TODO Check on whether this repository is really necessary. It gets filled in with everything that'll be used,
             * basically creating a Frankenstein folder for Frankenstein.csproj.
             */
            Directory.CreateDirectory("Repository");
            XmlWriter writer = XmlWriter.Create("./Repository/" + 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");

            // Creates a new GUID, since Frankie doesn't really have a formal structure, it's just a malformed beast.
            writer.WriteElementString("ProjectGuid", Guid.NewGuid().ToString());

            /* TODO IMPORTANT!!! This here be the line that decides the OutputType of the FINAL PRODUCT. It MUST be modified in order
             * to work with ANYTHING other than a Console Application.
             */
            writer.WriteElementString("OutputType", "Exe");

            #region Hardcoded
            writer.WriteElementString("AppDesignerFolder", "Properties");
            writer.WriteElementString("RootNamespace", pool.Root.Specification.Classes.First().Name);
            writer.WriteElementString("AssemblyName", pool.Root.Specification.Classes.First().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. Very important here, being that this is currently our final output, our "poster boy".
             */
            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
            // Frankie's refs being written.
            //TODO Gotta double-check this for consistency and duplicity.
            writer.WriteStartElement("ItemGroup");
            foreach (string reference in referenceNames)
            {
                writer.WriteStartElement("Reference");
                writer.WriteAttributeString("Include", reference);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            #endregion

            #region Project Classes?

            /* All of the classes in every project chosen, and possibly a few more if I did something wrong in the above code.
             * Which is likely.
             */
            writer.WriteStartElement("ItemGroup");
            foreach (string className in classNames)
            {
                writer.WriteStartElement("Compile");
                writer.WriteAttributeString("Include", className);
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            #endregion

            #region Resources?
            //TODO Figure this whole region out. I have fairly little idea what this is, given that we haven't really worked with it.
            writer.WriteStartElement("ItemGroup");
            foreach (string resource in embeddedResource)
            {
                writer.WriteStartElement("EmbeddedResource");
                writer.WriteAttributeString("Include", resource);
                writer.WriteEndElement();
            }
            //TODO So much tampering with my code without explicit justification. Gonna start whipping people 'round here.

            /*  <ItemGroup>
             *  <EmbeddedResource Include="Templates\globals.h" />
             *  <EmbeddedResource Include="Templates\vuser_end.c" />
             *  <EmbeddedResource Include="Templates\vuser_init.c" />
             * </ItemGroup>
             * <ItemGroup>
             *  <EmbeddedResource Include="Templates\default.cfg" />
             *  <EmbeddedResource Include="Templates\default.usp" />
             *  <EmbeddedResource Include="Templates\scenarioTemplate.lrs" />
             *  <EmbeddedResource Include="Templates\script.usr" />
             * </ItemGroup>*/
            writer.WriteEndElement();
            #endregion

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

            writer.Close();

            return(chosenOnes);
        }