public void CreateOutputFile(OutputFolder rootFolder, string folder)
        {
            string text     = GetText(rootFolder, WriteOutputsXML);
            string filePath = folder.PathSlash(OutputsFileName);

            fileController.WriteAllText(filePath, text);
        }
        public void WriteOutputsXML(OutputFolder folder, XmlWriter writer)
        {
            Document doc = new Document(writer);

            using (doc.StartElement("Outputs"))
            {
                writer.WriteAttributeString("version", "1");

                WriteOutputFolderXML(folder, writer);
            }
        }
예제 #3
0
 public void RemoveFolder(OutputFolder folder)
 {
     for (int i = 0; i < Folders.Count; i++)
     {
         if (Folders[i].Id == folder.Id)
         {
             Folders.RemoveAt(i);
             break;
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Gets a list of all the sub-folders in the folder.
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private static List <OutputFolder> GetAllSubFolders(OutputFolder folder)
        {
            List <OutputFolder> folders = new List <OutputFolder>(folder.Folders.Count);

            foreach (OutputFolder subFolder in folder.Folders)
            {
                folders.Add(subFolder);
                folders.AddRange(GetAllSubFolders(subFolder));
            }
            return(folders);
        }
예제 #5
0
        /// <summary>
        /// Gets a list of all the files in the folder and its sub-folders.
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private static List <OutputFile> GetAllFilesInFolder(OutputFolder folder)
        {
            List <OutputFile> files = new List <OutputFile>(folder.Files.Count);

            foreach (OutputFile file in folder.Files)
            {
                files.Add(file);
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                files.AddRange(GetAllFilesInFolder(subFolder));
            }
            return(files);
        }
        private static void SaveToXmlFolder(OutputFolder folder, XmlElement parentNode)
        {
            XmlElement folderNode = null;

            if (folder.Name != "root")
            {
                folderNode = AppendNewXmlElement(parentNode, "folder", "");
                AppendNewAttribute(folderNode, "id", folder.Id);
                AppendNewAttribute(folderNode, "name", folder.Name);
                AppendNewAttribute(folderNode, "iteratortype", folder.IteratorType == null ? "" : folder.IteratorType.FullName);
            }
            else
            {
                folderNode = parentNode;
            }

            #region Process files
            foreach (OutputFile file in folder.Files)
            {
                XmlElement fileNode;

                if (file.FileType == OutputFileTypes.File)
                {
                    fileNode = AppendNewXmlElement(folderNode, "file", "");
                    AppendNewAttribute(fileNode, "name", file.Name);
                    AppendNewAttribute(fileNode, "staticfilename", file.StaticFileName);

                    string staticFileIteratorTypeName = file.StaticFileIterator == null ? "" : Utility.GetDemangledGenericTypeName(file.StaticFileIterator);
                    AppendNewAttribute(fileNode, "iteratorname", staticFileIteratorTypeName);
                    AppendNewAttribute(fileNode, "id", file.Id);
                }
                else
                {
                    fileNode = AppendNewXmlElement(folderNode, "script", "");
                    AppendNewAttribute(fileNode, "filename", file.Name);
                    AppendNewAttribute(fileNode, "scriptname", file.ScriptName);
                    AppendNewAttribute(fileNode, "iteratorname", file.IteratorTypes);
                    AppendNewAttribute(fileNode, "id", file.Id);
                }
            }
            #endregion

            #region Process sub-folders
            foreach (OutputFolder subFolder in folder.Folders)
            {
                SaveToXmlFolder(subFolder, folderNode);
            }
            #endregion
        }
        protected virtual OutputFolder ReadFolder(XmlNode node)
        {
            NodeProcessor proc = new NodeProcessor(node);
            string name = proc.Attributes.GetString("name");
            string id = proc.Attributes.GetString("id");
            string iteratorType = proc.Attributes.Exists("iterator") ? proc.Attributes.GetString("iterator") : null;

            OutputFolder folder = new OutputFolder(name, id);
            if (iteratorType != null)
            {
                folder.IteratorType = Deserialiser.GetTypeNamed(iteratorType);
            }

            // Process child folders.
            ProcessChildrenOfFolder(node, folder);

            return folder;
        }
        private void WriteOutputFolderXML(OutputFolder folder, XmlWriter writer)
        {
            writer.WriteStartElement("Folder");

            writer.WriteAttributeString("name", folder.Name);
            writer.WriteAttributeString("id", folder.Id);
            if (folder.IteratorType != null)
            {
                writer.WriteAttributeString("iterator", folder.IteratorType.FullName);
            }

            foreach (var subfolder in folder.Folders)
            {
                WriteOutputFolderXML(subfolder, writer);
            }

            foreach (var file in folder.Files)
            {
                WriteOutputFileXML(file, writer);
            }

            writer.WriteEndElement();
        }
예제 #9
0
        private static OutputFolder FindFolderByQualifiedName(string[] qualifiedNames, OutputFolder folder)
        {
            foreach (OutputFolder subFolder in folder.Folders)
            {
                if (subFolder.Name == qualifiedNames[0])
                {
                    if (qualifiedNames.Length == 1)
                    {
                        return subFolder;
                    }

                    string[] remainingFolders = new string[qualifiedNames.Length - 1];
                    Array.Copy(qualifiedNames, 1, remainingFolders, 0, qualifiedNames.Length - 1);
                    return FindFolderByQualifiedName(remainingFolders, subFolder);
                }
            }
            return null;
        }
예제 #10
0
        /// <summary>
        /// Gets a list of all the sub-folders in the folder.
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private static List<OutputFolder> GetAllSubFolders(OutputFolder folder)
        {
            List<OutputFolder> folders = new List<OutputFolder>(folder.Folders.Count);

            foreach (OutputFolder subFolder in folder.Folders)
            {
                folders.Add(subFolder);
                folders.AddRange(GetAllSubFolders(subFolder));
            }
            return folders;
        }
예제 #11
0
        /// <summary>
        /// Gets a list of all the files in the folder and its sub-folders.
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private static List<OutputFile> GetAllFilesInFolder(OutputFolder folder)
        {
            List<OutputFile> files = new List<OutputFile>(folder.Files.Count);

            foreach (OutputFile file in folder.Files)
            {
                files.Add(file);
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                files.AddRange(GetAllFilesInFolder(subFolder));
            }
            return files;
        }
예제 #12
0
        private static List<string> FileAndFolderNamesAreValid(OutputFolder folder)
        {
            var invalidFilenames = new List<string>();
            List<string> placeholders;

            foreach (OutputFile file in folder.Files)
            {
                placeholders = GetPlaceholderNames(file.Name);

                foreach (string placeholder in placeholders)
                {
                    // Check whether this reference is valid
                    if (placeholder.IndexOf("UserOptions.") == 0)
                    {
                        if (Project.Instance.FindUserOption(placeholder.Replace("UserOptions.", "")) == null)
                        {
                            invalidFilenames.Add(file.Name);
                        }
                    }
                }
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                placeholders = GetPlaceholderNames(subFolder.Name);

                foreach (string placeholder in placeholders)
                {
                    // Check whether this reference is valid
                    if (placeholder.IndexOf("UserOptions.") == 0)
                    {
                        if (Project.Instance.FindUserOption(placeholder.Replace("UserOptions.", "")) == null)
                        {
                            invalidFilenames.Add(subFolder.Name);
                        }
                    }
                }
                invalidFilenames.AddRange(FileAndFolderNamesAreValid(subFolder));
            }
            return invalidFilenames;
        }
예제 #13
0
        private static OutputFolder FindSubFolder(OutputFolder folder, string id)
        {
            foreach (OutputFolder subFolder in folder.Folders)
            {
                if (subFolder != null && subFolder.Id == id)
                {
                    return subFolder;
                }
                OutputFolder temp = FindSubFolder(subFolder, id);

                if (temp != null)
                {
                    return temp;
                }
            }
            return null;
        }
예제 #14
0
        private static bool UserOptionIsUsedInFilenames(UserOption userOption, OutputFolder folder)
        {
            foreach (OutputFile file in folder.Files)
            {
                if (file.Name.IndexOf("#UserOptions." + userOption.VariableName + "#") >= 0)
                {
                    return true;
                }
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                if (subFolder.Name.IndexOf("#UserOptions." + userOption.VariableName + "#") >= 0)
                {
                    return true;
                }

                if (UserOptionIsUsedInFilenames(userOption, subFolder))
                {
                    return true;
                }
            }
            return false;
        }
예제 #15
0
        private void CreateNewStaticFileAndAddItToTheTree(Node selectedNode, OutputFolder folder, string filename)
        {
            Project.Instance.AddIncludedFile(new IncludedFile(filename));
            OutputFile file = new OutputFile(Path.GetFileName(filename), OutputFileTypes.File, Path.GetFileName(filename), Guid.NewGuid().ToString());
            folder.AddFile(file);

            AddFileNode(selectedNode, file);
        }
예제 #16
0
 public void RemoveFolder(OutputFolder folder)
 {
     for (int i = 0; i < Folders.Count; i++)
     {
         if (Folders[i].Id == folder.Id)
         {
             Folders.RemoveAt(i);
             break;
         }
     }
 }
        private static void SaveToXmlFolder(OutputFolder folder, XmlElement parentNode)
        {
            XmlElement folderNode = null;

            if (folder.Name != "root")
            {
                folderNode = AppendNewXmlElement(parentNode, "folder", "");
                AppendNewAttribute(folderNode, "id", folder.Id);
                AppendNewAttribute(folderNode, "name", folder.Name);
                AppendNewAttribute(folderNode, "iteratortype", folder.IteratorType == null ? "" : folder.IteratorType.FullName);
            }
            else
            {
                folderNode = parentNode;
            }

            #region Process files
            foreach (OutputFile file in folder.Files)
            {
                XmlElement fileNode;

                if (file.FileType == OutputFileTypes.File)
                {
                    fileNode = AppendNewXmlElement(folderNode, "file", "");
                    AppendNewAttribute(fileNode, "name", file.Name);
                    AppendNewAttribute(fileNode, "staticfilename", file.StaticFileName);

                    string staticFileIteratorTypeName = file.StaticFileIterator == null ? "" : Utility.GetDemangledGenericTypeName(file.StaticFileIterator);
                    AppendNewAttribute(fileNode, "iteratorname", staticFileIteratorTypeName);
                    AppendNewAttribute(fileNode, "id", file.Id);
                }
                else
                {
                    fileNode = AppendNewXmlElement(folderNode, "script", "");
                    AppendNewAttribute(fileNode, "filename", file.Name);
                    AppendNewAttribute(fileNode, "scriptname", file.ScriptName);
                    AppendNewAttribute(fileNode, "iteratorname", file.IteratorTypes);
                    AppendNewAttribute(fileNode, "id", file.Id);
                }
            }
            #endregion

            #region Process sub-folders
            foreach (OutputFolder subFolder in folder.Folders)
            {
                SaveToXmlFolder(subFolder, folderNode);
            }
            #endregion
        }
예제 #18
0
 private Node AddFolderNode(Node parentNode, OutputFolder subFolder)
 {
     string iteratorName = subFolder.IteratorType == null ? "" : subFolder.IteratorType.FullName;
     Node newNode = new Node();
     newNode.Text = subFolder.Name;
     newNode.DragDropEnabled = true;
     newNode.Cells.Add(new Cell(""));
     newNode.Cells.Add(new Cell(iteratorName));
     newNode.ImageIndex = IMG_CLOSED_FOLDER;
     newNode.Tag = new TagInfo(subFolder.Id, TagInfo.FileTypes.Folder);
     parentNode.Nodes.Add(newNode);
     return newNode;
 }
        /// <summary>
        /// Populates the project from the xml definition file
        /// </summary>
        /// <param name="project"></param>
        /// <param name="FilePath">The file to read the project definition from.</param>
        public static void ReadFromXml(Project project, string FilePath)
        {
            project.ClearUserOptions();
            project.Functions.Clear();
            XPathDocument doc = null;
            string ext = Path.GetExtension(FilePath);

            if (ext == ".st")
            {
                doc = new XPathDocument(FilePath);
            }
            else if (ext == ".stz")
            {
                // Delete all files in the temp folder
                if (Directory.Exists(Controller.TempPath))
                {
                    Directory.Delete(Controller.TempPath, true);
                }
                Directory.CreateDirectory(Controller.TempPath);
                Utility.UnzipFile(FilePath, Controller.TempPath);

                string[] includedFiles = Directory.GetFiles(Controller.TempPath, "*");
                project.ClearIncludedFiles();

                foreach (string file in includedFiles)
                {
                    if (!Utility.StringsAreEqual(Path.GetFileName(file), "definition.xml", false))
                    {
                        project.AddIncludedFile(new IncludedFile(Path.GetFileName(file)));
                    }
                }
                string xmlPath = Path.Combine(Controller.TempPath, "definition.xml");

                // Backward compatability mpr
                StreamReader reader = new StreamReader(xmlPath);
                string definitionXml = reader.ReadToEnd();
                reader.Close();

                StreamWriter writer = File.CreateText(xmlPath);
                //writer.Write(Convert.Script.Replace(definitionXml));
                writer.Write(definitionXml);
                writer.Close();
                // mpr

                doc = new XPathDocument(xmlPath);
            }
            XPathNavigator rootNavigator = doc.CreateNavigator();
            XPathNavigator navigator = rootNavigator.SelectSingleNode(@"ROOT/config/project");
            XPathNavigator fileVersionNavigator = rootNavigator.SelectSingleNode(@"ROOT/@fileversion");
            int fileVersion = fileVersionNavigator != null ? fileVersionNavigator.ValueAsInt : 0;
            List<string> missingTypesMessages = new List<string>();

            #region Project details

            project.ProjectName = navigator.SelectSingleNode("name").Value;
            project.ProjectDescription = navigator.SelectSingleNode("description").Value;
            ReadXmlReferencedFiles(project, FilePath, rootNavigator);
            string compileFolderRelPath = navigator.SelectSingleNode("compilefile") == null ? "" : navigator.SelectSingleNode("compilefile").Value;
            compileFolderRelPath = project.GetFullPath(compileFolderRelPath);
            project.DebugProjectFile = navigator.SelectSingleNode("debugfile") == null ? "" : navigator.SelectSingleNode("debugfile").Value;
            project.TestGenerateDirectory = navigator.SelectSingleNode("testgeneratedirectory") == null ? "" : navigator.SelectSingleNode("testgeneratedirectory").Value;

            if (Directory.Exists(compileFolderRelPath))
            {
                compileFolderRelPath = Path.GetDirectoryName(compileFolderRelPath);
            }
            else
            {
                compileFolderRelPath = Path.GetDirectoryName(project.ProjectFileName);
            }
            project.CompileFolderName = compileFolderRelPath;
            //CompileFolderName = GetFullPath(CompileFolderName);
            project.Version = navigator.SelectSingleNode("version") == null ? "0.0.0" : navigator.SelectSingleNode("version").Value;

            project.Namespaces.Clear();
            project.Namespaces.AddRange(rootNavigator.SelectSingleNode(@"ROOT/namespaces").Value.Split(','))
                ;
            #endregion

            //#region Default Value Functions
            //m_defaultValueFunctions = new List<DefaultValueFunction>();

            //foreach (XPathNavigator subNode in navigator.Select("defaultvaluefunctions/defaultvaluefunction"))
            //{
            //    ReadXmlDefaultValueFunctionNode(missingTypesMessages, subNode);
            //}
            //#endregion

            #region Functions
            foreach (XPathNavigator funcNode in rootNavigator.Select("/ROOT/function"))
            {
                ReadXmlFunctionNode(project, missingTypesMessages, funcNode);
            }
            project.SortFunctions();
            #endregion

            #region Outputs
            XPathNavigator outputNode = navigator.SelectSingleNode("rootoutput/rootfolder");
            project.RootOutput = new OutputFolder("ROOT", Guid.NewGuid().ToString());
            OutputFolder rootFolder = new OutputFolder("root", Guid.NewGuid().ToString());
            project.RootOutput.Folders.Add(rootFolder);
            project.ReadXmlFolderNode(ref rootFolder, outputNode);
            #endregion

            #region User options

            foreach (XPathNavigator subNode in navigator.Select("options/option"))
            {
                ReadXmlUserOptionNode(project, missingTypesMessages, subNode);
            }

            project.SortUserOptions();

            #endregion

            project.SetupDynamicfilesAndFolders();

            #region Clean up process
            // Remove DefaultValueFunctions which have no matching Function. This was required
            // when the implementation for DefaultValueFunctions was changed.
            for (int i = project.DefaultValueFunctions.Count - 1; i >= 0; i--)
            {
                if (project.FindFunction(project.DefaultValueFunctions[i].FunctionName, project.DefaultValueFunctions[i].ParameterTypes.ToList()) == null)
                {
                    project.DefaultValueFunctions.RemoveAt(i);
                }
            }
            if (fileVersion == 1)
            {
                CleanupVersion1Projects(project);
            }
            if (missingTypesMessages.Count > 0)
            {
                StringBuilder sb = new StringBuilder();

                foreach (string message in missingTypesMessages)
                {
                    sb.AppendLine("* " + message);
                }
                MessageBox.Show(Controller.Instance.MainForm, "A number of types could not be found. This is probably because one of the \nreferenced files used by this template has changed. Make a note of the changes \nand either remove them from the project or fix them:\n\n" + sb, "Unknown Types", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            #endregion
        }
예제 #20
0
        public void Clear()
        {
            if (Directory.Exists(Controller.TempPath))
            {
                try
                {
                    Directory.Delete(Controller.TempPath, true);
                }
                catch
                {
                    // Do nothing - usually some dev process is accessing the directory
                }
            }
            SharedData.ClearAssemblySearchPaths();
            DefaultValueFunctions.Clear();
            Settings.Default.CodeFile = "";
            CompileFolderName = "";
            Functions.Clear();
            ClearIncludedFiles();
            IsDirty = false;
            Namespaces.Clear();
            Parameters = new ParamInfo[0];
            ProjectFileName = "";
            ProjectXmlConfig = "";
            m_references.Clear();
            ScriptFunctionsFile = "";
            TargetFile = "";
            TemplateFile = "";
            TemplateNamespace = "";
            OutputNames.Clear();
            RootOutput = new OutputFolder("ROOT");
            Constants = new Constant[0];
            m_userOptions.Clear();
            DebugProjectFile = "";
            Actions = new BaseAction[0];
            m_referencedAssemblies.Clear();
            ApiExtensionMethods.Clear();

            TriggerProjectChangedEvent(true);
        }
예제 #21
0
 public void AddTopLevelFolder(OutputFolder folder)
 {
     RootOutput.Folders.Add(folder);
 }
예제 #22
0
        private static List<OutputFile> FindFilesUsingFunctionInFolder(OutputFolder folder, string functionName)
        {
            List<OutputFile> matchingFiles = new List<OutputFile>();

            foreach (OutputFile file in folder.Files)
            {
                if (file != null && file.ScriptName == functionName)
                {
                    matchingFiles.Add(file);
                }
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                matchingFiles.AddRange(FindFilesUsingFunctionInFolder(subFolder, functionName));
            }
            return matchingFiles;
        }
예제 #23
0
        private static OutputFile FindFileInFolder(OutputFolder folder, string id)
        {
            foreach (OutputFile file in folder.Files)
            {
                if (file != null && file.Id == id)
                {
                    return file;
                }
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                OutputFile file = FindFileInFolder(subFolder, id);

                if (file != null)
                {
                    return file;
                }
            }
            return null;
        }
예제 #24
0
        public void AddNewFolder()
        {
            try
            {
                if (treeFiles.SelectedNodes.Count == 0)
                {
                    MessageBox.Show(this, "Select a folder to add this file to first.", "No Folder Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                else if (treeFiles.SelectedNodes.Count > 1)
                {
                    throw new Exception("Only one node should be selected.");
                }
                Cursor = Cursors.WaitCursor;
                Refresh();
                Node selectedNode = treeFiles.SelectedNodes[0];
                TagInfo ti = (TagInfo)selectedNode.Tag;

                if (ti.FileType != TagInfo.FileTypes.Folder)
                {
                    MessageBox.Show(this, "A folder cannot be added as a child of a file. Select a parent folder", "Invalid Node Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                Wizards.frmOutputFileWizard.FileType = Wizards.frmOutputFileWizard.FileTypes.Folder;
                Wizards.frmOutputFileWizard.IterationType = null;
                Wizards.frmOutputFileWizard form = new Wizards.frmOutputFileWizard();

                if (form.ShowDialog() == DialogResult.OK)
                {
                    var fileName = Wizards.frmOutputFileWizard.FileName;
                    var iteratorType = Wizards.frmOutputFileWizard.IterationType;

                    OutputFolder newFolder = new OutputFolder(fileName, Guid.NewGuid().ToString());

                    CreateNewFolderAndAddToTree(selectedNode, newFolder, iteratorType);
                }
            }
            finally
            {
                Controller.Instance.MainForm.Activate();
                Cursor = Cursors.Default;
            }
        }
예제 #25
0
 private static void RenameFunctionInOuputFolder(OutputFolder outputFolder, string oldName, string newName)
 {
     foreach (OutputFile outputFile in outputFolder.Files)
     {
         if (outputFile.ScriptName == oldName)
         {
             outputFile.ScriptName = newName;
         }
     }
     foreach (OutputFolder subFolder in outputFolder.Folders)
     {
         RenameFunctionInOuputFolder(subFolder, oldName, newName);
     }
 }
예제 #26
0
        private void CreateNewFolderAndAddToTree(Node selectedNode, OutputFolder newFolder, Type iteratorType)
        {
            newFolder.IteratorType = iteratorType;
            string id = ((TagInfo)selectedNode.Tag).Id;
            OutputFolder parentFolder = Project.Instance.FindFolder(id);

            if (parentFolder != null)
            {
                parentFolder.Folders.Add(newFolder);
                Project.Instance.IsDirty = true;
                Node newFolderNode = AddFolderNode(selectedNode, newFolder);
                selectedNode.Expanded = true;
                treeFiles.SelectedNode = newFolderNode;
            }
            else
            {
                throw new Exception("No parent folder found.");
            }
        }
예제 #27
0
        private void ProcessChildrenOfFolder(XmlNode node, OutputFolder folder)
        {
            var folderNodes = node.SelectNodes("Folder");
            if (folderNodes != null)
            {
                foreach (XmlNode child in folderNodes)
                {
                    OutputFolder childFolder = ReadFolder(child);
                    folder.Folders.Add(childFolder);
                }
            }

            // Process child files.
            var fileNodes = node.SelectNodes("StaticFile");
            if (fileNodes != null)
            {
                foreach (XmlNode child in fileNodes)
                {
                    OutputFile childFile = ReadStaticFile(child);
                    folder.Files.Add(childFile);
                }
            }

            fileNodes = node.SelectNodes("ScriptFile");
            if (fileNodes != null)
            {
                foreach (XmlNode child in fileNodes)
                {
                    OutputFile childFile = ReadScriptFile(child);
                    folder.Files.Add(childFile);
                }
            }
        }
예제 #28
0
        private void ProcessFolder(OutputFolder folder, ref Node treenode)
        {
            if (treenode == null && Slyce.Common.Utility.StringsAreEqual(folder.Name, "root", false))
            {
                treenode = new Node();
                treenode.Text = "ROOT";
                treenode.Cells.Add(new Cell(""));
                treenode.Cells.Add(new Cell(""));
                treenode.ImageIndex = IMG_ROOT;
                treenode.Tag = new TagInfo(folder.Id, TagInfo.FileTypes.Folder);
                treeFiles.Nodes.Add(treenode);
            }
            else if (folder.Files.Count > 0 ||
                 folder.Folders.Count > 0 &&
                 treenode.ImageIndex != IMG_ROOT)
            {
                treenode.ImageIndex = IMG_OPEN_FOLDER;
            }
            foreach (OutputFolder subFolder in folder.Folders)
            {
                // TODO: This check for a root folder can be removed once all templates have been saved without
                // the extra root folders. Remove anytime after September 2006.
                if (Slyce.Common.Utility.StringsAreEqual(subFolder.Name, "root", false)) { continue; }

                Node newNode = AddFolderNode(treenode, subFolder);
                ProcessFolder(subFolder, ref newNode);
            }
            foreach (OutputFile file in folder.Files)
            {
                AddFileNode(treenode, file);
            }
        }
        /// <summary>
        /// Populates the project from the xml definition file
        /// </summary>
        /// <param name="project"></param>
        /// <param name="FilePath">The file to read the project definition from.</param>
        public static void ReadFromXml(Project project, string FilePath)
        {
            project.ClearUserOptions();
            project.Functions.Clear();
            XPathDocument doc = null;
            string        ext = Path.GetExtension(FilePath);

            if (ext == ".st")
            {
                doc = new XPathDocument(FilePath);
            }
            else if (ext == ".stz")
            {
                // Delete all files in the temp folder
                if (Directory.Exists(Controller.TempPath))
                {
                    Directory.Delete(Controller.TempPath, true);
                }
                Directory.CreateDirectory(Controller.TempPath);
                Utility.UnzipFile(FilePath, Controller.TempPath);

                string[] includedFiles = Directory.GetFiles(Controller.TempPath, "*");
                project.ClearIncludedFiles();

                foreach (string file in includedFiles)
                {
                    if (!Utility.StringsAreEqual(Path.GetFileName(file), "definition.xml", false))
                    {
                        project.AddIncludedFile(new IncludedFile(Path.GetFileName(file)));
                    }
                }
                string xmlPath = Path.Combine(Controller.TempPath, "definition.xml");

                // Backward compatability mpr
                StreamReader reader        = new StreamReader(xmlPath);
                string       definitionXml = reader.ReadToEnd();
                reader.Close();

                StreamWriter writer = File.CreateText(xmlPath);
                //writer.Write(Convert.Script.Replace(definitionXml));
                writer.Write(definitionXml);
                writer.Close();
                // mpr

                doc = new XPathDocument(xmlPath);
            }
            XPathNavigator rootNavigator        = doc.CreateNavigator();
            XPathNavigator navigator            = rootNavigator.SelectSingleNode(@"ROOT/config/project");
            XPathNavigator fileVersionNavigator = rootNavigator.SelectSingleNode(@"ROOT/@fileversion");
            int            fileVersion          = fileVersionNavigator != null ? fileVersionNavigator.ValueAsInt : 0;
            List <string>  missingTypesMessages = new List <string>();

            #region Project details

            project.ProjectName        = navigator.SelectSingleNode("name").Value;
            project.ProjectDescription = navigator.SelectSingleNode("description").Value;
            ReadXmlReferencedFiles(project, FilePath, rootNavigator);
            string compileFolderRelPath = navigator.SelectSingleNode("compilefile") == null ? "" : navigator.SelectSingleNode("compilefile").Value;
            compileFolderRelPath          = project.GetFullPath(compileFolderRelPath);
            project.DebugProjectFile      = navigator.SelectSingleNode("debugfile") == null ? "" : navigator.SelectSingleNode("debugfile").Value;
            project.TestGenerateDirectory = navigator.SelectSingleNode("testgeneratedirectory") == null ? "" : navigator.SelectSingleNode("testgeneratedirectory").Value;

            if (Directory.Exists(compileFolderRelPath))
            {
                compileFolderRelPath = Path.GetDirectoryName(compileFolderRelPath);
            }
            else
            {
                compileFolderRelPath = Path.GetDirectoryName(project.ProjectFileName);
            }
            project.CompileFolderName = compileFolderRelPath;
            //CompileFolderName = GetFullPath(CompileFolderName);
            project.Version = navigator.SelectSingleNode("version") == null ? "0.0.0" : navigator.SelectSingleNode("version").Value;

            project.Namespaces.Clear();
            project.Namespaces.AddRange(rootNavigator.SelectSingleNode(@"ROOT/namespaces").Value.Split(','))
            ;
            #endregion

            //#region Default Value Functions
            //m_defaultValueFunctions = new List<DefaultValueFunction>();

            //foreach (XPathNavigator subNode in navigator.Select("defaultvaluefunctions/defaultvaluefunction"))
            //{
            //    ReadXmlDefaultValueFunctionNode(missingTypesMessages, subNode);
            //}
            //#endregion

            #region Functions
            foreach (XPathNavigator funcNode in rootNavigator.Select("/ROOT/function"))
            {
                ReadXmlFunctionNode(project, missingTypesMessages, funcNode);
            }
            project.SortFunctions();
            #endregion

            #region Outputs
            XPathNavigator outputNode = navigator.SelectSingleNode("rootoutput/rootfolder");
            project.RootOutput = new OutputFolder("ROOT", Guid.NewGuid().ToString());
            OutputFolder rootFolder = new OutputFolder("root", Guid.NewGuid().ToString());
            project.RootOutput.Folders.Add(rootFolder);
            project.ReadXmlFolderNode(ref rootFolder, outputNode);
            #endregion

            #region User options

            foreach (XPathNavigator subNode in navigator.Select("options/option"))
            {
                ReadXmlUserOptionNode(project, missingTypesMessages, subNode);
            }

            project.SortUserOptions();

            #endregion

            project.SetupDynamicfilesAndFolders();

            #region Clean up process
            // Remove DefaultValueFunctions which have no matching Function. This was required
            // when the implementation for DefaultValueFunctions was changed.
            for (int i = project.DefaultValueFunctions.Count - 1; i >= 0; i--)
            {
                if (project.FindFunction(project.DefaultValueFunctions[i].FunctionName, project.DefaultValueFunctions[i].ParameterTypes.ToList()) == null)
                {
                    project.DefaultValueFunctions.RemoveAt(i);
                }
            }
            if (fileVersion == 1)
            {
                CleanupVersion1Projects(project);
            }
            if (missingTypesMessages.Count > 0)
            {
                StringBuilder sb = new StringBuilder();

                foreach (string message in missingTypesMessages)
                {
                    sb.AppendLine("* " + message);
                }
                MessageBox.Show(Controller.Instance.MainForm, "A number of types could not be found. This is probably because one of the \nreferenced files used by this template has changed. Make a note of the changes \nand either remove them from the project or fix them:\n\n" + sb, "Unknown Types", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            #endregion
        }
예제 #30
0
        /// <summary>
        /// Removes a folder from the collection.
        /// </summary>
        /// <param name="folderToRemove"></param>
        /// <param name="parentFolder"></param>
        /// <returns>True is folder was found and removed, false otherwise.</returns>
        public bool RemoveFolder(OutputFolder folderToRemove, OutputFolder parentFolder)
        {
            for (int i = 0; i < parentFolder.Folders.Count; i++)
            {
                OutputFolder folder = parentFolder.Folders[i];

                if (folder == folderToRemove)
                {
                    parentFolder.RemoveFolder(folder);
                    IsDirty = true;
                    return true;
                }
                if (RemoveFolder(folderToRemove, folder))
                {
                    return true;
                }
            }
            return false;
        }
예제 #31
0
        internal void ReadXmlFolderNode(ref OutputFolder folder, XPathNavigator folderNode)
        {
            #region Add Files
            XPathNodeIterator fileNodes = folderNode.Select("file");

            foreach (XPathNavigator fileNode in fileNodes)
            {
                XPathNavigator idNode = fileNode.SelectSingleNode("@id");
                string id = idNode == null ? Guid.NewGuid().ToString() : idNode.Value;
                OutputFile file = new OutputFile(fileNode.SelectSingleNode("@name").Value, OutputFileTypes.File, "", id);

                file.StaticFileName = fileNode.SelectSingleNode("@staticfilename") == null ? file.Name : fileNode.SelectSingleNode("@staticfilename").Value;
                file.StaticFileIterator = null;

                if (fileNode.SelectSingleNode("@iteratorname") != null && !string.IsNullOrEmpty(fileNode.SelectSingleNode("@iteratorname").Value))
                {
                    file.StaticFileIterator = GetTypeFromReferencedAssemblies(fileNode.SelectSingleNode("@iteratorname").Value, true);
                }
                folder.Files.Add(file);
            }
            #endregion

            #region Add Script Files
            fileNodes = folderNode.Select("script");

            foreach (XPathNavigator fileNode in fileNodes)
            {
                XPathNavigator idNode = fileNode.SelectSingleNode("@id");
                string id = idNode == null ? Guid.NewGuid().ToString() : idNode.Value;
                OutputFile file = new OutputFile(fileNode.SelectSingleNode("@filename").Value, OutputFileTypes.Script, fileNode.SelectSingleNode("@scriptname").Value, id);
                folder.Files.Add(file);
            }
            #endregion

            #region Process folders
            XPathNodeIterator subFolderNodes = folderNode.Select("folder");

            foreach (XPathNavigator subFolderNode in subFolderNodes)
            {
                string id = subFolderNode.SelectSingleNode("@id") == null ? Guid.NewGuid().ToString() : subFolderNode.SelectSingleNode("@id").Value;
                OutputFolder subFolder = new OutputFolder(subFolderNode.SelectSingleNode("@name").Value, id);
                string iteratorTypeName = subFolderNode.SelectSingleNode("@iteratortype") != null ? subFolderNode.SelectSingleNode("@iteratortype").Value : "";

                if (!string.IsNullOrEmpty(iteratorTypeName))
                {
                    Type iteratorType = Instance.GetTypeFromReferencedAssemblies(iteratorTypeName, false);

                    if (iteratorType == null)
                    {
                        throw new InvalidDataException("Data type of the iterator for folder [" + subFolderNode.Name + "] cannot be found in the referenced assemblies: " + iteratorTypeName);
                    }
                    subFolder.IteratorType = iteratorType;
                }

                folder.Folders.Add(subFolder);
                ReadXmlFolderNode(ref subFolder, subFolderNode);
            }
            #endregion
        }
 public void SetUp()
 {
     fileController = MockRepository.GenerateMock<IFileController>();
     rootFolder = new OutputFolder("ROOT", "1");
 }
예제 #33
0
        //public void RemoveUserOption(string variableName)
        //{
        //    ArrayList tempArray = new ArrayList(UserOptions.Count);
        //    bool functionsRemoved = false;
        //    for (int i = 0; i < UserOptions.Count; i++)
        //    {
        //        if (UserOptions[i].VariableName != variableName)
        //        {
        //            tempArray.Add(UserOptions[i]);
        //        }
        //        else
        //        {
        //            DeleteFunction(UserOptions[i].DefaultValue, false);
        //            DeleteFunction(UserOptions[i].DisplayToUserFunction, false);
        //            DeleteFunction(UserOptions[i].ValidatorFunction, false);
        //            IsDirty = true;
        //            functionsRemoved = true;
        //        }
        //    }
        //    m_userOptions = new List<UserOption>((UserOption[])tempArray.ToArray(typeof(UserOption)));
        //    if (functionsRemoved)
        //    {
        //        Controller.Instance.MainForm.PopulateFunctionList();
        //    }
        //}
        /// <summary>
        /// Removes a folder from the collection.
        /// </summary>
        /// <param name="folderToRemove"></param>
        /// <returns>True if the folder was found and removed, false otherwise.</returns>
        public bool RemoveFolder(OutputFolder folderToRemove)
        {
            for (int i = 0; i < RootOutput.Folders.Count; i++)
            {
                OutputFolder folder = RootOutput.Folders[i];

                if (folder == folderToRemove)
                {
                    RootOutput.RemoveFolder(folderToRemove);
                    IsDirty = true;
                    return true;
                }
                if (RemoveFolder(folderToRemove, folder))
                {
                    return true;
                }
            }
            return false;
        }