Beispiel #1
0
        public static void test()
        {
            SettingsModal data = new SettingsModal();

            CommandModel cmd1 = new CommandModel();

            cmd1.Name      = "Test";
            cmd1.ParamList = new string[] { "File Name", "Password" };
            cmd1.Help      = "<h3>Test</h3><p>Creates an Excel file with the contents of the clipboard. Has two params.</p><dl><dt>File Name <span class='label label-default'>optional</span></dt><dd>File name to use when creating Excel file. If file name is not provide, a temp file name will be created.</dd><dt>Password <span class='label label-default'>optional</span></dt>  <dd>Encrypt file using this password.</dd></dl>";

            cmd1.SourceCode =
                @"
                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                using System.Windows.Forms;
                public class Script
                {
                    public bool Execute(string[] args)
                    {
                        string text = Clipboard.GetText();
                        if ( !string.IsNullOrWhiteSpace( text ) )
                        {
                            Clipboard.SetText(text.ToUpper(), TextDataFormat.Text);
                        }
                        return true;
                    }
                }";

            data.Commands.Add(cmd1);
            SaveSettings(data);
        }
Beispiel #2
0
        public static bool SaveSettings(SettingsModal data)
        {
            bool retVal = false;

            string json         = JsonConvert.SerializeObject(data, new IsoDateTimeConverter());
            string path         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string fullFileName = string.Format("{0}\\{1}", path, "sugar.json");

            json.SaveAsTextFile(fullFileName);

            EventManager.Instance.FireSettingsChangedEvent();

            return(retVal);
        }
Beispiel #3
0
        public static SettingsModal LoadSettings()
        {
            SettingsModal retVal       = null;
            string        path         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string        fullFileName = string.Format("{0}\\{1}", path, "sugar.json");

            try
            {
                String json = "";
                using (StreamReader sr = new StreamReader(fullFileName))
                {
                    json = sr.ReadToEnd();
                }

                retVal = JsonConvert.DeserializeObject <SettingsModal>(json);
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            return(retVal);
        }