public virtual ItemDescriptor Generate(Bitmap bitmap) { // Parse arguments if (bitmap == null) { throw new ArgumentNullException("Bitmap may not be null."); } if (!SupportedDimensions.Contains(bitmap.Size)) { throw new ArgumentException("Bitmap does not match any of the expected dimensions: " + String.Join(", ", SupportedDimensions)); } // Load descriptor JObject config = JsonResourceManager.GetJsonObject(Config); ItemDescriptor descriptor = config["descriptor"].ToObject <ItemDescriptor>(); // Generate and apply directives string directives = descriptor.Parameters["directives"].Value <string>(); directives = directives.Replace("{directives}", DirectiveGenerator.Generate(Template, bitmap)); descriptor.Parameters["directives"] = directives; return(descriptor); }
/// <summary> /// Mark this vacancy as done so that the scraper ignores this vacancy for a while, and is available for export /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CmdMarkAsDone_Click(object sender, EventArgs e) { if (gridVacancies.SelectedRows.Count <= 0) { return; } //var message = gridVacancies.SelectedRows.Count > 1 // ? @"Mark " + gridVacancies.SelectedRows.Count + @" vacancies as done?" // : @"Mark this vacancy as done?"; //var result = MessageBox.Show(message, @"Mark as done", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //if (result == DialogResult.Yes) //{ var doneManager = new JsonResourceManager <VacancyObject>(ResourceType.Done); var rows = gridVacancies.SelectedRows; for (var i = 0; i < rows.Count; i++) { // Add to Done list var currentObject = (VacancyObject)rows[i].DataBoundItem; currentObject.Added = DateTime.Now; doneManager.Resources.Add(currentObject); // Remove from vacancies list _vacanciesManager.Resources.Remove((VacancyObject)rows[i].DataBoundItem); } doneManager.SaveChangesToFile(); _vacanciesManager.SaveChangesToFile(); ReloadContent(); //} }
/// <summary> /// Restore a blacklisted vacancy to the normal vacancy list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdRestore_Click(object sender, EventArgs e) { if (gridDoneVacancies.SelectedRows.Count <= 0) { return; } var message = gridDoneVacancies.SelectedRows.Count > 1 ? @"Restore " + gridDoneVacancies.SelectedRows.Count + @" vacancies?" : @"Restore this vacancy?"; var result = MessageBox.Show(message, @"Restore", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { JsonResourceManager <VacancyObject> vacanciesManager = new JsonResourceManager <VacancyObject>(ResourceType.Vacancies); var rows = gridDoneVacancies.SelectedRows; for (int i = 0; i < rows.Count; i++) { // Add to vacancies list var currentObject = (VacancyObject)rows[i].DataBoundItem; currentObject.Added = DateTime.Now; vacanciesManager.Resources.Add(currentObject); // Remove from done list _doneManager.Resources.Remove((VacancyObject)rows[i].DataBoundItem); } vacanciesManager.SaveChangesToFile(); _doneManager.SaveChangesToFile(); ReloadContent(); } }
public void LoadDatabase(CmdParser parser) { var dbFilename = parser.GetAttribute("file") ?? parser.GetAttribute(0); fileManager = new JsonResourceManager(dbFilename, false); Initialize(); Console.WriteLine("Loaded {0}.", dbFilename); }
public override ItemDescriptor Generate(Bitmap bitmap) { // Parse arguments if (bitmap == null) { throw new ArgumentNullException("Bitmap may not be null."); } if (!SupportedDimensions.Contains(bitmap.Size)) { throw new ArgumentException("Bitmap does not match any of the expected dimensions: " + String.Join(", ", SupportedDimensions)); } // Crop if (bitmap?.Height == 215) { bitmap = Crop(bitmap, 43, 0, 43, 43); } // Gemerate bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); // 01002B00 2B002B00 // 01000100 2B000100 StringBuilder dir = new StringBuilder("?crop;0;0;2;2?replace;fff0=fff;0000=fff?setcolor=fff" + "?blendmult=/objects/outpost/customsign/signplaceholder.png" + "?replace;01000101=01000100;02000101=2B000100?replace;01000201=01002B00;02000201=2B002B00" + "?scale=43?crop=0;0;43;43"); dir.Append("?replace"); for (int x = 0; x < 43; x++) { for (int y = 0; y < 43; y++) { Color pixel = bitmap.GetPixel(x, y); if (pixel.A == 0) { continue; } dir.AppendFormat(";{0}00{1}00={2}", x.ToString("X2"), y.ToString("X2"), ColorToString(pixel)); } } // Load descriptor JObject config = JsonResourceManager.GetJsonObject(Config); ItemDescriptor descriptor = config["descriptor"].ToObject <ItemDescriptor>(); // Generate and apply directives descriptor.Parameters["directives"] = dir.ToString(); return(descriptor); }
public void MakeDatabase(CmdParser parser) { var dbFilename = parser.GetAttribute("file") ?? parser.GetAttribute(0); var checkHash = parser.GetAttribute("hash") ?? parser.GetAttribute(1); var isCheckHash = checkHash == null ? true : false; fileManager = new JsonResourceManager(dbFilename, true, isCheckHash); Initialize(); Console.WriteLine("Loaded {0}.", dbFilename); }
/// <summary> /// Reloads the content of the user control /// </summary> public void ReloadContent() { txtSearch.Text = @"Search..."; txtSearch.ForeColor = SystemColors.GrayText; // Fill table _settingsManager = new SettingsManager(); _vacanciesManager = new JsonResourceManager <VacancyObject>(ResourceType.Vacancies); _bindingList = new BindingList <VacancyObject>(_vacanciesManager.Resources); gridVacancies.DataSource = new BindingList <VacancyObject>(_bindingList.OrderByDescending(x => x.Added).ToList()); // sort by newest first AdjustTableSettings(); }
public AddVacancyForm() { InitializeComponent(); ReturnVacancies = new List <VacancyObject>(); var companiesManager = new JsonResourceManager <CompanyObject>(ResourceType.Companies); foreach (var company in companiesManager.Resources) { comboCompanies.Items.Add(company.Name); } comboCompanies.Sorted = true; }
public ThumbnailManager() { var thumbPath = "{0}/{1}".FormatString(CommonStyleLib.AppInfo.GetAppPath(), ThumbnailChachePath); if (File.Exists(thumbPath)) { fileManager = new JsonResourceManager(thumbPath); } else { fileManager = new JsonResourceManager(thumbPath, true); } }
/// <summary> /// Import a list of companies to the existing list /// </summary> /// <param name="manager"></param> private void ImportCompanyFile(JsonResourceManager <CompanyObject> manager) { var countBefore = manager.Resources.Count; var filePath = BrowseForJsonFile(); if (string.IsNullOrEmpty(filePath)) { return; } var file = File.ReadAllText(filePath); var imported = JsonConvert.DeserializeObject <IList <CompanyObject> >(file); if (imported.Any(company => company.Name == null || company.Consultants == null || company.Url == null || company.Telephone == null)) { MessageBox.Show(@"Error while processing file. Please make sure the file contains only companies.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var companiesWaitingForConfirmation = new List <CompanyObject>(); foreach (var company in imported) { if (manager.Resources.Any(o => o.Equals(company))) { companiesWaitingForConfirmation.Add(company); } else { manager.Resources.Add(company); } } if (companiesWaitingForConfirmation.Count > 0) { var result = MessageBox.Show(@"Found " + companiesWaitingForConfirmation.Count + @" duplicates. Skip those?", @"Found duplicates", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { manager.Resources.AddRange(companiesWaitingForConfirmation); } } manager.SaveChangesToFile(); if (manager.Resources.Count - countBefore > 0) { MessageBox.Show(@"Added " + (manager.Resources.Count - countBefore) + @" companies!"); } ReloadContent(); }
/// <summary> /// Reloads the content of the user control /// </summary> public void ReloadContent() { txtSearch.Text = @"Search..."; txtSearch.ForeColor = SystemColors.GrayText; // Fill table _settingsManager = new SettingsManager(); _companiesManager = new JsonResourceManager <CompanyObject>(ResourceType.Companies); _bindingList = new BindingList <CompanyObject>(_companiesManager.Resources); gridCompanies.DataSource = new BindingList <CompanyObject>(_bindingList.OrderBy(x => x.Consultants).ToList()); // sort by consultants, unsorted within one consultant group so that the newest added company is at the bottom AdjustTableSettings(); gridCompanies.ClearSelection(); }
/// <summary> /// Reloads the content of the user control /// </summary> public void ReloadContent() { // Refresh company list _companyManager = new JsonResourceManager <CompanyObject>(ResourceType.Companies); _vacancyManager = new JsonResourceManager <VacancyObject>(ResourceType.Vacancies); _doneManager = new JsonResourceManager <VacancyObject>(ResourceType.Done); _blacklistManager = new JsonResourceManager <VacancyObject>(ResourceType.Blacklist); // Populate combo box of data source comboDataSource.Items.Clear(); comboDataSource.Items.AddRange(new object[] { "Done", "Vacancies", "Blacklist" }); comboDataSource.SelectedIndex = 0; // Set start date to start of week, end date to today datePickerStart.Value = StartOfWeek(DateTime.Today, DayOfWeek.Monday); datePickerEnd.Value = DateTime.Today; // Add items to the list of consultants checkedListConsultants.Items.Clear(); foreach (var company in _companyManager.Resources) { if (!checkedListConsultants.Items.Contains(company.Consultants)) { checkedListConsultants.Items.Add(company.Consultants, true); } } // Add path from settings to text field txtExportDirectory.Text = _settingsManager.Settings.ExportFolderPath; // Display count of already existing items in the files in the import page lblImportVacancies.Text = @"Vacancies in queue: " + _vacancyManager.Resources.Count; lblImportBlacklist.Text = @"Vacancies in blacklist: " + _blacklistManager.Resources.Count; lblImportCompleted.Text = @"Vacancies completed: " + _doneManager.Resources.Count; lblImportCompanies.Text = @"Companies: " + _companyManager.Resources.Count; // Display last Google Drive Synchronization Date UpdateLastDriveUploadLabel(); UpdateLastDriveDownloadLabel(); // Add items in the file type checkbox list checkedListDownloadUploadFiles.Items.Clear(); checkedListDownloadUploadFiles.Items.Add(ResourceType.Vacancies.ToString(), true); checkedListDownloadUploadFiles.Items.Add(ResourceType.Blacklist.ToString(), true); checkedListDownloadUploadFiles.Items.Add(ResourceType.Done.ToString(), true); checkedListDownloadUploadFiles.Items.Add(ResourceType.Companies.ToString(), true); }
/// <summary> /// Reloads the content of the user control /// </summary> public void ReloadContent() { // Disable pause and stop buttons cmdScrapePause.Enabled = false; cmdScrapeStop.Enabled = false; _companiesManager = new JsonResourceManager <CompanyObject>(ResourceType.Companies); _bindingList = new BindingList <ScrapeGridObject>(); // Add all enabled companies to the binding list and cast each object into an instance of ScrapeGridObject foreach (var company in _companiesManager.Resources.Where(o => o.Enabled)) { _bindingList.Add(new ScrapeGridObject(company)); } var source = new BindingSource(_bindingList, null); gridScrape.DataSource = source; AdjustTableSettings(); // Update status on every item UpdateEveryStatus(); }
/// <summary> /// Import a list of vacancies to a specific file /// </summary> /// <param name="manager"></param> private void ImportVacancyFile(JsonResourceManager <VacancyObject> manager) { try { var countBefore = manager.Resources.Count; var filePath = BrowseForJsonFile(); if (string.IsNullOrEmpty(filePath)) { return; } var file = File.ReadAllText(filePath); var imported = JsonConvert.DeserializeObject <IList <VacancyObject> >(file); if (imported.Any(vacancy => vacancy.Company == null || vacancy.Title == null || vacancy.Url == null)) { MessageBox.Show(@"Error while processing file. Please make sure the file contains only vacancies.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var vacanciesWaitingForConfirmation = new List <VacancyObject>(); foreach (var vacancy in imported) { if (manager.Resources.Any(o => o.Equals(vacancy))) { vacanciesWaitingForConfirmation.Add(vacancy); } else { manager.Resources.Add(vacancy); } } if (vacanciesWaitingForConfirmation.Count > 0) { var result = MessageBox.Show(@"Found " + vacanciesWaitingForConfirmation.Count + @" duplicates. Skip those?", @"Found duplicates", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { manager.Resources.AddRange(vacanciesWaitingForConfirmation); } } manager.SaveChangesToFile(); if (manager.Resources.Count - countBefore > 0) { MessageBox.Show(@"Added " + (manager.Resources.Count - countBefore) + @" vacancies!"); } ReloadContent(); } catch (Exception e) { Console.WriteLine(e.StackTrace); MessageBox.Show(@"The specified file is not valid for this application", @"Invalid file", MessageBoxButtons.OK, MessageBoxIcon.Error); } }