private void btnImportProfile_Click(object sender, EventArgs e) { var fd = new OpenFileDialog { Filter = "Orderbot profile (.xml)|*.xml", FilterIndex = 1, Multiselect = false }; if (fd.ShowDialog() != DialogResult.OK) { return; } try { var profileParser = new ProfileParser(fd.FileName); _profile = profileParser.ToProfile(); refreshForm(); } catch (NoParserException) { MessageBox.Show($"GatherUp can only import profiles generated with this tool from version: {GatherUp.version} and below."); } catch (ParsingException err) { MessageBox.Show(err.Message); } }
public async Task GetLastServerThrowsExceptionWhenFileDoesNotContainLastMPServerAsync() { MissingLastMPServer error = await Assert.ThrowsExceptionAsync <MissingLastMPServer>( () => ProfileParser.GetLastServer(filename, clock, source)); Assert.AreEqual("Unable to find last MP server in DayZ profile", error.Message); }
public override async Task <TaskRes> Execute(Account acc) { await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile"); ProfileParser.ParseVillageTribes(acc, acc.Wb.Html); return(TaskRes.Executed); }
static ProfileParserTest() { var source = File.ReadAllText("TestSource.txt"); var data = new ProfileClient.ProfileRequestData("", source, Platform.Pc); var parser = new ProfileParser(); _testPlayer = new Player(); parser.Parse(_testPlayer, data).GetAwaiter().GetResult(); }
public void TestProfileIteration() { string sessionName = "test-profile-iteration-session"; string traceName = "test-profile-iteration-trace"; var timeToMainParser = new TimeToMainParser(); var profileParser = new ProfileParser(timeToMainParser); var profileSession = TraceSessionManager.CreateSession(sessionName, traceName, traceDirectory, logger); TestSession(profileSession, profileParser); }
private void LoadProfilesClickedEventHandler(object sender, EventArgs e) { DialogResult result = MessageBox.Show( "Should profiles be loaded using the profiles.ini file? " + "If not, the path to the profile directory will need to be specified.", "Load Profiles", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ); if (result == DialogResult.Yes) { var dialog = new OpenFileDialog { Title = "Select a Firefox profiles.ini file", Filter = "INI files (*.ini)|*.ini|All files (*.*)|*.*", FilterIndex = 1 }; if (dialog.ShowDialog() == DialogResult.OK) { var profiles = (BindingList <ProfileInfo>) this.comboProfile.DataSource; foreach (ProfileInfo profile in ProfileParser.GetProfiles(dialog.FileNames).SkipExceptions()) { profiles.Add(profile); } } } else if (result == DialogResult.No) { var dialog = new FolderBrowserDialog { Description = "Select a Firefox Profile folder", ShowNewFolderButton = false }; if (dialog.ShowDialog() == DialogResult.OK) { var profiles = (BindingList <ProfileInfo>) this.comboProfile.DataSource; string dirName = new DirectoryInfo(dialog.SelectedPath).Name; var profile = new ProfileInfo { Name = dirName.Substring(dirName.IndexOf('.') + 1), Path = dialog.SelectedPath, Default = false, IsRelative = false }; profiles.Add(profile); this.comboProfile.SelectedItem = profile; } } }
public void CreateWrongHtmlString(string value) { // Arrange _profileParser = new ProfileParser(); // Action & Assert Assert.Throws <ArgumentNullException>(() => { var result = _profileParser.ParseObject <User>(value); }); }
public ProfileParserTest(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; var source = File.ReadAllText("TestSource.txt"); //var searchSource = File.ReadAllText("SearchTestSource.txt"); var data = new ProfileClient.ProfileRequestData("", source, Platform.Pc); var parser = new ProfileParser(); _testPlayer = new Player(); parser.Parse(_testPlayer, data).GetAwaiter().GetResult(); }
internal OverwatchClient(ProfileClient profileClient, params Platform[] platforms) { _profileClient = profileClient; _profileParser = new ProfileParser(); if (platforms == null || platforms.Length == 0) { DetectedPlatforms = Enum.GetValues(typeof(Platform)).Cast <Platform>().ToList(); } else { DetectedPlatforms = platforms.Distinct().ToList(); } }
public async Task GetLastServerReturnsLastMPServerValue() { File.WriteAllText( filename, "something=\"some-value\";\n" + "lastMPServer=\"87.65.43.21:1234\";\n" + "otherThing=\"other-value\";\n"); Server server = await ProfileParser.GetLastServer(filename, clock, source); Assert.AreEqual("87.65.43.21", server.Host); Assert.AreEqual(1234, server.Port); }
public static ProfileParser parseProfile(string text) { //using (StreamReader r = new StreamReader("Assets/Resources/profile_dir/profile_" + id + ".json")) //using (StreamReader r = new StreamReader(path)) //{ //var json = r.ReadToEnd(); var items = JsonConvert.DeserializeObject <RootObject>(text); int vulScore = calVulnerabilityScore(items.personal_info.residence.zipcode, items.financial_info.salary, items.connections.no_of_dependents, items.interests_info.checkins, items.personal_info.age); ProfileParser profileObj = new ProfileParser(items, vulScore); return(profileObj); //} }
public OverstatClient(params Platform[] platforms) { _profileClient = new HttpProfileClient(); _profileParser = new ProfileParser(); _rawPlayerStatsParser = new RawPlayerStatsParser(); if (platforms == null || platforms.Length == 0) { DetectedPlatforms = Enum.GetValues(typeof(Platform)).Cast <Platform>().ToList(); } else { DetectedPlatforms = platforms.Distinct().ToList(); } }
public async Task TestHandleReadAndWriteBlank() { using var stream = GenerateStreamFromString(BLANK); var copy = new MemoryStream(); await stream !.CopyToAsync(copy); stream !.Seek(0, SeekOrigin.Begin); var profile = await ProfileParser.Read(stream !); using var output = await ProfileParser.Write(profile); verifyNoDataLossOnWrite(copy, output); }
private async Task <ProfileRequestData> GetProfileUrl(string reqString, Platform platform) { using (var result = await _client.GetAsync(reqString)) { if (!result.IsSuccessStatusCode) { return(null); } var rsltContent = await result.Content.ReadAsStringAsync(); var rsltUrl = result.RequestMessage.RequestUri.ToString(); var rslt = new ProfileRequestData(rsltUrl, rsltContent, platform); return(ProfileParser.IsValidPlayerProfile(rslt) ? rslt : null); } }
public async Task GetLastServerReturnsLastMPServerValue() { using (FileStream fs = File.OpenWrite(filename)) { fs.Write(Encoding.UTF8.GetBytes( "something=\"some-value\";\n" + "lastMPServer=\"87.65.43.21:1234\";\n" + "otherThing=\"other-value\";\n")); } Server server = await ProfileParser.GetLastServer(filename); Assert.AreEqual("87.65.43.21", server.Host); Assert.AreEqual(1234, server.Port); }
public async Task GetLastServerRetriesWhenUnableToReadProfileDueToAccessViolation() { File.WriteAllText(filename, "lastMPServer=\"87.65.43.21:1234\";\n"); using (FileStream writeStream = File.OpenWrite(filename)) { clock.SetDelayCompleted(); clock.DelayCalled = (source, args) => writeStream.Close(); Server server = await ProfileParser.GetLastServer(filename, clock, source); Assert.AreEqual("87.65.43.21", server.Host); Assert.AreEqual(1234, server.Port); } }
public async Task TestNoDataLossOnWrite(string filename) { var filePath = Path.Combine(Constants.FILE_DIALOG_INITIAL_DIRECTORY, "2533274911688652", "Characters", filename); using var stream = await decryptFileIntoStream(filePath); var copy = new MemoryStream(); await stream !.CopyToAsync(copy); stream !.Seek(0, SeekOrigin.Begin); var profile = await ProfileParser.Read(stream !); using var output = await ProfileParser.Write(profile); verifyNoDataLossOnWrite(copy, output); }
private async Task <ProfileSaveFile?> tryParseFileStreamAsync(Stream stream) { try { stream.Seek(0, SeekOrigin.Begin); var profile = await ProfileParser.Read(stream); return(profile); } catch (Exception e) { EventLogger.logError(e.ToString()); showError?.Invoke(R.FAILED_TO_PARSE_FILE_ERROR_MESSAGE); } return(null); }
private void FormLoadEventHandler(object sender, EventArgs e) { this.Text = "Web Site Advantage Firefox to KeePass Importer (" + Version + ")"; IEnumerable <string> paths = ProfileParser.GetProfilePaths(); ProfileInfo[] profiles = ProfileParser.GetProfiles(paths).SkipExceptions().ToArray(); this.comboProfile.DataSource = new BindingList <ProfileInfo>(profiles); this.comboProfile.DisplayMember = "Name"; this.comboProfile.SelectedItem = ProfileParser.GetPrimaryProfile(profiles); string[] iconNames = Enum.GetNames(typeof(PwIcon)); // Last item is an undesirable virtual identifier this.comboIcon.DataSource = iconNames.Take(iconNames.Length - 1).ToArray(); this.comboIcon.SelectedIndex = 16; }
//parse the json here //then call all data controller's Begin() methods so they add data to the UI public void InsertData() { Display(); string profileJSON = "profile_" + FaceRecName.instance.recName; TextAsset jsonObj = Resources.Load("profile_dir/" + profileJSON) as TextAsset; currentProf = ProfileParser.parseProfile(jsonObj.text); FaceData.GetComponent <FacePaneDataController>().Begin(); UsernameData.GetComponent <UsernameController>().Begin(); PersonalData.GetComponent <PersonalController>().Begin(); RecentImagesData.GetComponent <RecentImagesController>().Begin(); FinancialData.GetComponent <FinancialController>().Begin(); CompanyLogoData.GetComponent <LogoController>().Begin(); RecentTransactionsData.GetComponent <RecentTransactionsController>().Begin(); InterestsData.GetComponent <InterestsController>().Begin(); FamilyMemberData.GetComponent <FamilyMembersController>().Begin(); TopFriendData.GetComponent <TopFriendsController>().Begin(); }
public OverwatchClient(OverwatchConfig config = null) { _profileParser = new ProfileParser(); Config = config ?? new OverwatchConfig.Builder().Default(); _profileClient = new HttpProfileClient(Config); }
public void GetExperimentalDayZFolderReturnsExperimentalDayZFolderPath() { Assert.AreEqual( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DayZ Exp", ProfileParser.GetExperimentalDayZFolder()); }
public void GetProfileFilenameReturnsDayZProfileFilename() { Assert.AreEqual( Environment.UserName + "_settings.DayZProfile", ProfileParser.GetProfileFilename()); }
public DayZServerMonitorForm() { InitializeComponent(); logger = new Logger(clock, StatusWriter); monitor = new Monitor(clock, clientFactory, logger); SelectionCombo.Items.Add(new ServerSelectionItem(new LatestServerSource("Stable", ProfileParser.GetDayZFolder(), ProfileParser.GetProfileFilename(), logger))); SelectionCombo.Items.Add(new ServerSelectionItem(new LatestServerSource("Experimental", ProfileParser.GetExperimentalDayZFolder(), ProfileParser.GetProfileFilename(), logger))); SelectionCombo.DisplayMember = "DisplayName"; SelectionCombo.ValueMember = "Value"; SelectionCombo.SelectedIndex = 0; SelectionCombo.SelectedValueChanged += new EventHandler(ServerSelectionChanged); }
public ProfilePage() { this.InitializeComponent(); parser = new ProfileParser(); }
/// <summary> /// Crawl an individual profile, then its connections. /// </summary> /// <param name="userName">User name of profile to parse</param> /// <param name="delayBetweenPages">Delay between pages</param> /// <param name="depth">Depth to parse from seed</param> public void CrawlNode(String userName, int delayBetweenPages, int depth) { if (depth + 1 > MaxDepth) { return; } if (File.Exists(UserNameCrawlLock(userName))) { Log(String.Format(@"Skip Locked Profile: UserName={0}", userName)); return; } #region Check if all connections have been parsed if (File.Exists(UserNameCompletePath(userName))) { try { CompleteFile checkFile = JsonConvert.DeserializeObject <CompleteFile>(File.ReadAllText(UserNameCompletePath(userName))); if (checkFile != null && checkFile.AllConnectionsParsed) { Log(String.Format(@"Skip Completed Profile: UserName={0}", userName)); return; } } catch (Exception chk) { Log(String.Format(@"Error Checking Lock File: UserName={0}, {1}", userName, chk?.Message)); } } #endregion #region Create Directory if not exists try { String path = Path.Combine(StoreDirectory, userName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } catch (Exception e) { Log(String.Format("Error Creating Directory: UserName={0}", userName)); } #endregion #region Create Lock file try { File.Create(UserNameCrawlLock(userName)).Dispose(); } catch (Exception e) { Log(String.Format(@"Error Creating Lock File: UserName={0}, {1}", userName, e?.Message)); } #endregion Profile profile = null; if (!UserNameHasBeenParsed(userName)) { bool captureConnections = CanCaptureConnections(userName); Log(String.Format(@"Parse Profile: UserName={0}, Depth={1}/{2}, CaptureConnections={3}", userName, depth.ToString(), MaxDepth.ToString(), captureConnections.ToString())); profile = new ProfileParser().Parse( this, HashKey, userName, DelayBetweenPages, DelayBetweenAPIRequests, captureConnections); if (profile != null) { ProfileFinished(profile); #region Download additional files if passes check if (CapturePhotos) { #region Profile Photos Log(String.Format(@"Download Profile Photos: UserName={0}", profile.UserName)); if (!String.IsNullOrEmpty(profile.ProfileImageURL) && !File.Exists(Path.Combine(StoreDirectory, profile.UserName, "profile.jpg")) && !File.Exists(Path.Combine(StoreDirectory, profile.UserName, "profile.jpg.error"))) { bool success = CrawlUtil.GetFile(profile.ProfileImageURL, Path.Combine(StoreDirectory, profile.UserName, "profile.jpg"), 30000); if (!success) { File.Create(Path.Combine(StoreDirectory, profile.UserName, "profile.jpg.error")).Dispose(); Log(String.Format(@"Error Profile Photo Thumbnail: UserName={0}", profile.UserName)); } } if (!String.IsNullOrEmpty(profile.ProfileThumbnailImageURL) && !File.Exists(Path.Combine(StoreDirectory, profile.UserName, "profile_sm.jpg")) && !File.Exists(Path.Combine(StoreDirectory, profile.UserName, "profile_sm.jpg.error"))) { bool success = CrawlUtil.GetFile(profile.ProfileThumbnailImageURL, Path.Combine(StoreDirectory, profile.UserName, "profile_sm.jpg"), 30000); if (!success) { File.Create(Path.Combine(StoreDirectory, profile.UserName, "profile_sm.jpg.error")).Dispose(); Log(String.Format(@"Error Profile Photo Thumbnail: UserName={0}", profile.UserName)); } } #endregion #region Photos Albums if (profile.Photos != null && profile.Photos.Count > 0) { Log(String.Format(@"Download Photos: UserName={0}", profile.UserName)); #region Ensure Photos directory exists String photoAlbumsPath = Path.Combine(UserNameDirectoryPath(profile.UserName), "Photos"); if (!Directory.Exists(photoAlbumsPath)) { Directory.CreateDirectory(photoAlbumsPath); } #endregion foreach (PhotoEntry entry in profile.Photos) { try { if (!String.IsNullOrEmpty(entry.PhotoID)) { String picturePath = photoAlbumsPath; if (!String.IsNullOrEmpty(entry.AlbumName)) { #region Ensure Photo album directory exists picturePath = Path.Combine(picturePath, entry.AlbumName); if (!Directory.Exists(picturePath)) { Directory.CreateDirectory(picturePath); } #endregion #region Download Thumbnail if (!String.IsNullOrEmpty(entry.ThumbnailImageURL) && !File.Exists(Path.Combine(picturePath, String.Format("{0}_sm.jpg", entry.PhotoID))) && !File.Exists(Path.Combine(picturePath, String.Format("{0}_sm.error", entry.PhotoID)))) { Log(String.Format(@"Download Photo Thumbnail: UserName={0}, PhotoID={1}, Album={2}", profile.UserName, entry.PhotoID, entry.AlbumName)); bool success = CrawlUtil.GetFile(entry.ThumbnailImageURL, Path.Combine(picturePath, String.Format("{0}_sm.jpg", entry.PhotoID)), 30000); if (!success) { File.Create(Path.Combine(picturePath, String.Format("{0}_sm.error", entry.PhotoID))).Dispose(); Log(String.Format(@"Error Downloading Photo Thumbnail: UserName={0}, PhotoID={1}, Album={2}", profile.UserName, entry.PhotoID, entry.AlbumName)); } } #endregion #region Download Full Photo if (!String.IsNullOrEmpty(entry.FullImageURL) && !File.Exists(Path.Combine(picturePath, String.Format("{0}.jpg", entry.PhotoID))) && !File.Exists(Path.Combine(picturePath, String.Format("{0}.error", entry.PhotoID)))) { Log(String.Format(@"Download Photo: UserName={0}, PhotoID={1}, Album={2}", profile.UserName, entry.PhotoID, entry.AlbumName)); bool success = CrawlUtil.GetFile(entry.FullImageURL, Path.Combine(picturePath, String.Format("{0}.jpg", entry.PhotoID)), 30000); if (!success) { File.Create(Path.Combine(picturePath, String.Format("{0}.error", entry.PhotoID))).Dispose(); Log(String.Format(@"Error Downloading Photo: UserName={0}, PhotoID={1}, Album={2}", profile.UserName, entry.PhotoID, entry.AlbumName)); } } #endregion } //Wait between each photo. Thread.Sleep(CrawlUtil.GetVariableDelay(200)); } } catch (Exception e) { Log(String.Format(@"Error Downloading Photo: UserName={0}, PhotoID={1}", profile.UserName, entry?.PhotoID)); } } } #endregion #region Song Artwork if (profile.Songs != null && profile.Songs.Count > 0) { Log(String.Format(@"Download Song Artwork: UserName={0}", profile.UserName)); #region Ensure Photos directory exists String songArtworkPath = Path.Combine(UserNameDirectoryPath(profile.UserName), "Song_Artwork"); if (!Directory.Exists(songArtworkPath)) { Directory.CreateDirectory(songArtworkPath); } #endregion foreach (SongEntry entry in profile.Songs) { #region Download Thumbnail String thumbnailFileName = entry.ImageThumbnailURL?.Replace(@"/", "___")?.Replace(":", "---"); if (!String.IsNullOrEmpty(thumbnailFileName) && !File.Exists(Path.Combine(songArtworkPath, thumbnailFileName)) && !File.Exists(Path.Combine(songArtworkPath, String.Format("{0}.error", thumbnailFileName)))) { Log(String.Format(@"Download Song Artwork Thumbnail: UserName={0}, Name={1}", profile.UserName, thumbnailFileName)); bool success = CrawlUtil.GetFile(entry.ImageThumbnailURL, Path.Combine(songArtworkPath, thumbnailFileName), 30000); if (!success) { File.Create(Path.Combine(songArtworkPath, String.Format("{0}.error", thumbnailFileName))).Dispose(); Log(String.Format(@"Error Downloading Song Artwork Thumbnail: UserName={0}, Name={1}", profile.UserName, thumbnailFileName)); } } #endregion #region Download Full Image String imageFileName = entry.ImageURL?.Replace(@"/", "___")?.Replace(":", "---"); if (!String.IsNullOrEmpty(imageFileName) && !File.Exists(Path.Combine(songArtworkPath, imageFileName)) && !File.Exists(Path.Combine(songArtworkPath, String.Format("{0}.error", imageFileName)))) { Log(String.Format(@"Download Song Artwork: UserName={0}, Name={1}", profile.UserName, imageFileName)); bool success = CrawlUtil.GetFile(entry.ImageURL, Path.Combine(songArtworkPath, imageFileName), 60000); if (!success) { File.Create(Path.Combine(songArtworkPath, String.Format("{0}.error", imageFileName))).Dispose(); Log(String.Format(@"Error Downloading Song Artwork: UserName={0}, Name={1}", profile.UserName, imageFileName)); } } #endregion //Wait between each photo. Thread.Sleep(CrawlUtil.GetVariableDelay(200)); } } #endregion } #endregion } } else { Log(String.Format(@"Load Profile: UserName={0}", userName)); try { profile = JsonConvert.DeserializeObject <Profile>(File.ReadAllText(UserNameProfilePath(userName))); } catch (Exception e) { Log(String.Format(@"Error Loading Profile: UserName={0}, {1}", userName, e?.Message)); } } if (profile != null) { CompleteFile completeFile = null; #region Ensure complete file has been created and populated if (!File.Exists(UserNameCompletePath(userName))) { try { completeFile = new CompleteFile(userName); if (profile.Connections != null) { foreach (ConnectionEntry c in profile.Connections) { completeFile.AllConnectionsParsed = false; completeFile.ConnectionsParsed.Add( new ConnectionParsedEntry() { UserName = c.UserName, Parsed = false, DateParsed = null } ); } } File.WriteAllText( UserNameCompletePath(userName), JsonConvert.SerializeObject(completeFile, Formatting.Indented)); } catch (Exception e) { Log(String.Format(@"Error Creating Complete File: UserName={0}", e?.Message)); } } else { completeFile = JsonConvert.DeserializeObject <CompleteFile>(File.ReadAllText(UserNameCompletePath(userName))); } #endregion foreach (ConnectionEntry c in profile.Connections) { ConnectionParsedEntry parsedEntry = completeFile.ConnectionsParsed.Where(x => String.Equals(x.UserName, c.UserName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (parsedEntry != null) { if (!parsedEntry.Parsed) { CrawlNode(c.UserName, DelayBetweenPages, depth + 1); #region Update complete file try { parsedEntry.Parsed = true; parsedEntry.DateParsed = DateTime.Now; File.WriteAllText( UserNameCompletePath(userName), JsonConvert.SerializeObject(completeFile, Formatting.Indented)); } catch (Exception p) { Log(String.Format(@"Error Updating Complete Entry: UserName={0}, ConnectionUserName={1}, {2]", userName, c.UserName, p?.Message)); } #endregion } } else { Log(String.Format(@"Error Missing Connection Complete Entry: UserName={0}, ConnectionUserName={1}", userName, c.UserName)); } } #region Update complete flag try { Log(String.Format(@"All Connections Parsed: UserName={0}", userName)); completeFile.AllConnectionsParsed = true; File.WriteAllText( UserNameCompletePath(userName), JsonConvert.SerializeObject(completeFile, Formatting.Indented)); } catch (Exception p) { Log(String.Format(@"Error Updating Complete File: UserName={0}, {1}", userName, p?.Message)); } #endregion } }
/// <summary> /// Startdownload process. /// </summary> public void Download() { #region Ensure path exists String path = UserNameDirectoryPath(UserName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } #endregion Logger = new Logger(UserNameDirectoryPath(UserName), String.Format("download_{0}", UserName)); Logger.Log(String.Format(@"Start Download Process: UserName={0}", UserName)); if (!File.Exists(UserNameProfilePath(UserName))) { #region Download Profile Logger.Log(String.Format(@"Download Profile: UserName={0}", UserName)); ProfileParser profileParse = new ProfileParser(); Profile = profileParse.Parse(Logger, HashKey, UserName, 250, 200, CaptureConnections); if (Profile == null) { Logger.Log(String.Format(@"Empty Profile: UserName={0}", UserName)); return; } Logger.Log(String.Format(@"Downloaded Profile: UserName={0}", UserName)); try { File.WriteAllText( UserNameProfilePath(UserName), JsonConvert.SerializeObject(Profile, Formatting.Indented)); } catch (Exception e) { Logger.Log(String.Format(@"Error Saving Profile: UserName={0}, {1}", UserName, e?.Message)); return; } Logger.Log(String.Format(@"Save Profile JSON: UserName={0}", UserName)); #endregion } else { #region Load Profile JSON Logger.Log(String.Format(@"Load Profile JSON: UserName={0}", UserName)); try { Profile = JsonConvert.DeserializeObject <Profile>(File.ReadAllText(UserNameProfilePath(UserName))); if (Profile == null) { Logger.Log(String.Format(@"Empty Profile: UserName={0}", UserName)); return; } } catch (Exception e) { Logger.Log(String.Format(@"Error loading profile: UserName={0}, {1}", UserName, e?.Message)); return; } Logger.Log(String.Format(@"Loaded Profile JSON: UserName={0}", UserName)); #endregion } //Download additional files if passes check if (CapturePhotos) { if (DownloadPhotosCheck == null || (Profile != null && DownloadPhotosCheck.Invoke(Profile))) { #region Profile Photos Logger.Log(String.Format(@"Download Profile Photos: UserName={0}", UserName)); if (!String.IsNullOrEmpty(Profile.ProfileImageURL) && !File.Exists(Path.Combine(StoreDirectory, UserName, "profile.jpg")) && !File.Exists(Path.Combine(StoreDirectory, UserName, "profile.jpg.error"))) { bool success = CrawlUtil.GetFile(Profile.ProfileImageURL, Path.Combine(StoreDirectory, UserName, "profile.jpg"), 30000); if (!success) { File.Create(Path.Combine(StoreDirectory, UserName, "profile.jpg.error")).Dispose(); Logger.Log(String.Format(@"Error Profile Photo Thumbnail: UserName={0}", UserName)); } } if (!String.IsNullOrEmpty(Profile.ProfileThumbnailImageURL) && !File.Exists(Path.Combine(StoreDirectory, UserName, "profile_sm.jpg")) && !File.Exists(Path.Combine(StoreDirectory, UserName, "profile_sm.jpg.error"))) { bool success = CrawlUtil.GetFile(Profile.ProfileThumbnailImageURL, Path.Combine(StoreDirectory, UserName, "profile_sm.jpg"), 30000); if (!success) { File.Create(Path.Combine(StoreDirectory, UserName, "profile_sm.jpg.error")).Dispose(); Logger.Log(String.Format(@"Error Profile Photo Thumbnail: UserName={0}", UserName)); } } #endregion #region Photos Albums if (Profile.Photos != null && Profile.Photos.Count > 0) { Logger.Log(String.Format(@"Download Photos: UserName={0}", UserName)); #region Ensure Photos directory exists String photoAlbumsPath = Path.Combine(UserNameDirectoryPath(UserName), "Photos"); if (!Directory.Exists(photoAlbumsPath)) { Directory.CreateDirectory(photoAlbumsPath); } #endregion foreach (PhotoEntry entry in Profile.Photos) { try { if (!String.IsNullOrEmpty(entry.PhotoID)) { String picturePath = photoAlbumsPath; if (!String.IsNullOrEmpty(entry.AlbumName)) { #region Ensure Photo album directory exists picturePath = Path.Combine(picturePath, entry.AlbumName); if (!Directory.Exists(picturePath)) { Directory.CreateDirectory(picturePath); } #endregion #region Download Thumbnail if (!String.IsNullOrEmpty(entry.ThumbnailImageURL) && !File.Exists(Path.Combine(picturePath, String.Format("{0}_sm.jpg", entry.PhotoID))) && !File.Exists(Path.Combine(picturePath, String.Format("{0}_sm.error", entry.PhotoID)))) { Logger.Log(String.Format(@"Download Photo Thumbnail: UserName={0}, PhotoID={1}, Album={2}", UserName, entry.PhotoID, entry.AlbumName)); bool success = CrawlUtil.GetFile(entry.ThumbnailImageURL, Path.Combine(picturePath, String.Format("{0}_sm.jpg", entry.PhotoID)), 30000); if (!success) { File.Create(Path.Combine(picturePath, String.Format("{0}_sm.error", entry.PhotoID))).Dispose(); Logger.Log(String.Format(@"Error Downloading Photo Thumbnail: UserName={0}, PhotoID={1}, Album={2}", UserName, entry.PhotoID, entry.AlbumName)); } } #endregion #region Download Full Photo if (!String.IsNullOrEmpty(entry.FullImageURL) && !File.Exists(Path.Combine(picturePath, String.Format("{0}.jpg", entry.PhotoID))) && !File.Exists(Path.Combine(picturePath, String.Format("{0}.error", entry.PhotoID)))) { Logger.Log(String.Format(@"Download Photo: UserName={0}, PhotoID={1}, Album={2}", UserName, entry.PhotoID, entry.AlbumName)); bool success = CrawlUtil.GetFile(entry.FullImageURL, Path.Combine(picturePath, String.Format("{0}.jpg", entry.PhotoID)), 30000); if (!success) { File.Create(Path.Combine(picturePath, String.Format("{0}.error", entry.PhotoID))).Dispose(); Logger.Log(String.Format(@"Error Downloading Photo: UserName={0}, PhotoID={1}, Album={2}", UserName, entry.PhotoID, entry.AlbumName)); } } #endregion } //Wait between each photo. Thread.Sleep(CrawlUtil.GetVariableDelay(200)); } } catch (Exception e) { Logger.Log(String.Format(@"Error Downloading Photo: UserName={0}, PhotoID={1}", UserName, entry?.PhotoID)); } } } #endregion #region Song Artwork if (Profile.Songs != null && Profile.Songs.Count > 0) { Logger.Log(String.Format(@"Download Song Artwork: UserName={0}", UserName)); #region Ensure Photos directory exists String songArtworkPath = Path.Combine(UserNameDirectoryPath(UserName), "Song_Artwork"); if (!Directory.Exists(songArtworkPath)) { Directory.CreateDirectory(songArtworkPath); } #endregion foreach (SongEntry entry in Profile.Songs) { #region Download Thumbnail String thumbnailFileName = entry.ImageThumbnailURL?.Replace(@"/", "___")?.Replace(":", "---"); if (!String.IsNullOrEmpty(thumbnailFileName) && !File.Exists(Path.Combine(songArtworkPath, thumbnailFileName)) && !File.Exists(Path.Combine(songArtworkPath, String.Format("{0}.error", thumbnailFileName)))) { Logger.Log(String.Format(@"Download Song Artwork Thumbnail: UserName={0}, Name={1}", UserName, thumbnailFileName)); bool success = CrawlUtil.GetFile(entry.ImageThumbnailURL, Path.Combine(songArtworkPath, thumbnailFileName), 30000); if (!success) { File.Create(Path.Combine(songArtworkPath, String.Format("{0}.error", thumbnailFileName))).Dispose(); Logger.Log(String.Format(@"Error Downloading Song Artwork Thumbnail: UserName={0}, Name={1}", UserName, thumbnailFileName)); } } #endregion #region Download Full Image String imageFileName = entry.ImageURL?.Replace(@"/", "___")?.Replace(":", "---"); if (!String.IsNullOrEmpty(imageFileName) && !File.Exists(Path.Combine(songArtworkPath, imageFileName)) && !File.Exists(Path.Combine(songArtworkPath, String.Format("{0}.error", imageFileName)))) { Logger.Log(String.Format(@"Download Song Artwork: UserName={0}, Name={1}", UserName, imageFileName)); bool success = CrawlUtil.GetFile(entry.ImageURL, Path.Combine(songArtworkPath, imageFileName), 60000); if (!success) { File.Create(Path.Combine(songArtworkPath, String.Format("{0}.error", imageFileName))).Dispose(); Logger.Log(String.Format(@"Error Downloading Song Artwork: UserName={0}, Name={1}", UserName, imageFileName)); } } #endregion //Wait between each photo. Thread.Sleep(CrawlUtil.GetVariableDelay(200)); } } #endregion } } Logger.Log(String.Format(@"Done: UserName={0}", UserName)); }
internal OverwatchClient(ProfileClient profileClient, OverwatchConfig config) { _profileClient = profileClient; _profileParser = new ProfileParser(); Config = config; }