예제 #1
0
        // Receive a Resume Point Update made by a Client
        private static void ReceiveResumeUpdate(RecordingsJson received)
        {
            // Write to Log
            log.WriteLine($"Setting Resume Points");
            var libraryRecordings = TVlibrary.Recordings;
            int currentIndex      = 1;

            foreach (RecordingEntry entry in received.recordingEntries)
            {
                // Write to Log
                log.WriteLine($"({currentIndex} of {received.recordingEntries.Count}): \"{entry.programTitle}\"");
                // Set current status in Form
                settings.SetStatus($"Processing recording {currentIndex} of {received.recordingEntries.Count}");
                libraryRecordings.FirstOrDefault(xx =>
                                                 xx.Program.Title == entry.programTitle &&
                                                 xx.Program.EpisodeTitle == entry.programEpisodeTitle &&
                                                 xx.Program.SeasonNumber == entry.programSeasonNumber &&
                                                 xx.Program.EpisodeNumber == entry.programEpisodeNumber &&
                                                 xx.FileSize == entry.fileSize &&
                                                 xx.StartTime == entry.startTime &&
                                                 xx.EndTime == entry.endTime
                                                 )?.SetBookmark("MCE_shell", TimeSpan.Parse(entry.resumePoint));
                currentIndex++;
            }
            // Write to Log
            log.WriteLine($"Resume Positions Up to Date");
            // Set current status in Form
            settings.SetStatus("Ready");
        }
예제 #2
0
        // Send all Resume Points to a new Client
        private static void SendAllResumePoints(string clientIp)
        {
            // Set current status in Form
            settings.SetStatus("Syncing all resume positions");
            // Get list of Recordings
            var libraryRecordings = TVlibrary.Recordings;
            // Create RecordingsJson Object
            RecordingsJson recordingsJson = new RecordingsJson {
                recordingEntries = new List <RecordingEntry>()
            };

            // Iterate through all Recordings
            foreach (Recording libraryRecording in libraryRecordings)
            {
                // Add RecordingEntry to RecordingsJson
                recordingsJson.recordingEntries.Add(new RecordingEntry {
                    programTitle         = libraryRecording.Program.Title,
                    programEpisodeTitle  = libraryRecording.Program.EpisodeTitle,
                    programSeasonNumber  = libraryRecording.Program.SeasonNumber,
                    programEpisodeNumber = libraryRecording.Program.EpisodeNumber,
                    fileSize             = libraryRecording.FileSize,
                    startTime            = libraryRecording.StartTime,
                    endTime     = libraryRecording.EndTime,
                    resumePoint = libraryRecording.GetBookmark("MCE_shell").ToString()
                });
            }

            // Serialise RecordingsJson to String
            string recordingsJsonString = JsonConvert.SerializeObject(recordingsJson);

            // Create Network Client
            NetworkClient client = new NetworkClient(clientIp, log);

            // Add Client RetryEvent Handler
            client.RetryEvent += Client_RetryEvent;
            // Send Resume Request to Client
            bool result = client.SendResumeUpdate(recordingsJsonString);

            // If the Request Completed Successfully
            if (result)
            {
                // Write to Log
                log.WriteLine($"Client ({clientIp}) Resume Positions Syncronised");
            }
            // Set current status in Form
            settings.SetStatus("Ready");
        }
예제 #3
0
        // Send a Specific Recording's Resume Point to Server
        private static void SendResumeUpdate(Recording libraryRecording)
        {
            // Write to Log
            log.WriteLine($"Syncronising resume position: \"{libraryRecording.Program.Title}\"");
            // Set current status in Form
            settings.SetStatus("Syncing resume position");

            // Create RecordingsJson Object
            RecordingsJson recordingsJson = new RecordingsJson {
                recordingEntries = new List <RecordingEntry>()
            };

            // Add RecordingEntry to RecordingsJson
            recordingsJson.recordingEntries.Add(new RecordingEntry {
                programTitle         = libraryRecording.Program.Title,
                programEpisodeTitle  = libraryRecording.Program.EpisodeTitle,
                programSeasonNumber  = libraryRecording.Program.SeasonNumber,
                programEpisodeNumber = libraryRecording.Program.EpisodeNumber,
                fileSize             = libraryRecording.FileSize,
                startTime            = libraryRecording.StartTime,
                endTime     = libraryRecording.EndTime,
                resumePoint = libraryRecording.GetBookmark("MCE_shell").ToString()
            });
            // Serialise RecordingsJson to String
            string recordingsJsonString = JsonConvert.SerializeObject(recordingsJson);

            // Create Network Client
            NetworkClient client = new NetworkClient(log);

            // Add Event Handler for Server Retry
            client.RetryEvent += Client_RetryEvent;
            // Add Event Handler for Connection Status
            client.StatusEvent += Client_StatusEvent;
            // Connect Client
            client.Connect(retry);
            // Send Resume Request to Server
            bool result = client.SendResumeUpdate(recordingsJsonString);

            // If the Request Completed Successfully
            if (result)
            {
                // Write to Log
                log.WriteLine($"Synchronised resume position: \"{libraryRecording.Program.Title}\"");
            }
            // Set current status in Form
            settings.SetStatus("Ready");
        }
예제 #4
0
        private static void Server_HeartbeatEvent(object sender, HeartbeatArgs e)
        {
            // Check if there is a pending Client Retry
            Retry retry = retryList.FirstOrDefault(xx => xx.ipAddress == e.clientIp);

            // If there is a pending Client Retry
            if (retry != null)
            {
                // Create RecordingsJson Object
                RecordingsJson recordingsJson = new RecordingsJson {
                    recordingEntries = retry.recordingEntries
                };
                // Remove Old Retry
                retryList.Remove(retry);
                // Retry ResumeUpdate
                RetryResumeUpdate(JsonConvert.SerializeObject(recordingsJson), retry.ipAddress);
            }
        }