public void SetUp()
 {
     fileController = MockRepository.GenerateMock<IFileController>();
     outputFile = new OutputFile("ROOT", OutputFileTypes.File, "aaaa", "1") { StaticFileIterator = typeof(string)};
 }
 public void SetUp()
 {
     fileController = MockRepository.GenerateMock<IFileController>();
     outputFile = new OutputFile("ROOT", OutputFileTypes.Script, "aaaa", "1");
 }
Esempio n. 3
0
 public void RemoveFile(OutputFile file)
 {
     for (int i = 0; i < Files.Count; i++)
     {
         if (Files[i].Id == file.Id)
         {
             Files.RemoveAt(i);
             break;
         }
     }
 }
 public void SetUp()
 {
     fileController = MockRepository.GenerateMock<IFileController>();
     outputFile = new OutputFile("ROOT", OutputFileTypes.File, "aaaa", "1") {StaticFileSkipFunctionName = "func1_Skip"};
 }
        public void AddNewFile()
        {
            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;
            }
            if (treeFiles.SelectedNodes.Count > 1)
            {
                throw new Exception("Only one node can be selected.");
            }

            Node selectedNode = treeFiles.SelectedNodes[0];
            TagInfo ti = (TagInfo)selectedNode.Tag;

            if (ti.FileType != TagInfo.FileTypes.Folder)
            {
                MessageBox.Show(this, "A file cannot be added as a child of a file. Select a parent folder", "No Folder Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            Cursor = Cursors.WaitCursor;

            try
            {
                Refresh();
                Wizards.frmOutputFileWizard.IterationType = null;
                Wizards.frmOutputFileWizard.FileType = Wizards.frmOutputFileWizard.FileTypes.Script;
                Wizards.frmOutputFileWizard.FileName = "";
                Wizards.frmOutputFileWizard.StaticFileName = "";
                Wizards.frmOutputFileWizard.FunctionName = "";
                Wizards.frmOutputFileWizard form = new Wizards.frmOutputFileWizard();
                bool showFunctions = false;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    var createNewFunction = Wizards.frmOutputFileWizard.ShowNewFunctionWizardOnClose &&
                            (Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.DontUse
                            || Wizards.frmOutputFileWizard.FileType == Wizards.frmOutputFileWizard.FileTypes.Script);
                    if (createNewFunction)
                    {
                        Controller.Instance.MainForm.Refresh();
                        FunctionInfo newFunc = Controller.Instance.MainForm.UcFunctions.NewFunction(Wizards.frmOutputFileWizard.IterationType);

                        if (newFunc != null)
                        {
                            Wizards.frmOutputFileWizard.FunctionName = newFunc.Name;
                            showFunctions = true;
                        }
                    }
                    else if (Wizards.frmOutputFileWizard.StaticSkipFunction == Wizards.frmOutputFileWizard.SkipFunctionChoice.CreateNew)
                    {
                        FunctionInfo newFunction = new FunctionInfo(
                                                        NamingHelper.CleanNameCSharp(Wizards.frmOutputFileWizard.StaticFileName) + "_SkipFile",
                                                            typeof(bool), "return false;", false, SyntaxEditorHelper.ScriptLanguageTypes.CSharp,
                                                            "Returns true if the static file should be skipped and not generated", "plain text", "Skip Static Files");

                        Project.Instance.AddFunction(newFunction);
                        Wizards.frmFunctionWizard functionForm = new Wizards.frmFunctionWizard(newFunction, true);

                        if (functionForm.ShowDialog(ParentForm) == DialogResult.Cancel)
                        {
                            Project.Instance.DeleteFunction(newFunction);
                            //OwnerTabStripPage.TabStrip.Pages.Remove(OwnerTabStripPage);
                        }
                    }

                    string id = ((TagInfo)selectedNode.Tag).Id;

                    OutputFolder folder = Project.Instance.FindFolder(id);

                    if (folder != null)
                    {
                        OutputFile file;

                        if (Wizards.frmOutputFileWizard.FileType == Wizards.frmOutputFileWizard.FileTypes.Static)
                        {
                            file = new OutputFile(Wizards.frmOutputFileWizard.FileName, OutputFileTypes.File, "", Guid.NewGuid().ToString());
                            file.StaticFileName = Wizards.frmOutputFileWizard.StaticFileName;
                            file.StaticFileIterator = Wizards.frmOutputFileWizard.IterationType;
                            file.StaticFileSkipFunctionName = Wizards.frmOutputFileWizard.StaticSkipFunctionName;
                        }
                        else if (Wizards.frmOutputFileWizard.FileType == Wizards.frmOutputFileWizard.FileTypes.Script)
                        {
                            file = new OutputFile(Wizards.frmOutputFileWizard.FileName, OutputFileTypes.Script, Wizards.frmOutputFileWizard.FunctionName, Guid.NewGuid().ToString());
                            file.IteratorFunction = Project.Instance.FindFunctionSingle(Wizards.frmOutputFileWizard.FunctionName);
                        }
                        else
                        {
                            throw new NotImplementedException("Not catered for yet.");
                        }
                        folder.AddFile(file);
                        Node newFileNode = AddFileNode(selectedNode, file);
                        selectedNode.Expanded = true;
                        treeFiles.SelectedNode = newFileNode;
                    }
                    else
                    {
                        MessageBox.Show(this, "No matching folder found.", "No matching folder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    Project.Instance.IsDirty = true;
                }
                if (showFunctions)
                {
                    Controller.Instance.MainForm.HidePanelControls(Controller.Instance.MainForm.UcFunctions);
                }
            }
            finally
            {
                Controller.Instance.MainForm.Activate();
                Cursor = Cursors.Default;
            }
        }
Esempio n. 6
0
 public void AddFile(OutputFile file)
 {
     foreach (OutputFile exitingFile in Files)
     {
         if (exitingFile.Id == file.Id)
         {
             return;
         }
     }
     Files.Add(file);
     //Files.Sort();
 }
        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);
        }
        private Node AddFileNode(Node parentNode, OutputFile file)
        {
            int imageType = file.ScriptName.Length == 0 ? IMG_FILE : IMG_TEMPLATE_SCRIPT;
            string secondColumn = "";

            switch (file.FileType)
            {
                case OutputFileTypes.Script:
                    secondColumn = file.ScriptName;
                    break;
                case OutputFileTypes.File:
                    secondColumn = "[File] " + file.StaticFileName;
                    break;
                default:
                    throw new NotImplementedException("Not coded yet.");
            }
            Node newNode = new Node();
            newNode.Text = file.Name;
            newNode.DragDropEnabled = true;
            newNode.Cells.Add(new Cell(secondColumn));
            newNode.Cells.Add(new Cell(file.IteratorTypes));
            newNode.Cells.Add(new Cell());
            newNode.ImageIndex = imageType;
            TagInfo.FileTypes fileType = file.ScriptName.Length == 0 ? TagInfo.FileTypes.NormalFile : TagInfo.FileTypes.ScriptFile;
            newNode.Tag = new TagInfo(file.Id, fileType);
            newNode.Cells[(int)CellTypes.Function].StyleNormal = treeFiles.Styles["functionLinkStyle"];
            newNode.Cells[(int)CellTypes.Function].StyleMouseOver = treeFiles.Styles["functionLinkHoverStyle"];
            newNode.Cells[(int)CellTypes.Function].Cursor = Cursors.Hand;

            if (file.StaticFileIterator != null)
            {
                newNode.Cells[(int)CellTypes.Iterator].Text = file.StaticFileIterator.FullName;
                newNode.Cells[(int)CellTypes.Iterator].StyleNormal = treeFiles.Styles["functionLinkStyle"];
                newNode.Cells[(int)CellTypes.Iterator].StyleMouseOver = treeFiles.Styles["functionLinkHoverStyle"];
                newNode.Cells[(int)CellTypes.Iterator].Cursor = Cursors.Hand;
            }

            if (string.IsNullOrEmpty(file.StaticFileSkipFunctionName) == false)
            {
                newNode.Cells[(int)CellTypes.SkipFunction].Text = file.StaticFileSkipFunctionName;
                newNode.Cells[(int)CellTypes.SkipFunction].StyleNormal = treeFiles.Styles["functionLinkStyle"];
                newNode.Cells[(int)CellTypes.SkipFunction].StyleMouseOver = treeFiles.Styles["functionLinkHoverStyle"];
                newNode.Cells[(int)CellTypes.SkipFunction].Cursor = Cursors.Hand;
            }

            parentNode.Nodes.Add(newNode);
            return newNode;
        }
        private OutputFile ReadStaticFile(XmlNode node)
        {
            NodeProcessor proc = new NodeProcessor(node);
            string name = proc.Attributes.GetString("name");
            string id = proc.Attributes.GetString("id");

            string staticFileName = proc.Attributes.Exists("staticfilename")
                                        ? proc.Attributes.GetString("staticfilename") : null;
            string iteratorname = proc.Attributes.Exists("iteratorname")
                                    ? proc.Attributes.GetString("iteratorname") : null;
            string skipFunction = proc.Attributes.Exists("skipfunction")
                                    ? proc.Attributes.GetString("skipfunction") : null;

            OutputFile file = new OutputFile(name, OutputFileTypes.File, staticFileName, id);
            if (iteratorname != null) file.StaticFileIterator = Deserialiser.GetTypeNamed(iteratorname);
            file.StaticFileSkipFunctionName = skipFunction;

            return file;
        }
Esempio n. 10
0
 public void AddTopLevelFile(OutputFile file)
 {
     RootOutput.Files.Add(file);
 }
Esempio n. 11
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
        }