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);
        }
Exemple #2
0
		public void PopulateFunctionList()
		{
			try
			{
				superTooltip1 = new SuperTooltip();
				superTooltip1.BeforeTooltipDisplay += superTooltip1_BeforeTooltipDisplay;
				List<string> specialFunctions = Project.Instance.InternalFunctionNames;

				treeFunctions.BeginUpdate();
				treeFunctions.Nodes.Clear();

				foreach (string category in Project.Instance.FunctionCategories)
				{
					RemoveTabsOfDeletedFunctions();
					var categoryNode = new Node();
					categoryNode.Text = " " + (string.IsNullOrEmpty(category) ? "General" : category);
					bool categoryAdded = false;

					foreach (FunctionInfo function in Project.Instance.Functions)
					{
						if (function.Category != category || specialFunctions.BinarySearch(function.Name) >= 0)
						{
							continue;
						}
						if (function.IsExtensionMethod)
							continue;
						if (!categoryAdded)
						{
							categoryNode.Style = treeFunctions.Styles["elementStyleGroup"];
							treeFunctions.Nodes.Add(categoryNode);
							categoryAdded = true;
						}
						var functionNode = new Node { Text = function.Name, Tag = function };

						if (!function.IsTemplateFunction)
						{
							functionNode.Image = imageListFunctions.Images[0];
						}
						else
						{
							switch (SyntaxEditorHelper.LanguageEnumFromName(function.TemplateReturnLanguage))
							{
								case TemplateContentLanguage.CSharp:
									functionNode.Image = imageListFunctions.Images[3];
									break;
								case TemplateContentLanguage.VbDotNet:
									functionNode.Image = imageListFunctions.Images[5];
									break;
								case TemplateContentLanguage.Sql:
									functionNode.Image = imageListFunctions.Images[0];
									break;
								case TemplateContentLanguage.Html:
									functionNode.Image = imageListFunctions.Images[4];
									break;
								case TemplateContentLanguage.Css:
									functionNode.Image = imageListFunctions.Images[2];
									break;
								case TemplateContentLanguage.IniFile:
									functionNode.Image = imageListFunctions.Images[0];
									break;
								case TemplateContentLanguage.JScript:
									functionNode.Image = imageListFunctions.Images[0];
									break;
								case TemplateContentLanguage.Python:
									functionNode.Image = imageListFunctions.Images[0];
									break;
								case TemplateContentLanguage.VbScript:
									functionNode.Image = imageListFunctions.Images[5];
									break;
								case TemplateContentLanguage.Xml:
									functionNode.Image = imageListFunctions.Images[6];
									break;
								case TemplateContentLanguage.PlainText:
									functionNode.Image = imageListFunctions.Images[0];
									break;
								default:
									functionNode.Image = imageListFunctions.Images[0];
									//throw new Exception("This function return type not handled yet in CreateDirectiveXmlToCSharpLanguage: " + function.ReturnType);
									break;
							}
						}
						//toolTipForNavBar.SetToolTip(functionNode, string.Format("({1}) {0}", function.Name, function.ReturnType));
						var sti = new SuperTooltipInfo(function.Name, "", function.Description, functionNode.Image, null, eTooltipColor.Office2003);
						superTooltip1.SetSuperTooltip(functionNode, sti);
						categoryNode.Nodes.Add(functionNode);
					}
				}
				foreach (Node node in treeFunctions.Nodes)
				{
					node.ExpandAll();
					node.Expand();
				}
			}
			finally
			{
				treeFunctions.EndUpdate();
			}
		}
Exemple #3
0
        private bool ProcessScriptObject(object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode)
        {
            bool   success    = true;
            string scriptName = UpdateScriptName(scriptObject, script);
            string fileName   = Path.Combine(folderName, scriptName);

            _Loader.SetGeneratedFileNameOnTemplate(Path.Combine(_Project.ProjectSettings.OutputPath, fileName));

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

                try
                {
                    // Reset the SkipCurrentFile and CurrentFileName variable
                    _Loader.CallTemplateFunction(TemplateHelper.ResetSkipCurrentFileFunctionName);
                    _Loader.CallTemplateFunction(TemplateHelper.ResetCurrentFileNameFunctionName);
                    // Call the script file function to get the file text body
                    object[] parameters = new[] { scriptObject };
                    // Check whether we must skip the current file
                    string templateOutput = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters);

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

                    bool skipCurrentFile = (bool)_Loader.CallTemplateFunction(TemplateHelper.GetSkipCurrentFileFunctionName);

                    if (!skipCurrentFile)
                    {
                        templateOutput = Utility.StandardizeLineBreaks(templateOutput, Utility.LineBreaks.Windows);

                        string codeInsertionFilename =
                            (string)_Loader.CallTemplateFunction(TemplateHelper.GetCurrentFileNameFunctionName);

                        if (string.IsNullOrEmpty(codeInsertionFilename))
                        {
                            string fullPath = Path.Combine(absoluteBasePath, fileName);
                            _FileController.WriteAllText(fullPath, templateOutput);

                            // The file has successfully been written - add it to the GeneratedFiles
                            _Project.AddGeneratedFile(new GeneratedFile(script.FileName, fullPath, fileName, script.ScriptName, script.IteratorName));

                            // Set the NewGen text to point to that file.
                            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;
                                }
                            }

                            if (addToProjectFileTree)
                            {
                                parentNode.AddChildNode(fileInfo, scriptName);
                            }
                        }
                        else
                        {
                            // Code insertions were performed. Need to update a node in the tree.
                            // expand the path
                            if (Path.IsPathRooted(codeInsertionFilename) == false)
                            {
                                codeInsertionFilename = RelativePaths.RelativeToAbsolutePath(absoluteBasePath, codeInsertionFilename);
                            }
                            codeInsertionFilename = _FileController.GetFullPath(codeInsertionFilename);

                            // Get the relative path
                            string relativeCodeInsertionFilename = RelativePaths.GetRelativePath(_Project.ProjectSettings.OutputPath, codeInsertionFilename);

                            // If the file is not under the output path, then reset it to the full path
                            if (relativeCodeInsertionFilename.StartsWith(".."))
                            {
                                relativeCodeInsertionFilename = codeInsertionFilename;

                                // We need to add its folder as a root node of the tree
                                if (!parentNode.IsTreeRoot)
                                {
                                    parentNode = parentNode.ParentTree;
                                }
                            }

                            fileInfo.RelativeFilePath = relativeCodeInsertionFilename;
                            string relPathStart = "." + Path.DirectorySeparatorChar;

                            if (fileInfo.RelativeFilePath.StartsWith(relPathStart))
                            {
                                fileInfo.RelativeFilePath = fileInfo.RelativeFilePath.Substring(2);
                            }

                            if (addToProjectFileTree)
                            {
                                ProjectFileTree tree;

                                if (!parentNode.IsTreeRoot)
                                {
                                    tree = parentNode.ParentTree;
                                }
                                else
                                {
                                    tree = (ProjectFileTree)parentNode;
                                }

                                var possibleNode = tree.GetNodeAtPath(codeInsertionFilename);

                                if (possibleNode == null)
                                {
                                    // Need to create this node.


                                    // Create the node and it's parent folders if need be
                                    var node = tree.CreateFileNodeForPath(relativeCodeInsertionFilename);
                                    node.AssociatedFile = fileInfo;
                                }
                                else
                                {
                                    // Update the NewGen text, don't add it to the generated files list.
                                    fileInfo = possibleNode.AssociatedFile as TextFileInformation;
                                    if (fileInfo == null)
                                    {
                                        throw new NotSupportedException("Cannot code merge a binary file");
                                    }
                                }
                            }
                            else
                            {
                                // Write the file to disk
                                _FileController.WriteAllText(codeInsertionFilename, templateOutput);
                            }

                            fileInfo.NewGenFile = new TextFile(templateOutput);
                        }

                        AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1);
                    }
                }
                catch (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.
                    if (addToProjectFileTree)
                    {
                        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;
                    }

                    if (addToProjectFileTree)
                    {
                        parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                    }
                    // Make sure any other type of exception gets thrown
                    throw;
                }
            }
            return(success);
        }