Esempio n. 1
0
        /// <summary>
        /// Loads code from a file, must be in native format
        /// </summary>
        /// <param name="Filename">Filename to load from</param>
        public void LoadScript(string Filename)
        {
            if (!System.IO.File.Exists(Filename))
            {
                MessageBox.Show(string.Format(Properties.Resources.FileDoesNotExist, Filename), Properties.Resources.FileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (UnsavedScript)
            {
                if (MessageBox.Show(Properties.Resources.EraseAndContinueLoading, Properties.Resources.Confirmation,MessageBoxButtons.YesNo)==DialogResult.No)
                {
                    return;
                }
            }

            try
            {
                Settings scriptfile = new Settings(Filename);

                string scriptlang = scriptfile.GetSetting("CodeLanguage","CSharp");
                if (scriptlang != settings.CodeLanguage.ToString())
                {
                    MessageBox.Show(Properties.Resources.LoadedCodeInDifferentLang,Properties.Resources.CodeLanguage,MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                string[] arrTestNames = scriptfile.GetSetting("Tests", "").Split(Environment.NewLine.ToCharArray());

                RecordedTests.Clear();

                for (int i = 0; i < arrTestNames.Length; i++)
                {
                    if (arrTestNames[i].Trim()=="")
                    {
                        continue;
                    }
                    RecordedTests.Add(arrTestNames[i], scriptfile.GetSetting(arrTestNames[i], ""));
                }

                string[] arrAssemblies = scriptfile.GetSetting("Assemblies", "").Split(Environment.NewLine.ToCharArray());
                for (int i = 0; i < arrAssemblies.Length; i++)
                {
                    if (arrAssemblies[i].Trim() != "")
                    {
                        FunctionAssemblies.Add(arrAssemblies[i]);
                    }
                }

                UnsavedScript = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
Esempio n. 2
0
        /// <summary>
        /// Saves the test script using the "native" format
        /// Only the native format can be loaded
        /// </summary>
        /// <param name="Filename">Filename to save to</param>
        public void SaveScript(string Filename)
        {
            if (System.IO.File.Exists(Filename))
            {
                System.IO.File.Delete(Filename);
            }

            try
            {
                Settings scriptfile = new Settings(Filename);
                StringBuilder sbTestNames = new StringBuilder();
                for (int i = 0; i < RecordedTests.Count; i++)
                {
                    sbTestNames.AppendLine(RecordedTests.GetKey(i));
                    scriptfile.PutSetting(RecordedTests.GetKey(i), RecordedTests[i]);
                }
                string strAssemblies = Template.JoinList(FunctionAssemblies);

                scriptfile.PutSetting("Tests", sbTestNames.ToString());
                scriptfile.PutSetting("CodeLanguage", settings.CodeLanguage.ToString());
                scriptfile.PutSetting("Assemblies", strAssemblies);

                UnsavedScript = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Properties.Resources.SaveErrorNotSaved, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }