private void MnuAppSaveNew_Click() { Microsoft.Win32.SaveFileDialog sXml = new Microsoft.Win32.SaveFileDialog(); string dir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); sXml.InitialDirectory = dir; sXml.Title = "Select a folder for creating a new projectfile!"; sXml.Filter = "XML (*.xml)|*.xml"; // pressed OK: if (sXml.ShowDialog() == true) { this._pfadKonfigurationsdatei = sXml.FileName.ToString(); } //if (File.Exists(this.txtKonfigurationsdatei.Text)) if (this._pfadKonfigurationsdatei != String.Empty) { // Create customer object based on Form values. FormularData formdata = this.FormData;//this.CreateFormularData(); //Save form object to XML file using our ObjectXMLSerializer class... try { ObjectXmlSerializer <FormularData> .Save(formdata, this._pfadKonfigurationsdatei); this.Title = "Legend Generator 5.0 für ArcMap 10.0 - " + this._pfadKonfigurationsdatei; } catch (Exception ex) { MessageBox.Show("Unable to save formular data object!" + Environment.NewLine + Environment.NewLine + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public void WriteProduct() { string filePath = "xmltest.xml"; Product product = new Product(); product.ListPrice = 10.0m; product.Name = "testname"; product.ProductID = 10; ObjectXmlSerializer <Product> .Save(product, filePath); }
public void Write() { //try to serialize a derived class while xml tags are only present in the baseclass string filePath1 = @"CustomSerializerTest.Write.xml"; derived.Id = 121; derived.AnotherId = 1600; test.SomeClass = derived; ObjectXmlSerializer <TestClass> .Save(test, filePath1); //reload the class, compare the property values TestClass myClassFromFile = ObjectXmlSerializer <TestClass> .Load(filePath1); Assert.AreEqual(test.SomeClass.Id, myClassFromFile.SomeClass.Id); }
private void MnuAppSave_Click() { if (File.Exists(this._pfadKonfigurationsdatei) == true) { // Create form object based on Form values. FormularData formdata = this.FormData;// this.CreateFormularData(); //Save form object to XML file using our ObjectXMLSerializer class... try { ObjectXmlSerializer <FormularData> .Save(formdata, this._pfadKonfigurationsdatei); } catch (Exception ex) { MessageBox.Show("Unable to save formular data object!" + Environment.NewLine + Environment.NewLine + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { this.MnuAppSaveNew_Click(); } }
/// <summary> /// Tries the save. /// </summary> /// <returns></returns> public bool TrySave() { // Get target path file var targetPathFilename = this.PathFileNameOf(this._name); // Check validity if (Path.GetFileName(targetPathFilename).IsValidFileName() == false) { ServiceContext2.MessageDisplayService.ShowError("Saving Trend", $"Invalid fileName : {Path.GetFileName(targetPathFilename)}"); return(false); } if (!File.Exists(this.SourcePathFilename)) { this.SourcePathFilename = null; } // Check if not already exist if (this.IsNew || (this.SourcePathFilename != null && targetPathFilename != this.SourcePathFilename)) { if (File.Exists(targetPathFilename)) { if ( ServiceContext.MessageDisplayService.Question("Saving Trend", $"A trend named {this._name} already exist. Do you want to overwrite it ?") == false) { return(false); } } } // Have to manage previous ? if (this.SourcePathFilename != null && (targetPathFilename != this.SourcePathFilename)) { try { File.Delete(this.SourcePathFilename); } catch (Exception e) { ServiceContext.MessageDisplayService.ShowError("Deleting file", e); } } // Save try { ObjectXmlSerializer <TrendDeltaV> .Save(this, targetPathFilename); // No more new this._isNew = false; // Keep previous this.SourcePathFilename = targetPathFilename; return(true); } catch (Exception e) { ServiceContext2.MessageDisplayService.ShowError("Saving Trend", e); return(false); } }
private void SaveSettings() { if (PnlDomains.Controls.Cast <DomainControl>().Any(control => control.Keywords.Count > 3)) { MessageBox.Show(@"Only 3 keywords per domain!"); return; } if (PnlDomains.Controls.Cast <DomainControl>().Any(control => !control.Domain.Contains("."))) { MessageBox.Show(@"Please check your domains for proper TLD's", @"Warning - Check TLD's", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (PnlDomains.Controls.Cast <DomainControl>().Any(control => control.Keywords.Count < 1)) { MessageBox.Show(@"Please enter at least 1 keyword for each domain", @"Warning - Check Keywords", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (string.IsNullOrEmpty(TxtProjectName.Text)) { MessageBox.Show(@"Please enter a project name!"); return; } if (LstEngines.CheckedItems.Count < 1) { MessageBox.Show(@"Please select at least 1 search engine", @"Warning - Check Search Engines", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (PnlDomains.Controls.Count < 1) { MessageBox.Show(@"Please add at least 1 domain"); return; } if (!_load) { if (Directory.Exists(DirStructure.ProjectsDir + TxtProjectName.Text)) { MessageBox.Show(@"Project name already exist, choose a new name please", @"Error - Project Exist", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } var sites = (from DomainControl domain in PnlDomains.Controls where !string.IsNullOrEmpty(domain.Domain) && domain.Keywords != null select new SiteModel { Keywords = domain.Keywords, Site = domain.Domain }).ToList(); Directory.CreateDirectory(DirStructure.ProjectsDir + TxtProjectName.Text); var engines = (from CheckListBoxItem item in LstEngines.CheckedItems select item.Text + "|" + item.Tag).ToList(); var project = new ProjectModel { ProjectName = TxtProjectName.Text, ClickLinks = ChkClickMyLinks.Checked, ThreadCount = TrkThreadCount.Value, LoopCount = TrkLoopCount.Value, MaxWait = TrkMaxWait.Value, Engines = engines, Sites = sites, ProxyList = TxtProxyList.Text, UsePremiumProxies = ChkPremiumProxies.Checked }; //Save project settings file ObjectXmlSerializer <ProjectModel> .Save(project, DirStructure.ProjectsDir + project.ProjectName + "\\" + project.ProjectName + ".xml"); //Globals.OpenProjectName = project.ProjectName; Close(); }