public void UpdateTest()
        {
            var temp  = new[] { "gsa", "dfb", "sar", "ac", "fgfbg", "hek", "fsaw", "l;fg", "" };
            var temp2 = new[] { "aba", "zzz", "aac", "aaa ", "aca", "abb", "aab", "abc", "acb", "acc", "jhgj" };


            var testObject = new ObservableSortedCollection <string>(temp, Comparer <string> .Default.Compare);

            foreach (var item in temp2)
            {
                testObject.Add(item);
            }
        }
Exemplo n.º 2
0
        public void GetAllEpisode(ObservableSortedCollection <ProgramInfo> programs)
        {
            Task.Run(() =>
            {
                try
                {
                    if (GetAll)
                    {
                        return;
                    }
                    GetAll = true;

                    ObservableSortedCollection <EpisodeInfo> films = null;
                    Parallel.ForEach(new List <ProgramInfo>(programs), (ProgramInfo program) =>
                    {
                        GetEpisodeListSync(program, (p) => program.Progress = p);
                        if (program.Episodes.Count == 0)
                        {
                            programs.Remove(program);
                        }
                        else if (program.IsMovie)
                        {
                            programs.Remove(program);
                            program.Name = GulliDataSource.FilmProgramName;
                            DbUpdate(program);
                            lock (GetAllLocker)
                                if (films == null)
                                {
                                    films = program.Episodes;
                                    programs.Add(program);
                                }
                                else
                                {
                                    films.Add(program.Episodes);
                                }
                        }
                    });
                }
                catch (Exception e)
                {
                    Debug.Write(e.Message);
                }
                GetAll = false;
            });
        }
Exemplo n.º 3
0
        public Exception GetProgramListSync(ObservableSortedCollection <ProgramInfo> programs, Action <double> onProgress = null)
        {
            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(programs.SynchronizationObject);
            }

            try
            {
                lock (ProgramLock)
                {
                    if (PogrameUpdating)
                    {
                        onProgress?.Invoke(1);
                        return(null);
                    }
                    else
                    {
                        onProgress?.Invoke(0);
                        PogrameUpdating = true;
                    }
                }

                TableQuery <ProgramInfo> query = null;
                lock (DbLocker)
                    query = db.Table <ProgramInfo>();

                if (query != null)
                {
                    programs.Add(query);
                }

                Regex ProgramRegex =
                    new Regex(@"(<div\s+class=""wrap-img\s+program""\s*>" +
                              @"\s*<a\s+href=""(?<url>http://replay\.gulli\.fr/(?<type>[^/]+)/[^""]+)""\s*>" +
                              @"\s*<img\s+src=""(?<img>http://[a-z1-9]+-gulli\.ladmedia\.fr/r/[^""]+/img/var/storage/imports/(?<filename>[^""]+))""\s*alt=""(?<name>[^""]+)""\s*/>" +
                              @"\s*</a>\s*</div>)", RegexOptions.Multiline | RegexOptions.ExplicitCapture | RegexOptions.Singleline);

                string          content    = ProgramPage.GetContent();
                MatchCollection matches    = ProgramRegex.Matches(content);
                List <Match>    matcheList = new List <Match>(matches.Count);
                for (int i = 0; i < matches.Count; i++)
                {
                    matcheList.Add(matches[i]);
                }

                int count = 0;
                Parallel.ForEach(matcheList, (Match m) =>
                {
                    count++;
                    onProgress?.Invoke((double)count / matcheList.Count);
                    string s = m.Value;

                    string url = m.Groups["url"].Value;
                    if (query.Where((p) => p.Url == url).Count() == 0)
                    {
                        if (SynchronizationContext.Current == null)
                        {
                            SynchronizationContext.SetSynchronizationContext(programs.SynchronizationObject);
                        }

                        ProgramInfo program = new ProgramInfo(
                            m.Groups["url"].Value,
                            m.Groups["type"].Value,
                            WebUtility.HtmlDecode(m.Groups["name"].Value),
                            GetImageUrl(m.Groups["filename"].Value));
                        DbInsert(program);
                        programs.Add(program);
                    }
                });

                GetAllEpisode(programs);
            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
                return(e);
            }
            finally { PogrameUpdating = false; }

            return(null);
        }