Example #1
0
        private void TemporaryAdvertismentUpdate()
        {
            string baseURL = MicroPrinter.App.AppContext.Instance.BaseURL;

            while (!this.cancellationToken.IsCancellationRequested)
            {
                Thread.Sleep(0x1388);
                if (this.temporaryGroup == null)
                {
                    try
                    {
                        JObject obj2 = JObject.Parse(HttpUtils.Get(baseURL + "/adv/temporary/?1=1", "1"));
                        if (obj2 == null)
                        {
                            continue;
                        }
                        if (obj2["data"].ToString() == "[]")
                        {
                            continue;
                        }
                        JObject obj3 = obj2["data"]["group"] as JObject;
                        JObject obj4 = obj2["data"]["groupitem"] as JObject;
                        if (((this.temporaryGroup == null) || (this.temporaryGroup.Id == null)) || !this.temporaryGroup.Id.Equals(obj3["id"].ToString()))
                        {
                            WybAdvGroup group1 = new WybAdvGroup();
                            group1.Id           = obj3["id"].ToString();
                            group1.Name         = obj3["name"].ToString();
                            this.temporaryGroup = group1;
                            WybAdvGroupItem item2 = new WybAdvGroupItem {
                                Id        = obj4["id"].ToString(),
                                Type      = obj4["type"].ToString(),
                                Duration  = int.Parse(obj4["duration"].ToString()),
                                Thumbnail = obj4["thumbnail"].ToString()
                            };
                            char[] separator = new char[] { ';' };
                            item2.FileList = obj4["fileUrls"].ToString().Split(separator).ToList <string>();
                            WybAdvGroupItem item = item2;
                            this.temporaryGroup.wybAdvGroupItems.Add(item.Id, item);
                            Console.WriteLine("获取临时广告 [" + this.temporaryGroup.Id + "] 成功!");
                        }
                        string[] textArray1 = new string[] { baseURL, "/adv/removeTemporary/?1=1", "&groupID=", this.temporaryGroup.Id };
                        obj2 = JObject.Parse(HttpUtils.Get(string.Concat(textArray1), "1"));
                        if ((obj2 == null) && !bool.Parse(obj2["success"].ToString()))
                        {
                            Console.WriteLine("取消临时广告 [" + this.temporaryGroup.Id + "] 失败!");
                        }
                        else if (bool.Parse(obj2["success"].ToString()))
                        {
                            Console.WriteLine("取消临时广告 [" + this.temporaryGroup.Id + "] 成功!");
                        }
                    }
                    catch (Exception exception)
                    {
                        this.log.Error("TemporaryAdvertismentUpdate: " + exception.Message);
                    }
                }
            }
        }
Example #2
0
        private void _Timer_Tick(bool continuePlay = false)
        {
            this.AdvertismentDirDelete();
            this.CommonAdvertismentRemove();
            Console.WriteLine("定时器触发 Timer_Tick,当前时间:" + $"{DateTime.Now}");
            string str3 = @"\download\";

            this.timer.Interval = new TimeSpan(0, 0, 0, this.durTime);
            this.timer.Stop();
            string baseURL = MicroPrinter.App.AppContext.Instance.BaseURL;
            bool   flag    = Common.WhetherNeedUpdate("getDefault");

            try
            {
                if (this.isTemporary && (this.temporaryGroup != null))
                {
                    this.temporaryGroup = null;
                    this.isTemporary    = false;
                }
                if (this.temporaryGroup != null)
                {
                    str3 = @"\download\adv\tempAdv\";
                    Console.WriteLine("开始处理临时广告的播放 downloadPath: " + str3);
                    WybAdvGroupItem item = this.temporaryGroup.wybAdvGroupItems.Values.First <WybAdvGroupItem>();
                    if (item.Type.Equals("10"))
                    {
                        string   url        = baseURL + "/file/download/?from=1&ftype=2&source=" + item.FileList.First <string>();
                        char[]   separator  = new char[] { '.' };
                        string[] textArray1 = item.FileList.First <string>().Split(separator);
                        string   str6       = textArray1[textArray1.Length - 1].ToLower();
                        string[] textArray2 = new string[5];
                        textArray2[0] = Environment.CurrentDirectory;
                        textArray2[1] = str3;
                        Guid guid = Guid.NewGuid();
                        textArray2[2] = guid.ToString();
                        textArray2[3] = ".";
                        textArray2[4] = str6;
                        string path = string.Concat(textArray2);
                        if (this.httpUtils.HttpDownload(url, path))
                        {
                            Console.WriteLine("播放临时广告-图片");
                            this.UpdateImage(path);
                        }
                    }
                    else if (!item.Type.Equals("20"))
                    {
                        item.Type.Equals("30");
                    }
                    else
                    {
                        foreach (string local1 in item.FileList)
                        {
                            string   url        = baseURL + "/file/download/?from=2&ftype=2&source=" + item.FileList.First <string>();
                            char[]   separator  = new char[] { '.' };
                            string[] textArray3 = item.FileList.First <string>().Split(separator);
                            string   str9       = textArray3[textArray3.Length - 1].ToLower();
                            string[] textArray4 = new string[5];
                            textArray4[0] = Environment.CurrentDirectory;
                            textArray4[1] = str3;
                            string[] strArray = textArray4;
                            strArray[2] = Guid.NewGuid().ToString();
                            strArray[3] = ".";
                            strArray[4] = str9;
                            string str5 = string.Concat(strArray);
                            if (this.httpUtils.HttpDownload(url, str5))
                            {
                                Console.WriteLine("播放临时广告的图片序列");
                                this.taskFactory.StartNew(() => this.UpdateImage(str5), new CancellationTokenSource().Token, TaskCreationOptions.None, this._syncContextTaskScheduler).Wait();
                            }
                        }
                    }
                    this.isTemporary = true;
                }
                else if (!this.isDefaultAdvHandled | flag)
                {
                    string path = Environment.CurrentDirectory + @"\Resources\media\default.avi";
                    Console.WriteLine("开始处理默认广告的播放  是否已经拉取过默认数据:" + this.isDefaultAdvHandled.ToString());
                    Console.Write(",  地址:" + path);
                    Console.WriteLine(",  是否需要强制更新:" + flag.ToString());
                    if (!File.Exists(path))
                    {
                        Console.WriteLine("开始处理默认广告的播放 本地默认文件不存在:" + path);
                        this.handleGetDefault(baseURL, path);
                    }
                    else
                    {
                        Console.WriteLine("开始处理默认广告的播放 本地默认文件存在:" + path);
                        if (!flag)
                        {
                            Console.Write(",不需要从服务器更新默认广告");
                            this.UpdateMedia(new FileInfo(path).FullName);
                        }
                        else
                        {
                            Console.Write(",需要从服务器更新默认广告");
                            this.log.Info("needUpdateGetDefault 删除同名文件:" + path);
                            File.Delete(path);
                            this.handleGetDefault(baseURL, path);
                        }
                    }
                    this.isDefaultAdvHandled = true;
                }
                else
                {
                    str3 = @"\download\adv\commonAdv\";
                    Console.WriteLine("开始处理常规广告的播放 downloadPath: " + str3);
                    if ((((this.commonPlayIndex == 0) && (this.commonOrderIndex == 0)) | (this.commonOrderIndex >= (this.commAdvItems[this.commonPlayIndex].PlayOrder + this.commAdvItems[this.commonPlayIndex].DurationCount))) | continuePlay)
                    {
                        if (this.commonPlayIndex == (this.commAdvItems.Count <WybAdvGroupItem>() - 1))
                        {
                            Console.WriteLine("常规轮回");
                            this.commonPlayIndex  = 0;
                            this.commonOrderIndex = 0;
                        }
                        else if ((this.commonPlayIndex != 0) || (this.commonOrderIndex != 0))
                        {
                            this.commonPlayIndex++;
                        }
                        else
                        {
                            this.commonPlayIndex = 0;
                        }
                        WybAdvGroupItem item2   = this.commAdvItems[this.commonPlayIndex];
                        string          fileURL = item2.FileList.First <string>();
                        if (fileURL != null)
                        {
                            if (item2.Type.Equals("10"))
                            {
                                string   str;
                                string   str12      = this.getFileRealName(fileURL);
                                string   url        = baseURL + "/file/download/?from=3&ftype=2&source=" + fileURL;
                                char[]   separator  = new char[] { '.' };
                                string[] textArray5 = fileURL.Split(separator);
                                textArray5[textArray5.Length - 1].ToLower();
                                if ((item2.RealFileList.Count <string>() != 0) && !string.IsNullOrEmpty(item2.RealFileList.First <string>()))
                                {
                                    str = item2.RealFileList.First <string>();
                                }
                                else
                                {
                                    str = Environment.CurrentDirectory + str3 + str12;
                                    if (!File.Exists(str) && this.httpUtils.HttpDownload(url, str))
                                    {
                                        this.downloadedFiles.Add(str);
                                    }
                                }
                                Console.WriteLine("from=3 10 播放常规广告-图片");
                                this.UpdateImage(str);
                            }
                            else if (!item2.Type.Equals("20") && item2.Type.Equals("30"))
                            {
                                string   str2;
                                string   str14      = this.getFileRealName(fileURL);
                                string   url        = baseURL + "/file/download/?from=4&ftype=2&source=" + fileURL;
                                char[]   separator  = new char[] { '.' };
                                string[] textArray6 = fileURL.Split(separator);
                                textArray6[textArray6.Length - 1].ToLower();
                                if ((item2.RealFileList.Count <string>() != 0) && !string.IsNullOrEmpty(item2.RealFileList.First <string>()))
                                {
                                    str2 = item2.RealFileList.First <string>();
                                }
                                else
                                {
                                    str2 = Environment.CurrentDirectory + str3 + str14;
                                    if (!File.Exists(str2) && this.httpUtils.HttpDownload(url, str2))
                                    {
                                        this.downloadedFiles.Add(str2);
                                    }
                                }
                                Console.WriteLine("from=4 30 播放常规广告-视频");
                                this.UpdateMedia(str2);
                            }
                        }
                    }
                    this.commonOrderIndex++;
                }
            }
            catch (Exception exception)
            {
                this.log.Error("Timer_Tick: " + exception.Message);
            }
            this.timer.Start();
        }