Exemplo n.º 1
0
 private void btnSaveAs_Click(object sender, EventArgs e)
 {
   TemplateCollection templateCollection = this.ReadTemplates();
   SaveTemplateDialog saveTemplateDialog = new SaveTemplateDialog();
   saveTemplateDialog.SetNames(templateCollection.Names);
   if (saveTemplateDialog.ShowDialog((IWin32Window) this) == DialogResult.OK)
   {
     Template template1 = this.settings.Template;
     template1.Name = saveTemplateDialog.TemplateName;
     templateCollection[template1.Name] = template1;
     TemplateXmlDocument templateXmlDocument = new TemplateXmlDocument();
     foreach (Template template2 in templateCollection)
       templateXmlDocument.Templates.Add(template2);
     ((XmlDocument) templateXmlDocument).Save(string.Format("{0}\\{1}", (object) this.templateDirectory.FullName, (object) "import.templates.xml"));
     this.UpdateTemplateList();
   }
   saveTemplateDialog.Dispose();
 }
Exemplo n.º 2
0
 private TemplateCollection ReadTemplates()
 {
   string str = string.Format("{0}\\{1}", (object) this.templateDirectory.FullName, (object) "import.templates.xml");
   if (!File.Exists(str))
     return new TemplateCollection();
   try
   {
     TemplateCollection templateCollection = new TemplateCollection();
     TemplateXmlDocument templateXmlDocument = new TemplateXmlDocument();
     ((XmlDocument) templateXmlDocument).Load(str);
     foreach (TemplateXmlNode templateXmlNode in templateXmlDocument.Templates)
     {
       Template template = new Template();
       template.Name = templateXmlNode.TemplateName;
       template.CSVOptions.Separator = Separator.GetSeparator(templateXmlNode.CSV.Separator);
       template.CSVOptions.HeaderLineCount = templateXmlNode.CSV.HeaderLineCount;
       template.CSVOptions.CultureInfo = CultureInfo.CreateSpecificCulture(templateXmlNode.CSV.Culture);
       template.DataOptions.DataType = templateXmlNode.Data.DataType;
       template.DataOptions.BarSize = templateXmlNode.Data.BarSize;
       template.DataOptions.BarDateTime = templateXmlNode.Data.BarDateTime;
       template.DateOptions.DateType = templateXmlNode.Date.DateType;
       template.DateOptions.Date = templateXmlNode.Date.Date;
       template.SymbolOptions.Option = templateXmlNode.Symbol.SymbolOption;
       template.SymbolOptions.Name = templateXmlNode.Symbol.Name_;
       template.OtherOptions.CreateInstrument = templateXmlNode.Other.CreateInstrument;
       template.OtherOptions.InstrumentType = templateXmlNode.Other.InstrumentType;
       template.OtherOptions.ClearSeries = templateXmlNode.Other.ClearSeries;
       template.OtherOptions.SkipDataInsideExistingRange = templateXmlNode.Other.SkipDataInsideExistingRange;
       foreach (ColumnXmlNode columnXmlNode in templateXmlNode.Columns)
         template.Columns.Add(new Column()
         {
           ColumnType = columnXmlNode.ColumnType,
           ColumnFormat = columnXmlNode.Format
         });
       templateCollection.Add(template);
     }
     return templateCollection;
   }
   catch (Exception ex)
   {
     int num = (int) MessageBox.Show((IWin32Window) this, ((object) ex).ToString(), "Error reading templates!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     return new TemplateCollection();
   }
 }