Exemplo n.º 1
0
        public IOption ToOption()
        {
            Option option = new Option();

            option.Category = Category;
            option.Description = Description;
            option.EnumValues = Values.ToArray();
            option.IteratorName = IteratorType == null ? "" : IteratorType.FullName;
            option.ResetPerSession = ResetPerSession;
            option.Text = Text;
            option.VariableName = VariableName;
            option.VarType = VarType;
            option.DefaultValueIsFunction = true; // Always true for options defined in a template

            return option;
        }
Exemplo n.º 2
0
        private void LoadOldDesignerProjectXml(XmlNode doc)
        {
            TemplateName = doc.SelectSingleNode("ROOT/config/project/name").InnerText;
            TemplateDescription = doc.SelectSingleNode("ROOT/config/project/description").InnerText;

            #region Referenced Assemblies
            ProvidersToBeDisplayed.Clear();
            string[] allPaths = doc.SelectSingleNode("ROOT/referencedfiles").InnerText.Split(',');

            foreach (var path in allPaths)
            {
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }
                string[] parts = path.Split('|');
                string currentPath = parts[0];
                currentPath = currentPath.Substring(currentPath.LastIndexOf(@"\") + 1);
                bool isProvider = parts.Length > 3 ? parts[3] == "useInWorkbench=True" : true;
                List<string> providerAssemblyFiles = new List<string>();

                if (isProvider)
                {
                    ProvidersToBeDisplayed.Add(currentPath);
                }
                bool asssemblyFound = false;
                string pathsSearched = "";

                foreach (string searchPath in SharedData.AssemblySearchPaths)
                {
                    pathsSearched += searchPath + Environment.NewLine;
                    string filePath = Path.Combine(searchPath, currentPath);

                    if (File.Exists(filePath))
                    {
                        log.DebugFormat("Loading Provider from {0}", filePath);
                        asssemblyFound = true;
                        providerAssemblyFiles.Add(filePath);
                        break;
                    }
                }

                ReferencedAssemblyPaths.AddRange(providerAssemblyFiles.ToArray());

                if (!asssemblyFound)
                {
                    if (MessageBox.Show(string.Format("'{0}' can't be located. The following folders have been searched: \n\n{1}\nDo you want to locate this file?", currentPath, pathsSearched), "File not found - Loading Project", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        OpenFileDialog openFileDialog = new OpenFileDialog();
                        openFileDialog.FileName = currentPath;

                        if (openFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            if (File.Exists(openFileDialog.FileName))
                            {
                                // Add this path to the search paths, because related assemblies might be in here as well.
                                SharedData.AddAssemblySearchPath(Path.GetDirectoryName(openFileDialog.FileName));
                                providerAssemblyFiles.Add(openFileDialog.FileName);
                                asssemblyFound = true;
                            }
                        }
                    }
                    if (!asssemblyFound)
                    {
                        throw new FileNotFoundException(string.Format("Referenced assembly not found: {0}\n\nPlease make sure the assembly exists in one of these folders:{1}", currentPath, pathsSearched));
                    }
                }
            }

            LoadReferencedAssemblies();
            LoadAndFillProviders();

            #endregion

            #region User Options
            XmlNodeList nodes = doc.SelectNodes("ROOT/config/project/options/option");
            _Options.Clear();

            if (nodes != null)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode subNode = nodes[i];
                    Option opt = new Option();
                    _Options.Add(opt);
                    opt.Description = subNode.SelectSingleNode("description").InnerText;
                    opt.Text = subNode.SelectSingleNode("text").InnerText;
                    opt.VariableName = subNode.SelectSingleNode("variablename").InnerText;
                    opt.VarType = GetTypeFromReferencedAssemblies(subNode.SelectSingleNode("type").InnerText, true);
                    opt.Category = subNode.SelectSingleNode("category").InnerText.Replace("_", " ");
                    opt.DefaultValue = subNode.SelectSingleNode("defaultvalue") != null ? subNode.SelectSingleNode("defaultvalue").InnerText : "";
                    opt.DefaultValueIsFunction = subNode.SelectSingleNode("defaultvalueisfunction") != null ? bool.Parse(subNode.SelectSingleNode("defaultvalueisfunction").InnerText) : false;
                    opt.IteratorName = subNode.SelectSingleNode("iteratorname") != null ? subNode.SelectSingleNode("iteratorname").InnerText : "";
                    opt.ValidatorFunction = subNode.SelectSingleNode("validatorfunction") != null ? subNode.SelectSingleNode("validatorfunction").InnerText : "";
                    opt.ResetPerSession = subNode.SelectSingleNode("resetpersession") != null ? bool.Parse(subNode.SelectSingleNode("resetpersession").InnerText) : false;

                    opt.IsValidValue = null;

                    if (subNode.SelectSingleNode("isvalidvalue") != null && !string.IsNullOrEmpty(subNode.SelectSingleNode("isvalidvalue").InnerText))
                    {
                        opt.IsValidValue = bool.Parse(subNode.SelectSingleNode("isvalidvalue").InnerText);
                    }
                    opt.DisplayToUserValue = null;

                    if (subNode.SelectSingleNode("displaytouserfunction") != null)
                    {
                        opt.DisplayToUserFunction = subNode.SelectSingleNode("displaytouserfunction").InnerText;
                    }

                    XmlNodeList valueNodes = subNode.SelectNodes("values/value");
                    if (valueNodes != null)
                    {
                        opt.EnumValues = new string[valueNodes.Count];

                        for (int x = 0; x < valueNodes.Count; x++)
                        {
                            opt.EnumValues[x] = valueNodes[x].InnerText;
                        }
                    }
                    else
                    {
                        opt.EnumValues = new string[0];
                    }
                }
            }
            #endregion

            #region Default Value Functions
            nodes = doc.SelectNodes("ROOT/config/project/defaultvaluefunctions/defaultvaluefunction");
            _DefaultValueFunctions.Clear();

            if (nodes != null)
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode subNode = nodes[i];
                    DefaultValueFunction defaultValueFunction = new DefaultValueFunction();
                    defaultValueFunction.ObjectType = GetTypeFromReferencedAssemblies(subNode.SelectSingleNode("objecttype").InnerText, true);
                    defaultValueFunction.PropertyName = subNode.SelectSingleNode("propertyname").InnerText;
                    defaultValueFunction.UseCustomCode = bool.Parse(subNode.SelectSingleNode("usecustomcode").InnerText);
                    defaultValueFunction.FunctionType = (FunctionTypes)Enum.Parse(typeof(FunctionTypes), subNode.SelectSingleNode("functiontype").InnerText, true);
                    _DefaultValueFunctions.Add(defaultValueFunction);
                }

            #endregion

            #region Outputs
            XmlNode rootFolderNode = doc.SelectSingleNode("ROOT/config/project/rootoutput/rootfolder");

            CombinedOutput = new Output();
            CombinedOutput.RootFolder = new Folder();
            CombinedOutput.RootFolder.Name = "Root";
            CombinedOutput.Name = "Combined";

            Output output = new Output();
            _Outputs.Add(output);
            output.RootFolder = new Folder();
            output.RootFolder.Name = "Root";
            output.Name = "";
            ProcessFolderNode(rootFolderNode, output.RootFolder);
            ProcessFolderNode(rootFolderNode, CombinedOutput.RootFolder);
            #endregion
        }