예제 #1
0
        public T CacheManagement <T>(string url, Func <String, T> method, double timeCache)
        {
            lock (_lockThis2) {
                var model = default(T);

                if (!string.IsNullOrEmpty(url))
                {
                    CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Buscando em DB"));
                    if (_libraryContext.Cache.Find().Where(x => x.Link == url).Execute().FirstOrDefault() is Cache cache)
                    {
                        CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Encontrado!"));
                        if (!InternetChecker.IsConnectedToInternet())
                        {
                            model = cache.ModelsCache.ToObject <T>();
                        }
                        else
                        {
                            if ((DateTime.Now - cache.Date).TotalMinutes < timeCache)
                            {
                                model = cache.ModelsCache.ToObject <T>();
                            }
                            else
                            {
                                CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Cache Vencido"));
                                CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Atualizando..."));
                                model = method.Invoke(url);
                                if (model != null)
                                {
                                    _libraryContext.Cache.Update(x => new { x.ModelsCache, x.Date }, model.ToBytes(), DateTime.Now)
                                    .Where(x => x.Link == url).Execute();
                                }
                                else
                                {
                                    model = cache.ModelsCache.ToObject <T>();
                                }
                            }
                        }
                    }
                    else
                    {
                        CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Não encontrado!"));
                        if (InternetChecker.IsConnectedToInternet())
                        {
                            model = method.Invoke(url);
                            if (model != null)
                            {
                                CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Criando Cache"));
                                var updt = new Cache {
                                    Link = url, Date = DateTime.Now, ModelsCache = model.ToBytes()
                                };
                                _libraryContext.Cache.Save(updt);
                            }
                        }
                    }
                }

                return(model);
            }
        }
예제 #2
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     Debug.Log("Internet: " + gameObject.name);
 }
예제 #3
0
 void Start()
 {
     ICInstance = new InternetChecker();
     if (ICInstance != null)
     {
         GameObject.Destroy(ICInstance);
     }
     else
     {
         ICInstance = this;
     }
 }
예제 #4
0
 void MakeSingleton()
 {
     if (instance != null)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
 }
예제 #5
0
        private void btnGetInfoJob_Click(object sender, RoutedEventArgs e)
        {
            // привязка lstw к свойству коллекции
            //lstw.DataContext = "";
            //List<CarTable> lk = new List<CarTable>() {
            //    new CarTable(1), new CarTable(2),new CarTable(3)
            //};
            //lstw.ItemsSource = lk;

            //WorkFinder htd = new WorkFinder();

            //List<JobInfo> j = htd.GetJobLinksInMozaika();
            //lstw.ItemsSource = j;
            MessageBox.Show(ComputerEnum.GetComEnum());
            if (InternetChecker.InternetGetConnectedState())
            {
                // Подготовка вызова в другом потоке
                BeginGetJobInMozaika();
            }
            else
            {
                MessageBox.Show("Не могу подключится к интернету");
            }
        }
예제 #6
0
 void Start()
 {
     simpleAdScript  = GameObject.Find("simpleAd").GetComponent <simpleAd>();
     internetChecker = GameObject.Find("InternetChecker").GetComponent <InternetChecker>();
 }
예제 #7
0
        public T ModelCache <T>(string url, Func <String, T> method, double timeCache, bool withoutCache) where T : ModelBase
        {
            lock (_lockThis) {
                var model = default(T);

                if (!string.IsNullOrEmpty(url))
                {
                    if (typeof(T).IsAssignableFrom(typeof(Hq)))
                    {
                        if (withoutCache)
                        {
                            model = SaveHqInfo <T>(url, method);
                        }
                        else
                        {
                            if (_libraryContext.Hq.Find().Where(x => x.Link == url).Execute().FirstOrDefault() is Hq hqModel)
                            {
                                hqModel.Chapters = _libraryContext.Chapter.Find().Where(x => x.Hq == hqModel).Execute();
                                model            = hqModel as T;
                                if (InternetChecker.IsConnectedToInternet())
                                {
                                    if (!hqModel.IsDetailedInformation)
                                    {
                                        CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Atualizando Informações"));
                                        model = SaveHqInfo <T>(url, method);
                                    }
                                    else
                                    {
                                        if ((DateTime.Now - hqModel.TimeInCache).TotalMinutes > timeCache)
                                        {
                                            CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Cache Vencido"));
                                            CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Atualizando..."));
                                            model = SaveHqInfo <T>(url, method);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                model = SaveHqInfo <T>(url, method);
                            }
                        }
                    }
                    if (typeof(T).IsAssignableFrom(typeof(Chapter)))
                    {
                        if (withoutCache)
                        {
                            model = method.Invoke(url) as T;
                        }
                        else
                        {
                            if (_libraryContext.Chapter.Find().Where(x => x.Link == url).Execute().FirstOrDefault() is Chapter chapterModel)
                            {
                                chapterModel.Pages = _libraryContext.Page.Find().Where(x => x.Chapter == chapterModel).Execute();
                                if (chapterModel.Pages == null || chapterModel.Pages.Count == 0)
                                {
                                    if (method.Invoke(url) is Chapter chapterFromSite)
                                    {
                                        chapterModel.Pages = chapterFromSite.Pages;
                                        SavePagesInDb(chapterModel);
                                    }
                                }
                                model = chapterModel as T;
                            }
                            else
                            {
                                model = method.Invoke(url) as T;
                                SavePagesInDb(model as Chapter);
                            }
                        }
                    }
                }

                return(model);
            }
        }
예제 #8
0
        public List <Update> UpdatesCache(string url, Func <String, List <Update> > method, double timeCache)
        {
            lock (_lockThis6) {
                var updates = new List <Update>();
                CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Buscando em DB"));
                var time = DateTime.Now;
                if (_libraryContext.Update.Find().Where(x => x.Source == url && x.TimeCache > time).Execute() is List <Update> updt && updt.Count > 0)
                {
                    CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Encontrado!"));
                    foreach (var up in updt)
                    {
                        var hq = up.Hq;
                        if (hq != null)
                        {
                            CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Adicionando {up.Hq.Title}"));
                            up.Chapters = _libraryContext.Chapter.Find().Where(x => x.Hq == hq && x.IsUpdate == true && x.Date > time).Execute();
                            updates.Add(up);
                        }
                    }
                }
                else
                {
                    CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Não encontrado!"));
                    _libraryContext.Chapter.Update(x => x.IsUpdate, false).Where(x => x.IsUpdate == true && x.Date < time).Execute();
                    if (InternetChecker.IsConnectedToInternet())
                    {
                        updates = method.Invoke(url);
                        if (updates != null)
                        {
                            CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Criando Cache"));
                            foreach (var upd in updates)
                            {
                                upd.Source    = url;
                                upd.TimeCache = DateTime.Now.AddMinutes(timeCache);
                                var link = upd.Hq.Link;
                                if (_libraryContext.Hq.Find().Where(x => x.Link == link).Execute().FirstOrDefault() is Hq hq)
                                {
                                    upd.Hq = hq;
                                    foreach (var chap in upd.Chapters)
                                    {
                                        chap.Hq       = upd.Hq;
                                        chap.IsUpdate = true;
                                        chap.Date     = DateTime.Now.AddDays(3);
                                        if (_libraryContext.Chapter.Find(x => x.Id).Where(x => x.Link == chap.Link).Execute().FirstOrDefault() is Chapter chapDb)
                                        {
                                            chap.Id = chapDb.Id;
                                        }
                                        else
                                        {
                                            chap.Id = Convert.ToInt32(_libraryContext.Chapter.Save(chap));
                                        }
                                    }
                                }
                                else
                                {
                                    CoreEventHub.OnProcessingProgress(this, new ProcessingEventArgs(DateTime.Now, $"Criando Cache para {upd.Hq.Title}"));
                                    upd.Hq.CoverSource = _coveCacheHelper.CreateCache(upd.Hq);
                                    upd.Hq.Id          = Convert.ToInt32(_libraryContext.Hq.Save(upd.Hq));
                                    foreach (var chap in upd.Chapters)
                                    {
                                        chap.Hq       = upd.Hq;
                                        chap.IsUpdate = true;
                                        chap.Date     = DateTime.Now.AddDays(3);
                                        if (_libraryContext.Chapter.Find(x => x.Id).Where(x => x.Link == chap.Link).Execute().FirstOrDefault() is Chapter chapDb)
                                        {
                                            chap.Id = chapDb.Id;
                                        }
                                        else
                                        {
                                            chap.Id = Convert.ToInt32(_libraryContext.Chapter.Save(chap));
                                        }
                                    }
                                }

                                _libraryContext.Update.Save(upd);
                            }
                        }
                    }
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(updates);
            }
        }
예제 #9
0
 void Awake()
 {
     Instance = this;
 }
        public MainPageOfPlayer()
        {
            InitializeComponent();

            if (!InternetChecker.ConnectionAvailable("https://www.google.by/"))
            {
                ErrorForm erForm = new ErrorForm("Отсутствует соединение с интернетом. Часть функционала программы недоступна. Попробуйте позже.");
                erForm.ShowDialog();
                buttonVK.Visible               = false;
                vkCom.Visible                  = false;
                buttonLoginVk.Visible          = false;
                imageSoundCloud.Visible        = false;
                soundCloud.Visible             = false;
                buttonSearchSoundCloud.Visible = false;
            }

            if (Settings.Default.red == 0 && Settings.Default.green == 0 && Settings.Default.blue == 0)
            {
                CustomColor.maincolor = CustomColor.defaultcolor;
            }
            else
            {
                CustomColor.maincolor = Color.FromArgb(Settings.Default.red, Settings.Default.green, Settings.Default.blue);
            }

            BassClass.InitBass(BassClass.HZ);
            openFileDialog1.Filter            = TrackBase.GetInputFormats();
            ButtonAdd.Image                   = CustomColor.FillShape(Properties.Resources.add);
            buttonDelete.Image                = CustomColor.FillShape(Properties.Resources.delete);
            ButtonPlay.Image                  = CustomColor.FillShape(Properties.Resources.Circled_Play_100px);
            ButtonStop.Image                  = CustomColor.FillShape(Properties.Resources.stop1);
            ButtonPause.Image                 = CustomColor.FillShape(Properties.Resources.pause1);
            ButtonSkipLeft.Image              = CustomColor.FillShape(Properties.Resources.SkipLeft);
            ButtonSkipRight.Image             = CustomColor.FillShape(Properties.Resources.SkipRight);
            ButtonSettings.Image              = CustomColor.FillShape(Properties.Resources.settings);
            ButtonSettings.Image              = CustomColor.FillShape(Properties.Resources.settings);
            buttonVK.Image                    = CustomColor.ColoredObject(Properties.Resources.VK_com_100px, Color.FromArgb(80, 114, 153));
            buttonLogoutVk.Image              = CustomColor.ColoredObject(Properties.Resources.logout, Color.FromArgb(80, 114, 153));
            buttonMute.Image                  = CustomColor.FillShape(Properties.Resources.yes_audio);
            streamTrackBar.UseCustomBackColor = true;
            streamTrackBar.UseCustomForeColor = true;
            streamTrackBar.ForeColor          = CustomColor.defaultcolor;

            playlist.Size               = new Size(1088, 609);
            playlist.Location           = new Point(52, 47);
            searchTextBox.Visible       = false;
            buttonSearchStartVK.Visible = false;
            buttonDelete.Visible        = true;
            buttonDownload.Visible      = false;

            soundCloud.Location             = new Point(46, 224);
            imageSoundCloud.Location        = new Point(4, 226);
            buttonSearchSoundCloud.Location = new Point(0, 271);
            if (!VkAuthLog.GetAuth())
            {
                buttonLogoutVk.Visible = false;
            }

            vkCom.Font     = new Font("Phenomena", 16.25F);
            vkCom.Location = new Point(46, 133);

            buttonDownload.Image = CustomColor.FillShape(Properties.Resources.Download);

            if (Settings.Default.path == "" || Settings.Default.path == null)
            {
                Settings.Default.path = TrackBase.AppPath;
            }
        }