Пример #1
0
        /// <summary>
        /// 显示陌生人详情
        /// </summary>
        /// <param name="userId">UserId</param>
        private void ShowStrangerDetial(string userId)
        {
            var dclient = APIHelper.GetUserDetialAsync(userId);//详情

            LogHelper.log.Info("陌生用户GetUserDetial" + userId);
            dclient.UploadDataCompleted += (s, res) =>
            {
                var user   = JsonConvert.DeserializeObject <JsonuserDetial>(Encoding.UTF8.GetString(res.Result));
                var tmpFri = user.data.ConvertToDataFriend();
                if (tmpFri != null)
                {
                    Friend = user.data;
                    var downloads = new List <DownLoadFile>();
                    downloads.Add(new DownLoadFile()
                    {
                        Jid      = userId,
                        Token    = userId,
                        Name     = user.data.nickname,
                        Type     = DownLoadFileType.Image,
                        LocalUrl = Applicate.LocalConfigData.GetDownloadAvatorPath(userId),
                        ShouldDeleteWhileFileExists = true
                    });
                    //下载头像
                    HttpDownloader.Download(downloads, (file) =>
                    {
                        switch (file.State)
                        {
                        case DownloadState.Successed:
                            App.Current.Dispatcher.Invoke(() =>
                            {
                                Friend.userId = file.Jid;
                            });
                            break;

                        case DownloadState.Error:
                            break;

                        default:
                            break;
                        }
                    });
                    if (!string.IsNullOrWhiteSpace(user.data._remarkName))
                    {
                        RemarkName = user.data._remarkName;
                    }
                    else
                    {
                        RemarkName = Friend.remarkName;
                    }
                    var stranger = new DataOfFriends();
                    stranger        = user.data.ToDataOfFriend();
                    stranger.status = 0;
                    stranger.AutoInsert();
                }
            };
        }
 private void Start_btn_Click(object sender, EventArgs e)
 {
     httpdownloader = new HttpDownloader(url_txtbox.Text, $"{Application.StartupPath}\\{Path.GetFileName(url_txtbox.Text)}");
     httpdownloader.DownloadCompleted += HttpDownloader_DownloadComplete;
     httpdownloader.ProgressChanged   += HttpDownloader_ProgressChanged;
     httpdownloader.Start();
     Start_btn.Enabled  = false;
     resume_btn.Enabled = true;
     pause_btn.Enabled  = true;
 }
Пример #3
0
        private static string AddNewGameFile(string path, Guid gameId, GameDatabase database)
        {
            var          fileName = Guid.NewGuid().ToString() + Path.GetExtension(path);
            MetadataFile metaFile = null;

            try
            {
                if (path.IsHttpUrl())
                {
                    metaFile = new MetadataFile(fileName, HttpDownloader.DownloadData(path));
                }
                else
                {
                    if (File.Exists(path))
                    {
                        if (path.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                        {
                            var icon = IconExtension.ExtractIconFromExe(path, true);
                            if (icon == null)
                            {
                                return(null);
                            }

                            fileName = Path.ChangeExtension(fileName, ".png");
                            metaFile = new MetadataFile(fileName, icon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                        }
                        else
                        {
                            metaFile = new MetadataFile(fileName, File.ReadAllBytes(path));
                        }
                    }
                    else
                    {
                        logger.Error($"Can't add game file during game import, file doesn't exists: {path}");
                    }
                }
            }
            catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(e, $"Failed to import game file during game import from {path}");
            }

            if (metaFile != null)
            {
                if (metaFile.FileName.EndsWith(".tga", StringComparison.OrdinalIgnoreCase))
                {
                    metaFile.FileName = Path.ChangeExtension(metaFile.FileName, ".png");
                    metaFile.Content  = BitmapExtensions.TgaToBitmap(metaFile.Content).ToPngArray();
                }

                return(database.AddFile(metaFile, gameId));
            }

            return(null);
        }
        private void BtnCapNhat_Click(object sender, RoutedEventArgs e)
        {
            lblSpeed.Content     = "Đang kết nối, vui lòng đợi . . .";
            btnCapNhat.IsEnabled = false;
            var urlSetup = "https://github.com/duongvanson/ss/raw/master/SetupStudentSocial.msi";

            downloader = new HttpDownloader(urlSetup, setup);
            downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;;
            downloader.DownloadCompleted       += Downloader_DownloadCompleted;;
            downloader.Start();
        }
Пример #5
0
        public async Task <RatingData> UpdateRatingDataAsync(Proxy proxy, int?ratingValue)
        {
            string content = await HttpDownloader.GetContentOrNull(string.Format(Resources.UpdateProxyRatingUrlFormat, proxy.Address, proxy.Port, ratingValue ?? 0), null);

            if (content == null)
            {
                return(RatingData.Error);
            }

            return(new RatingData(RatingState.Updated, GetRatingOrDefault(content)));
        }
Пример #6
0
        public async Task <RatingData> GetRatingDataAsync(Proxy proxy)
        {
            string content = await HttpDownloader.GetContentOrNull(string.Format(Resources.GetProxyRatingUrlFormat, proxy.Address, proxy.Port), null);

            if (content == null)
            {
                return(RatingData.Error);
            }

            return(new RatingData(RatingState.Ready, GetRatingOrDefault(content)));
        }
Пример #7
0
 public DownloadItem(string name, string path, Uri uri)
 {
     Name            = name;
     Path            = path;
     Uri             = uri;
     Progress        = 0;
     Operation       = new HttpDownloader(uri.AbsoluteUri, path);
     State           = ItemState.Standby;
     _timer          = new Timer(100);
     _timer.Elapsed += _timer_Elapsed;
 }
Пример #8
0
        public void ConnectTo(TVInfo info)
        {
            iRemote.SetConnectCallback(this.connectOk, this.connectFail, this.disc, this.authentic, this.authenticFail, this.authenticDeny, this.authenticFull);
            iRemote.SetPacketParser(this.packetCb);

            this.curTv = info;

            HttpDownloader.SetTvIp(info.Ip);

            iRemote.Connect(ref this.curTv, 0xd6d8, new StringBuilder("Mobile Simulator"));
        }
        internal static GameStoreDataResponse GetGameStoreData(string gameId, IPlayniteAPI PlayniteApi)
        {
            string lang      = CodeLang.GetOriginLang(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath));
            string langShort = CodeLang.GetOriginLangCountry(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath));

            var url = string.Format(@"https://api2.origin.com/ecommerce2/public/supercat/{0}/{1}?country={2}", gameId, lang, langShort);

            var stringData = Encoding.UTF8.GetString(HttpDownloader.DownloadData(url));

            return(JsonConvert.DeserializeObject <GameStoreDataResponse>(stringData));
        }
Пример #10
0
        private List <Achievements> GetGameInfoAndUserProgress(int gameID)
        {
            List <Achievements> Achievements = new List <Achievements>();

            string Target = "API_GetGameInfoAndUserProgress.php";
            string url    = string.Format(BaseUrl + Target + @"?z={0}&y={1}&u={0}&g={2}", User, Key, gameID);

            string ResultWeb = "";

            try
            {
                ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8);
            }
            catch (WebException ex)
            {
                Common.LogError(ex, "SuccessStory", $"Failed to load from {url}");
                return(Achievements);
            }

            try
            {
                JObject resultObj = new JObject();
                resultObj = JObject.Parse(ResultWeb);

                int NumDistinctPlayersCasual = (int)resultObj["NumDistinctPlayersCasual"];

                if (resultObj["Achievements"] != null)
                {
                    foreach (var item in resultObj["Achievements"])
                    {
                        foreach (var it in item)
                        {
                            Achievements.Add(new Achievements
                            {
                                Name         = (string)it["Title"],
                                Description  = (string)it["Description"],
                                UrlLocked    = string.Format(BaseUrlLocked, (string)it["BadgeName"]),
                                UrlUnlocked  = string.Format(BaseUrlUnlocked, (string)it["BadgeName"]),
                                DateUnlocked = (it["DateEarned"] == null) ? default(DateTime) : Convert.ToDateTime((string)it["DateEarned"]),
                                Percent      = (int)it["NumAwarded"] * 100 / NumDistinctPlayersCasual
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", $"[{gameID}] Failed to parse {ResultWeb}");
                return(Achievements);
            }

            return(Achievements);
        }
Пример #11
0
 private void OnDownloadComplete(HttpDownloader loader, string error)
 {
     if (error != null)
     {
         SetError(error);
     }
     else if (_loadedSize < _totalSize)
     {
         SetError($"文件大小不一致: {_loadedSize} / {_totalSize}");
     }
     _isDone = true;
 }
        public GameMetadata GetGameData(string gameId)
        {
            var            game  = GetParsedGame(ulong.Parse(gameId));
            FileDefinition image = null;

            if (!string.IsNullOrEmpty(game.Image))
            {
                var name = Path.GetFileName(game.Image);
                image = new FileDefinition($"images/custom/{name}", name, HttpDownloader.DownloadData(game.Image));
            }

            return(new GameMetadata(game, null, image, string.Empty));
        }
Пример #13
0
        internal GetOwnedGamesResult GetPrivateOwnedGames(ulong userId, string apiKey, bool freeSub)
        {
            var libraryUrl = @"https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={0}&include_appinfo=1&include_played_free_games=1&format=json&steamid={1}&skip_unvetted_apps=0";

            if (freeSub)
            {
                libraryUrl += "&include_free_sub=1";
            }

            var stringLibrary = HttpDownloader.DownloadString(string.Format(libraryUrl, apiKey, userId));

            return(JsonConvert.DeserializeObject <GetOwnedGamesResult>(stringLibrary));
        }
Пример #14
0
        private void OnDownloadFinish(HttpDownloader downloader)
        {
            if (downloader.IsError)
            {
                Error      = downloader.Error;
                IsFinished = true;
                return;
            }

            IsFinished = true;
            // finish all, write record
            File.WriteAllText(_metaFilePath, _currentLastModifiedUtc.Ticks.ToString());
        }
        public GameMetadata GetMetadata(string gameId)
        {
            var          game  = GetParsedGame(ulong.Parse(gameId));
            MetadataFile image = null;

            if (!string.IsNullOrEmpty(game.CoverImage))
            {
                var name = Path.GetFileName(game.CoverImage);
                image = new MetadataFile(name, HttpDownloader.DownloadData(game.CoverImage));
            }

            return(new GameMetadata(game, null, image, string.Empty));
        }
Пример #16
0
        private string GetGameBackground(uint appId)
        {
            foreach (var url in backgroundUrls)
            {
                var bk = string.Format(url, appId);
                if (HttpDownloader.GetResponseCode(bk) == HttpStatusCode.OK)
                {
                    return(bk);
                }
            }

            return(null);
        }
Пример #17
0
        private static void Main(string[] p_Args)
        {
            Startup.Start();

            s_HttpDownloader = new HttpDownloader();
            s_Configuration  = new Configuration();
            s_Response       = new G2CoveoResponse();

            //First of all, we load the connector configuration file.
            if (!File.Exists(m_ConfigFilePath))
            {
                //We cannot work without a configuration file.
                m_Logger.Fatal("ConnectorConfig.json file not found, closing now.");
                return;
            }
            else if (!UpdateAndValidateConfig())
            {
                //Something is not right with the configuration file.
                m_Logger.Fatal("ConnectorConfig.json file has definition error(s), closing now.");
                return;
            }

            // Only create a new log file if one hasn't been created today
            m_Logger = new SimpleLogger(s_Configuration, true);

            string ListeningRecordsUrl = "http://" + s_Configuration.ListeningHost + ":" + s_Configuration.ListeningPort + "/xmlfeed/";
            string ListeningGroupsUrl  = "http://" + s_Configuration.ListeningHost + ":" + s_Configuration.ListeningPort + "/xmlgroups/";

            //Make sure the TEMP_FOLDER has been created before we start
            try
            {
                Directory.CreateDirectory(s_Configuration.TempFolder);
            } catch
            {
                m_Logger.Fatal("Not able to create TEMP_FOLDER.");
                return;
            }

            WebServer webServer = new WebServer(ProcessRequestForFeed, ProcessFeed, ListeningRecordsUrl);

            webServer.Run();
            WebServer webServerGroups = new WebServer(ProcessRequestForGroups, ProcessGroups, ListeningGroupsUrl);

            webServerGroups.Run();

            Console.ReadKey();

            s_HttpDownloader.Dispose();
            webServer.Stop();
            webServerGroups.Stop();
        }
Пример #18
0
 public static GameLocalDataResponse GetGameLocalData(string gameId)
 {
     try
     {
         var url        = string.Format(@"https://api1.origin.com/ecommerce2/public/{0}/en_US", gameId);
         var stringData = Encoding.UTF8.GetString(HttpDownloader.DownloadData(url));
         return(JsonConvert.DeserializeObject <GameLocalDataResponse>(stringData));
     }
     catch (Exception e)
     {
         logger.Error(e, "Failed to get local game Origin manifest.");
         return(null);
     }
 }
Пример #19
0
        public async Task GetBinaryAsync()
        {
            // Arrange
            HttpDownloader httpDownloader = new HttpDownloader();

            // Act
            byte[] result = await httpDownloader.GetBinary("http://farm4.staticflickr.com/3492/4045844654_fa980e2591.jpg");

            // test runner waits for the result...
            File.WriteAllBytes("test" + Guid.NewGuid() + ".jpg", result);

            // Assert
            Assert.True(result.Length > 0);
        }
Пример #20
0
 private void OnDownloadProgress(HttpDownloader loader, long loaded, long total)
 {
     _lastProgressChangedDT = DateTime.Now;
     _loadedSize            = loader.LoadedSize;
     _totalSize             = total;
     if (0 == _totalSize)
     {
         _progress = 0;
     }
     else
     {
         _progress = _loadedSize / (float)_totalSize;
     }
 }
Пример #21
0
        //bool wait = true;
        /// <summary>
        /// 生成启动参数
        /// </summary>
        /// <returns></returns>
        public string BuildArguments()
        {
            string        nativeDir  = string.Format("{0}\\versions\\{1}\\{1}-natives", Game.PublicDirectory, Game.id);//生成natives文件夹,放那些DLL用
            StringBuilder libBuilder = new StringBuilder();

            foreach (var item in Game.libraries)
            {
                libBuilder.Append(item.AbsolutelyJarPath).Append(";");
                if (!File.Exists(item.AbsolutelyJarPath))
                {
                    //Console.WriteLine(item.AbsolutelyJarPath);
                    HttpDownloader hdl = new HttpDownloader(item.BmclUri, item.AbsolutelyJarPath);
                    hdl.Work(null, new System.ComponentModel.DoWorkEventArgs(null));

                    //while (wait) ;
                    //wait = true;
                }
                if (item.natives != null)
                {
                    UnZip(item.AbsolutelyJarPath, nativeDir); //通通解压到natives文件夹
                }
            }
            libBuilder.Append(Game.AbsolutelyJarPath).Append(";");
            string libDirs = libBuilder.ToString();

            StringBuilder gameArgBuilder = new StringBuilder(Game.minecraftArguments);

            string guid = User.SID == null?SettingProxy.GetUuidByName(User.Name) : User.SID;

            gameArgBuilder.Replace("${auth_player_name}", User.Name)
            .Replace("${version_name}", Game.id)
            .Replace("${game_directory}", ".")
            .Replace("${game_assets}", "assets")
            .Replace("${assets_root}", "assets")
            .Replace("${user_type}", "Legacy")
            .Replace("${assets_index_name}", Game.assets)
            .Replace("${auth_uuid}", guid)
            .Replace("${auth_access_token}", User.accessToken ?? guid)
            .Replace("${user_properties}", "{}");

            string gameArg = gameArgBuilder.ToString();

            string arguments = string.Format(Game.RefArguments, MaxMem, nativeDir, libDirs, Game.mainClass, gameArg);

            //FileStream fs = new FileStream(@"E:\\1.txt", FileMode.Create);
            //byte[] buffer = arguments.ToBytes();
            //fs.Write(buffer,0,buffer.Length);
            //fs.Close();
            return(arguments);
        }
Пример #22
0
        public override async Task <List <BookInfo> > SearchBook(string author, string title)
        {
            var goodreadsSearchUrlBase = @"https://www.goodreads.com/search?q={0}%20{1}";

            title  = Uri.EscapeDataString(title);
            author = Uri.EscapeDataString(Functions.FixAuthor(author));

            var goodreadsHtmlDoc = new HtmlDocument();

            goodreadsHtmlDoc.LoadHtml(await HttpDownloader.GetPageHtmlAsync(String.Format(goodreadsSearchUrlBase, author, title)));
            return(!goodreadsHtmlDoc.DocumentNode.InnerText.Contains("No results")
                ? ParseSearchResults(goodreadsHtmlDoc)
                : null);
        }
Пример #23
0
        internal GogGameMetadata DownloadGameMetadata(string id, string storeUrl = null)
        {
            var metadata   = new GogGameMetadata();
            var gameDetail = apiClient.GetGameDetails(id);

            metadata.GameDetails = gameDetail;

            if (gameDetail != null)
            {
                if (gameDetail.links.product_card != @"https://www.gog.com/" && !string.IsNullOrEmpty(gameDetail.links.product_card))
                {
                    metadata.StoreDetails = apiClient.GetGameStoreData(gameDetail.links.product_card);
                }
                else if (!string.IsNullOrEmpty(storeUrl))
                {
                    metadata.StoreDetails = apiClient.GetGameStoreData(storeUrl);
                }

                var icon     = HttpDownloader.DownloadData("http:" + gameDetail.images.icon);
                var iconName = Path.GetFileName(new Uri(gameDetail.images.icon).AbsolutePath);
                metadata.Icon = new MetadataFile(iconName, icon);

                if (metadata.StoreDetails != null)
                {
                    var imageUrl  = metadata.StoreDetails.image + "_product_card_v2_mobile_slider_639.jpg";
                    var image     = HttpDownloader.DownloadData(imageUrl);
                    var imageName = Path.GetFileName(new Uri(imageUrl).AbsolutePath);
                    metadata.Image = new MetadataFile(imageName, image);
                }
                else
                {
                    var image     = HttpDownloader.DownloadData("http:" + gameDetail.images.logo2x);
                    var imageName = Path.GetFileName(new Uri(gameDetail.images.logo2x).AbsolutePath);
                    metadata.Image = new MetadataFile(imageName, image);
                }

                if (metadata.StoreDetails != null)
                {
                    var url = metadata.StoreDetails.galaxyBackgroundImage ?? metadata.StoreDetails.backgroundImage;
                    metadata.BackgroundImage = url.Replace(".jpg", "_bg_crop_1920x655.jpg");
                }
                else
                {
                    metadata.BackgroundImage = "http:" + gameDetail.images.background;
                }
            }

            return(metadata);
        }
Пример #24
0
        private void CreateDownloader(string token, byte[] checkPoint = null)
        {
            AbstractDownloader downloader = null;

            try
            {
                var task = tasks.First(t => t.Key.Equals(token));
                if (task.Target is HttpRangableTarget httpRangableTarget)
                {
                    downloader = new HttpParallelDownloader(
                        task,
                        coreFolderManager,
                        coreCacheManager.GetCacheProviderForTask(token),
                        coreBufferProvider,
                        checkPoint,
                        settingEntries.ThreadNumber);
                }
                else if (task.Target is HttpTarget httpTarget)
                {
                    downloader = new HttpDownloader(
                        task, coreFolderManager,
                        coreCacheManager.GetCacheProviderForTask(token),
                        coreBufferProvider);
                }
                else if (task.Target is TorrentTarget torrentTarget)
                {
                    downloader = new TorrentDownloader(
                        task, torrentProvider.Engine, coreFolderManager,
                        coreCacheManager.GetCacheProviderForTask(token),
                        checkPoint: checkPoint,
                        maximumConnections: settingEntries.MaximumConnections,
                        maximumDownloadSpeed: settingEntries.MaximumDownloadSpeed,
                        maximumUploadSpeed: settingEntries.MaximumUploadSpeed,
                        announceUrls: announceUrls);
                }
            }
            catch (Exception e)
            {
                D($"Downloader with task {token} creation failed, {e.Message}");
            }

            if (downloader != null)
            {
                D($"Downloader with task {token} created");
                downloader.MaximumRetries = settingEntries.MaximumRetries;
                downloader.StatusChanged += AnyDownloader_StatusChanged;
                downloaders.Add(downloader);
            }
        }
Пример #25
0
        private void OnHeaderRequestFinish(HttpRequester req)
        {
            if (req.IsError)
            {
                Error      = req.Error;
                IsFinished = true;
                return;
            }

            using (req)
            {
                var lastModified = req.Response.LastModified;
                // md5(savepath) to save the last modified time
                var metaKey = SavePath;
                _metaFilePath = Path.Combine(_pullerMetaFolderPath, Md5Helper.Md5String(metaKey));

                // no handle for UTC or time zone
                DateTime metaFileDateTime = DateTime.MinValue;
                if (File.Exists(_metaFilePath))
                {
                    long metaFileTicks;
                    var  metaFileTicksStr = File.ReadAllText(_metaFilePath);
                    if (!long.TryParse(metaFileTicksStr, out metaFileTicks))
                    {
                        Error      = new Exception("meta file ticks parse error");
                        IsFinished = true;
                        return;
                    }

                    metaFileDateTime = new DateTime(metaFileTicks);
                }

                _currentLastModifiedUtc = lastModified.ToUniversalTime();
                HasDownloaded           = _currentLastModifiedUtc != metaFileDateTime || !File.Exists(SavePath);

                if (HasDownloaded)
                {
                    // do download
                    _downloader = new HttpDownloader(_url, SavePath);
                    _downloader.SetFinishCallback(OnDownloadFinish);
                    _downloader.Start();
                }
                else
                {
                    // no modified, ignore!
                    IsFinished = true;
                }
            }
        }
        public async Task <List <ImageModel> > FindImageUrls(ImagePageModel imagePageModel)
        {
            string html = await HttpDownloader.DownloadHtmlPage(imagePageModel.ImagePageUrl);

            IBrowsingContext context  = BrowsingContext.New();
            IDocument        document = await context.OpenAsync(response => response.Content(html));

            List <ImageModel> imageModels  = new List <ImageModel>();
            IElement          titleElement = document.QuerySelector("title");
            string            albumTitle   = titleElement?.InnerHtml;

            IElement divElement    = document.QuerySelector("div.picture");
            var      imageElements = divElement.QuerySelectorAll("img");

            if (imageElements == null || imageElements.Count() == 0)
            {
                Debug.WriteLine("在图片页面hmtl中没有匹配到图片url元素: " + imagePageModel.ImagePageUrl);
                throw new Exception("在图片页面hmtl中没有匹配到图片url元素");
            }

            string   pageNum        = "";
            IElement pageNumElement = document.QuerySelector("div.paging");

            pageNum = pageNumElement?.QuerySelector("b")?.InnerHtml;



            int index = 0;

            foreach (IElement imgElement in imageElements)
            {
                string imageName;
                string url = imgElement.GetAttribute("src");
                if (index > 0)
                {
                    imageName = albumTitle + "_" + pageNum + "_" + index;
                }
                else
                {
                    imageName = albumTitle + "_" + pageNum;
                }
                ImageModel imageModel = new ImageModel(imagePageModel, imageName, url);
                index++;

                Debug.WriteLine("成功:找到图片" + imageModel.ImageUrl + imageModel.ImageName + imageModel.ImagePage.ImagePageUrl);
                imageModels.Add(imageModel);
            }
            return(imageModels);
        }
Пример #27
0
        protected override void OnDownloaderFinished(HttpDownloader downloader)
        {
            var amz_downloader = (AmzMp3Downloader)downloader;
            var track          = amz_downloader.Track;

            bool last_file = (TotalDownloadCount == 1);

            if (downloader.State.Success)
            {
                switch (amz_downloader.FileExtension)
                {
                case "mp3":
                case "wmv":
                case "mp4":
                    if (last_file)
                    {
                        import_event.Reset();
                    }
                    Log.InformationFormat("Finished downloading \"{0}\" by {1}; adding to import queue", track.Title, track.Creator);
                    try {
                        import_manager.Enqueue(amz_downloader.LocalPath);
                    } catch (Exception e) {
                        Log.Error("Trying to queue amz file", e);
                    }
                    break;

                default:
                    non_mp3_queue.Enqueue(amz_downloader);
                    break;
                }
            }

            // This is the final download; ensure the non-MP3 items have their metadata
            // updated and are imported, and wait until the import_manager is done before
            // calling base.OnDownloaderFinished since that will make the Job finished which will
            // mean all references to the manager are gone and it may be garbage collected.
            if (last_file)
            {
                Log.InformationFormat("Amazon downloader: waiting for last file to be imported");
                TryToFixNonMp3Metadata();
                import_event.WaitOne();
                Log.InformationFormat("Amazon downloader: last file imported; finishing");
            }

            base.OnDownloaderFinished(downloader);

            //Log.InformationFormat ("Finished downloading \"{0}\" by {1}; Success? {2} File: {3}", track.Title, track.Creator,
            //downloader.State.Success, amz_downloader.LocalPath);
        }
Пример #28
0
        internal static string GetGameInfoFromUrl(string url)
        {
            var data  = HttpDownloader.DownloadString(url);
            var regex = Regex.Match(data, @"games\/(\d+)\/rates");

            if (regex.Success)
            {
                return(regex.Groups[1].Value);
            }
            else
            {
                logger.Error($"Failed to get game id from {url}");
                return(string.Empty);
            }
        }
Пример #29
0
        public void CookieContainerCanParseSetCookieHeader(string url)
        {
            var downloader = new HttpDownloader();
            var response   = downloader.Download(new HttpGetRequest(url, new HttpHeadersCollection())).Result;

            var cookieContainer = new CookieContainer();
            var uri             = new Uri(url);

            string setCookieHeader;

            response.Headers.TryGetValue("Set-Cookie", out setCookieHeader);
            cookieContainer.SetCookies(uri, setCookieHeader);

            Assert.DoesNotThrow(() => cookieContainer.GetCookieHeader(uri));
        }
Пример #30
0
        public WikiPage GetPage(string pageTitle)
        {
            var url          = string.Format(@"https://en.wikipedia.org/w/api.php?action=parse&page={0}&format=json", HttpUtility.UrlEncode(pageTitle));
            var stringResult = HttpDownloader.DownloadString(url);
            var result       = JsonConvert.DeserializeObject <ParseResponse>(stringResult);

            if (result.error != null)
            {
                throw new Exception(result.error.info);
            }
            else
            {
                return(result.parse);
            }
        }
        public ActionResult Index(ImportContentViewModel model)
        {
            cleanModel(model);
            var configuration = updateDatabase(model);
            
            var credential = $"DefaultEndpointsProtocol=https;AccountName={ model.StorageInfo.AccountName };AccountKey={ model.StorageInfo.StorageKey }";
            var storageAccount = CloudStorageAccount.Parse(credential);
            var tableClient = storageAccount.CreateCloudBlobClient();
            var blobRef = tableClient.GetContainerReference("scripts");
            blobRef.CreateIfNotExists();

            var styleText = string.Empty;
            var ReferenceOldName = string.Empty;
            var ReferenceName = string.Empty;
            foreach (var item in model.ReferenceFileURLs)
            {
                if (item.IndexOf("style.css") > -1)
                {
                    var ReferHttp = new HttpDownloader(item);
                    styleText = ReferHttp.GetPage();
                    ReferenceOldName = item;
                    ReferenceName = item.Replace("?", "/").Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(element => element.IndexOf("style.css") > -1);
                }
            }

            foreach (var item in model.ReferenceFileURLs)
            {
                if(item.IndexOf("style.css") == -1) {
                    var fontsHttp = new HttpDownloader(item);
                    var fontsText = fontsHttp.GetPage();
                    var fontsName = item.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

                    using (var fileStream = GenerateStreamFromString(fontsText))
                    {
                        var blockBlob = blobRef.GetBlockBlobReference(fontsName);
                        blockBlob.UploadFromStream(fileStream);
                        var url = blockBlob.Uri.AbsoluteUri;
                        styleText = replaceFontReference(styleText, fontsName, url);
                    }
                }
            }

            using (var fileStream = GenerateStreamFromString(styleText))
            {
                var blockBlob = blobRef.GetBlockBlobReference(ReferenceName);
                blockBlob.Properties.ContentType = "text/css";
                blockBlob.UploadFromStream(fileStream);
                blockBlob.SetProperties();
                ReferenceName = blockBlob.Uri.AbsoluteUri;
            }

            blobRef = tableClient.GetContainerReference("htmls");
            blobRef.CreateIfNotExists();

            // Create home page
            var Http = new HttpDownloader($"{model.BaseURL}{model.HomePageURL}");
            var rawText = Http.GetPage();
            var replacedText = replaceContent(rawText, model.ReplaceSections);
            replacedText = replaceLink(replacedText, model.BaseURL, model.PagesURLs);
            replacedText = replaceStyleReference(replacedText, ReferenceOldName, ReferenceName);

            using (var fileStream = GenerateStreamFromString(replacedText))
            {
                var blockBlob = blobRef.GetBlockBlobReference(HomePageName);
                blockBlob.Properties.ContentType = "text/html";
                blockBlob.UploadFromStream(fileStream);
                blockBlob.SetProperties();
            }

            // Other pages
            foreach (var item in model.PagesURLs)
            {
                Http = new HttpDownloader($"{model.BaseURL}{item}");
                rawText = Http.GetPage();
                replacedText = replaceContent(rawText, model.ReplaceSections);
                replacedText = replaceLink(replacedText, model.BaseURL, model.PagesURLs);
                replacedText = replaceStyleReference(replacedText, ReferenceOldName, ReferenceName);
                var fileName = item.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

                using (var fileStream = GenerateStreamFromString(replacedText))
                {
                    var blockBlob = blobRef.GetBlockBlobReference(fileName);
                    blockBlob.Properties.ContentType = "text/html";
                    blockBlob.UploadFromStream(fileStream);
                    blockBlob.SetProperties();
                }
            }
            
            return RedirectToAction("Index");
        }
Пример #32
0
        public static void CheckForUpdates(bool silent = true)
        {
            HttpDownloader downloader = new HttpDownloader(Constants.UpdateJsonURL);
            downloader.DownloadString(delegate(string response, Exception error)
            {
                if (error != null)
                {
                    Log.e(error, "Can't get updater info");
                    if (!silent)
                    {
                        Utils.ShowDialog(kMessageBoxTitle, "Update info is not available.\n\nTry again later.", "OK");
                    }
                    return;
                }

                UpdateInfo info;
                if (response != null && TryParseUpdateInfo(response, out info))
                {
                    if (IsShouldSkipVersion(info.version))
                    {
                        Log.d("User decided to skip version {0}", info.version);
                        return;
                    }

                    if (PluginVersionChecker.IsNewerVersion(info.version))
                    {
                        StringBuilder message = new StringBuilder();
                        message.AppendFormat("A new version {0} is available!\n\n", info.version);
                        if (info.message != null && info.message.Length > 0)
                        {
                            message.Append(info.message);
                            message.AppendLine();
                        }

                        Utils.ShowDialog(kMessageBoxTitle, message.ToString(),
                            new DialogButton("Details...", delegate(string obj)
                            {
                                Application.OpenURL(info.url);
                            }),
                            new DialogButton("Remind me later"),
                            new DialogButton("Skip this version", delegate(string obj)
                            {
                                SetShouldSkipVersion(info.version);
                            })
                        );
                    }
                    else
                    {
                        if (!silent)
                        {
                            Utils.ShowMessageDialog(kMessageBoxTitle, "Everything is up to date");
                        }
                        Debug.Log("Everything is up to date");
                    }
                }
                else
                {
                    Log.e("Unable to parse response: '{0}'", response);
                    if (!silent)
                    {
                        Utils.ShowDialog(kMessageBoxTitle, "Update info is not available.\n\nTry again later.", "OK");
                    }
                }
            });
        }