Beispiel #1
0
 public void goon5(LinearTimeCode ltc)
 {
     Console.WriteLine();
     Console.WriteLine(ltc.fps.ToString());
     Console.WriteLine(ltc.ToString());
     for (int i = 1; i < 5; i++)
     {
         ltc.nextFrame();
         Console.WriteLine(ltc.ToString());
     }
 }
        private void NewAsrunEvent(object sender, System.IO.FileSystemEventArgs e)
        {
            int numFilesInThisPass = 0;

            do
            {
                DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(e.FullPath));
                // Create an array representing the files in the current directory.
                FileInfo[] fi = di.GetFiles();
                foreach (FileInfo fiTemp in fi)
                {
                    if (fiTemp.Extension.Equals(".xml"))
                    {
                        string  thisFilePath = fiTemp.FullName;
                        DataSet dsAsrun      = new DataSet("asrun");
                        int     fps;
                        try
                        {
                            dsAsrun.ReadXml(thisFilePath, XmlReadMode.InferSchema);
                            // TODO: Look at good way of getting round this.
                            // currently user is Local Service, which can't delete files.
                            File.Delete(thisFilePath);
                            archiveDataset(dsAsrun);
                            numberOfAsrunFiles++;
                            numFilesInThisPass++;
                            // Look up channel name against dsChannels dataset
                            DataView dvChannel = new DataView(dsChannels.Tables["channels"], "",
                                                              "name", DataViewRowState.CurrentRows);
                            DataTable dtAsrun = dsAsrun.Tables["AsRun"];
                            foreach (DataRow drAsrun in dtAsrun.Rows)
                            {                             // There can be more than one row entered in one file on asrun log.
                                int rowIndex = dvChannel.Find(drAsrun["channel"].ToString());
                                if (rowIndex == -1)
                                {
                                    WriteLogEntry("error", "Invalid Channel : " + thisFilePath);
                                }
                                else
                                {
                                    int channel_id = Int32.Parse(dvChannel[rowIndex]["id"].ToString());
                                    fps = Int32.Parse(dvChannel[rowIndex]["fps"].ToString());
                                    DateTime start_tc = new LinearTimeCode(fps,
                                                                           drAsrun["startDate"].ToString(),
                                                                           drAsrun["startTimeCode"].ToString()).dt;
                                    DateTime end_tc = new LinearTimeCode(fps,
                                                                         drAsrun["startDate"].ToString(),
                                                                         drAsrun["startTimeCode"].ToString()).dt;
                                    long   duration  = ConvertToFrames(drAsrun["duration"].ToString(), fps);
                                    int    offset    = 0;                               // The offset will be added later.
                                    int    isblank   = 0;                               // Not blank, obviously!
                                    string id        = drAsrun["id"].ToString();
                                    string title     = drAsrun["title"].ToString();
                                    string s         = drAsrun["s"].ToString();
                                    string status    = drAsrun["status"].ToString();
                                    string ch        = drAsrun["ch"].ToString();
                                    string reconcile = drAsrun["reconcile"].ToString();
                                    string ty        = drAsrun["ty"].ToString();
                                    // Execute the stored procedure with these parameters.
                                    // @start_tc datetime, @channel_id int, @end_tc datetime, @duration bigint,
                                    // @offset int, @isblank bit, @id varchar(64), @title varchar(64), @s varchar(64),
                                    // @status varchar(64), @ch varchar(64), @reconcile varchar(64), @ty varchar(64)
                                    mwConnection.Open();
                                    SqlCommand insCmd = new SqlCommand("dbo.InsertAsrun", mwConnection);
                                    insCmd.CommandType = CommandType.StoredProcedure;
                                    insCmd.Parameters.Add("@start_tc", SqlDbType.DateTime, 8);
                                    insCmd.Parameters["@start_tc"].Value = start_tc;
                                    insCmd.Parameters.Add("@channel_id", SqlDbType.Int, 4);
                                    insCmd.Parameters["@channel_id"].Value = channel_id;
                                    insCmd.Parameters.Add("@duration", SqlDbType.Int, 8);
                                    insCmd.Parameters["@duration"].Value = duration;
                                    insCmd.Parameters.Add("@offset", SqlDbType.Int, 4);
                                    insCmd.Parameters["@offset"].Value = offset;
                                    insCmd.Parameters.Add("@isblank", SqlDbType.TinyInt);
                                    insCmd.Parameters["@isblank"].Value = isblank;
                                    insCmd.Parameters.Add("@id", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@id"].Value = id;
                                    insCmd.Parameters.Add("@title", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@title"].Value = title;
                                    insCmd.Parameters.Add("@s", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@s"].Value = s;
                                    insCmd.Parameters.Add("@status", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@status"].Value = status;
                                    insCmd.Parameters.Add("@ch", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@ch"].Value = ch;
                                    insCmd.Parameters.Add("@reconcile", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@reconcile"].Value = reconcile;
                                    insCmd.Parameters.Add("@ty", SqlDbType.NVarChar, 64);
                                    insCmd.Parameters["@ty"].Value = ty;
                                    insCmd.ExecuteNonQuery();
                                    mwConnection.Close();
                                    insCmd.Dispose();
                                    WriteLogEntry("info", String.Format("dbo.InsertAsrun {0},{1},{2}", start_tc.ToString(), channel_id.ToString(), title));
                                    if ((numberOfAsrunFiles < 64) || (numberOfAsrunFiles % 64 == 0))
                                    {
                                        messageListBox.Items.Add("INFO: Asrun Watcher at point " + numberOfAsrunFiles.ToString());
                                    }
                                }
                            }
                        }
                        catch (System.IO.IOException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        catch (System.ArgumentException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        catch (SqlException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        finally
                        {
                            mwConnection.Close();
                        }
                    }
                }
            } while (numFilesInThisPass > 0);
        }
        private void NewChunkEvent(object sender, System.IO.FileSystemEventArgs e)
        {
            int numFilesInThisPass = 0;

            do
            {
                numFilesInThisPass = 0;
                DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(e.FullPath));
                // Create an array representing the files in the current directory.
                FileInfo[] fi = di.GetFiles();
                foreach (FileInfo fiTemp in fi)
                {
                    if (fiTemp.Extension.Equals(".xml"))
                    {
                        string  thisFilePath = fiTemp.FullName;
                        DataSet dsChunk      = new DataSet("assets");
                        try
                        {
                            dsChunk.ReadXml(thisFilePath, XmlReadMode.InferSchema);
                            File.Delete(thisFilePath);
                            archiveDataset(dsChunk);
                            numberOfChunkFiles++;
                            numFilesInThisPass++;
                            // Look up channel name against dsChannels dataset.
                            DataView  dvChannel = new DataView(dsChannels.Tables["channels"], "", "name", DataViewRowState.CurrentRows);
                            DataTable dtChunk   = dsChunk.Tables["Asset"];
                            foreach (DataRow drChunk in dtChunk.Rows)
                            {
                                int rowIndex = dvChannel.Find(drChunk["userID"].ToString());
                                if (rowIndex == -1)
                                {
                                    WriteLogEntry("error", "Invalid Channel : " + thisFilePath);
                                }
                                else
                                {
                                    int      channelID = Int32.Parse(dvChannel[rowIndex]["id"].ToString());
                                    int      fps       = Int32.Parse(dvChannel[rowIndex]["fps"].ToString());
                                    DateTime start_tc  = new LinearTimeCode(fps, drChunk["startDate"].ToString(), drChunk["startTimeCode"].ToString()).dt;
                                    DateTime end_tc    = new LinearTimeCode(fps, drChunk["startDate"].ToString(), drChunk["startTimeCode"].ToString()).dt;
                                    long     duration  = ConvertToFrames(drChunk["fileDuration"].ToString(), fps);
                                    int      offset    = 0;
                                    int      isblank   = 0;
                                    String   url       = urlPrefix + drChunk["fileName"].ToString() + ".mpg";
                                    mwConnection.Open();
                                    SqlCommand insCmd = new SqlCommand("dbo.InsertChunk", mwConnection);
                                    insCmd.CommandType = CommandType.StoredProcedure;
                                    insCmd.Parameters.Add("@start_tc", SqlDbType.DateTime, 8);
                                    insCmd.Parameters["@start_tc"].Value = start_tc;
                                    insCmd.Parameters.Add("@channel_id", SqlDbType.Int, 4);
                                    insCmd.Parameters["@channel_id"].Value = channelID;
                                    insCmd.Parameters.Add("@duration", SqlDbType.Int, 8);
                                    insCmd.Parameters["@duration"].Value = duration;
                                    insCmd.Parameters.Add("@offset", SqlDbType.Int, 4);
                                    insCmd.Parameters["@offset"].Value = offset;
                                    insCmd.Parameters.Add("@isblank", SqlDbType.TinyInt);
                                    insCmd.Parameters["@isblank"].Value = isblank;
                                    insCmd.Parameters.Add("@url", SqlDbType.NVarChar, 512);
                                    insCmd.Parameters["@url"].Value = url;
                                    insCmd.ExecuteNonQuery();
                                    mwConnection.Close();
                                    insCmd.Dispose();
                                    WriteLogEntry("info", String.Format("dbo.InsertChunk {0},{1},{2}", start_tc.ToString(), channelID.ToString(), url));
                                }
                            }
                            if ((numberOfChunkFiles < 64) || (numberOfChunkFiles % 64 == 0))
                            {
                                messageListBox.Items.Add("INFO: Chunk Watcher at point " + numberOfChunkFiles.ToString());
                            }
                        }
                        catch (System.IO.FileNotFoundException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        catch (System.IO.IOException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        catch (System.ArgumentException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        catch (System.Data.SqlClient.SqlException ex)
                        {
                            WriteLogEntry("error", ex.ToString());
                        }
                        finally
                        {
                            mwConnection.Close();
                        }
                    }
                }
            } while (numFilesInThisPass > 0);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Class1         c     = new Class1();
            LinearTimeCode myltc = new LinearTimeCode(25, "2000-06-23", "01:15:23:21");

            c.goon5(myltc);
            myltc = new LinearTimeCode(25, "2000-06-23", "20:24:36:23");
            Console.WriteLine(myltc.ToString());
            myltc.addFrames(2);
            Console.WriteLine("2 frames, Should take it onto next second.");
            Console.WriteLine(myltc.ToString());
            myltc.addFrames(600);
            Console.WriteLine("600 frames, 24 seconds, should take it onto next minute.");
            Console.WriteLine(myltc.ToString());
            myltc.addFrames(52500);
            Console.WriteLine("52,500 frames, 35 minutes, should take it onto next hour.");
            Console.WriteLine(myltc.ToString());
            myltc.addFrames(270000);
            Console.WriteLine("270,000 frames, 3 hours, should take it onto next day.");
            Console.WriteLine(myltc.ToString());
            Console.WriteLine("Now lets try to go back!");
            try
            {
                myltc.addFrames(-270000);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            // myltc = new LinearTimeCode(30,"2000-06-23","01:01:59:28");
            // c.goon5(myltc);
            // myltc = new LinearTimeCode(30,"2000-06-23","01:00:59:28");
            // c.goon5(myltc);
            // myltc = new LinearTimeCode(30,"2000-06-23","01:09:59:28");
            // c.goon5(myltc);
            // Console.WriteLine("This should result in a drop frame exception");
            // try
            // {
            //  myltc = new LinearTimeCode(30,"2000-06-23","01:01:00:00");
            // }
            // catch (ArgumentException ae)
            // {
            //  Console.WriteLine(ae.ToString());
            // }
            // Console.WriteLine("and this.");
            // try
            // {
            // myltc = new LinearTimeCode(30,"2000-06-23","01:01:00:01");
            // }
            // catch (ArgumentException ae)
            // {
            //  Console.WriteLine(ae.ToString());
            // }
            // Console.WriteLine("but not this.");
            // try
            // {
            //  myltc = new LinearTimeCode(30,"2000-06-23","01:01:00:02");
            // }
            //     catch (ArgumentException ae)
//			{
//				Console.WriteLine(ae.ToString());
//			}
//			Console.WriteLine("frame out of range.");
//			try
//			{
//				myltc = new LinearTimeCode(30,"2000-06-23","01:09:59:36");
//			}
//			catch (ArgumentException ae)
//			{
//				Console.WriteLine(ae.ToString());
//			}
//			try
//			{
//				myltc = new LinearTimeCode(25,"2000-06-23","01:09:59:26");
//			}
//			catch (ArgumentException ae)
//			{
//				Console.WriteLine(ae.ToString());
//			}
//			Console.WriteLine("wrong fps");
//			try
//			{
//				myltc = new LinearTimeCode(29,"2000-06-23","01:09:59:21");
//			}
//			catch (ArgumentException ae)
//			{
//				Console.WriteLine(ae.ToString());
//			}
//			Console.WriteLine("wrong date");
//			try
//			{
//				myltc = new LinearTimeCode(30,"frefsafsdf-06-23","01:09:59:21");
//			}
//			catch (ArgumentException ae)
//			{
//				Console.WriteLine(ae.ToString());
//			}
            String wait = Console.ReadLine();
        }