private string GetMemberConfigValue(ConfigurationMemberAttribute attrib, object value) { string valueString; if (value == null) { valueString = string.Empty; } else if (value is DateTime) { valueString = ((DateTime)value).ToString("s"); } else { valueString = value.ToString(); } if (!attrib.Encrypted) { return(valueString); } if (string.IsNullOrEmpty(attrib.KeyFile)) { return(Encryption.EncryptConfigurationValue(valueString)); } try { return(Encryption.EncryptConfigurationValue(valueString, attrib.KeyFile)); } catch (Exception ex) { ErrorHandling.LogException(ex); return(Encryption.EncryptConfigurationValue(valueString)); } }
public bool SetCurrentDatabase(string database) { if (dataAccessProvider == null) { throw new DataProviderNotInitializedException(); } if (string.IsNullOrEmpty(database)) { return(false); } try { if (dataAccessProvider.CheckDatabaseExists(database)) { dataAccessProvider.Database = database; return(true); } return(false); } catch (Exception ex) { ErrorHandling.LogException(ex); dataAccessProvider.Database = string.Empty; return(false); } }
public static void Deinitialize() { OnDeinitialized(); if (feedbackProvider != null) { feedbackProvider.Dispose(); feedbackProvider = null; } DataHelper.Dispose(); try { DeviceManager.DisconnectKitchenPrinters(); if (DeviceManager.CardReaderConnected) { DeviceManager.DisconnectCardReader(); } if (DeviceManager.ExternalDisplayConnected) { DeviceManager.DisconnectExternalDisplay(); } if (DeviceManager.CustomerOrderPrinterConnected) { DeviceManager.DisconnectCustomerOrderPrinter(); } if (DeviceManager.CashReceiptPrinterConnected) { DeviceManager.DisconnectCashReceiptPrinter(); } if (DeviceManager.ElectronicScaleConnected) { DeviceManager.DisconnectElectronicScale(); } if (DeviceManager.SalesDataControllerConnected) { DeviceManager.DisconnectSalesDataController(); } if (DeviceManager.BarcodeScannerConnected) { DeviceManager.DisconnectBarcodeScanner(); } } catch (Exception ex) { ErrorHandling.LogException(ex); } DeviceManager.Dispose(); DeviceManager = null; Device.Flush(); WindowSettings.Flush(); baseProvider.Deinitialize(); }
public string GetDefaultPrinterName() { try { return(new PrinterSettings().PrinterName); } catch (Exception ex) { ErrorHandling.LogException(ex); return(null); } }
public List <string> GetAllInstalledPrinters() { try { return(PrinterSettings.InstalledPrinters.Cast <string> ().ToList()); } catch (Exception ex) { ErrorHandling.LogException(ex); return(new List <string> ()); } }
private void SmtpClient_SendCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error == null) { OnSendCompleted(new SendCompletedEventArgs(EmailResult.Success)); } else { ErrorHandling.LogException(e.Error); OnSendCompleted(new SendCompletedEventArgs(EmailResult.SmtpError)); } }
public string [] GetDatabases() { if (dataAccessProvider == null) { throw new DataProviderNotInitializedException(); } try { return(dataAccessProvider.GetDatabases()); } catch (Exception ex) { ErrorHandling.LogException(ex); } return(new string [0]); }
public static string EncryptToBase64(string sourceData, byte [] rgbKey, byte [] rgbIV) { try { using (MemoryStream outStream = new MemoryStream()) { using (DESCryptoServiceProvider cProvider = new DESCryptoServiceProvider()) { using (CryptoStream cStream = new CryptoStream(outStream, cProvider.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write)) { byte [] data = Encoding.UTF8.GetBytes(sourceData); cStream.Write(data, 0, data.Length); cStream.FlushFinalBlock(); return(Convert.ToBase64String(outStream.ToArray())); } } } } catch (Exception ex) { ErrorHandling.LogException(new Exception(string.Format("Error while encrypting string \"{0}\"", sourceData), ex)); } return(string.Empty); }
public void Deinitialize() { if (appConfiguration != null) { try { if (dataAccessProvider != null) { appConfiguration.DbProvider = dataAccessProvider.GetType().FullName; appConfiguration.DbServer = dataAccessProvider.Server; appConfiguration.DbUser = dataAccessProvider.User; appConfiguration.DbPassword = dataAccessProvider.Password; appConfiguration.DbDatabase = dataAccessProvider.Database; } appConfiguration.Save(false); } catch (Exception ex) { ErrorHandling.LogException(ex); } finally { AppConfiguration = null; } } if (dataAccessProvider != null) { try { if (reportQueryStates != null) { dataAccessProvider.SaveReportsQueryState(reportQueryStates); } if (documentQueryStates != null) { dataAccessProvider.SaveDocumentQueryStates(documentQueryStates); } dataAccessProvider.Disconnect(); } catch (Exception ex) { ErrorHandling.LogException(ex); } finally { dataAccessProvider = null; } } }
public bool TryConnect(string provider, string server, string slaveServer, string user, string password, string database) { if (dataAccessProvider != null) { if (dataAccessProvider.GetType().FullName == provider) { dataAccessProvider.Server = server; dataAccessProvider.SlaveServer = slaveServer; dataAccessProvider.User = user; dataAccessProvider.Password = password; dataAccessProvider.Database = database; } else { dataAccessProvider.Disconnect(); dataAccessProvider = null; } } if (dataAccessProvider == null) { dataAccessProvider = DataProvider.CreateProvider(provider, Translator.GetHelper(), server, slaveServer, user, password); dataAccessProvider.ConnectTimeout = AppConfiguration.DbConnectTimeout; dataAccessProvider.CommandTimeout = AppConfiguration.DbCommandTimeout; dataAccessProvider.LogFile = appConfiguration.DbLogFile; UpdatePurchaseCurrencyPrecision(); } try { return(dataAccessProvider.TryConnect()); } catch (Exception ex) { dataAccessProvider = null; ErrorHandling.LogException(ex); return(false); } }
public EmailResult SendEmail(string recipients, string subject, string body, bool async, params string [] attachments) { string smtpServer = BusinessDomain.AppConfiguration.SmtpServer; EmailResult emailResult = 0; if (string.IsNullOrEmpty(smtpServer)) { emailResult = EmailResult.NoSmtpServer; } if (string.IsNullOrEmpty(BusinessDomain.AppConfiguration.EmailSender)) { emailResult = EmailResult.NoSender; } int smtpPort = BusinessDomain.AppConfiguration.SmtpPort; if (smtpPort <= 0) { emailResult = EmailResult.InvalidPort; } if (emailResult != 0) { OnSendCompleted(new SendCompletedEventArgs(emailResult)); return(emailResult); } try { MailMessage mailMessage = new MailMessage( BusinessDomain.AppConfiguration.EmailSender ?? string.Empty, recipients, subject ?? BusinessDomain.AppConfiguration.EmailSubject, body); foreach (string attachment in attachments) { mailMessage.Attachments.Add(new Attachment(attachment)); } string smtpUserName = BusinessDomain.AppConfiguration.SmtpUserName; SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort) { Credentials = string.IsNullOrEmpty(smtpUserName) ? CredentialCache.DefaultNetworkCredentials : new NetworkCredential(smtpUserName, BusinessDomain.AppConfiguration.SmtpPassword), EnableSsl = BusinessDomain.AppConfiguration.SmtpUseSsl, Timeout = 30000 }; if (async) { smtpClient.SendCompleted += SmtpClient_SendCompleted; smtpClient.SendAsync(mailMessage, string.Empty); } else { smtpClient.Send(mailMessage); mailMessage.Dispose(); } } catch (Exception exception) { ErrorHandling.LogException(exception); return(EmailResult.SmtpError); } return(EmailResult.Success); }
private static void AddinManager_AddinLoadError(object sender, AddinErrorEventArgs args) { ErrorHandling.LogException(args.Exception); }
public static void InitAddins() { AddinManager.AddinLoadError += AddinManager_AddinLoadError; bool retry = false; bool errorDeletingFolder = false; AutoResetEvent initialized = new AutoResetEvent(false); do { Thread thread = new Thread(() => { try { AddinManager.Initialize(); AddinManager.Registry.Update(null); foreach (TypeExtensionNode addonOperation in AddinManager.GetExtensionNodes("/Warehouse/Business/Operations")) { IAdditionalOperation instance = (IAdditionalOperation)addonOperation.CreateInstance(); Operation.GetByIdHandlers [instance.Type] = instance.GetByOperationId; Operation.GetPendingHandlers [instance.Type] = instance.GetPendingOperation; } foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/Warehouse/Business/Config")) { IConfigurationAddin addin = (IConfigurationAddin)node.CreateInstance(); AppConfiguration.Addins [addin.GetType()] = addin; } retry = false; initialized.Set(); } catch (Exception ex) { try { AddinManager.Shutdown(); } catch { } if (Directory.Exists(StoragePaths.MonoAddinsDataFolder) && !errorDeletingFolder) { try { Directory.Delete(StoragePaths.MonoAddinsDataFolder, true); } catch (Exception) { errorDeletingFolder = true; } finally { retry = true; } } else { ErrorHandling.LogException(ex); } } }); thread.Start(); if (!initialized.WaitOne(10000)) { thread.Abort(); thread.Join(); } } while (retry); if (AppConfiguration.Addins.Count > 0) { AppConfiguration.Load(true); } }
protected static void SetMember(object configHolder, MemberInfo member, Type type, string value, ConfigurationMemberAttribute attrib) { if (value == null) { throw new ArgumentNullException("value"); } if (attrib != null && attrib.Encrypted) { if (!string.IsNullOrEmpty(value)) { string keyFile = PlatformHelper.IsWindows ? attrib.KeyFile : (string.IsNullOrWhiteSpace(attrib.UnixKeyFile) ? attrib.KeyFile : attrib.UnixKeyFile); if (string.IsNullOrEmpty(keyFile)) { value = Encryption.DecryptConfigurationValue(value); } else { try { value = Encryption.DecryptConfigurationValue(value, keyFile); } catch (Exception ex) { ErrorHandling.LogException(ex); value = Encryption.DecryptConfigurationValue(value); } } } } string memberTypeName = type.Name.ToLowerInvariant(); switch (memberTypeName) { case "string": SetMemberValue(configHolder, member, value); break; case "boolean": SetMemberValue(configHolder, member, Convert.ToBoolean(value)); break; case "datetime": DateTime dateTime; try { dateTime = Convert.ToDateTime(value); } catch (FormatException) { dateTime = DateTime.MinValue; } SetMemberValue(configHolder, member, dateTime); break; case "decimal": SetMemberValue(configHolder, member, Convert.ToDecimal(value)); break; case "single": SetMemberValue(configHolder, member, Convert.ToSingle(value)); break; case "double": SetMemberValue(configHolder, member, Convert.ToDouble(value)); break; default: if (memberTypeName.StartsWith("int32")) { SetMemberValue(configHolder, member, Convert.ToInt32(value)); } else if (memberTypeName.StartsWith("int")) { SetMemberValue(configHolder, member, Convert.ToInt64(value)); } else if (type.IsEnum) { SetMemberValue(configHolder, member, Enum.Parse(type, value)); } break; } }
public void LogException(Exception ex) { ErrorHandling.LogException(ex); }