Exemple #1
0
        static void Main(string[] args)
        {
            Time t1 = new Time();

            t1.Parse("00:01:45,000");
            
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+1000ms");
            t1.AddMil(1000);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+1s");
            t1.AddSec(1);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+40s");
            t1.AddSec(40);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+59mn");
            t1.AddMin(59);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+3600000ms");
            t1.AddMil(3600000);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t-29s");
            t1.AddSec(-29);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+29s");
            t1.AddSec(29);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t+63m");
            t1.AddMin(63);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t-63m");
            t1.AddMin(-63);
            Console.WriteLine("t1 = " + t1.ToString() + "\n\t-1000ms");
            t1.AddMil(-1000);
            Console.WriteLine("t1 = " + t1.ToString());
            

            Console.WriteLine("Press key ");
            Console.ReadKey();
        }
Exemple #2
0
        public bool ResynkLines(string[] lines)
        {
            if ((_isTestMode && _window != null) || (!_isTestMode && _window == null))
            {
                Debug.WriteLine("\tError with window or testMode...");
                return false;
            }

            int cpt = 1;

            /*
            cTime tapartirde = new cTime();
            
            if(!tapartirde.Parse(apartirde))
                return;
            */

            // Chiffre seul
            string patternC = @"^[0-9]+$";
            // Temps => 00:00:00,000 --> 00:00:00,000
            string patternT = @"^([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3})\s?$";

            // Instantiate the regular expression object.
            Regex chi = new Regex(patternC, RegexOptions.IgnoreCase);
            Regex tps = new Regex(patternT, RegexOptions.IgnoreCase);

            // output file
            //System.IO.StreamWriter file = new System.IO.StreamWriter(path + "\\" + ofile);

            FileStream fs = null;
            StreamWriter file = StreamWriter.Null;
            if (!_isTestMode)
            {
                fs = File.Create(this._path + "\\" + this._ofile);
                file = new StreamWriter(fs, this._enc);
            }

            int total = this.GetNb(lines, chi);

            if (!_isTestMode && _window != null)
                _window.Pb.Visibility = System.Windows.Visibility.Visible;

            foreach (string line in lines)
            {
                string ligne = line;

                //si ligne de chiffre
                if (chi.Match(line).Success)
                {
                    if (int.Parse(line) != cpt)
                        ligne = cpt.ToString();
                    ++cpt;

                    // StatusBar
                    // binding???
                    if (_window != null)
                    {
                        _window.Percent = cpt*100.0/total;
                        _window.Pb.Value = _window.Percent;
                    }
                }

                Match m = tps.Match(line);

                if (m.Success) //si ligne de temps
                {
                    string tps1 = m.Groups[1].ToString();
                    string tps2 = m.Groups[2].ToString();

                    Time ti1 = new Time();
                    ti1.Parse(tps1);

                    Time ti2 = new Time();
                    ti2.Parse(tps2);

                    if (ti1 >= this._tapartirde)
                    {
                        ti1.AddMil(this._milToAdd);
                        ti2.AddMil(this._milToAdd);

                        ligne = ti1.ToString() + " --> " + ti2.ToString();
                    }
                }

                if (!_isTestMode)
                    file.WriteLine(ligne);
                else
                    TestContent.Add(ligne);
            }

            // ReSharper disable once InvertIf
            if (!_isTestMode && fs != null)
            {
                file.Close();
                fs.Close();
            }

            return true;
        }
Exemple #3
0
        public bool ResynkLines(string[] lines)
        {
            if ((_isTestMode && _window != null) || (!_isTestMode && _window == null))
            {
                Debug.WriteLine("\tError with window or testMode...");
                return(false);
            }

            int cpt = 1;

            /*
             * cTime tapartirde = new cTime();
             *
             * if(!tapartirde.Parse(apartirde))
             *  return;
             */

            // Chiffre seul
            string patternC = @"^[0-9]+$";
            // Temps => 00:00:00,000 --> 00:00:00,000
            string patternT = @"^([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3})\s?$";

            // Instantiate the regular expression object.
            Regex chi = new Regex(patternC, RegexOptions.IgnoreCase);
            Regex tps = new Regex(patternT, RegexOptions.IgnoreCase);

            // output file
            //System.IO.StreamWriter file = new System.IO.StreamWriter(path + "\\" + ofile);

            FileStream   fs   = null;
            StreamWriter file = StreamWriter.Null;

            if (!_isTestMode)
            {
                fs   = File.Create(this._path + "\\" + this._ofile);
                file = new StreamWriter(fs, this._enc);
            }

            int total = this.GetNb(lines, chi);

            if (!_isTestMode && _window != null)
            {
                _window.Pb.Visibility = System.Windows.Visibility.Visible;
            }

            foreach (string line in lines)
            {
                string ligne = line;

                //si ligne de chiffre
                if (chi.Match(line).Success)
                {
                    if (int.Parse(line) != cpt)
                    {
                        ligne = cpt.ToString();
                    }
                    ++cpt;

                    // StatusBar
                    // binding???
                    if (_window != null)
                    {
                        _window.Percent  = cpt * 100.0 / total;
                        _window.Pb.Value = _window.Percent;
                    }
                }

                Match m = tps.Match(line);

                if (m.Success) //si ligne de temps
                {
                    string tps1 = m.Groups[1].ToString();
                    string tps2 = m.Groups[2].ToString();

                    Time ti1 = new Time();
                    ti1.Parse(tps1);

                    Time ti2 = new Time();
                    ti2.Parse(tps2);

                    if (ti1 >= this._tapartirde)
                    {
                        ti1.AddMil(this._milToAdd);
                        ti2.AddMil(this._milToAdd);

                        ligne = ti1.ToString() + " --> " + ti2.ToString();
                    }
                }

                if (!_isTestMode)
                {
                    file.WriteLine(ligne);
                }
                else
                {
                    TestContent.Add(ligne);
                }
            }

            // ReSharper disable once InvertIf
            if (!_isTestMode && fs != null)
            {
                file.Close();
                fs.Close();
            }

            return(true);
        }