Example #1
0
        static int Main(string[] args)
        {
            try
            {
                if (args.Length > 0 && String.Equals(args[0], "Help", StringComparison.InvariantCultureIgnoreCase))
                {
                    ShowHelp();
                }
                else if (args.Length >= 2 && String.Equals(args[0], "MyVideo", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, "Creating MP xml");
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];

                            Recording recording = controlServiceAgent.GetRecordingByFileName(recordedFileName);
                            if (recording != null)
                            {
                                Tags tags = new Tags();
                                tags.SimpleTags.Add(new SimpleTag("TITLE", recording.Title));
                                tags.SimpleTags.Add(new SimpleTag("COMMENT", recording.Description));
                                tags.SimpleTags.Add(new SimpleTag("GENRE", recording.Category));
                                tags.SimpleTags.Add(new SimpleTag("CHANNEL_NAME", recording.ChannelDisplayName));

                                string myVideoFileName = Path.ChangeExtension(recordedFileName, "xml");
                                FileStream outFile = new FileStream(myVideoFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                                try
                                {
                                    XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();
                                    nspaces.Add(String.Empty, String.Empty);

                                    XmlSerializer serializer = new XmlSerializer(typeof(Tags));
                                    serializer.Serialize(outFile, tags, nspaces);
                                }
                                catch (SerializationException ex)
                                {
                                    Debug.WriteLine("Failed to serialize. Reason: " + ex.Message, "Error");
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                                finally
                                {
                                    outFile.Close();
                                }
                            }
                            else
                            {
                                Log(LogSeverity.Error, string.Format("Failed to find recording \"{0}\"", recordedFileName));
                            }
                        }
                    }
                }
                else if (args.Length == 2 && String.Equals(args[0], "Log", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log(LogSeverity.Information, args[1]);
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Delete", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Deleting {0} from ARGUS TV {1} the actual recording", args[1], (args[2] == "1" ? "and" : "but not")));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            Boolean keepGile = (args[2] == "1" ? true : false);
                            controlServiceAgent.DeleteRecording(recordedFileName, keepGile);

                        }
                    }
                }
                else if (args.Length == 4 && String.Equals(args[0], "description", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    string recordedFileName = args[1];
                    string outputFileName = Path.ChangeExtension(args[1], args[2]);
                    string fileString = args[3].ToLower();
                    Log(LogSeverity.Information, string.Format("Creating description file for {0} called {1}", args[1], outputFileName));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            Recording tvRecording = controlServiceAgent.GetRecordingByFileName(recordedFileName);
                            fileString = fileString.Replace("{description}", tvRecording.Description);
                            fileString = fileString.Replace("{starttime}", tvRecording.StartTime.ToString());
                            fileString = fileString.Replace("{stoptime}", tvRecording.StopTime.ToString());
                            fileString = fileString.Replace("{title}", tvRecording.Title.ToString());
                            fileString = fileString.Replace("{episodenumber}", tvRecording.EpisodeNumber.ToString());
                            fileString = fileString.Replace("{seriesnumber}", tvRecording.SeriesNumber.ToString());
                            using (StreamWriter descriptionfile = new StreamWriter(outputFileName, false, Encoding.UTF8))
                            {
                                descriptionfile.WriteLine(fileString);
                            }
                        }
                    }
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Rename", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Renaming {0} to {1}", args[1], args[2]));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            string newFileName = args[2];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(newFileName);
                            }

                            if (recording == null)
                            {
                                string lUncPath;
                                if (newFileName.StartsWith("\\"))
                                    lUncPath = newFileName;
                                else
                                {
                                    try
                                    {
                                        lUncPath = GetUncPath(newFileName);
                                    }
                                    catch (IOException)
                                    {
                                        Console.Error.WriteLine("Could not get a UNC path for recording");
                                        Log(LogSeverity.Warning, string.Format("Could not convert {0} to an unc path", newFileName));
                                        LogArgs(LogSeverity.Information, args);
                                        return -2;
                                    }
                                }
                                controlServiceAgent.ChangeRecordingFile(recordedFileName, lUncPath, null, null);
                            }
                            else
                            {
                                Console.Error.WriteLine("Could not move recording as another one with same name allready exsist");
                                Log(LogSeverity.Warning, string.Format("Could not rename as a recording with the name {0} allready exist in database", newFileName));
                                LogArgs(LogSeverity.Information, args);
                                return -2;
                            }
                        }
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "IsPartial", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(recordedFileName);
                            }

                            if (recording != null)
                                return (recording.IsPartialRecording ? -1 : 0);
                            else
                            {
                                Console.Error.WriteLine("Could not check recording as it could not be found in the database");
                                Log(LogSeverity.Warning, string.Format("{0} not found in the ARGUS TV database", args[1]));
                                LogArgs(LogSeverity.Information, args);
                                return -2;
                            }
                        }
                    }
                    else
                    {
                        return -2;
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "Exist", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(recordedFileName);
                            }

                            if (recording != null)
                                return 0;
                            else
                                return -1;
                        }
                    }
                    else
                    {
                        return -2;
                    }
                }
                else if (args.Length >= 1 && String.Equals(args[0], "Wake", StringComparison.InvariantCultureIgnoreCase))
                {

                }
                else
                {
                    Log(LogSeverity.Warning, "Batch processor did not get valid command(s)");
                    LogArgs(LogSeverity.Information, args);
                }
            }
            catch
            {
                return -2;
            }
            if (ServiceChannelFactories.IsInitialized)
                return 0;
            else
                return -3;
        }
Example #2
0
        static int Main(string[] args)
        {
            try
            {
                if (args.Length > 0 && String.Equals(args[0], "Help", StringComparison.InvariantCultureIgnoreCase))
                {
                    ShowHelp();
                }
                else if (args.Length >= 2 && String.Equals(args[0], "MyVideo", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, "Creating MP xml");
                    if (Proxies.IsInitialized)
                    {
                        string recordedFileName = args[1];

                        Recording recording = Proxies.ControlService.GetRecordingByFileName(recordedFileName).Result;
                        if (recording != null)
                        {
                            Tags tags = new Tags();
                            tags.SimpleTags.Add(new SimpleTag("TITLE", recording.Title));
                            tags.SimpleTags.Add(new SimpleTag("COMMENT", recording.Description));
                            tags.SimpleTags.Add(new SimpleTag("GENRE", recording.Category));
                            tags.SimpleTags.Add(new SimpleTag("CHANNEL_NAME", recording.ChannelDisplayName));

                            string     myVideoFileName = Path.ChangeExtension(recordedFileName, "xml");
                            FileStream outFile         = new FileStream(myVideoFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                            try
                            {
                                XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();
                                nspaces.Add(String.Empty, String.Empty);

                                XmlSerializer serializer = new XmlSerializer(typeof(Tags));
                                serializer.Serialize(outFile, tags, nspaces);
                            }
                            catch (SerializationException ex)
                            {
                                Debug.WriteLine("Failed to serialize. Reason: " + ex.Message, "Error");
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            finally
                            {
                                outFile.Close();
                            }
                        }
                        else
                        {
                            Log(LogSeverity.Error, string.Format("Failed to find recording \"{0}\"", recordedFileName));
                        }
                    }
                }
                else if (args.Length == 2 && String.Equals(args[0], "Log", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log(LogSeverity.Information, args[1]);
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Delete", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Deleting {0} from ARGUS TV {1} the actual recording", args[1], (args[2] == "1" ? "and" : "but not")));
                    if (Proxies.IsInitialized)
                    {
                        string  recordedFileName = args[1];
                        Boolean keepGile         = (args[2] == "1" ? true : false);
                        Proxies.ControlService.DeleteRecording(recordedFileName, keepGile).Wait();
                    }
                }
                else if (args.Length == 4 && String.Equals(args[0], "description", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    string recordedFileName = args[1];
                    string outputFileName   = Path.ChangeExtension(args[1], args[2]);
                    string fileString       = args[3].ToLower();
                    Log(LogSeverity.Information, string.Format("Creating description file for {0} called {1}", args[1], outputFileName));
                    if (Proxies.IsInitialized)
                    {
                        Recording tvRecording = Proxies.ControlService.GetRecordingByFileName(recordedFileName).Result;
                        fileString = fileString.Replace("{description}", tvRecording.Description);
                        fileString = fileString.Replace("{starttime}", tvRecording.StartTime.ToString());
                        fileString = fileString.Replace("{stoptime}", tvRecording.StopTime.ToString());
                        fileString = fileString.Replace("{title}", tvRecording.Title.ToString());
                        fileString = fileString.Replace("{episodenumber}", tvRecording.EpisodeNumber.ToString());
                        fileString = fileString.Replace("{seriesnumber}", tvRecording.SeriesNumber.ToString());
                        using (StreamWriter descriptionfile = new StreamWriter(outputFileName, false, Encoding.UTF8))
                        {
                            descriptionfile.WriteLine(fileString);
                        }
                    }
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Rename", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Renaming {0} to {1}", args[1], args[2]));
                    if (Proxies.IsInitialized)
                    {
                        string    recordedFileName = args[1];
                        string    newFileName      = args[2];
                        Recording recording        = Proxies.ControlService.GetRecordingByFileName(newFileName).Result;

                        if (recording == null)
                        {
                            string lUncPath;
                            if (newFileName.StartsWith("\\"))
                            {
                                lUncPath = newFileName;
                            }
                            else
                            {
                                try
                                {
                                    lUncPath = GetUncPath(newFileName);
                                }
                                catch (IOException)
                                {
                                    Console.Error.WriteLine("Could not get a UNC path for recording");
                                    Log(LogSeverity.Warning, string.Format("Could not convert {0} to an unc path", newFileName));
                                    LogArgs(LogSeverity.Information, args);
                                    return(-2);
                                }
                            }
                            Proxies.ControlService.ChangeRecordingFile(recordedFileName, lUncPath, null, null).Wait();
                        }
                        else
                        {
                            Console.Error.WriteLine("Could not move recording as another one with same name already exists");
                            Log(LogSeverity.Warning, string.Format("Could not rename as a recording with the name {0} already exists in database", newFileName));
                            LogArgs(LogSeverity.Information, args);
                            return(-2);
                        }
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "IsPartial", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (Proxies.IsInitialized)
                    {
                        string    recordedFileName = args[1];
                        Recording recording;

                        recording = Proxies.ControlService.GetRecordingByFileName(recordedFileName).Result;

                        if (recording != null)
                        {
                            return(recording.IsPartialRecording ? -1 : 0);
                        }
                        else
                        {
                            Console.Error.WriteLine("Could not check recording as it could not be found in the database");
                            Log(LogSeverity.Warning, string.Format("{0} not found in the ARGUS TV database", args[1]));
                            LogArgs(LogSeverity.Information, args);
                            return(-2);
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "Exist", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (Proxies.IsInitialized)
                    {
                        string    recordedFileName = args[1];
                        Recording recording;

                        recording = Proxies.ControlService.GetRecordingByFileName(recordedFileName).Result;

                        if (recording != null)
                        {
                            return(0);
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else if (args.Length >= 1 && String.Equals(args[0], "Wake", StringComparison.InvariantCultureIgnoreCase))
                {
                }
                else
                {
                    Log(LogSeverity.Warning, "Batch processor did not get valid command(s)");
                    LogArgs(LogSeverity.Information, args);
                }
            }
            catch
            {
                return(-2);
            }
            if (Proxies.IsInitialized)
            {
                return(0);
            }
            else
            {
                return(-3);
            }
        }