/// <summary> /// Writes <paramref name="properties"/> to XML. Does nothing if <paramref name="properties"/> collection is empty /// </summary> /// <param name="properties"><see cref="PropertyCollection"/> instance with custom properties</param> /// <param name="parentElement"><see cref="XElement"/> instance to write custom properties collection to (as a child element)</param> private static void WritePropertyCollection(PropertyCollection properties, XElement parentElement) { if (properties.Count == 0) { return; } XElement propertiesCollectionElement = new XElement(Elements.Properties); foreach (KeyValuePair <string, CustomProperty> property in properties) { IExportable exportableProperty = property.Value as IExportable; if (exportableProperty != null) { XElement propertyElement = new XElement(Elements.Property, new XAttribute(Attributes.Key, property.Key), new XAttribute(Attributes.Type, property.Value.GetType().FullName) ); exportableProperty.Export(propertyElement); propertiesCollectionElement.Add(propertyElement); } } parentElement.Add(propertiesCollectionElement); }
private void excelToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl.TabPages.Count != 0) { IExportable isExportable = tabControl.SelectedTab.Controls[0] as IExportable; if (isExportable != null) { isExportable.Export(); } } }
private void DoExport() { IExportable action = tvProjects.SelectedNode.Tag as IExportable; action.Export(); }
/// <summary> /// Fetch TCMB Today's Currency Rates with GetRateRequest Object. /// </summary> /// <param name="rateRequest">GetRateRequest</param> /// <returns>GetRateResponse</returns> public GetRateResponse ExportTodaysCurrencyRates(GetRateRequest rateRequest) { var getRateResponse = new GetRateResponse(); const string tcmbTodayUrl = "https://www.tcmb.gov.tr/kurlar/today.xml"; var tcmbXmlDoc = new XmlDocument(); try { // Get Rates from TCMB and Load as XmlDocument. tcmbXmlDoc.Load(tcmbTodayUrl); using var stringReader = new StringReader(tcmbXmlDoc.InnerXml); var serializer = new XmlSerializer(typeof(Tarih_Date)); // Deserialize Xml response to TCMB proxy class. var ratesDeserialized = (Tarih_Date)serializer.Deserialize(stringReader); // Generate IQueryable Rates From Deserialized Response. var rates = TCMBServiceHelpers.GenerateRatesFromDeserializedResponse(ratesDeserialized); // Aggregated list for filters & orders. var filteredAndOrderedRates = new List <Rate>(); // Check filter options. if (rateRequest.FilterByOptions != null) { foreach (FilterByOption filterByOption in rateRequest.FilterByOptions) { filteredAndOrderedRates.AddRange(TCMBServiceHelpers.ApplyFilterBy(rates, filterByOption.Field, filterByOption.Value).ToList()); } } // Check order options if (rateRequest.OrderByOptions != null) { foreach (OrderByOption orderByOption in rateRequest.OrderByOptions) { filteredAndOrderedRates = orderByOption.OrderType switch { OrderType.Ascending => TCMBServiceHelpers.ApplyOrderByAscending(filteredAndOrderedRates.AsQueryable(), orderByOption.Field).ToList(), OrderType.Descending => TCMBServiceHelpers.ApplyOrderByDescending(filteredAndOrderedRates.AsQueryable(), orderByOption.Field).ToList(), _ => TCMBServiceHelpers.ApplyOrderByAscending(filteredAndOrderedRates.AsQueryable(), orderByOption.Field).ToList() }; } } // For the sake of simlicity it exports to current application's running directory. // Can be converted to parameter like path which can be taken at RateRequest object. var exportPath = Directory.GetCurrentDirectory() + $"\\Rates_of_{DateTime.Today:dd_MM_yyyy}"; // Check export type and create Exporter. IExportable exporter = ExporterFactory.CreatExporter(rateRequest.ExportType); // Do export. exporter.Export(filteredAndOrderedRates, exportPath + $".{rateRequest.ExportType.ToString().ToLowerInvariant()}"); // Add exported path to GetRateResponse. getRateResponse.ExportedPath = exportPath; } catch (Exception e) { // Handle Exception getRateResponse.HasError = true; getRateResponse.ErrorMessage = e.Message; } return(getRateResponse); }