static public String SerializeObject(Object pObject, System.Type objectType) { try { String XmlizedString = null; MemoryStream memoryStream = new MemoryStream(); XmlSerializer xs = new XmlSerializer(objectType); XmlTextWriter XmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); xs.Serialize(XmlTextWriter, pObject); memoryStream = (MemoryStream)XmlTextWriter.BaseStream; XmlizedString = CommonLogic.UTF8ByteArrayToString(memoryStream.ToArray()); return(XmlizedString); } catch (Exception ex) { return(CommonLogic.GetExceptionDetail(ex, "\n")); } }
static public void GetLiveRates() { String PN = AppLogic.AppConfig("Localization.CurrencyFeedXmlPackage"); if (PN.Length != 0) { try { using (XmlPackage2 p = new XmlPackage2(PN)) { m_LastRatesResponseXml = p.XmlDataDocument.InnerXml; m_LastRatesTransformedXml = p.TransformString(); if (m_LastRatesTransformedXml.Length != 0) { // update master db table: XmlDocument d = new XmlDocument(); d.LoadXml(m_LastRatesTransformedXml); foreach (XmlNode n in d.SelectNodes("//currency")) { String CurrencyCode = XmlCommon.XmlAttribute(n, "code"); String rate = XmlCommon.XmlAttribute(n, "rate"); DB.ExecuteSQL("update Currency set ExchangeRate=" + rate + ", WasLiveRate=1, LastUpdated=getdate() where CurrencyCode=" + DB.SQuote(CurrencyCode)); } } } FlushCache(); // flush anyway for safety } catch (Exception ex) { try { AppLogic.SendMail(AppLogic.AppConfig("StoreName") + " Currency.GetLiveRates Failure", "Occurred at: " + Localization.ToNativeDateTimeString(System.DateTime.Now) + CommonLogic.GetExceptionDetail(ex, ""), false, AppLogic.AppConfig("MailMe_FromAddress"), AppLogic.AppConfig("MailMe_FromName"), AppLogic.AppConfig("MailMe_ToAddress"), AppLogic.AppConfig("MailMe_ToName"), String.Empty, AppLogic.MailServer()); } catch { } } } }
string LoadLine(string name, string configValue, string localeSetting, int storeId, ImportOption options, bool preview, SqlConnection connection) { if (String.IsNullOrEmpty(name)) { return(AppLogic.ro_OK); } try { var existing = false; var modified = false; var resourceGuid = string.Empty; // Check if the string resource exists and what its status is using (var command = new SqlCommand()) { command.Connection = connection; command.CommandText = @"select Name, Modified, StringResourceGuid from StringResource where Name = @name AND LocaleSetting = @localeSetting and StoreId = @storeId" ; command.Parameters.AddRange(new[] { new SqlParameter("@name", name), new SqlParameter("@localeSetting", localeSetting), new SqlParameter("@storeId", storeId), }); using (var reader = command.ExecuteReader()) if (reader.Read()) { existing = true; modified = DB.RSFieldTinyInt(reader, "Modified") > 0; resourceGuid = DB.RSFieldGUID(reader, "StringResourceGuid"); } } // Execute behavior based on the status of the string resource if (!existing) { if (!preview) { InsertStringResource(name, localeSetting, configValue, storeId); } return(AppLogic.ro_OK); } if (modified && ((options & ImportOption.LeaveModified) == ImportOption.LeaveModified)) { return("Not Imported (was already modified)"); } if ((options & ImportOption.OverWrite) == ImportOption.OverWrite) { if (!preview) { DeleteStringResource(resourceGuid); InsertStringResource(name, localeSetting, configValue, storeId); } return(AppLogic.ro_OK); } return("Not Imported (existing duplicate)"); } catch (Exception exception) { return(CommonLogic.GetExceptionDetail(exception, "<br/>")); } }