private List<Channel> GetAllChannels()
        {
            List<Channel> allChannels = new List<Channel>();

            MergedLineups ml = new MergedLineups(os);
            foreach (Lineup lu in ml)
            {
                if (lu == null)
                {
                    Debug.WriteLine("Null lineup found within mergedLineups");
                    continue;
                }

                Channel[] channels = lu.GetChannels();
                foreach (Channel c in channels)
                {
                    if (c != null && !IsHiddenChannel(c))
                    {
                        allChannels.Add(c);
                    }
                }
            }

            return allChannels;
        }
        private void FullMergeButton_Click(object sender, EventArgs e)
        {
            MergedLineup merged_lineup = new MergedLineups(object_store).First;

            merged_lineup.FullMerge();
            merged_lineup.Update();
        }
Example #3
0
        private static MergedLineup GetMergedLineupFromScannedLineup(Lineup scanned_lineup)
        {
            MergedLineup merged_lineup = scanned_lineup.PrimaryProvider;

            if (null == merged_lineup)
            {
                merged_lineup = scanned_lineup.SecondaryProvider;
                if (null == merged_lineup)
                {
                    merged_lineup = new MergedLineups(object_store).First;
                    if (merged_lineup.GetChannels().Length == 0)
                    {
                        foreach (MergedLineup ml in new MergedLineups(object_store))
                        {
                            if (ml.GetChannels().Length > 0)
                            {
                                merged_lineup = ml;
                                break;
                            }
                        }
                    }
                }
            }
            return(merged_lineup);
        }
        private void UpdateTunerObjects()
        {
            MergedLineup merged_lineup = new MergedLineups(object_store).First;

            foreach (DeviceWrapper wrapper in TunerSelectionListBox.Items)
            {
                wrapper.device.Update();
                //                wrapper.device.ScannedLineup.InitializeChannelNumbers();
                //                wrapper.device.ScannedLineup.RaiseLineupUpdatedEvent();
                //                wrapper.device.ScannedLineup.Update();
            }
            foreach (Lineup wmi_lineup in WMILineupListBox.Items)
            {
                //merged_lineup.OnChannelsAdded(wmi_lineup, wmi_lineup.GetChannels().ToList());
            }
            merged_lineup.Update();
        }
Example #5
0
        static int Main(string[] args)
        {
            // setup catch to fatal program crash
            AppDomain.CurrentDomain.UnhandledException += MyUnhandledException;
            Application.ThreadException += MyThreadException;

            // verify WMC is installed
            if (!File.Exists(Helper.EhshellExeFilePath))
            {
                MessageBox.Show("Could not verify Windows Media Center is installed on this machine. EPG123 Client cannot be started without WMC being present.", "Missing Windows Media Center", MessageBoxButtons.OK);
                return(-1);
            }

            // establish file/folder locations
            Logger.Initialize("Media Center", "epg123Client");
            EstablishFileFolderPaths();

            // create a mutex and keep alive until program exits
            using (Mutex mutex = new Mutex(false, "Global\\" + appGuid))
            {
                bool match, nologo, import, force, showGui, advanced;
                match = nologo = import = force = showGui = advanced = false;

                if ((args != null) && (args.Length > 0))
                {
                    for (int i = 0; i < args.Length; ++i)
                    {
                        switch (args[i].ToLower())
                        {
                        case "-match":
                            match = true;
                            break;

                        case "-nologo":
                            nologo = true;
                            break;

                        case "-i":
                            if ((i + 1) < args.Length)
                            {
                                if (!File.Exists(filename = args[++i]))
                                {
                                    string err = string.Format("File \"{0}\" does not exist.", filename);
                                    Logger.WriteError(err);
                                    return(-1);
                                }
                                filename = new FileInfo(filename).FullName.ToLower();

                                string testNewFile = filename.Replace("\\epg123.mxf", "\\output\\epg123.mxf");
                                if (File.Exists(testNewFile))
                                {
                                    Logger.WriteWarning(string.Format("It appears the MXF file to import is incorrect. Changing the import file from \"{0}\" to \"{1}\".", filename, testNewFile));
                                    filename = testNewFile;
                                }
                                statusLogo.mxfFile = filename;
                            }
                            else
                            {
                                string err = "Missing input filename and path.";
                                Logger.WriteError(err);
                                return(-1);
                            }
                            import = true;
                            break;

                        case "-f":
                            force = true;
                            break;

                        case "-p":
                            showProgress = true;
                            break;

                        case "-x":
                            advanced = true;
                            showGui  = true;
                            break;

                        default:
                            Console.WriteLine("ERROR: \"{0}\" is not a valid argument.", args[i]);
                            return(-1);
                        }
                    }
                }
                else
                {
                    showGui = true;
                }

                if (showGui)
                {
                    // use another mutex if the GUI is open
                    using (Mutex mutex2 = new Mutex(false, "Global\\" + guiGuid))
                    {
                        // check for a gui instance already running
                        if (!mutex2.WaitOne(2000, false))
                        {
                            MessageBox.Show("An instance of EPG123 Client is already running.", "Initialization Aborted");
                            return(0);
                        }

                        Logger.WriteMessage("===============================================================================");
                        Logger.WriteMessage(string.Format(" Activating the epg123 client GUI. version {0}", Helper.epg123Version));
                        Logger.WriteMessage("===============================================================================");
                        clientForm client = new clientForm(advanced);
                        client.ShowDialog();
                        mutex2.ReleaseMutex();
                        Logger.Close();
                        client.Dispose();
                        return(0);
                    }
                }

                // prevent machine from entering sleep mode
                uint prevThreadState = NativeMethods.SetThreadExecutionState((uint)ExecutionFlags.ES_CONTINUOUS |
                                                                             (uint)ExecutionFlags.ES_SYSTEM_REQUIRED |
                                                                             (uint)ExecutionFlags.ES_AWAYMODE_REQUIRED);

                // and yet another mutex for the import action
                using (Mutex mutex3 = new Mutex(false, "Global\\" + impGuid))
                {
                    // check for an import instance is already running
                    if (!mutex3.WaitOne(0, false))
                    {
                        Logger.WriteError("An instance of EPG123 Client import is already running. Aborting this instance.");
                        return(-1);
                    }

                    Logger.WriteMessage("===============================================================================");
                    Logger.WriteMessage(string.Format(" Beginning epg123 client execution. version {0}", Helper.epg123Version));
                    Logger.WriteMessage("===============================================================================");
                    Logger.WriteInformation(string.Format("Beginning epg123 client execution. {0:u}", DateTime.Now.ToUniversalTime()));
                    Logger.WriteVerbose(string.Format("Import: {0} , Match: {1} , NoLogo: {2} , Force: {3} , ShowProgress: {4}", import, match, nologo, force, showProgress));
                    DateTime startTime = DateTime.UtcNow;

                    // remove all channel logos
                    if (nologo)
                    {
                        clearLineupChannelLogos();
                    }

                    notifyIcon = new NotifyIcon()
                    {
                        Text = "EPG123\nImporting guide listings...",
                        Icon = epg123.Properties.Resources.EPG123_import
                    };
                    notifyIcon.Visible = true;

                    // ensure no recordings are active if importing
                    if (import && !force && programRecording())
                    {
                        Logger.WriteError("A program recording is still in progress after 5 hours. Aborting the mxf file import.");
                        Logger.Close();
                        NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS);
                        mutex3.ReleaseMutex();

                        notifyIcon.Visible = false;
                        notifyIcon.Dispose();

                        statusLogo.statusImage();
                        return(-1);
                    }

                    // import mxf file
                    if (import && !importMxfFile(filename))
                    {
                        Logger.WriteError("Failed to import .mxf file. Exiting.");
                        Logger.Close();
                        NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS);
                        mutex3.ReleaseMutex();

                        notifyIcon.Visible = false;
                        notifyIcon.Dispose();

                        statusLogo.statusImage();
                        return(-1);
                    }
                    notifyIcon.Visible = false;
                    notifyIcon.Dispose();

                    // get lineup and configure lineup type and devices
                    if (import && !mxfImport.activateLineupAndGuide())
                    {
                        Logger.WriteError("Failed to locate any lineups from EPG123.");
                        Logger.Close();
                        NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS);
                        mutex3.ReleaseMutex();

                        statusLogo.statusImage();
                        return(-1);
                    }

                    // perform automatch
                    if (match)
                    {
                        try
                        {
                            matchLineups();
                            Logger.WriteInformation("Completed the automatch of lineup stations to tuner channels.");
                        }
                        catch
                        {
                            Logger.WriteError("Failed to perform the automatch of lineup stations to tuner channels task.");
                        }
                    }

                    // refresh the lineups after import
                    if (import)
                    {
                        using (MergedLineups mergedLineups = new MergedLineups(Store.objectStore))
                        {
                            foreach (MergedLineup mergedLineup in mergedLineups)
                            {
                                mergedLineup.Refresh();
                            }
                        }
                        Logger.WriteInformation("Completed lineup refresh.");
                    }

                    // reindex database
                    if (import)
                    {
                        mxfImport.reindexDatabase();
                    }

                    // set all active recording requests to anyLanguage=true
                    if (setSeriesRecordingRequestAnyLanguage() || import)
                    {
                        mxfImport.reindexPvrSchedule();
                    }

                    // update status logo
                    if (import)
                    {
                        statusLogo.statusImage();
                    }

                    // all done
                    Logger.WriteInformation("Completed EPG123 client execution.");
                    Logger.WriteVerbose(string.Format("EPG123 client execution time was {0}.", DateTime.UtcNow - startTime));
                    Logger.Close();
                    mutex3.ReleaseMutex();
                }

                NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS);
                return(0);
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            MergedLineups merged_lineups = new MergedLineups(ChannelEditing.object_store);
            MergedLineup main_lineup = merged_lineups.ToArray()[1];
            Lineup[] lineups = ChannelEditing.GetLineups();
            foreach (Lineup lineup in lineups)
            {
                if ((lineup.Name == "Scanned (Digital Cable (ClearQAM))") && lineup.ScanDevices.Empty) {
                    foreach (Channel ch in lineup.GetChannels())
                    {
                        lineup.RemoveChannel(ch);
                    }
                    lineup.Unlock();
                }
                if (!lineup.ScanDevices.Empty)
                {
                    lineup.PrimaryProvider = main_lineup;
                }
            }
            foreach (MergedLineup mergedlineup in merged_lineups)
            {
                if (mergedlineup.GetChannels().Count() == 0)
                {
                    mergedlineup.Unlock();
                    //merged_lineups.RemoveAllMatching(mergedlineup);
                }
            }
            Service[] services = new Services(ChannelEditing.object_store).ToArray();
            DeviceGroup[] device_groups = new DeviceGroups(ChannelEditing.object_store).ToArray();
            foreach (DeviceGroup device_group in device_groups)
            {
                Console.WriteLine("DeviceGroup: {0}", device_group.Name);
            }
            Device[] devices = new Devices(ChannelEditing.object_store).ToArray();
            foreach (Device d in devices)
            {
                Console.WriteLine("Device: {0}", d.Name);
            }
            DeviceType[] device_types = new DeviceTypes(ChannelEditing.object_store).ToArray();
            foreach (DeviceType dt in device_types)
            {
                Console.WriteLine("DeviceType: {0} DisplayName: {1} HeadendType: {2} Id: {3} IsSetTopBox: {4} NetworkType: {5} TuningSpaceName: {6} VideoSource: {7} ViewPriority: {8}",
                    dt.Name, dt.DisplayName, dt.HeadendType, dt.Id, dt.IsSetTopBox, dt.NetworkType, dt.TuningSpaceName, dt.VideoSource, dt.ViewPriority);
                Microsoft.MediaCenter.TV.Tuning.TuningSpace tuning_space = dt.TuningSpace;
                if (tuning_space != null)
                {
                    Console.WriteLine("Tuning space CLSID: {0} FriendlyName: {1} UniqueName: {2}", tuning_space.CLSID, tuning_space.FriendlyName, tuning_space.UniqueName);
                }
            }
            foreach (Service service in services)
            {
                Console.WriteLine("Service: {0} IsCached: {1} IsMerged: {2}", service.Name, service.IsCached, service.IsMergedService);
            }
            if (false)
                foreach (Lineup lineup in lineups)
            {
                Console.WriteLine("Lineup: {0} ", lineup.Name);
                if (lineup.DeviceGroup != null)
                {
                    Console.WriteLine("DeviceGroup: {0}", lineup.DeviceGroup.Name);
                    if (lineup.DeviceGroup.Devices != null)
                        foreach(Device d in lineup.DeviceGroup.Devices)
                            Console.WriteLine(d.Name);
                }
                if (lineup.ScanDevices != null)
                    foreach (Device d in lineup.ScanDevices)
                        Console.WriteLine("ScanDevice: {0}", d);
                if (lineup.WmisDevices != null)
                {
                    foreach (Device d in lineup.WmisDevices)
                        Console.WriteLine("WmiDevice: {0}", d);
                    //if (lineup.WmisDevices.Empty && lineup.ScanDevices.Empty)
                        foreach (Channel ch in lineup.GetChannels())
                        {
                            if (ch.Service != null)
                            {
                                Console.WriteLine("Callsign: {0}, CHannelNumber {1}, Service Callsign {2}, Service Name {3}",
                                    ch.CallSign, ch.ChannelNumber, ch.Service.CallSign, ch.Service.Name);
                                if (!ch.Service.ScheduleEntries.Empty)
                                {
                                    foreach (ScheduleEntry entry in ch.Service.ScheduleEntries)
                                    {
                                        if (entry.Program != null)
                                        Console.WriteLine(entry.Program.Title);
                                    }
                                }
                            }
                        }
                }

             /*   foreach (Channel ch in lineup.GetChannels())
                {
                    Console.WriteLine("Channel: {0} Service: {1}", ch.Number, ch.Service);
                } */
            }
            MergedLineup merged_lineup = lineups[0].PrimaryProvider;
            Console.WriteLine("MergedLineup: {0}", merged_lineup);
            if (merged_lineup.SecondaryLineups != null)
                foreach (Lineup lineup in merged_lineup.SecondaryLineups)
                    Console.WriteLine("Secondary Lineup: {0}", lineup.Name);
            Console.ReadLine();
            FavoriteLineups favorite_lineups = new FavoriteLineups(ChannelEditing.object_store);
            foreach (FavoriteLineup favorite in favorite_lineups)
            {
                Console.WriteLine(favorite.Name);
            }
            PackageSubscriptions subscriptions = new PackageSubscriptions(ChannelEditing.object_store);
            foreach (PackageSubscription sub in subscriptions) {
                Console.WriteLine(sub.Package.Description);
            }
        }
        private List<Channel> GetChannelsInFirstLineup(bool mergeLineups)
        {
            List<Channel> output = new List<Channel>();

            if (mergeLineups)
            {
                MergedLineups ml = new MergedLineups(os);
                foreach (Lineup lu in ml)
                {
                    if (lu == null)
                    {
                        DebugNormal("Null lineup found within mergedLineups");
                        continue;
                    }

                    Channel[] channels = lu.GetChannels();
                    foreach (Channel c in channels)
                    {
                        if (c != null)
                            output.Add(c);
                    }
                }
            }
            else
            {
                Lineup lu = Util.GetFirstLineup(os);
                if (lu == null)
                {
                    DebugNormal("No lineup was found.");
                    return output;
                }
                else
                {
                    Channel[] channels = lu.GetChannels();
                    foreach (Channel c in channels)
                    {
                        if (c != null)
                            output.Add(c);
                    }
                }

            }

            return output;
        }
        public static void AddUserChannelInLineup(Lineup lineup, string callsign, int channel_number, int subchannel, ModulationType modulation_type)
        {
            List <ChannelTuningInfo> tuning_infos = new List <ChannelTuningInfo>();

            foreach (Device device in lineup.ScanDevices)
            {
                string old_tuningspace_name = device.DeviceType.TuningSpaceName;
                if (string.IsNullOrEmpty(old_tuningspace_name))
                {
                    // hacky.  For now I'm just trying to get it to work with ClearQAM.  Ultimately I guess this would be a case
                    // statement picking a value based on modulation_type.  Why is it null for all my devices currently?
                    string temp_tuningspace_name = GetTuningSpaceNameForModulation(modulation_type);
                    // What really seems to matter looking at
                    // ChannelTuningInfo(Device device, SerializationFormat format, byte[] serializedTuneRequest, TuneRequest tr) : base(device, format, serializedTuneRequest, tr)
                    // in .NET Reflector is whether the tuning space has subnumbers or not.  So if we can't figure out
                    // what TuningSpace makes sense, pick one based on if subchannel is 0.
                    if (string.IsNullOrEmpty(temp_tuningspace_name))
                    {
                        temp_tuningspace_name = ((subchannel != 0) ? "ClearQAM" : "Cable");
                    }
                    device.DeviceType.TuningSpaceName = temp_tuningspace_name;
                }
                try
                {
                    ChannelTuningInfo channel_tuning_info = new ChannelTuningInfo(device, channel_number, subchannel, modulation_type);
                    tuning_infos.Add(channel_tuning_info);
                }
                finally
                {
                    device.DeviceType.TuningSpaceName = old_tuningspace_name;
                }
            }
            Channel ch = new Channel();

            ch.CallSign    = callsign;
            ch.ChannelType = ChannelType.UserAdded;
            ch.Number      = channel_number;
            ch.SubNumber   = subchannel;
            lineup.AddChannel(ch);
            foreach (ChannelTuningInfo channel_tuning_info in tuning_infos)
            {
                ch.TuningInfos.Add(channel_tuning_info);
            }
            ch.Update();
            MergedChannel merged_channel = new MergedChannel();

            merged_channel.Number      = channel_number;
            merged_channel.SubNumber   = subchannel;
            merged_channel.CallSign    = callsign;
            merged_channel.ChannelType = ChannelType.UserAdded;
            merged_channel.FullMerge(ch);
            MergedLineup merged_lineup = (lineup.PrimaryProvider != null) ? lineup.PrimaryProvider : lineup.SecondaryProvider;

            if (merged_lineup == null)
            {
                merged_lineup = new MergedLineups(lineup.ObjectStore).First;
            }
            List <Channel> new_channels_list = new List <Channel>();

            new_channels_list.Add(ch);
            bool old_keepAllPrimary   = merged_lineup.LineupMergeRule.KeepAllPrimary;
            bool old_keepAllSecondary = merged_lineup.LineupMergeRule.KeepAllSecondary;

            merged_lineup.LineupMergeRule.KeepAllPrimary   = true;
            merged_lineup.LineupMergeRule.KeepAllSecondary = true;
            try
            {
                lineup.NotifyChannelAdded(ch);
//                merged_lineup.OnChannelsAdded(lineup, new_channels_list);
            }
            finally
            {
                merged_lineup.LineupMergeRule.KeepAllPrimary   = old_keepAllPrimary;
                merged_lineup.LineupMergeRule.KeepAllSecondary = old_keepAllSecondary;
            }
        }
Example #9
0
        private static int Main(string[] args)
        {
            // setup catch to fatal program crash
            AppDomain.CurrentDomain.UnhandledException += MyUnhandledException;
            Application.ThreadException += MyThreadException;

            // filter out mcupdate calls that may be redirected
            var arguments = string.Join(" ", args);

            switch (arguments)
            {
            case "-u -nogc":     // opening WMC
            case "-uf -nogc":
                Logger.WriteVerbose($"**** Intercepted \"mcupdate.exe {arguments}\" call. Ignored. ****");
                Logger.Close();
                return(0);

            case "-u -manual -nogc -p 0":     // guide update
            case "-manual -nogc -p 0":
                var startTime = DateTime.Now;
                var startInfo = new ProcessStartInfo()
                {
                    FileName        = "schtasks.exe",
                    Arguments       = "/run /tn \"epg123_update\"",
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                };

                // begin update
                var proc = Process.Start(startInfo);
                proc?.WaitForExit();

                Logger.WriteInformation("**** Attempted to kick off the epg123_update task on demand. ****");
                Logger.Close();

                // monitor the task status until it is complete
                var ts = new epgTaskScheduler();
                while (true)
                {
                    // looks like WMC may have a 30000 ms timeout for the update action
                    // no reason to continue with the mcupdate run if it is going to be ignored
                    if (DateTime.Now - startTime > TimeSpan.FromMinutes(5.0))
                    {
                        return(0);
                    }

                    ts.QueryTask(true);
                    if (ts.StatusString.ToLower().Contains("running"))
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        break;
                    }
                }

                // kick off mcupdate so it can fail but signal WMC that update is complete
                startInfo = new ProcessStartInfo()
                {
                    FileName  = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\ehome\mcupdate.exe"),
                    Arguments = arguments
                };
                proc = Process.Start(startInfo);
                proc?.WaitForExit();
                return(0);
            }

            // evaluate arguments
            bool nologo, import, force, showGui, advanced, nogc, verbose, noverify;
            var  match = nologo = import = force = showGui = advanced = nogc = verbose = noverify = false;

            if (File.Exists($"{Helper.Epg123ProgramDataFolder}\\nogc.txt"))
            {
                File.Delete($"{Helper.Epg123ProgramDataFolder}\\nogc.txt");
                nogc = true;
            }
            if (args.Length > 0)
            {
                for (var i = 0; i < args.Length; ++i)
                {
                    switch (args[i].ToLower())
                    {
                    case "-match":
                        match = true;
                        break;

                    case "-nologo":
                        nologo = true;
                        break;

                    case "-i":
                        if (i + 1 < args.Length)
                        {
                            filename = args[++i].Replace("EPG:", "http:");
                            if (filename.StartsWith("http"))
                            {
                                statusLogo.MxfFile = Helper.Epg123MxfPath;
                                import             = true;
                                break;
                            }

                            if (!File.Exists(filename))
                            {
                                var err = $"File \"{filename}\" does not exist.";
                                Logger.WriteError(err);
                                return(-1);
                            }
                            filename = new FileInfo(filename).FullName.ToLower();

                            var testNewFile = filename.Replace("\\epg123.mxf", "\\output\\epg123.mxf");
                            if (File.Exists(testNewFile))
                            {
                                Logger.WriteWarning($"It appears the MXF file to import is incorrect. Changing the import file from \"{filename}\" to \"{testNewFile}\". Delete and re-create your Scheduled Task.");
                                filename = testNewFile;
                            }
                            statusLogo.MxfFile = filename;
                        }
                        else
                        {
                            Logger.WriteError("Missing input filename and path.");
                            return(-1);
                        }
                        import = true;
                        break;

                    case "-f":
                        force = true;
                        break;

                    case "-p":
                        showProgress = true;
                        break;

                    case "-x":
                        advanced = true;
                        showGui  = true;
                        break;

                    case "-nogc":
                        nogc = true;
                        break;

                    case "-verbose":
                        verbose = true;
                        break;

                    case "-noverify":
                        noverify = true;
                        break;

                    default:
                        Logger.WriteVerbose($"**** Invalid arguments for epg123Client.exe; \"{arguments}\" ****");
                        Logger.Close();
                        return(-1);
                    }
                }
            }
            else
            {
                showGui = true;
            }

            // create a mutex and keep alive until program exits
            using (var mutex = !showGui && showProgress ? new Mutex(false, $"Global\\{AppGuid}") : Helper.GetProgramMutex($"Global\\{AppGuid}", !showGui))
            {
                // check for an instance already running
                if (mutex == null)
                {
                    return(-1);
                }

                Logger.WriteMessage("===============================================================================");
                Logger.WriteMessage($" {(showGui ? "Activating the epg123 client GUI." : "Beginning epg123 client execution.")} version {Helper.Epg123Version}");
                Logger.WriteMessage("===============================================================================");
                Logger.WriteMessage($"*** {Helper.GetOsDescription()} ***");
                Logger.WriteMessage($"*** {Helper.GetWmcDescription()} ***");

                // show gui if needed
                if (showGui)
                {
                    var client = new clientForm(advanced);
                    client.ShowDialog();
                    GC.Collect();

                    if (client.RestartClientForm)
                    {
                        // start a new process
                        _ = Process.Start(new ProcessStartInfo
                        {
                            FileName         = Helper.Epg123ClientExePath,
                            WorkingDirectory = Helper.ExecutablePath,
                            UseShellExecute  = true,
                            Verb             = client.RestartAsAdmin ? "runas" : null
                        });
                    }
                    client.Dispose();
                }
                else
                {
                    // prevent machine from entering sleep mode
                    var prevThreadState = NativeMethods.SetThreadExecutionState(
                        (uint)ExecutionFlags.ES_CONTINUOUS |
                        (uint)ExecutionFlags.ES_SYSTEM_REQUIRED |
                        (uint)ExecutionFlags.ES_AWAYMODE_REQUIRED);

                    Logger.WriteVerbose($"Import: {import} , Match: {match} , NoLogo: {nologo} , Force: {force} , ShowProgress: {showProgress} , NoGC: {force || nogc} , NoVerify: {noverify} , Verbose: {verbose}");
                    var startTime = DateTime.UtcNow;

                    if (import)
                    {
                        // check if garbage cleanup is needed
                        if (!nogc && !force && WmcRegistries.IsGarbageCleanupDue() && !ProgramRecording(60))
                        {
                            _ = WmcUtilities.PerformGarbageCleanup();
                        }

                        // ensure no recordings are active if importing
                        if (!force && ProgramRecording(10))
                        {
                            Logger.WriteError($"A program recording is still in progress after {MaximumRecordingWaitHours} hours. Aborting the mxf file import.");
                            goto CompleteImport;
                        }
                        WmcStore.Close();

                        // import mxf file
                        if (!ImportMxfFile(filename))
                        {
                            Logger.WriteError("Failed to import .mxf file. Exiting.");
                            goto CompleteImport;
                        }

                        // perform verification
                        if (!noverify)
                        {
                            _ = new VerifyLoad(filename, verbose);
                        }

                        // get lineup and configure lineup type and devices
                        if (!WmcStore.ActivateEpg123LineupsInStore() || !WmcRegistries.ActivateGuide())
                        {
                            Logger.WriteError("Failed to locate any lineups from EPG123.");
                            goto CompleteImport;
                        }
                    }

                    // remove all channel logos
                    if (nologo)
                    {
                        WmcStore.ClearLineupChannelLogos();
                    }

                    // perform automatch
                    if (match)
                    {
                        try
                        {
                            WmcStore.AutoMapChannels();
                            Logger.WriteInformation("Completed the automatch of lineup stations to tuner channels.");
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteError($"{ex.Message}");
                            Logger.WriteError("Failed to perform the automatch of lineup stations to tuner channels task.");
                        }
                    }

                    // import success
                    if (import)
                    {
                        // refresh the lineups after import
                        using (var mergedLineups = new MergedLineups(WmcStore.WmcObjectStore))
                        {
                            foreach (MergedLineup mergedLineup in mergedLineups)
                            {
                                _ = mergedLineup.Refresh();
                            }
                        }
                        Logger.WriteInformation("Completed lineup refresh.");

                        // reindex database
                        _ = WmcUtilities.ReindexPvrSchedule();
                        _ = WmcUtilities.ReindexDatabase();
                    }

                    // import complete
CompleteImport:
                    if (import)
                    {
                        // update status logo
                        statusLogo.StatusImage();

                        // signal the notification tray to update the icon
                        Helper.SendPipeMessage("Import Complete");
                    }

                    WmcStore.Close();

                    // all done
                    Logger.WriteInformation("Completed EPG123 client execution.");
                    Logger.WriteVerbose($"EPG123 client execution time was {DateTime.UtcNow - startTime}.");
                    Logger.Close();
                    NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS);
                }
            }
            Environment.Exit(0);
            return(0);
        }
Example #10
0
 // cleanup invalid/orphaned objects left from previous app runs in the development process.
 public static void CleanupCrud()
 {
     using (Channels full_channel_list = new Channels(object_store))
     {
         foreach (Channel ch in full_channel_list)
         {
             if (ch.ChannelType == ChannelType.UserAdded)
             {
                 if (ch.Lineup == null || ch.TuningInfos == null || ch.TuningInfos.Empty)
                 {
                     ch.CallSign   = "DELE";
                     ch.Visibility = ChannelVisibility.NotTunable;
                     foreach (MergedChannel mc in ch.ReferencingSecondaryChannels)
                     {
                         mc.RemoveSecondaryChannel(ch);
                     }
                     foreach (MergedChannel mc in ch.ReferencingPrimaryChannels)
                     {
                         mc.PrimaryChannel = null;
                     }
                     using (TuningInfos tuning_infos = new TuningInfos(object_store))
                     {
                         foreach (TuningInfo ti in tuning_infos)
                         {
                             if (ti.Channels.Contains(ch))
                             {
                                 ti.Channels.RemoveAllMatching(ch);
                             }
                         }
                     }
                     ch.Service = null;
                     try {
                         full_channel_list.RemoveAllMatching(ch);
                     } catch {}
                     try {
                         new Lineups(object_store).First.DeleteUserAddedChannel(ch);
                     } catch {}
                     try
                     {
                         Lineup oldLineup = ch.TuningInfos.First.Device.ScannedLineup;
                         ch.TuningInfos.Clear();
                         oldLineup.DeleteUserAddedChannel(ch);
                     } catch {
                     }
                     ch.UserBlockedState = UserBlockedState.Blocked;
                 }
             }
         }
     }
     using (MergedLineups merged_lineups = new MergedLineups(object_store))
         foreach (MergedLineup merged_lineup in merged_lineups)
         {
             foreach (Channel ch in merged_lineup.GetChannels())
             {
                 if (ch.TuningInfos.Empty && ch.Number < 9000)
                 {
                     merged_lineup.RemoveChannel(ch);
                 }
             }
         }
 }
 private void UpdateTunerObjects()
 {
     MergedLineup merged_lineup = new MergedLineups(object_store).First;
     foreach (DeviceWrapper wrapper in TunerSelectionListBox.Items)
     {
         wrapper.device.Update();
         //                wrapper.device.ScannedLineup.InitializeChannelNumbers();
         //                wrapper.device.ScannedLineup.RaiseLineupUpdatedEvent();
         //                wrapper.device.ScannedLineup.Update();
     }
     foreach (Lineup wmi_lineup in WMILineupListBox.Items)
     {
         //merged_lineup.OnChannelsAdded(wmi_lineup, wmi_lineup.GetChannels().ToList());
     }
     merged_lineup.Update();
 }
 private void FullMergeButton_Click(object sender, EventArgs e)
 {
     MergedLineup merged_lineup = new MergedLineups(object_store).First;
     merged_lineup.FullMerge();
     merged_lineup.Update();
 }
Example #13
0
        static void Main(string[] args)
        {
            MergedLineups merged_lineups = new MergedLineups(ChannelEditing.object_store);
            MergedLineup  main_lineup    = merged_lineups.ToArray()[1];

            Lineup[] lineups = ChannelEditing.GetLineups();
            foreach (Lineup lineup in lineups)
            {
                if ((lineup.Name == "Scanned (Digital Cable (ClearQAM))") && lineup.ScanDevices.Empty)
                {
                    foreach (Channel ch in lineup.GetChannels())
                    {
                        lineup.RemoveChannel(ch);
                    }
                    lineup.Unlock();
                }
                if (!lineup.ScanDevices.Empty)
                {
                    lineup.PrimaryProvider = main_lineup;
                }
            }
            foreach (MergedLineup mergedlineup in merged_lineups)
            {
                if (mergedlineup.GetChannels().Count() == 0)
                {
                    mergedlineup.Unlock();
                    //merged_lineups.RemoveAllMatching(mergedlineup);
                }
            }
            Service[]     services      = new Services(ChannelEditing.object_store).ToArray();
            DeviceGroup[] device_groups = new DeviceGroups(ChannelEditing.object_store).ToArray();
            foreach (DeviceGroup device_group in device_groups)
            {
                Console.WriteLine("DeviceGroup: {0}", device_group.Name);
            }
            Device[] devices = new Devices(ChannelEditing.object_store).ToArray();
            foreach (Device d in devices)
            {
                Console.WriteLine("Device: {0}", d.Name);
            }
            DeviceType[] device_types = new DeviceTypes(ChannelEditing.object_store).ToArray();
            foreach (DeviceType dt in device_types)
            {
                Console.WriteLine("DeviceType: {0} DisplayName: {1} HeadendType: {2} Id: {3} IsSetTopBox: {4} NetworkType: {5} TuningSpaceName: {6} VideoSource: {7} ViewPriority: {8}",
                                  dt.Name, dt.DisplayName, dt.HeadendType, dt.Id, dt.IsSetTopBox, dt.NetworkType, dt.TuningSpaceName, dt.VideoSource, dt.ViewPriority);
                Microsoft.MediaCenter.TV.Tuning.TuningSpace tuning_space = dt.TuningSpace;
                if (tuning_space != null)
                {
                    Console.WriteLine("Tuning space CLSID: {0} FriendlyName: {1} UniqueName: {2}", tuning_space.CLSID, tuning_space.FriendlyName, tuning_space.UniqueName);
                }
            }
            foreach (Service service in services)
            {
                Console.WriteLine("Service: {0} IsCached: {1} IsMerged: {2}", service.Name, service.IsCached, service.IsMergedService);
            }
            if (false)
            {
                foreach (Lineup lineup in lineups)
                {
                    Console.WriteLine("Lineup: {0} ", lineup.Name);
                    if (lineup.DeviceGroup != null)
                    {
                        Console.WriteLine("DeviceGroup: {0}", lineup.DeviceGroup.Name);
                        if (lineup.DeviceGroup.Devices != null)
                        {
                            foreach (Device d in lineup.DeviceGroup.Devices)
                            {
                                Console.WriteLine(d.Name);
                            }
                        }
                    }
                    if (lineup.ScanDevices != null)
                    {
                        foreach (Device d in lineup.ScanDevices)
                        {
                            Console.WriteLine("ScanDevice: {0}", d);
                        }
                    }
                    if (lineup.WmisDevices != null)
                    {
                        foreach (Device d in lineup.WmisDevices)
                        {
                            Console.WriteLine("WmiDevice: {0}", d);
                        }
                        //if (lineup.WmisDevices.Empty && lineup.ScanDevices.Empty)
                        foreach (Channel ch in lineup.GetChannels())
                        {
                            if (ch.Service != null)
                            {
                                Console.WriteLine("Callsign: {0}, CHannelNumber {1}, Service Callsign {2}, Service Name {3}",
                                                  ch.CallSign, ch.ChannelNumber, ch.Service.CallSign, ch.Service.Name);
                                if (!ch.Service.ScheduleEntries.Empty)
                                {
                                    foreach (ScheduleEntry entry in ch.Service.ScheduleEntries)
                                    {
                                        if (entry.Program != null)
                                        {
                                            Console.WriteLine(entry.Program.Title);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    /*   foreach (Channel ch in lineup.GetChannels())
                     * {
                     *     Console.WriteLine("Channel: {0} Service: {1}", ch.Number, ch.Service);
                     * } */
                }
            }
            MergedLineup merged_lineup = lineups[0].PrimaryProvider;

            Console.WriteLine("MergedLineup: {0}", merged_lineup);
            if (merged_lineup.SecondaryLineups != null)
            {
                foreach (Lineup lineup in merged_lineup.SecondaryLineups)
                {
                    Console.WriteLine("Secondary Lineup: {0}", lineup.Name);
                }
            }
            Console.ReadLine();
            FavoriteLineups favorite_lineups = new FavoriteLineups(ChannelEditing.object_store);

            foreach (FavoriteLineup favorite in favorite_lineups)
            {
                Console.WriteLine(favorite.Name);
            }
            PackageSubscriptions subscriptions = new PackageSubscriptions(ChannelEditing.object_store);

            foreach (PackageSubscription sub in subscriptions)
            {
                Console.WriteLine(sub.Package.Description);
            }
        }