Exemple #1
0
        private RecordingList[] GenerateRecordingList(Candidate candidate)
        {
            // Get list of available recordings
            var recordingList = _context.Recordings
                                .Where(r => r.Available == true).AsQueryable();

            // Randomize question
            RecordingList[] recordpart = new RecordingList[4];
            for (int i = 0; i < 4; i++)
            {
                Recording[] recordingArray = recordingList.Where(r => r.Part == i + 1).ToArray();

                Random random      = new Random();
                int    randomIndex = random.Next(recordingArray.Length);

                RecordingList part = new RecordingList
                {
                    RecordingID = recordingArray[randomIndex].RecordingId,
                    CandidateID = candidate.CandidateID
                };

                recordpart[i] = part;
            }

            _context.RecordingLists.AddRange(recordpart);
            _context.SaveChanges();

            return(recordpart);
        }
        static void Main(string[] args)
        {
            // Create FreeClimbClient object
            FreeClimbClient client = new FreeClimbClient(getFreeClimbAccountId(), getFreeClimbApiKeys());

            // Invoke get method to retrieve initial list of recording information
            RecordingList recordingList = client.getRecordingsRequester.getMeta();

            // Check if list is empty by checking total size of the list
            if (recordingList.getTotalSize > 0)
            {
                // retrieve all recording for server
                while (recordingList.getLocalSize < recordingList.getTotalSize)
                {
                    recordingList.loadNextPage();
                }

                // Convert current pages recording information to a linked list
                LinkedList <IFreeClimbCommon> commonList = recordingList.export();

                // Loop through linked list to process recording information
                foreach (IFreeClimbCommon element in commonList)
                {
                    // Cast each element to the Recording element for processing
                    Recording recording = element as Recording;

                    // Process recording element
                    Console.Write(recording.getRecordingId);
                }
            }
        }
        public void GetRecordingListTest()
        {
            try
            {
                RecordingsRequester recordingsRequester = new RecordingsRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(recordingsRequester, "http://GetRecordingListTest:3000");
                }

                WebRequest.RegisterPrefix("http://GetRecordingListTest:3000", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"total\":3,\"start\":0,\"end\":1,\"page\":0,\"numPages\":2,\"pageSize\":2,\"nextPageUri\":\"/Accounts/ACabe7063197551fe51671f9ac3a9708e9dad51c4d/Recordings&cursor=492dc883a811bd0204204ea9047122f93a2788a2\",\"recordings\":[{\"uri\":\"/Accounts/ACabe7063197551fe51671f9ac3a9708e9dad51c4d/Recordings/REb1eecfce410141ad1749c0fc84dfbb6fc4c2a810\",\"revision\":1,\"dateCreated\":\"Mon, 27 Jun 2016 17:53:55 GMT\",\"dateUpdated\":\"Mon, 27 Jun 2016 17:53:55 GMT\",\"recordingId\":\"REb1eecfce410141ad1749c0fc84dfbb6fc4c2a810\",\"accountId\":\"ACabe7063197551fe51671f9ac3a9708e9dad51c4d\",\"callId\":\"CF3cb8a52f461bcf64cbd3111d9492c3f61943eef9\",\"duration\":9},{\"uri\":\"/Accounts/ACabe7063197551fe51671f9ac3a9708e9dad51c4d/Recordings/RE9cae4798ca0803cbd52209c1bfe99d25027cc2cf\",\"revision\":1,\"dateCreated\":\"Mon, 27 Jun 2016 20:38:16 GMT\",\"dateUpdated\":\"Mon, 27 Jun 2016 20:38:16 GMT\",\"recordingId\":\"RE9cae4798ca0803cbd52209c1bfe99d25027cc2cf\",\"accountId\":\"ACabe7063197551fe51671f9ac3a9708e9dad51c4d\",\"callId\":\"CFa32e912be62fff5d0b1bcd99610a69281918800a\",\"duration\":9}]}");

                RecordingList recordingList = recordingsRequester.getMeta();

                Assert.IsNotNull(recordingList);

                Assert.AreEqual(recordingList.getLocalSize, 2);
                Assert.AreEqual((recordingList.export()).Count, 2);

                Recording recording = recordingList.get(0) as Recording;

                Assert.IsNotNull(recording);
                Assert.AreEqual(recording.getRecordingId, "REb1eecfce410141ad1749c0fc84dfbb6fc4c2a810");

                type      = typeof(APIRequester);
                fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(recordingList, "http://GetRecordingListTest:3000");
                }

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"total\":3,\"start\":2,\"end\":2,\"page\":1,\"numPages\":2,\"pageSize\":2,\"nextPageUri\":null,\"recordings\":[{\"uri\":\"/Accounts/ACabe7063197551fe51671f9ac3a9708e9dad51c4d/Recordings/REb1eecfce410141ad1749c0fc84dfbb6fc4c2a815\",\"revision\":1,\"dateCreated\":\"Mon, 27 Jun 2016 17:53:55 GMT\",\"dateUpdated\":\"Mon, 27 Jun 2016 17:53:55 GMT\",\"recordingId\":\"REb1eecfce410141ad1749c0fc84dfbb6fc4c2a815\",\"accountId\":\"ACabe7063197551fe51671f9ac3a9708e9dad51c4d\",\"callId\":\"CF3cb8a52f461bcf64cbd3111d9492c3f61943eef9\",\"duration\":9}]}");

                recordingList.loadNextPage();

                Assert.IsNotNull(recordingList);

                Assert.AreEqual(recordingList.getLocalSize, 3);
                Assert.AreEqual((recordingList.export()).Count, 3);

                recording = recordingList.get(2) as Recording;
                Assert.IsNotNull(recording);
                Assert.AreEqual(recording.getRecordingId, "REb1eecfce410141ad1749c0fc84dfbb6fc4c2a815");
            }
            catch (PersyException pe)
            {
                Assert.Fail(pe.Message);
            }
        }
        public void GetRecordingListByCallIdTest()
        {
            try
            {
                RecordingsRequester recordingsRequester = new RecordingsRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(recordingsRequester, "http://GetRecordingListTest:3000");
                }

                WebRequest.RegisterPrefix("http://GetRecordingListTest:3000/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Recordings?callId=CF3cb8a52f461bcf64cbd3111d9492c3f61943eef9", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"total\":1,\"start\":0,\"end\":0,\"page\":1,\"numPages\":1,\"pageSize\":20,\"nextPageUri\":null,\"recordings\":[{\"uri\":\"/Accounts/ACabe7063197551fe51671f9ac3a9708e9dad51c4d/Recordings/REb1eecfce410141ad1749c0fc84dfbb6fc4c2a815\",\"revision\":1,\"dateCreated\":\"Mon, 27 Jun 2016 17:53:55 GMT\",\"dateUpdated\":\"Mon, 27 Jun 2016 17:53:55 GMT\",\"recordingId\":\"REb1eecfce410141ad1749c0fc84dfbb6fc4c2a815\",\"accountId\":\"ACabe7063197551fe51671f9ac3a9708e9dad51c4d\",\"callId\":\"CF3cb8a52f461bcf64cbd3111d9492c3f61943eef9\",\"duration\":9}]}");

                RecordingsSearchFilters filters = new RecordingsSearchFilters();
                filters.setCallId("CF3cb8a52f461bcf64cbd3111d9492c3f61943eef9");
                RecordingList recordingList = recordingsRequester.getMeta(filters);

                Assert.IsNotNull(recordingList);

                Assert.AreEqual(recordingList.getLocalSize, 1);
                Assert.AreEqual((recordingList.export()).Count, 1);

                Recording recording = recordingList.get(0) as Recording;

                Assert.IsNotNull(recording);
                Assert.AreEqual(recording.getRecordingId, "REb1eecfce410141ad1749c0fc84dfbb6fc4c2a815");
            }
            catch (PersyException pe)
            {
                Assert.Fail(pe.Message);
            }
        }
 public RecordingMetadataWrapper()
 {
     Collection = new RecordingList();
 }
Exemple #6
0
 public RecordingListTests()
 {
     this.data = TestHelper.GetJson <RecordingList>("recording-search.json");
 }
 public RecordingMetadataWrapper()
 {
     Collection = new RecordingList();
 }
Exemple #8
0
        /// <summary>
        /// Get the recording (track data) from MusicBrainz via query using the artist, album an track names
        /// </summary>
        /// <returns>MusicBrainz Recording object</returns>
        public Recording GetRecordingFromMusicBrainz(string artist, string album, string track)
        {
            try
            {
                while (IsLastRequestTooSoon())
                {
                    ThreadHelper.SafeSleep(1100);
                }

                QueryParameters <Recording> query = null;
                if (!string.IsNullOrEmpty(album))
                {
                    query = new QueryParameters <Recording>()
                    {
                        { "artist", artist },
                        { "release", album },
                        { "recording", track }
                    };
                }
                else
                {
                    query = new QueryParameters <Recording>()
                    {
                        { "artist", artist },
                        { "recording", track }
                    };
                }

                RecordingList recordings = null;
                try
                {
                    MusicBrainzLastRequest = DateTime.Now;
                    recordings             = MusicBrainzClient.Recordings.SearchAsync(query).GetAwaiter().GetResult();
                }
                catch
                {
                    ThreadHelper.SafeSleep(1100); // MusicBrains throttle handler
                    try
                    {
                        MusicBrainzLastRequest = DateTime.Now;
                        recordings             = MusicBrainzClient.Recordings.SearchAsync(query).GetAwaiter().GetResult();
                    }
                    catch { }
                }

                if (recordings != null && recordings.Count > 0)
                {
                    IEnumerable <Recording> matches = null;
                    if (!string.IsNullOrEmpty(album))
                    {
                        matches = recordings.Items.Where(r => r.Title == track && r.Releases.Any(s => s.Title == album));
                    }
                    else
                    {
                        matches = recordings.Items.Where(r => r.Title == track);
                    }

                    if (matches != null && matches.Count() > 0)
                    {
                        return(matches.OrderByDescending(r => r.Releases.Count).FirstOrDefault());
                    }
                }
            }
            catch { }

            return(null);
        }
        static void Main(string[] args)
        {
            string filePath = "";

            if (args.Length == 1 && File.Exists(args[0]))
            {
                filePath = args[0];
            }
            else
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (File.Exists(args[i]))
                    {
                        filePath = args[i];
                    }
                }
            }
            if (filePath != "")
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(filePath);
                string       outputDir, outputFile;
                StreamWriter channelStats, showStats;
                string       rootName = xmlDoc.DocumentElement.Name;
                if (string.Equals(rootName, "recordings"))
                {
                    Console.WriteLine("NextPVR Recording List Xml File Recognized.");
                    string                outputPath;
                    RecordingList         show;
                    RecordingList[]       shows;
                    RecordingList.Channel channel;
                    outputDir    = CreateOutputDirectory(filePath);
                    channelStats = new StreamWriter(Path.Combine(outputDir, "ChannelStats.txt"));
                    RecordingList list = new RecordingList(xmlDoc);
                    Console.WriteLine(string.Concat(list.Count.ToString(), " recordings found."));
                    RecordingList.Channel[] channels = list.DivideByChannelAndShow();
                    Console.WriteLine(string.Concat(channels.Length.ToString(), " unique channels found."));
                    for (int i = 0; i < channels.Length; i++)
                    {
                        channel = channels[i];
                        shows   = channel.Shows;
                        channelStats.Write(channel.ChannelName);
                        channelStats.Write(" | ");
                        channelStats.WriteLine(shows.Length.ToString());
                        outputPath = Path.Combine(outputDir, channel.ChannelName);
                        if (!Directory.Exists(outputPath))
                        {
                            Directory.CreateDirectory(outputPath);
                        }
                        outputFile = Path.Combine(outputDir, string.Concat(channel.ChannelName, "_ShowStats.txt"));
                        showStats  = new StreamWriter(outputFile);
                        for (int j = 0; j < shows.Length; j++)
                        {
                            show       = shows[j];
                            outputFile = Path.Combine(outputPath, string.Concat(show.ShowName, ".xml"));
                            show.Serialize(outputFile);
                            showStats.Write(show.ShowName);
                            showStats.Write(" | ");
                            showStats.WriteLine(show.Count.ToString());
                        }
                        showStats.Flush();
                        showStats.Close();
                    }
                    channelStats.Flush();
                    channelStats.Close();
                }
                else if (string.Equals(rootName, "recurrings"))
                {
                    Console.WriteLine("NextPVR Recurring Time List Xml File Recognized.");
                    outputDir    = CreateOutputDirectory(filePath);
                    channelStats = new StreamWriter(Path.Combine(outputDir, "ChannelStats.txt"));
                    RecurringRecordingList list = new RecurringRecordingList(xmlDoc);
                    Console.WriteLine(string.Concat(list.Count.ToString(), " recurring timers found."));
                    RecurringRecordingList[] channels = list.DivideByChannel(RecNameSort.NameAscending, RecSizeSort.Descending);
                    Console.WriteLine(string.Concat(channels.Length.ToString(), " unique channels found."));
                    for (int i = 0; i < channels.Length; i++)
                    {
                        list       = channels[i];
                        outputFile = string.Concat("recurring_", list.ChannelName);
                        outputFile = Path.Combine(outputDir, outputFile);
                        list.Serialize(string.Concat(outputFile, ".xml"));
                        channelStats.Write(list.ChannelName);
                        channelStats.Write(" | ");
                        channelStats.WriteLine(list.Count.ToString());
                        showStats = new StreamWriter(string.Concat(outputFile, "_ShowStats.txt"));
                        foreach (RecurringRecording rec in list)
                        {
                            showStats.Write(rec.Name);
                            showStats.Write(" | ");
                            //showStats.Write(rec.EPGTitle);
                            //showStats.Write(" | ");
                            showStats.WriteLine(rec.CreateRuleString());
                        }
                        showStats.Flush();
                        showStats.Close();
                    }
                    outputFile = Path.Combine(outputDir, DateTime.Now.ToString("'recurring_'yyyy-MM-dd_HH'h'mm_ss"));
                    list       = RecurringRecordingList.MergeLists(channels, channels.Length);
                    list.Serialize(string.Concat(outputFile, ".xml"));
                    channelStats.Flush();
                    channelStats.Close();
                }
            }
        }