Example #1
0
 public void ParseTimeFromContentStringWithException()
 {
     Assert.Throws <InvalidOperationException>(
         () =>
         SRT.ParseTimeFromContent("0:0:4,200", out var _, out var _)
         );
 }
Example #2
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     if (!IsStart)
     {
         Method.AddRanmodProcess();
         Init();
     }
     else
     {
         if (Method.ProcessArray.Count < 10)
         {
             Eprocess p     = new Eprocess();
             var      seed  = Guid.NewGuid().GetHashCode();
             Random   r     = new Random(seed);
             int      Rname = r.Next(1, 10000);
             // 增加相同id的重新分配
             int Rprimary = r.Next(50, 100);
             int Rtimes   = r.Next(1, 50);
             p.status  = 1;
             p.name    = Rname;
             p.primary = Rprimary;
             p.times   = Rtimes;
             RR.Add(new Eprocess(p.name, p.status, p.primary, p.times));
             DP.Add(new Eprocess(p.name, p.status, p.primary, p.times));
             SRT.Add(new Eprocess(p.name, p.status, p.primary, p.times));
             SPN.Add(new Eprocess(p.name, p.status, p.primary, p.times));
         }
     }
 }
Example #3
0
        public void ParseTimeFromContentString()
        {
            SRT.ParseTimeFromContent("0:0:4,200 --> 0:0:8,200", out var startTime, out var endTime);

            Assert.AreEqual(4.200d, startTime);
            Assert.AreEqual(8.200d, endTime);
        }
Example #4
0
 static void DestInit(SelectDest dest, SRT dest2, int parmId)
 {
     dest.Dest = dest2;
     dest.SDParmId = parmId;
     dest.AffSdst = '\0';
     dest.SdstId = 0;
     dest.Sdsts = 0;
 }
Example #5
0
        ///<summary>
        /// Returns a single repetition of Sort-by Field(RCP-6).
        /// throws HL7Exception if the repetition number is invalid.
        /// <param name="rep">The repetition number (this is a repeating field)</param>
        ///</summary>
        public SRT GetSortByField(int rep)
        {
            SRT ret = null;

            try
            {
                IType t = this.GetField(6, rep);
                ret = (SRT)t;
            } catch (System.Exception ex) {
                HapiLogFactory.GetHapiLog(GetType()).Error("Unexpected problem obtaining field value.  This is a bug.", ex);
                throw new System.Exception("An unexpected error ocurred", ex);
            }
            return(ret);
        }
Example #6
0
        /// <summary> Returns a single repetition of Sort-by Field (RCP-6).</summary>
        /// <param name="rep">the repetition number (this is a repeating field)
        /// </param>
        /// <throws>  HL7Exception if the repetition number is invalid. </throws>
        public virtual SRT getSortByField(int rep)
        {
            SRT ret = null;

            try
            {
                Type t = this.getField(6, rep);
                ret = (SRT)t;
            }
            catch (System.InvalidCastException)
            {
                throw new Exception();
            }
            return(ret);
        }
Example #7
0
 ///<summary>
 /// Returns all repetitions of Sort-by Field (RCP-6).
 ///</summary>
 public SRT[] GetSortByField()
 {
     SRT[] ret = null;
     try {
         IType[] t = this.GetField(6);
         ret = new SRT[t.Length];
         for (int i = 0; i < ret.Length; i++)
         {
             ret[i] = (SRT)t[i];
         }
     } catch (HL7Exception he) {
         HapiLogFactory.GetHapiLog(this.GetType()).Error("Unexpected problem obtaining field value.  This is a bug.", he);
         throw new System.Exception("An unexpected error ocurred", he);
     } catch (System.Exception cce) {
         HapiLogFactory.GetHapiLog(GetType()).Error("Unexpected problem obtaining field value.  This is a bug.", cce);
         throw new System.Exception("An unexpected error ocurred", cce);
     }
     return(ret);
 }
Example #8
0
        public void ParseSubtitlesFromSRTContents()
        {
            var subtitles =
                SRT.ParseSubtitlesFromString(MOCK_SUBTITLE_CONTENTS);

            Assert.AreEqual(1, subtitles[0].id);
            Assert.AreEqual(4.200d, subtitles[0].startTime);
            Assert.AreEqual(8.200d, subtitles[0].endTime);
            Assert.AreEqual("Hello, world.", subtitles[0].text);

            Assert.AreEqual(4, subtitles[3].id);
            Assert.AreEqual(32.200d, subtitles[3].startTime);
            Assert.AreEqual(36.200d, subtitles[3].endTime);
            Assert.AreEqual("If you can see me,\ncan you wave?", subtitles[3].text);

            Assert.AreEqual(5, subtitles[4].id);
            Assert.AreEqual(40.200d, subtitles[4].startTime);
            Assert.AreEqual(44.200d, subtitles[4].endTime);
            Assert.AreEqual("Fine. If you can't wave, just yell out.", subtitles[4].text);
        }
Example #9
0
 /// <summary> Returns all repetitions of Sort-by Field (RCP-6).</summary>
 public virtual SRT[] getSortByField()
 {
     SRT[] ret = null;
     try
     {
         Type[] t = this.getField(6);
         ret = new SRT[t.Length];
         for (int i = 0; i < ret.Length; i++)
         {
             ret[i] = (SRT)t[i];
         }
     }
     catch (System.InvalidCastException)
     {
         throw new Exception();
     }
     catch (NuGenHL7Exception)
     {
         throw new Exception();
     }
     return(ret);
 }
Example #10
0
        private SRT getSRTFromText(string input)
        {
            SRT result = new SRT();


            using (StringReader reader = new StringReader(input))
            {
                string line;
                for (int i = 0; i < 5 && ((line = reader.ReadLine()) != null); i++)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        i--;
                    }
                    else
                    {
                        switch (i)
                        {
                        case 0: result.SRTId = int.Parse(line);
                            break;

                        case 1:
                            var splitedTime = line.Split(new string[] { "-->" }, StringSplitOptions.None);
                            result.StartDate = DateTime.ParseExact(splitedTime[0].Trim(), "HH:mm:ss,fff",
                                                                   CultureInfo.InvariantCulture);
                            result.EndDate = DateTime.ParseExact(splitedTime[1].Trim(), "HH:mm:ss,fff",
                                                                 CultureInfo.InvariantCulture);
                            break;

                        default:
                            result.Translation += line;
                            break;
                        }
                    }
                }
            }
            result.SetInterval();
            return(result);
        }
Example #11
0
        private void running()
        {
            int time_quantum = Convert.ToInt32(lfMenu.sliderTimequantum.Value);
            //data = get_data();        // 얕은 복사 실행(이 코드에선 사용금지)
            List <ProcessData> tmp = GenericCopier <List <ProcessData> > .DeepCopy(get_data());    // 깊은 복사 실행

            if (!checkValues(tmp))
            {
                MessageBox.Show("테이블 값의 범위는 우선순위 0~9, 나머지는 1~30 이어야 합니다.\n확인 후 다시 작업을 요청하십시오.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List <ProcessData> data_fcfs = GenericCopier <List <ProcessData> > .DeepCopy(tmp);   // 깊은 복사 실행

            List <ProcessData> data_sjf = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            List <ProcessData> data_srt = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            List <ProcessData> data_hrn = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            List <ProcessData> data_prio = GenericCopier <List <ProcessData> > .DeepCopy(tmp);   // 깊은 복사 실행

            List <ProcessData> data_rrb = GenericCopier <List <ProcessData> > .DeepCopy(tmp);    // 깊은 복사 실행

            fcfs = new FCFS(data_fcfs);
            sjf  = new SJF(data_sjf);
            srt  = new SRT(data_srt);
            hrn  = new HRN(data_hrn);
            prio = new Priority(data_prio);
            rrb  = new RoundRobin(data_rrb, time_quantum);

            List <ProcessData> temp;

            switch (select_flag)
            {
            case ( int )proc.FCFS:
                temp = fcfs.working();
                sjf.working(); srt.working(); hrn.working();
                prio.working(); rrb.working();
                calc_time(fcfs.get_wait_time(), fcfs.get_return_time());
                break;

            case ( int )proc.SJF:
                temp = sjf.working();
                fcfs.working(); srt.working();
                hrn.working(); prio.working(); rrb.working();
                calc_time(sjf.get_wait_time(), sjf.get_return_time());
                break;

            case ( int )proc.SRT:
                temp = srt.working();
                fcfs.working(); sjf.working();
                hrn.working(); prio.working(); rrb.working();
                calc_time(srt.get_wait_time(), srt.get_return_time());
                break;

            case ( int )proc.HRN:
                temp = hrn.working();
                fcfs.working(); sjf.working(); srt.working();
                prio.working(); rrb.working();
                calc_time(hrn.get_wait_time(), hrn.get_return_time());
                break;

            case ( int )proc.PRIORITY:
                temp = prio.working();
                fcfs.working(); sjf.working(); srt.working();
                hrn.working(); rrb.working();
                calc_time(prio.get_wait_time(), prio.get_return_time());
                break;

            case ( int )proc.ROUNDROBIN:
                temp = rrb.working();
                fcfs.working(); sjf.working(); srt.working();
                hrn.working(); prio.working();
                calc_time(rrb.get_wait_time(), rrb.get_return_time());
                break;

            default:
                MessageBox.Show("올바르지 않은 접근입니다.\n확인 후 다시 작업을 요청하십시오.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            wait_time[( int )proc.FCFS - 1]       = Convert.ToDouble(string.Format("{0:#0.00}", fcfs.avg_wait()));
            wait_time[( int )proc.SJF - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", sjf.avg_wait()));
            wait_time[( int )proc.SRT - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", srt.avg_wait()));
            wait_time[( int )proc.HRN - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", hrn.avg_wait()));
            wait_time[( int )proc.PRIORITY - 1]   = Convert.ToDouble(string.Format("{0:#0.00}", prio.avg_wait()));
            wait_time[( int )proc.ROUNDROBIN - 1] = Convert.ToDouble(string.Format("{0:#0.00}", rrb.avg_wait()));

            return_time[( int )proc.FCFS - 1]       = Convert.ToDouble(string.Format("{0:#0.00}", fcfs.avg_return()));
            return_time[( int )proc.SJF - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", sjf.avg_return()));
            return_time[( int )proc.SRT - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", srt.avg_return()));
            return_time[( int )proc.HRN - 1]        = Convert.ToDouble(string.Format("{0:#0.00}", hrn.avg_return()));
            return_time[( int )proc.PRIORITY - 1]   = Convert.ToDouble(string.Format("{0:#0.00}", prio.avg_return()));
            return_time[( int )proc.ROUNDROBIN - 1] = Convert.ToDouble(string.Format("{0:#0.00}", rrb.avg_return()));

            ProcessUpdate(temp);
            WaitUpdate();
            ReturnUpdate();
        }
Example #12
0
 private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     SRT.Run();
 }
Example #13
0
 public void ParseMillisecondsFromTimeStampString()
 {
     Assert.AreEqual(4200d, SRT.ParseMillisecondsFromTimestamp("0:0:4,200"));
 }
Example #14
0
    public bool Load(string path)
    {
        // Handle any problems that might arise when reading the text
        try
        {
            string line;
            // Create a new StreamReader, tell it which file to read and what encoding the file
            // was saved as
            StreamReader theReader = new StreamReader(path, Encoding.UTF8);

            // Immediately clean up the reader after this block of code is done.
            // You generally use the "using" statement for potentially memory-intensive objects
            // instead of relying on garbage collection.
            // (Do not confuse this with the using directive for namespace at the
            // beginning of a class!)
            using (theReader)
            {
                readState state;
                state = readState.srtNumber;
                string temp     = "";
                float  diffTime = 0;
                // While there's lines left in the text file, do this:
                do
                {
                    line = theReader.ReadLine();
                    if (line != null)
                    {
                        line = line.Trim();
                        switch (state)
                        {
                        case readState.srtNumber:
                            state = readState.time;
                            break;

                        case readState.time:
                            string[] entries = line.Split(new string[] { "-->" }, System.StringSplitOptions.None);
                            if (entries.Length > 0)
                            {
                                Debug.Log("initial Time : " + getTime(entries[0]));
                                Debug.Log("final Time : " + getTime(entries[1]));
                            }
                            diffTime = getTime(entries[1]) - getTime(entries[0]);
                            state    = readState.text;
                            break;

                        case readState.text:
                            if (line.Equals(""))
                            {
                                state = readState.srtNumber;
                                Debug.Log("text : " + temp);
                                srtArray.Add(SRT.CreateInstance(temp, diffTime));
                                temp = "";
                            }
                            else
                            {
                                temp = temp + " " + line;
                            }
                            break;
                        }
                    }
                }while (line != null);
                Debug.Log("text : " + temp);
                srtArray.Add(SRT.CreateInstance(temp, diffTime));
                // Done reading, close the reader and return true to broadcast success
                theReader.Close();
                return(true);
            }
        }

        // If anything broke in the try block, we throw an exception with information
        // on what didn't work
        catch (IOException e)
        {
            Debug.LogError("Error : " + e.Data.ToString());
            return(false);
        }
    }