Esempio n. 1
0
 /// <summary>
 /// Raise the TreeNodeChanged event.
 /// </summary>
 /// <param name="childrenChanged">Whether the children of this node also changed.</param>
 /// <param name="node">The node that changed.</param>
 internal override void RaiseNodeChangedEvent(ProjectFileTreeNode node, bool childrenChanged)
 {
     if (TreeNodeChanged != null && treeRestructuring == false)
     {
         TreeNodeChanged(this, new ProjectFileTreeChangedEventArgs(node, childrenChanged));
     }
 }
 public virtual void AddItemToQueue(ProjectFileTreeNode node)
 {
     lock (nodesToProcess)
     {
         nodesToProcess.Add(node);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Raise the TreeNodeChanged event.
 /// </summary>
 /// <param name="childrenChanged">Whether the children of this node also changed.</param>
 /// <param name="node">The node that changed.</param>
 internal virtual void RaiseNodeChangedEvent(ProjectFileTreeNode node, bool childrenChanged)
 {
     if (parentTree != null)
     {
         parentTree.RaiseNodeChangedEvent(node, childrenChanged);
     }
 }
 public virtual void ShiftToFrontOfQueue(ProjectFileTreeNode node)
 {
     lock (nodesToProcess)
     {
         if (nodesToProcess.Contains(node))
         {
             nodesToProcess.Remove(node);
             nodesToProcess.Insert(0, node);
         }
     }
 }
 public virtual ProjectFileTreeNode Dequeue()
 {
     lock (nodesToProcess)
     {
         if (nodesToProcess.Count != 0)
         {
             ProjectFileTreeNode node = nodesToProcess[0];
             nodesToProcess.RemoveAt(0);
             return(node);
         }
     }
     return(null);
 }
Esempio n. 6
0
 /// <summary>
 /// Does a depth first search and returns the first node that satisfies the SearchCondition.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="condition"></param>
 /// <returns></returns>
 public static ProjectFileTreeNode DepthFirstSearch(ProjectFileTreeNode node, ProjectFileSearchCondition condition)
 {
     if (condition.Satisfied(node))
     {
         return(node);
     }
     foreach (ProjectFileTreeNode childNode in node.ChildNodes)
     {
         ProjectFileTreeNode result = DepthFirstSearch(childNode, condition);
         if (result != null)
         {
             return(result);
         }
     }
     return(null);
 }
Esempio n. 7
0
        /// <summary>
        /// Analyses the files in the given ProjectFileTree, reporting progress through the given ProgressHelper.
        /// </summary>
        /// <param name="progressHelper">The progress helper to use to report progress.</param>
        /// <param name="cont">The Controller to use.</param>
        /// <param name="tree">The project information to analyse.</param>
        public void StartAnalysis(IAnalysisProgressHelper progressHelper, IController cont, ProjectFileTree tree)
        {
            controller = cont;
            //output.BusyAnalysing = true;
            //output.ResetCounts();

            numConflicts = 0;
            numExactCopy = 0;
            numResolved  = 0;
            numNewFiles  = 0;

            log.Debug("Analysis started");

            if (progressHelper.IsCancellationPending())
            {
                progressHelper.Cancel();
                log.Debug("Analysis cancelled before it did anything.");
                return;
            }

            List <ProjectFileTreeNode> nodes = GetListOfNodesToProcess(tree.AllNodes, true);

            progressHelper.AddItemRangeToQueue(nodes);

            progressHelper.ReportProgress(0, progressHelper);
            progressHelper.ReportProgress(10, new AnalyseFilesProgress(nodes.Count, 0, 0, 0, 0, 0));

            log.Debug("Got all items to analyse, starting to process them.");

            while (progressHelper.HasItemsLeftToProcess())
            {
                if (progressHelper.IsCancellationPending())
                {
                    progressHelper.Cancel();
                    return;
                }

                ProjectFileTreeNode node = progressHelper.Dequeue();
                if (node == null)
                {
                    break;
                }
                AnalyseFile(progressHelper, node);
                progressHelper.ReportProgress(10, new AnalyseFilesProgress(progressHelper.Count, numExactCopy, numResolved, numConflicts, numAnalysisErrors + numGenerationErrors, numNewFiles, node.Path, node.Status));
                Application.DoEvents();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new node and adds it as a child.
        /// </summary>
        /// <param name="associatedFileInformation">The IFileInformation to associated with the node. Can be null if it needs to be set later.</param>
        /// <param name="nodeText">The text of the node. Can be null if it needs to be set later.</param>
        /// <returns>The created node.</returns>
        public virtual ProjectFileTreeNode AddChildNode(IFileInformation associatedFileInformation, String nodeText)
        {
            if (nodeText == null)
            {
                nodeText = "";
            }

            ProjectFileTreeNode node = new ProjectFileTreeNode(this, parentTree);

            node.Text           = nodeText;
            node.associatedFile = associatedFileInformation;
            childNodes.Add(node);
            parentTree.AddNode(node);
            status = ProjectFileStatusEnum.Folder;
            RaiseNodeChangedEvent(this, true);
            return(node);
        }
Esempio n. 9
0
        private static void LoadMD5sForNode(ProjectFileTreeNode node, string dir)
        {
            if (node.IsFolder == false)
            {
                return;
            }
            string manifestFile = System.IO.Path.Combine(dir, ManifestConstants.MANIFEST_FILENAME);

            if (File.Exists(manifestFile) == false)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(manifestFile);
            } catch (Exception)
            {
                return;
            }

            foreach (ProjectFileTreeNode childNode in node.ChildNodes)
            {
                if (childNode.AssociatedFile != null)
                {
                    string userMD5, templateMD5, prevgenMD5;
                    PrevGenUtility.GetMD5sForFile(doc, System.IO.Path.GetFileName(childNode.Path), out prevgenMD5,
                                                  out templateMD5, out userMD5);
                    childNode.AssociatedFile.SetPreviousVersionMD5s(prevgenMD5, templateMD5, userMD5);
                }
                else if (childNode.IsFolder)
                {
                    LoadMD5sForNode(childNode, System.IO.Path.Combine(dir, childNode.Text));
                }
            }
        }
        /// <summary>
        /// Creates the actual files, or returns a count of the number of files that will be created, depending on value of createFiles.
        /// </summary>
        /// <param name="progressHelper"></param>
        /// <param name="folderName"></param>
        /// <param name="script"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        private int CreateScriptFile(ITaskProgressHelper <GenerateFilesProgress> progressHelper, string folderName, IScript script, ProjectFileTreeNode parentNode)
        {
            int fileCount = 0;

            if (string.IsNullOrEmpty(script.IteratorName))
            {
                if (ProcessScriptObject(progressHelper, null, folderName, script, parentNode))
                {
                    fileCount++;
                }
                return(fileCount);
            }
            ProviderInfo provider;
            Type         iteratorType = project.GetTypeFromProviders(script.IteratorName, out provider);

            if (iteratorType != null)
            {
                IEnumerable <IScriptBaseObject> iteratorObjects;

                if (CurrentRootObject == null)
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName);
                }
                else if (iteratorType.IsInstanceOfType(CurrentRootObject))
                {
                    iteratorObjects = new[] { CurrentRootObject };
                }
                else
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, CurrentRootObject);
                }
                if (iteratorObjects != null)
                {
                    if (iteratorType.IsArray)
                    {
                        if (ProcessScriptObject(progressHelper, iteratorObjects, folderName, script, parentNode))
                        {
                            fileCount++;
                        }
                    }
                    else
                    {
                        foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                        {
                            if (iteratorObject != null && ProcessScriptObject(progressHelper, iteratorObject, folderName, script, parentNode))
                            {
                                fileCount++;
                            }
                        }
                    }
                }
            }
            else
            {
                throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", script.IteratorName));
            }
            return(fileCount);
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a new node and adds it as a child.
        /// </summary>
        /// <param name="associatedFileInformation">The IFileInformation to associated with the node. Can be null if it needs to be set later.</param>
        /// <param name="nodeText">The text of the node. Can be null if it needs to be set later.</param>
        /// <returns>The created node.</returns>
        public virtual ProjectFileTreeNode AddChildNode(IFileInformation associatedFileInformation, String nodeText)
        {
            if (nodeText == null)
                nodeText = "";

            ProjectFileTreeNode node = new ProjectFileTreeNode(this, parentTree);
            node.Text = nodeText;
            node.associatedFile = associatedFileInformation;
            childNodes.Add(node);
            parentTree.AddNode(node);
            status = ProjectFileStatusEnum.Folder;
            RaiseNodeChangedEvent(this, true);
            return node;
        }
Esempio n. 12
0
 internal ProjectFileTreeNode(ProjectFileTreeNode parentNode, ProjectFileTree parentTree)
 {
     this.parentNode = parentNode;
     this.parentTree = parentTree;
 }
Esempio n. 13
0
 public bool Satisfied(ProjectFileTreeNode node)
 {
     return node.IsFolder == false && node.ChildNodes.Count == 0;
 }
Esempio n. 14
0
        /// <summary>
        /// Creates the actual files, or returns a count of the number of files that will be created, depending on value of createFiles.
        /// </summary>
        /// <param name="progressHelper"></param>
        /// <param name="folderName"></param>
        /// <param name="script"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        private int CreateScriptFile(ITaskProgressHelper<GenerateFilesProgress> progressHelper, string folderName, IScript script, ProjectFileTreeNode parentNode)
        {
            int fileCount = 0;

            if (string.IsNullOrEmpty(script.IteratorName))
            {
                if (ProcessScriptObject(progressHelper, null, folderName, script, parentNode))
                {
                    fileCount++;
                }
                return fileCount;
            }
            ProviderInfo provider;
            Type iteratorType = project.GetTypeFromProviders(script.IteratorName, out provider);

            if (iteratorType != null)
            {
                IEnumerable<IScriptBaseObject> iteratorObjects;

                if (CurrentRootObject == null)
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName);
                }
                else if (iteratorType.IsInstanceOfType(CurrentRootObject))
                {
                    iteratorObjects = new[] { CurrentRootObject };
                }
                else
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, CurrentRootObject);
                }
                if (iteratorObjects != null)
                {
                    if (iteratorType.IsArray)
                    {
                        if (ProcessScriptObject(progressHelper, iteratorObjects, folderName, script, parentNode))
                        {
                            fileCount++;
                        }
                    }
                    else
                    {
                        foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                        {
                            if (iteratorObject != null && ProcessScriptObject(progressHelper, iteratorObject, folderName, script, parentNode))
                            {
                                fileCount++;
                            }
                        }
                    }
                }
            }
            else
            {
                throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", script.IteratorName));
            }
            return fileCount;
        }
        /// <summary>
        /// Runs through a project and generates the files in it.
        /// </summary>
        /// <param name="progressHelper">The TaskProgressHelper to use to report progress and cancel the operation.</param>
        /// <param name="projectInfo">The Project we are generating files from.</param>
        /// <param name="folderName">The name of the root folder to generate into. Not the full path, just the relative path to the
        /// current folder.</param>
        /// <param name="folder"></param>
        /// <param name="parentNode"></param>
        /// <param name="thisLevelRootObject"></param>
        /// <returns></returns>
        /// <param name="loader"></param>
        /// <param name="controller"></param>
        public int GenerateAllFiles(ITaskProgressHelper <GenerateFilesProgress> progressHelper, IProjectHelper projectInfo, string folderName, IFolder folder, ProjectFileTreeNode parentNode, IScriptBaseObject thisLevelRootObject, ILoader loader, IController controller)
        {
            if (parentNode is ProjectFileTree)
            {
                ((ProjectFileTree)parentNode).TreeRestructuring = true;
                ((ProjectFileTree)parentNode).Clear();
            }
            int fileCount = 0;

            try
            {
                _Controller       = controller;
                _Loader           = loader;
                _ProgressHelper   = progressHelper;
                project           = projectInfo;
                CurrentRootObject = thisLevelRootObject;
                absoluteBasePath  = controller.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator);


                {
                    Version version         = new Version(loader.GetAssemblyVersionNumber());
                    Version expectedVersion = new Version(1, 1, 9, 49);
                    if (version < expectedVersion)
                    {
                        throw new OldVersionException("The template was compiled with an old version of ArchAngel, and cannot be used in this version of Workbench");
                    }
                }


                foreach (IFolder subFolder in folder.SubFolders)
                {
                    if (progressHelper.IsCancellationPending())
                    {
                        progressHelper.Cancel();
                        return(fileCount);
                    }

                    ProjectFileTreeNode folderNode = null;

                    if (parentNode != null && subFolder.Name != "ROOT")
                    {
                        folderNode          = parentNode.AddChildNode(subFolder.Name);
                        folderNode.IsFolder = true;
                    }

                    if (!string.IsNullOrEmpty(subFolder.IteratorName))
                    {
                        // The folder has an iterator
                        ProviderInfo provider;
                        Type         iteratorType = project.GetTypeFromProviders(subFolder.IteratorName, out provider);

                        if (progressHelper.IsCancellationPending())
                        {
                            progressHelper.Cancel();
                            return(fileCount);
                        }

                        if (iteratorType != null)
                        {
                            IEnumerable <IScriptBaseObject> iteratorObjects;

                            if (thisLevelRootObject == null)
                            {
                                iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName);
                            }
                            else if (iteratorType.IsInstanceOfType(thisLevelRootObject))
                            {
                                iteratorObjects = new[] { thisLevelRootObject };
                            }
                            else
                            {
                                iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, thisLevelRootObject);
                            }
                            if (iteratorObjects != null)
                            {
                                foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                                {
                                    if (progressHelper.IsCancellationPending())
                                    {
                                        progressHelper.Cancel();
                                        return(fileCount);
                                    }

                                    CurrentRootObject = iteratorObject;

                                    string subFolderName = UpdateScriptName(iteratorObject, subFolder);

                                    if (folderNode != null)
                                    {
                                        folderNode.Text = subFolderName;
                                    }

                                    subFolderName = Path.Combine(folderName, subFolderName);

                                    //Directory.CreateDirectory(Path.Combine(Controller.Instance.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), subFolderName));

                                    fileCount += GenerateAllFiles(progressHelper, project, subFolderName, subFolder, folderNode, CurrentRootObject, loader, controller);
                                }
                            }
                        }
                        else
                        {
                            throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", subFolder.IteratorName));
                        }
                    }
                    else
                    {
                        // The folder doesn't have an iterator
                        if (progressHelper.IsCancellationPending())
                        {
                            progressHelper.Cancel();
                            return(fileCount);
                        }
                        string subFolderName = UpdateScriptName(null, subFolder);

                        if (folderNode != null)
                        {
                            folderNode.Text = subFolderName;
                        }
                        subFolderName = Path.Combine(folderName, subFolderName);
                        //Directory.CreateDirectory(Path.Combine(Controller.Instance.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), subFolderName));

                        fileCount += GenerateAllFiles(progressHelper, projectInfo, subFolderName, subFolder, folderNode, thisLevelRootObject, loader, controller);
                    }

                    //progressHelper.ReportProgress(20, new GenerateFilesProgress(fileCount));
                }

                //progressHelper.ReportProgress(50, new GenerateFilesProgress(fileCount));

                foreach (IScript script in folder.Scripts)
                {
                    if (progressHelper.IsCancellationPending())
                    {
                        progressHelper.Cancel();
                        return(fileCount);
                    }
                    fileCount += CreateScriptFile(progressHelper, folderName, script, parentNode);
                }

                // progressHelper.ReportProgress(80, new GenerateFilesProgress(fileCount));

                foreach (IFile file in folder.Files)
                {
                    if (progressHelper.IsCancellationPending())
                    {
                        progressHelper.Cancel();
                        return(fileCount);
                    }
                    fileCount += CreateStaticFile(progressHelper, folderName, file, parentNode);
                }

                //progressHelper.ReportProgress(95, new GenerateFilesProgress(fileCount));

                //Application.DoEvents();
            }
            catch (Exception e)
            {
                progressHelper.ReportProgress(100, new GenerateFilesProgress(fileCount, e));
                return(fileCount);
            }
            finally
            {
                if (parentNode is ProjectFileTree)
                {
                    ((ProjectFileTree)parentNode).TreeRestructuring = false;
                    parentNode.RaiseNodeChangedEvent(parentNode, true);
                }
            }
            progressHelper.ReportProgress(50, new GenerateFilesProgress(fileCount));
            return(fileCount);
        }
Esempio n. 16
0
 /// <summary>
 /// Override this in the Tree class to provide a method of adding nodes to a collection of all nodes.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <exception cref="InvalidOperationException">Thrown if the base version of this method is called. It must be overridden.</exception>
 protected virtual void AddNode(ProjectFileTreeNode node)
 {
     throw new InvalidOperationException("Cannot call this on a node, must be called on the root Tree.");
 }
Esempio n. 17
0
 /// <summary>
 /// Does a depth first search and returns the first node that satisfies the SearchCondition.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="condition"></param>
 /// <returns></returns>
 public static ProjectFileTreeNode DepthFirstSearch(ProjectFileTreeNode node, ProjectFileSearchCondition condition)
 {
     if (condition.Satisfied(node))
         return node;
     foreach(ProjectFileTreeNode childNode in node.ChildNodes)
     {
         ProjectFileTreeNode result = DepthFirstSearch(childNode, condition);
         if (result != null)
             return result;
     }
     return null;
 }
Esempio n. 18
0
 /// <summary>
 /// Raise the TreeNodeChanged event.
 /// </summary>
 /// <param name="childrenChanged">Whether the children of this node also changed.</param>
 /// <param name="node">The node that changed.</param>
 internal virtual void RaiseNodeChangedEvent(ProjectFileTreeNode node, bool childrenChanged)
 {
     if(parentTree != null)
     {
         parentTree.RaiseNodeChangedEvent(node, childrenChanged);
     }
 }
Esempio n. 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="childrenChanged">Whether the children of this node also changed.</param>
 /// <param name="changedNode">The node that changed.</param>
 public ProjectFileTreeChangedEventArgs(ProjectFileTreeNode changedNode, bool childrenChanged)
 {
     this.childrenChanged = childrenChanged;
     this.changedNode     = changedNode;
 }
Esempio n. 20
0
 /// <summary>
 /// Override this in the Tree class to provide a method of adding nodes to a collection of all nodes.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <exception cref="InvalidOperationException">Thrown if the base version of this method is called. It must be overridden.</exception>
 protected virtual void AddNode(ProjectFileTreeNode node)
 {
     throw new InvalidOperationException("Cannot call this on a node, must be called on the root Tree.");
 }
        /// <summary>
        /// Creates the static files and writes them to the WorkbenchFileGenerator component directory.
        /// </summary>
        /// <param name="progressHelper"></param>
        /// <param name="folderName">The relative path of the folder this file will be placed in.</param>
        /// <param name="file"></param>
        /// <param name="parentNode"></param>
        /// <returns>The number of files created.</returns>
        private int CreateStaticFile(ITaskProgressHelper <GenerateFilesProgress> progressHelper, string folderName, IFile file, ProjectFileTreeNode parentNode)
        {
            int fileCount = 0;

            if (string.IsNullOrEmpty(file.IteratorName))
            {
                fileCount++;
                string fileName         = UpdateScriptName(null, file);
                string relativeFilePath = Path.Combine(folderName, fileName);
                string fullPath         = Path.Combine(absoluteBasePath, relativeFilePath);

                _Loader.WriteResourceToFile(file.StaticFileName, fullPath);

                BinaryFile            outFile     = new BinaryFile(fullPath, false);
                BinaryFileInformation binFileInfo = new BinaryFileInformation();
                binFileInfo.NewGenFile       = outFile;
                binFileInfo.RelativeFilePath = relativeFilePath;
                parentNode.AddChildNode(binFileInfo, fileName);
                //Project.CurrentProject.AddGeneratedFile(new ProjectHelper.GeneratedFile(file.Name, fileName, fullPath, null, file.IteratorName));
                AddFileCountToPreviousEventAndRefire(progressHelper, 1);

                return(fileCount);
            }
            ProviderInfo provider;
            Type         iteratorType = project.GetTypeFromProviders(file.IteratorName, out provider);

            if (iteratorType != null)
            {
                IEnumerable <IScriptBaseObject> iteratorObjects;

                if (CurrentRootObject == null)
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName);
                }
                else if (iteratorType.IsInstanceOfType(CurrentRootObject))
                {
                    iteratorObjects = new[] { CurrentRootObject };
                }
                else
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, CurrentRootObject);
                }
                if (iteratorObjects != null)
                {
                    if (iteratorType.IsArray)
                    {
                        throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error.");
                    }

                    foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                    {
                        string fileName         = UpdateScriptName(iteratorObject, file);
                        string relativeFilePath = Path.Combine(folderName, fileName);
                        string fullPath         = Path.Combine(absoluteBasePath, relativeFilePath);

                        _Loader.WriteResourceToFile(file.StaticFileName, fullPath);

                        BinaryFile            outFile     = new BinaryFile(fullPath, false);
                        BinaryFileInformation binFileInfo = new BinaryFileInformation();
                        binFileInfo.RelativeFilePath = relativeFilePath;
                        binFileInfo.NewGenFile       = outFile;


                        parentNode.AddChildNode(binFileInfo, fileName);

                        fileCount++;
                        AddFileCountToPreviousEventAndRefire(progressHelper, 1);
                    }
                }
            }
            else
            {
                throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", file.IteratorName));
            }
            return(fileCount);
        }
Esempio n. 22
0
        private bool ProcessScriptObject(ITaskProgressHelper<GenerateFilesProgress> progressHelper, object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode)
        {
            bool success = true;
            string scriptName = UpdateScriptName(scriptObject, script);
            string fileName = Path.Combine(folderName, scriptName);

            if (scriptName.IndexOf("#") >= 0)
            {
                success = false;
            }
            if (success)
            {
                TextFileInformation fileInfo = new TextFileInformation();
                fileInfo.RelativeFilePath = fileName;

                try
                {
                    object[] parameters = new object[0];

                    if (project.FileSkippingIsImplemented)
                    {
                        try
                        {
                            // Reset the SkipCurrentFile variable
                            _Loader.CallTemplateFunction("InternalFunctions.ResetSkipCurrentFile", ref parameters);
                        }
                        catch
                        {
                            project.FileSkippingIsImplemented = false;
                        }
                    }
                    // Call the script file function to get the file text body
                    parameters = new[] { scriptObject };
                    // Check whether we must skip the current file
                    string str = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters);

                    if (progressHelper.IsCancellationPending())
                        return false;

                    parameters = new object[0];

                    bool skipCurrentFile = false;

                    if (project.FileSkippingIsImplemented)
                    {
                        skipCurrentFile = (bool)_Loader.CallTemplateFunction("InternalFunctions.MustSkipCurrentFile", ref parameters);
                    }
                    if (!skipCurrentFile)
                    {
                        str = Utility.StandardizeLineBreaks(str, Utility.LineBreaks.Windows);
                        string fullPath = Path.Combine(
                            _Controller.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator),
                            fileName);

                        _Loader.WriteScriptToFile(str, fullPath);

                        fileInfo.NewGenFile = new TextFile(fullPath, false);

                        string versionNumberString = _Loader.GetAssemblyVersionNumber();
                        VersionNumber versionNumber;
                        if (VersionNumber.TryParse(versionNumberString, out versionNumber))
                        {
                            // Get the template language from the template function.
                            string templateLanguageString = _Loader.GetTemplateFunctionLanguage(script.ScriptName);
                            try
                            {
                                fileInfo.TemplateLanguage = SyntaxEditorHelper.LanguageEnumFromName(templateLanguageString);
                            } catch (NotImplementedException)
                            {
                                fileInfo.TemplateLanguage = null;
                            }
                        }

                        parentNode.AddChildNode(fileInfo, scriptName);
                        AddFileCountToPreviousEventAndRefire(progressHelper, 1);
                    }

                }
                catch (Slyce.Loader.Exceptions.TemplateFunctionException ex)
                {
                    success = false;
                    string message = "<span class='error'>" + ex.Message + "</span>";

                    if (ex.InnerException != null)
                    {
                        message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" +
                                   Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) +
                                   Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite;
                    }
                    RaiseTemplateFunctionCallErrorEvent(ex);
                    // Do nothing, just skip the file because the error will get reported to the user.
                    parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                }
                catch (Exception ex)
                {
                    string message = "<span class='error'>" + ex.Message + "</span>";

                    if (ex.InnerException != null)
                    {
                        message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" +
                                   Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) +
                                   Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite;
                    }

                    parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                    // Make sure any other type of exception gets thrown
                    throw;
                }
            }
            return success;
        }
        private bool ProcessScriptObject(ITaskProgressHelper <GenerateFilesProgress> progressHelper, object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode)
        {
            bool   success    = true;
            string scriptName = UpdateScriptName(scriptObject, script);
            string fileName   = Path.Combine(folderName, scriptName);

            if (scriptName.IndexOf("#") >= 0)
            {
                success = false;
            }
            if (success)
            {
                TextFileInformation fileInfo = new TextFileInformation();
                fileInfo.RelativeFilePath = fileName;

                try
                {
                    object[] parameters = new object[0];

                    if (project.FileSkippingIsImplemented)
                    {
                        try
                        {
                            // Reset the SkipCurrentFile variable
                            _Loader.CallTemplateFunction("InternalFunctions.ResetSkipCurrentFile", ref parameters);
                        }
                        catch
                        {
                            project.FileSkippingIsImplemented = false;
                        }
                    }
                    // Call the script file function to get the file text body
                    parameters = new[] { scriptObject };
                    // Check whether we must skip the current file
                    string str = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters);

                    if (progressHelper.IsCancellationPending())
                    {
                        return(false);
                    }

                    parameters = new object[0];

                    bool skipCurrentFile = false;

                    if (project.FileSkippingIsImplemented)
                    {
                        skipCurrentFile = (bool)_Loader.CallTemplateFunction("InternalFunctions.MustSkipCurrentFile", ref parameters);
                    }
                    if (!skipCurrentFile)
                    {
                        str = Utility.StandardizeLineBreaks(str, Utility.LineBreaks.Windows);
                        string fullPath = Path.Combine(
                            _Controller.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator),
                            fileName);

                        _Loader.WriteScriptToFile(str, fullPath);

                        fileInfo.NewGenFile = new TextFile(fullPath, false);

                        string        versionNumberString = _Loader.GetAssemblyVersionNumber();
                        VersionNumber versionNumber;
                        if (VersionNumber.TryParse(versionNumberString, out versionNumber))
                        {
                            // Get the template language from the template function.
                            string templateLanguageString = _Loader.GetTemplateFunctionLanguage(script.ScriptName);
                            try
                            {
                                fileInfo.TemplateLanguage = SyntaxEditorHelper.LanguageEnumFromName(templateLanguageString);
                            } catch (NotImplementedException)
                            {
                                fileInfo.TemplateLanguage = null;
                            }
                        }

                        parentNode.AddChildNode(fileInfo, scriptName);
                        AddFileCountToPreviousEventAndRefire(progressHelper, 1);
                    }
                }
                catch (Slyce.Loader.Exceptions.TemplateFunctionException ex)
                {
                    success = false;
                    string message = "<span class='error'>" + ex.Message + "</span>";

                    if (ex.InnerException != null)
                    {
                        message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" +
                                   Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) +
                                   Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite;
                    }
                    RaiseTemplateFunctionCallErrorEvent(ex);
                    // Do nothing, just skip the file because the error will get reported to the user.
                    parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                }
                catch (Exception ex)
                {
                    string message = "<span class='error'>" + ex.Message + "</span>";

                    if (ex.InnerException != null)
                    {
                        message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" +
                                   Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) +
                                   Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite;
                    }

                    parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                    // Make sure any other type of exception gets thrown
                    throw;
                }
            }
            return(success);
        }
Esempio n. 24
0
        internal void AnalyseFile(IAnalysisProgressHelper progressHelper, ProjectFileTreeNode fileNode)
        {
            if (fileNode == null || fileNode.AssociatedFile == null)
            {
                return;
            }

            fileNode.Status = ProjectFileStatusEnum.Busy;
            progressHelper.ReportProgress(10, new AnalyseFilesProgress(progressHelper.Count, numExactCopy, numResolved, numConflicts, numAnalysisErrors + numGenerationErrors, numNewFiles, fileNode.Path, fileNode.Status));

            try
            {
                fileNode.AssociatedFile.LoadCustomMatches(controller.GetTempFilePathForComponent(ComponentKey.SlyceMerge_PrevGen));
                bool result = fileNode.AssociatedFile.PerformDiff();

                if (result == false)
                {
                    fileNode.Status = ProjectFileStatusEnum.AnalysisError;
                    numAnalysisErrors++;
                    return;
                }
            }
            catch (DiffException e)
            {
                if (e.InnerException == null || e.InnerException is MergeException == false)
                {
                    throw;
                }

                MergeException mergeEx = (MergeException)e.InnerException;
                // There was an error during the Merge. Display this to the user.
                fileNode.Status     = ProjectFileStatusEnum.MergeError;
                fileNode.MergeError = new MergeError(mergeEx.BaseConstructName, mergeEx.BaseConstructType, mergeEx.Message);
                numAnalysisErrors++;
                return;
            }

            fileNode.Status = ProjectFileStatusEnum.AnalysedFile;

            switch (fileNode.AssociatedFile.CurrentDiffResult.DiffType)
            {
            case TypeOfDiff.Conflict:
                numConflicts++;
                break;

            case TypeOfDiff.ExactCopy:
                numExactCopy++;
                break;

            case TypeOfDiff.UserAndTemplateChange:
            case TypeOfDiff.UserChangeOnly:
            case TypeOfDiff.TemplateChangeOnly:
                numResolved++;
                break;

            case TypeOfDiff.Warning:
                // TODO: handle warnings
                break;

            case TypeOfDiff.NewFile:
                numNewFiles++;
                break;

            default:
                throw new NotImplementedException("Not coded yet: " + fileNode.AssociatedFile.CurrentDiffResult.DiffType);
            }
        }
Esempio n. 25
0
        public void LoadCheckedStatusFromXml(XmlDocument xmlDocument)
        {
            XmlNodeList nodes = xmlDocument.GetElementsByTagName("Options");

            if (nodes.Count != 1)
            {
                throw new ArgumentException("The given XmlDocument is not a valid CheckedStatus file.");
            }

            XmlElement rootNode = nodes[0] as XmlElement;

            if (rootNode == null)
            {
                throw new ArgumentException("The given XmlDocument is not a valid CheckedStatus file.");
            }

            nodes = rootNode.GetElementsByTagName("CheckedFiles");
            if (nodes.Count != 1)
            {
                throw new ArgumentException("The given XmlDocument is not a valid CheckedStatus file.");
            }

            XmlElement checkedFilesNode = nodes[0] as XmlElement;

            if (checkedFilesNode == null)
            {
                throw new ArgumentException("The given XmlDocument is not a valid CheckedStatus file.");
            }

            nodes = checkedFilesNode.GetElementsByTagName("File");

            TreeRestructuring = true;

            foreach (XmlNode node in nodes)
            {
                string relativePath = node.InnerText;

                ProjectFileTreeNode treeNode = GetNodeAtPath(relativePath);
                if (treeNode == null)
                {
                    continue;
                }

                bool checkedStatus;
                try
                {
                    checkedStatus = bool.Parse(node.Attributes["checked"].Value);
                }
                catch
                {
                    checkedStatus = true;
                }
                treeNode.SetSingleNodeSelected(checkedStatus);

                if (treeNode.AssociatedFile == null)
                {
                    continue;
                }

                if (node.Attributes["intellimerge"] != null)
                {
                    if (rootNode.Attributes["version"] == null)
                    {
                        bool overwriteStatus;
                        try
                        {
                            overwriteStatus = bool.Parse(node.Attributes["intellimerge"].Value);
                        }
                        catch
                        {
                            overwriteStatus = true;
                        }

                        treeNode.AssociatedFile.IntelliMerge = overwriteStatus
                                                                                        ? IntelliMergeType.Overwrite
                                                                                        : IntelliMergeType.AutoDetect;
                    }
                    else
                    {
                        int version = int.Parse(rootNode.Attributes["version"].Value);

                        if (version == 1 && node.Attributes["intellimerge"] != null)
                        {
                            IntelliMergeType mergeType =
                                (IntelliMergeType)Enum.Parse(typeof(IntelliMergeType), node.Attributes["intellimerge"].Value);
                            treeNode.AssociatedFile.IntelliMerge = mergeType;
                        }
                    }
                }
            }

            TreeRestructuring = false;
        }
Esempio n. 26
0
 public bool Satisfied(ProjectFileTreeNode node)
 {
     return(node.IsFolder == false && node.ChildNodes.Count == 0);
 }
Esempio n. 27
0
 /// <summary>
 /// Raise the TreeNodeChanged event.
 /// </summary>
 /// <param name="childrenChanged">Whether the children of this node also changed.</param>
 /// <param name="node">The node that changed.</param>
 internal override void RaiseNodeChangedEvent(ProjectFileTreeNode node, bool childrenChanged)
 {
     if(TreeNodeChanged != null && treeRestructuring == false)
     {
         TreeNodeChanged(this, new ProjectFileTreeChangedEventArgs(node, childrenChanged));
     }
 }
Esempio n. 28
0
 internal ProjectFileTreeNode(ProjectFileTreeNode parentNode, ProjectFileTree parentTree)
 {
     this.parentNode = parentNode;
     this.parentTree = parentTree;
 }
Esempio n. 29
0
        /// <summary>
        /// Creates the static files and writes them to the WorkbenchFileGenerator component directory.
        /// </summary>
        /// <param name="progressHelper"></param>
        /// <param name="folderName">The relative path of the folder this file will be placed in.</param>
        /// <param name="file"></param>
        /// <param name="parentNode"></param>
        /// <returns>The number of files created.</returns>
        private int CreateStaticFile(ITaskProgressHelper<GenerateFilesProgress> progressHelper, string folderName, IFile file, ProjectFileTreeNode parentNode)
        {
            int fileCount = 0;

            if (string.IsNullOrEmpty(file.IteratorName))
            {
                fileCount++;
                string fileName = UpdateScriptName(null, file);
                string relativeFilePath = Path.Combine(folderName, fileName);
                string fullPath = Path.Combine(absoluteBasePath, relativeFilePath);

                _Loader.WriteResourceToFile(file.StaticFileName, fullPath);

                BinaryFile outFile = new BinaryFile(fullPath, false);
                BinaryFileInformation binFileInfo = new BinaryFileInformation();
                binFileInfo.NewGenFile = outFile;
                binFileInfo.RelativeFilePath = relativeFilePath;
                parentNode.AddChildNode(binFileInfo, fileName);
                //Project.CurrentProject.AddGeneratedFile(new ProjectHelper.GeneratedFile(file.Name, fileName, fullPath, null, file.IteratorName));
                AddFileCountToPreviousEventAndRefire(progressHelper, 1);

                return fileCount;
            }
            ProviderInfo provider;
            Type iteratorType = project.GetTypeFromProviders(file.IteratorName, out provider);

            if (iteratorType != null)
            {
                IEnumerable<IScriptBaseObject> iteratorObjects;

                if (CurrentRootObject == null)
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName);
                }
                else if (iteratorType.IsInstanceOfType(CurrentRootObject))
                {
                    iteratorObjects = new[] { CurrentRootObject };
                }
                else
                {
                    iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, CurrentRootObject);
                }
                if (iteratorObjects != null)
                {
                    if (iteratorType.IsArray)
                    {
                        throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error.");
                    }

                    foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                    {
                        string fileName = UpdateScriptName(iteratorObject, file);
                        string relativeFilePath = Path.Combine(folderName, fileName);
                        string fullPath = Path.Combine(absoluteBasePath, relativeFilePath);

                        _Loader.WriteResourceToFile(file.StaticFileName, fullPath);

                        BinaryFile outFile = new BinaryFile(fullPath, false);
                        BinaryFileInformation binFileInfo = new BinaryFileInformation();
                        binFileInfo.RelativeFilePath = relativeFilePath;
                        binFileInfo.NewGenFile = outFile;

                        parentNode.AddChildNode(binFileInfo, fileName);

                        fileCount++;
                        AddFileCountToPreviousEventAndRefire(progressHelper, 1);
                    }
                }
            }
            else
            {
                throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", file.IteratorName));
            }
            return fileCount;
        }
Esempio n. 30
0
 /// <summary>
 /// Adds the node to the list of nodes contained in this tree.
 /// </summary>
 /// <param name="node">The node that has been added to the tree.</param>
 protected override void AddNode(ProjectFileTreeNode node)
 {
     allNodes.Add(node);
     treeNodeCache[node.Path] = node;
 }
Esempio n. 31
0
        /// <summary>
        /// Runs through a project and generates the files in it.
        /// </summary>
        /// <param name="progressHelper">The TaskProgressHelper to use to report progress and cancel the operation.</param>
        /// <param name="projectInfo">The Project we are generating files from.</param>
        /// <param name="folderName">The name of the root folder to generate into. Not the full path, just the relative path to the 
        /// current folder.</param>
        /// <param name="folder"></param>
        /// <param name="parentNode"></param>
        /// <param name="thisLevelRootObject"></param>
        /// <returns></returns>
        /// <param name="loader"></param>
        /// <param name="controller"></param>
        public int GenerateAllFiles(ITaskProgressHelper<GenerateFilesProgress> progressHelper, IProjectHelper projectInfo, string folderName, IFolder folder, ProjectFileTreeNode parentNode, IScriptBaseObject thisLevelRootObject, ILoader loader, IController controller)
        {
            if (parentNode is ProjectFileTree)
            {
                ((ProjectFileTree)parentNode).TreeRestructuring = true;
                ((ProjectFileTree)parentNode).Clear();
            }
            int fileCount = 0;

            try
            {
                _Controller = controller;
                _Loader = loader;
                _ProgressHelper = progressHelper;
                project = projectInfo;
                CurrentRootObject = thisLevelRootObject;
                absoluteBasePath = controller.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator);

                {
                    Version version = new Version(loader.GetAssemblyVersionNumber());
                    Version expectedVersion = new Version(1, 1, 9, 49);
                    if (version < expectedVersion)
                    {
                        throw new OldVersionException("The template was compiled with an old version of ArchAngel, and cannot be used in this version of Workbench");
                    }
                }

                foreach (IFolder subFolder in folder.SubFolders)
                {
                    if (progressHelper.IsCancellationPending())
                    {
                        progressHelper.Cancel();
                        return fileCount;
                    }

                    ProjectFileTreeNode folderNode = null;

                    if (parentNode != null && subFolder.Name != "ROOT")
                    {
                        folderNode = parentNode.AddChildNode(subFolder.Name);
                        folderNode.IsFolder = true;
                    }

                    if (!string.IsNullOrEmpty(subFolder.IteratorName))
                    {
                        // The folder has an iterator
                        ProviderInfo provider;
                        Type iteratorType = project.GetTypeFromProviders(subFolder.IteratorName, out provider);

                        if (progressHelper.IsCancellationPending())
                        {
                            progressHelper.Cancel();
                            return fileCount;
                        }

                        if (iteratorType != null)
                        {
                            IEnumerable<IScriptBaseObject> iteratorObjects;

                            if (thisLevelRootObject == null)
                            {
                                iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName);
                            }
                            else if (iteratorType.IsInstanceOfType(thisLevelRootObject))
                            {
                                iteratorObjects = new[] { thisLevelRootObject };
                            }
                            else
                            {
                                iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, thisLevelRootObject);
                            }
                            if (iteratorObjects != null)
                            {
                                foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                                {
                                    if (progressHelper.IsCancellationPending())
                                    {
                                        progressHelper.Cancel();
                                        return fileCount;
                                    }

                                    CurrentRootObject = iteratorObject;

                                    string subFolderName = UpdateScriptName(iteratorObject, subFolder);

                                    if (folderNode != null)
                                    {
                                        folderNode.Text = subFolderName;
                                    }

                                    subFolderName = Path.Combine(folderName, subFolderName);

                                        //Directory.CreateDirectory(Path.Combine(Controller.Instance.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), subFolderName));

                                    fileCount += GenerateAllFiles(progressHelper, project, subFolderName, subFolder, folderNode, CurrentRootObject, loader, controller);

                                }
                            }
                        }
                        else
                        {
                            throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", subFolder.IteratorName));
                        }
                    }
                    else
                    {
                        // The folder doesn't have an iterator
                        if (progressHelper.IsCancellationPending())
                        {
                            progressHelper.Cancel();
                            return fileCount;
                        }
                        string subFolderName = UpdateScriptName(null, subFolder);

                        if (folderNode != null)
                        {
                            folderNode.Text = subFolderName;
                        }
                        subFolderName = Path.Combine(folderName, subFolderName);
                        //Directory.CreateDirectory(Path.Combine(Controller.Instance.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), subFolderName));

                        fileCount += GenerateAllFiles(progressHelper, projectInfo, subFolderName, subFolder, folderNode, thisLevelRootObject, loader, controller);
                    }

                    //progressHelper.ReportProgress(20, new GenerateFilesProgress(fileCount));
                }

                //progressHelper.ReportProgress(50, new GenerateFilesProgress(fileCount));

                foreach (IScript script in folder.Scripts)
                {
                    if (progressHelper.IsCancellationPending())
                    {
                        progressHelper.Cancel();
                        return fileCount;
                    }
                    fileCount += CreateScriptFile(progressHelper, folderName, script, parentNode);
                }

                // progressHelper.ReportProgress(80, new GenerateFilesProgress(fileCount));

                foreach (IFile file in folder.Files)
                {
                    if (progressHelper.IsCancellationPending())
                    {
                        progressHelper.Cancel();
                        return fileCount;
                    }
                    fileCount += CreateStaticFile(progressHelper, folderName, file, parentNode);
                }

                //progressHelper.ReportProgress(95, new GenerateFilesProgress(fileCount));

                //Application.DoEvents();
            }
            catch(Exception e)
            {
                progressHelper.ReportProgress(100, new GenerateFilesProgress(fileCount, e));
                return fileCount;
            }
            finally
            {
                if (parentNode is ProjectFileTree)
                {
                    ((ProjectFileTree) parentNode).TreeRestructuring = false;
                    parentNode.RaiseNodeChangedEvent(parentNode, true);
                }
            }
            progressHelper.ReportProgress(50, new GenerateFilesProgress(fileCount));
            return fileCount;
        }
Esempio n. 32
0
        private static void LoadMD5sForNode(ProjectFileTreeNode node, string dir)
        {
            if (node.IsFolder == false)
                return;
            string manifestFile = System.IO.Path.Combine(dir, ManifestConstants.MANIFEST_FILENAME);

            if(File.Exists(manifestFile) == false)
            {
                return;
            }

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(manifestFile);
            } catch (Exception)
            {
                return;
            }

            foreach(ProjectFileTreeNode childNode in node.ChildNodes)
            {
                if(childNode.AssociatedFile != null)
                {
                    string userMD5, templateMD5, prevgenMD5;
                    PrevGenUtility.GetMD5sForFile(doc, System.IO.Path.GetFileName(childNode.Path), out prevgenMD5,
                                                  out templateMD5, out userMD5);
                    childNode.AssociatedFile.SetPreviousVersionMD5s(prevgenMD5, templateMD5, userMD5);
                }
                else if (childNode.IsFolder)
                {
                    LoadMD5sForNode(childNode, System.IO.Path.Combine(dir, childNode.Text));
                }
            }
        }
Esempio n. 33
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="childrenChanged">Whether the children of this node also changed.</param>
 /// <param name="changedNode">The node that changed.</param>
 public ProjectFileTreeChangedEventArgs(ProjectFileTreeNode changedNode, bool childrenChanged)
 {
     this.childrenChanged = childrenChanged;
     this.changedNode = changedNode;
 }
Esempio n. 34
0
 /// <summary>
 /// Adds the node to the list of nodes contained in this tree.
 /// </summary>
 /// <param name="node">The node that has been added to the tree.</param>
 protected override void AddNode(ProjectFileTreeNode node)
 {
     allNodes.Add(node);
     treeNodeCache[node.Path] = node;
 }