Example #1
0
        /// <summary>
        /// Reads a test Sequence file from the grade dir and writes to TesterObject.
        /// To write file from Jade, call bladeFileWrite and then this.
        /// </summary>
        /// <param name="NewConfig"></param>
        public void SetConfig(string NewConfig)
        {
            FileStream fs1 = null;

            try
            {
                WriteLine("SetConfig called " + NewConfig);
                // Translate into a real path.
                string fromWholePath = fixUpThePaths(NewConfig);

                // Get destination dir (from our translated path).
                string destinationDir = Path.GetDirectoryName(fromWholePath);
                // Does it exist?
                if (!Directory.Exists(destinationDir))
                {
                    WriteLineContent("SetConfig Source dir does not exist " + destinationDir);
                    return;
                }
                // Open file stream.
                fs1 = new FileStream(fromWholePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                TestSequence newSequence = new TestSequence();
                // Read file into sequence struct.
                newSequence.ReadInTests((Stream)fs1, false);
                fs1.Close();

                // Set fileName (was changed when writing to temp file before getting here).
                newSequence.FileName = Path.GetFileNameWithoutExtension(fromWholePath);

                // if saving this struct then wait
                while (_SavingSettings)
                {
                    if (_Exit || _Escape)
                    {
                        return;
                    }
                    Application.DoEvents();
                    Thread.Sleep(10);
                }

                // if already doing then wait
                while (_SetConfigGoing)
                {
                    if (_Exit || _Escape)
                    {
                        return;
                    }
                    Application.DoEvents();
                    Thread.Sleep(10);
                }
                _SetConfigGoing = true;

                // Remove any old instances of this sequence name.
                for (int i = 0; i < _CurrentSequenceList.Count; i++)
                {
                    // get one sequence from the list.
                    TestSequence testSeq = _CurrentSequenceList[i];
                    // See it this is the same name
                    if (testSeq.FileName == newSequence.FileName)
                    {
                        // If the name is the same as new one then delete old.
                        _CurrentSequenceList.RemoveAt(i);
                        i--;
                    }
                }

                // add new one
                _CurrentSequenceList.Add(newSequence);
                WriteLineContent("File read from: " + fromWholePath);
                // SaveSettings();
            }
            catch (Exception e) // Catch for debug; can comment out.
            {
                throw e;
            }
            finally
            {
                _SetConfigGoing = false;
                if (fs1 != null)
                {
                    try
                    {
                        fs1.Dispose();
                    }
                    catch { }
                }
            }
        }