Ejemplo n.º 1
0
        /// <summary>
        /// Adds the algorithms stored on disk and in the SCRIPTS.RESX file.
        /// </summary>
        private static void PopulateFiles <T>(AlgoCollection <T> targetCollection, UiControls.EInitialFolder searchFolder, Delegate_Constructor <T> constructorMethod)
            where T : AlgoBase
        {
            string folder         = UiControls.GetOrCreateFixedFolder(searchFolder);
            string resourcePrefix = "scripts~" + Path.GetFileName(folder).ToLower() + "~";

            ResourceSet resources = UiControls.GetScriptsResources();

            // Search Scripts.resx
            foreach (DictionaryEntry resource in resources)
            {
                string key = (string)resource.Key;

                if (key.StartsWith(resourcePrefix))
                {
                    string subPart = key.Substring(resourcePrefix.Length);
                    string id      = GetId(searchFolder, subPart, true);
                    targetCollection.Add(constructorMethod(Encoding.UTF8.GetString((byte[])resource.Value), id, subPart.Replace("_", " "), null));
                }
            }

            // Search folder
            foreach (string fileName in Directory.GetFiles(folder, "*.r"))
            {
                string id   = GetId(searchFolder, fileName, false);
                string name = Path.GetFileName(fileName);
                targetCollection.Add(constructorMethod(File.ReadAllText(fileName), id, name, fileName));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Retrieves/generates the ID for a script based algorithm loaded from disk.
 /// </summary>
 /// <param name="folder">Folder the script is in (one of the FOLDER_* constants)</param>
 /// <param name="fileName">Full or partial filename of the script</param>
 /// <param name="isInternal">Is internal (part of Scripts.resx)</param>
 /// <returns>The ID</returns>
 public static string GetId(UiControls.EInitialFolder folder, string fileName, bool isInternal)
 {
     if (isInternal)
     {
         return("RES:" + folder.ToUiString().ToUpper() + "\\" + Path.GetFileNameWithoutExtension(fileName));
     }
     else
     {
         return("FILE:" + folder.ToUiString().ToUpper() + "\\" + Path.GetFileNameWithoutExtension(fileName));
     }
 }
Ejemplo n.º 3
0
        internal static string Show(Form owner, string title, string inputTable, UiControls.EInitialFolder folder, string fileName, bool workOnCopy, string defaultContent, bool readOnly)
        {
            using (FrmInputScript frm = new FrmInputScript(title, inputTable, folder, fileName, workOnCopy, defaultContent, readOnly))
            {
                if (UiControls.ShowWithDim(owner, frm) == DialogResult.OK)
                {
                    return(frm._fileName);
                }

                return(null);
            }
        }
Ejemplo n.º 4
0
        public FrmInputScript(string title, string inputTable, UiControls.EInitialFolder saveFolder, string fileName, bool workOnCopy, string defaultContent, bool readOnly)
            : this()
        {
            this.Text           = "Script Editor";
            this._titleBar.Text = title;
            this._saveFolder    = saveFolder;

            RScript.RScriptMarkup markup = new RScript.RScriptMarkup(inputTable);

            StringBuilder defaultCode = new StringBuilder();
            StringBuilder helpText    = new StringBuilder();

            helpText.AppendLine(title.ToUpper() + " OUTLINE");
            helpText.AppendLine(markup.Summary);
            helpText.AppendLine();

            foreach (RScript.RScriptMarkupElement element in markup.Inputs)
            {
                defaultCode.AppendLine("## " + element.Name + " = " + element.Key);

                helpText.AppendLine(element.Key.PadRight(16) + ": " + element.Comment);

                if (element.Name == "-")
                {
                    helpText.AppendLine(new string( ' ', 16 ) + "  Not available by default.");
                }
                else
                {
                    helpText.AppendLine(new string( ' ', 16 ) + "  Default name: " + element.Name);
                }

                helpText.AppendLine();
            }

            helpText.AppendLine("EXPECTED RESULT".PadRight(16) + ": " + markup.ReturnValue);
            helpText.AppendLine();
            helpText.AppendLine(Resx.Manual.RScript);
            this._titleBar.HelpText = helpText.ToString();

            defaultCode.AppendLine();

            this._titleBar.SubText = "Enter an R script. Click the help button to see the available inputs.";

            if (string.IsNullOrEmpty(defaultContent))
            {
                this.textBox1.Text = defaultCode.ToString();
            }
            else
            {
                this.textBox1.Text = defaultContent;
            }

            if (string.IsNullOrEmpty(fileName))
            {
                this.toolStripStatusLabel1.Text = "NEW FILE";
            }
            else if (workOnCopy)
            {
                this.toolStripStatusLabel1.Text = "COPY OF: " + fileName;
            }
            else
            {
                this._fileName = fileName;
                this.toolStripStatusLabel1.Text = fileName;
            }

            if (readOnly)
            {
                this._btnOk.Visible    = false;
                this.btnCancel.Text    = "Close";
                this.textBox1.ReadOnly = true;
            }

            // UiControls.CompensateForVisualStyles(this);
        }
Ejemplo n.º 5
0
 private void Edit(UiControls.EInitialFolder folder)
 {
     this._result      = folder;
     this.DialogResult = DialogResult.OK;
 }