protected void Initialize( string assemblyName, string assemblyFileName, AssemblyBuilderAccess assemblyBuilderAccess) { if (assemblyName != null) { assemblyName = assemblyName.Trim(); } if (string.IsNullOrEmpty(assemblyName)) { throw new NullReferenceException(string.Format( "{0} may not be null when constructing a {1}.", EntityReaderGeneric <OrmAssemblyWindows> .GetPropertyName(p => p.AssemblyName, false), this.GetType().FullName)); } _assemblyName = assemblyName; _assemblyFileName = assemblyFileName; _assemblyBuilderAccess = assemblyBuilderAccess; _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(_assemblyName), _assemblyBuilderAccess); string domainName = AppDomain.CurrentDomain.FriendlyName; if (string.IsNullOrEmpty(_assemblyFileName)) { _moduleBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName); } else { _moduleBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName, _assemblyFileName); } _ormTypes = new EntityCacheGeneric <string, OrmTypeWindows>(); }
public static bool HandleException( Exception exception, Form form, KeyEventHandler keyEventHandler, string eventDetailsMessage, bool emailException, out string emailErrorMessage, out string emailLogMessageText, List <EmailNotificationRecipient> emailNotificationRecipients) { try { emailErrorMessage = string.Empty; emailLogMessageText = string.Empty; bool closeApplication = false; if (exception == null) { throw new NullReferenceException("exception to be handled may not be null."); } if (GOCWindows.Instance.ShowMessageBoxOnException) { UIHelperWindows.DisplayException(exception, form, keyEventHandler, eventDetailsMessage); } if (GOCWindows.Instance.ShowWindowsFormsNotificationOnException && GOCWindows.Instance.NotifyIcon != null) { string applicationName = string.IsNullOrEmpty(GOCWindows.Instance.ApplicationName) ? "Notification" : GOCWindows.Instance.ApplicationName; GOCWindows.Instance.NotifyIcon.ShowBalloonTip(10, applicationName, exception.Message, ToolTipIcon.Error); } UserThrownException userThrownException = exception as UserThrownException; if (userThrownException != null) { closeApplication = userThrownException.CloseApplication; GOCWindows.Instance.Logger.LogMessage(new LogError(exception, eventDetailsMessage, userThrownException.LoggingLevel)); } else { GOCWindows.Instance.Logger.LogMessage(new LogError(exception, eventDetailsMessage, LoggingLevel.Normal)); } if (emailException && GOCWindows.Instance.SendEmailOnException) { if (GOCWindows.Instance.EmailClient == null) { throw new Exception(string.Format("{0} enabled, but {1} not set.", EntityReaderGeneric <GOCWindows> .GetPropertyName(p => p.SendEmailOnException, false), EntityReaderGeneric <GOCWindows> .GetPropertyName(p => p.EmailClient, false))); } GOCWindows.Instance.EmailClient.SendExceptionEmailNotification(exception, out emailErrorMessage, out emailLogMessageText, GOCWindows.Instance.AppendHostNameToExceptionEmails, emailNotificationRecipients); } return(closeApplication); } catch (Exception ex) { Exception wrappedException = new Exception(ex.Message, exception); Console.WriteLine(LogError.GetErrorMessageFromException(new Exception(ex.Message, exception), eventDetailsMessage)); GOCWindows.Instance.Logger.LogMessageToFile(new LogError(wrappedException, eventDetailsMessage, LoggingLevel.Minimum)); emailErrorMessage = string.Empty; emailLogMessageText = string.Empty; return(true); } }
public DatabaseWindows( string name, string connectionString, bool populateTablesFromSchema, bool createOrmAssembly, bool saveOrmAssembly, string ormAssemblyOutputDirectory, bool overrideNameWithDatabaseNameFromSchema) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(string.Format( "{0} not be null or empty when constructing {1}.", EntityReaderGeneric <DatabaseWindows> .GetPropertyName(p => p.Name, false), this.GetType().FullName)); } _name = name; Initialize( connectionString, populateTablesFromSchema, createOrmAssembly, saveOrmAssembly, ormAssemblyOutputDirectory, overrideNameWithDatabaseNameFromSchema); }
public virtual void RefreshFromFile(bool saveIfFileDoesNotExist, bool validateAllSettingValuesSet) { Type thisType = this.GetType(); if (!File.Exists(_filePath)) { if (GOC.Instance.Logger != null) { GOC.Instance.Logger.LogMessage(new LogMessage(string.Format("Could not find {0} at {1} ...", thisType.FullName, _filePath), LogMessageType.Warning, LoggingLevel.Normal)); } if (saveIfFileDoesNotExist) { SaveToFile(); } else { throw new FileNotFoundException(string.Format("Could not find {0}.", Path.GetFileName(_filePath))); } } if (GOC.Instance.Logger != null) { GOC.Instance.Logger.LogMessage(new LogMessage(string.Format("Loading {0} from {1} ...", thisType.FullName, _filePath), LogMessageType.Information, LoggingLevel.Normal)); } object fileSettings = GOC.Instance.GetSerializer(SerializerType.XML).DeserializeFromFile(this.GetType(), _filePath); bool requireSave = false; foreach (PropertyInfo p in thisType.GetProperties()) { object valueFromFile = p.GetValue(fileSettings, null); if (p.Name == EntityReaderGeneric <Settings> .GetPropertyName(sp => sp.FilePath, false)) { if (valueFromFile.ToString() != _filePath) { /*The location of the settings file has changed and we need * to keep the latest file path (not the one from the file) * and save the file with this new file path in place.*/ requireSave = true; } continue; } if (validateAllSettingValuesSet && valueFromFile == null) { throw new NullReferenceException(string.Format( "{0} not set in {1}.", p.Name, _filePath)); } if (valueFromFile is string) { valueFromFile = RemoveEscapeSequencesFromNewLineSettingValue((string)valueFromFile); } p.SetValue(this, valueFromFile, null); } if (requireSave) { SaveToFile(); } }
private static void ValidateMandatoryNodeFields(ScopeNode node) { if (string.IsNullOrEmpty(node.DisplayName)) { throw new NullReferenceException(string.Format( "{0} may not be null or empty on MMC {1}.", EntityReaderGeneric <ScopeNode> .GetPropertyName(p => p.DisplayName, false), typeof(ScopeNode).FullName)); } }
public WebRequestToExtensionHandlerWindows(string name) { if (string.IsNullOrEmpty(name)) { throw new NullReferenceException(string.Format( "{0} may not be null or empty when constructing a {1}.", EntityReaderGeneric <WebRequestToExtensionHandlerWindows> .GetPropertyName(p => p.Name, false), typeof(WebRequestToExtensionHandlerWindows).FullName)); } _name = name; }
public ExtensionManagedEntityWindows(string entityFullTypeName) : base() { if (string.IsNullOrEmpty(entityFullTypeName)) { throw new NullReferenceException(string.Format( "{0} may not be null when constructing an {1}.", EntityReaderGeneric <ExtensionManagedEntityWindows> .GetPropertyName(p => p.EntityFullTypeName, false), typeof(ExtensionManagedEntityWindows).FullName)); } _entityFullTypeName = entityFullTypeName; }
public NKitWebServiceClientWrapperWindows(IMimeWebServiceClient webServiceClient, int timeout) { if (webServiceClient == null) { throw new NullReferenceException(string.Format( "{0} may not be set to null when constructing {1}.", EntityReaderGeneric <NKitWebServiceClientWrapperWindows> .GetPropertyName(p => p.WebServiceClient, false), this.GetType().FullName)); } _webServiceClient = webServiceClient; _timeout = timeout; }
public SettingsCategoryInfo(Settings settings, string category) { _settings = settings; if (string.IsNullOrEmpty(category)) { throw new NullReferenceException(string.Format( "{0} may not be set to null when constructing a {1}.", EntityReaderGeneric <SettingsCategoryInfo> .GetPropertyName(p => p.Category, false), this.GetType().FullName)); } _category = category; }
public SqliteDatabaseBaseWindows(string name, string connectionString) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(string.Format( "{0} not be null or empty when constructing {1}.", EntityReaderGeneric <SqliteDatabaseBaseWindows> .GetPropertyName(p => p.Name, false), this.GetType().FullName)); } _tables = new EntityCacheGeneric <string, SqliteDatabaseTableWindows> (); _name = name; _connectionString = connectionString; }
public static bool HandleException( Exception exception, string eventDetailsMessage, bool emailException, out string emailErrorMessage, out string emailLogMessageText, List <EmailNotificationRecipient> emailNotificationRecipients) { try { emailErrorMessage = string.Empty; emailLogMessageText = string.Empty; bool closeApplication = false; if (exception == null) { throw new NullReferenceException("exception to be handled may not be null."); } UserThrownException userThrownException = exception as UserThrownException; if (userThrownException != null) { closeApplication = userThrownException.CloseApplication; GOC.Instance.Logger.LogMessage(new LogError(exception, eventDetailsMessage, userThrownException.LoggingLevel)); } else { GOC.Instance.Logger.LogMessage(new LogError(exception, eventDetailsMessage, LoggingLevel.Normal)); } if (emailException && GOC.Instance.SendEmailOnException) { if (GOC.Instance.EmailClient == null) { throw new Exception(string.Format("{0} enabled, but {1} not set.", EntityReaderGeneric <GOC> .GetPropertyName(p => p.SendEmailOnException, false), EntityReaderGeneric <GOC> .GetPropertyName(p => p.EmailClient, false))); } GOC.Instance.EmailClient.SendExceptionEmailNotification(exception, out emailErrorMessage, out emailLogMessageText, GOC.Instance.AppendHostNameToExceptionEmails, emailNotificationRecipients); } return(closeApplication); } catch (Exception ex) { Exception wrappedException = new Exception(ex.Message, exception); Console.WriteLine(LogError.GetErrorMessageFromException(new Exception(ex.Message, exception), eventDetailsMessage)); GOC.Instance.Logger.LogMessageToFile(new LogError(wrappedException, eventDetailsMessage, LoggingLevel.Minimum)); emailErrorMessage = string.Empty; emailLogMessageText = string.Empty; return(true); } }
public FtpFileInfo(string localFilePath, string ftpFileUri) { if (string.IsNullOrEmpty(localFilePath)) { throw new NullReferenceException(string.Format( "{0} may not be null or empty.", EntityReaderGeneric <FtpFileInfo> .GetPropertyName(p => p.LocalFilePath, false))); } if (string.IsNullOrEmpty(ftpFileUri)) { throw new NullReferenceException(string.Format( "{0} may not be null or empty.", EntityReaderGeneric <FtpFileInfo> .GetPropertyName(p => p.FtpFileUri, false))); } _localFilePath = localFilePath; _ftpFileUri = ftpFileUri; }
public IntervalJob(int executionMilliSecondsInterval, bool startImmediately) { if (executionMilliSecondsInterval < 0) { throw new ArgumentOutOfRangeException(string.Format("{0} may not be less than 0 when constructing a {1}.", EntityReaderGeneric <IntervalJob> .GetPropertyName(p => p.ExecutionMilliSecondsInterval, false), this.GetType().Name)); } _executionMilliSecondsInterval = executionMilliSecondsInterval; _timer = new System.Timers.Timer(); _timer.Elapsed += _timer_Elapsed; ChangeExecutionInterval(_executionMilliSecondsInterval); if (startImmediately) { StartJob(); } }
public static DataGridTableStyle GetDataGridTableStyle <T>(int width, List <string> hiddenColumns, bool shapeColumnNames) { DataGridTableStyle result = new DataGridTableStyle(); result.MappingName = shapeColumnNames ? DataShaperWindows.ShapeCamelCaseString(typeof(T).Name) : typeof(T).Name; List <string> columns = EntityReaderGeneric <T> .GetAllPropertyNames(shapeColumnNames); foreach (string c in columns) { int modifiedWidth = width; if (hiddenColumns.Contains(c)) { modifiedWidth = -1; } result.GridColumnStyles.Add(GetColumnStyle(c, c, modifiedWidth)); } return(result); }
public ExtensionManagedEntityWindows AddExtensionManagedEntity(string entityFullTypeName) { if (string.IsNullOrEmpty(entityFullTypeName)) { throw new NullReferenceException(string.Format( "{0} of {1} to be added may not be null or empty.", EntityReaderGeneric <ExtensionManagedEntityWindows> .GetPropertyName(p => p.EntityFullTypeName, false), typeof(ExtensionManagedEntityWindows).FullName)); } if (Exists(entityFullTypeName)) { throw new ArgumentException(string.Format( "A {0} of {1} has already been added to this {2}.", EntityReaderGeneric <ExtensionManagedEntityWindows> .GetPropertyName(p => p.EntityFullTypeName, false), entityFullTypeName, this.GetType().FullName)); } ExtensionManagedEntityWindows result = new ExtensionManagedEntityWindows(entityFullTypeName); base.Add(entityFullTypeName, result); return(result); }
public OrmTypeWindows CreateOrmType(string typeName, bool prefixWithAssemblyNamespace) { if (_ormTypes.Exists(typeName)) { throw new ArgumentException(string.Format( "{0} with {1} {2} already created on {3}.", typeof(OrmTypeWindows).FullName, EntityReaderGeneric <OrmTypeWindows> .GetPropertyName(p => p.TypeName, false), typeName, this.GetType().FullName)); } if (prefixWithAssemblyNamespace) { typeName = string.Format("{0}.{1}", _assemblyName, typeName); } TypeBuilder typeBuilder = _moduleBuilder.DefineType(typeName, TypeAttributes.Class | TypeAttributes.Public); ConstructorBuilder constructorBuilder = typeBuilder.DefineDefaultConstructor(MethodAttributes.Public); OrmTypeWindows result = new OrmTypeWindows(typeName, typeBuilder); _ormTypes.Add(result.TypeName, result); return(result); }
protected void Initialize( string propertyName, PropertyAttributes propertyAttributes, Type propertyType) { if (propertyName != null) { propertyName = propertyName.Trim(); } if (string.IsNullOrEmpty(propertyName)) { throw new NullReferenceException(string.Format( "{0} may not be null when constructing a {1}.", EntityReaderGeneric <OrmPropertyWindows> .GetPropertyName(p => p.PropertyName, false), this.GetType().FullName)); } if (propertyType == null) { throw new NullReferenceException(string.Format( "{0} may not be null when constructing a {1}.", EntityReaderGeneric <OrmPropertyWindows> .GetPropertyName(p => p.PropertyType, false), this.GetType().FullName)); } _propertyName = propertyName; _propertyAttributes = propertyAttributes; _propertyType = propertyType; _fieldName = string.Format( "_{0}{1}", _propertyName[0].ToString().ToLower(), _propertyName.Substring(1)); _fieldAttributes = FieldAttributes.Private; _getMethodName = string.Format("get_{0}", _propertyName); _setMethodName = string.Format("set_{0}", _propertyName); }
public override List <object> Query( string sqlQueryString, OrmAssemblySqlWindows ormCollectibleAssembly, string typeName, string propertyNameFilter, out OrmTypeWindows ormCollecibleType) { if (ormCollectibleAssembly == null) { throw new NullReferenceException(string.Format("ormCollectibleAssembly may not be null.")); } if (ormCollectibleAssembly.AssemblyBuilderAccess != AssemblyBuilderAccess.RunAndCollect) { throw new ArgumentException(string.Format( "Querying the database with a raw SQL query string requires an {0} with the {1} property set to {2}.", typeof(OrmAssemblyWindows).FullName, EntityReaderGeneric <OrmAssemblyWindows> .GetPropertyName(p => p.AssemblyBuilderAccess, false), AssemblyBuilderAccess.RunAndCollect)); } List <object> result = null; using (SQLiteConnection connection = new SQLiteConnection(_connectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(sqlQueryString, connection)) { command.CommandType = System.Data.CommandType.Text; using (SQLiteDataReader reader = command.ExecuteReader()) { ormCollecibleType = ormCollectibleAssembly.CreateOrmTypeFromSqlDataReader(typeName, reader, true); result = DataHelperWindows.ParseReaderToEntities(reader, ormCollecibleType.DotNetType, propertyNameFilter); } } } return(result); }
public int Update( object e, string columnName, bool disposeConnectionAfterExecute, SQLiteConnection connection, SQLiteTransaction transaction) { int result = -1; Type entityType = e.GetType(); List <SQLiteParameter> parameters = new List <SQLiteParameter>(); StringBuilder sqlUpdateCommand = new StringBuilder(); sqlUpdateCommand.AppendLine(string.Format("UPDATE [{0}]", entityType.Name)); sqlUpdateCommand.AppendLine("SET "); PropertyInfo[] entityProperties = entityType.GetProperties(); if (entityProperties.Length < 1) { throw new ArgumentException(string.Format( "{0} has no properties to update in the local database.", entityType.FullName)); } bool firstUpdateColumn = true; StringBuilder whereClause = new StringBuilder(); whereClause.AppendLine("WHERE "); foreach (PropertyInfo p in entityProperties) { if ((p.PropertyType != typeof(string) && p.PropertyType != typeof(byte) && p.PropertyType != typeof(byte[])) && (p.PropertyType.IsClass || p.PropertyType.IsEnum || p.PropertyType.IsInterface || p.PropertyType.IsNotPublic || p.PropertyType.IsPointer)) { continue; } SqliteDatabaseTableColumnWindows column = (SqliteDatabaseTableColumnWindows)_columns[p.Name]; if (!firstUpdateColumn) { sqlUpdateCommand.AppendLine(","); } object value = p.GetValue(e, null); if (value == null) { value = DBNull.Value; } SQLiteParameter parameter = new SQLiteParameter(string.Format("@{0}", p.Name), value) { DbType = column.SqlDbType }; parameters.Add(parameter); sqlUpdateCommand.Append(string.Format("[{0}] = @{0}", p.Name)); if (string.IsNullOrEmpty(columnName)) //Look up the record to update based on the key columns because no column name was specified. { if (column.IsKey) { if (!firstUpdateColumn) { whereClause.AppendLine(","); } whereClause.Append(string.Format("[{0}] = @{0}", p.Name)); } } firstUpdateColumn = false; } sqlUpdateCommand.AppendLine(); if (!string.IsNullOrEmpty(columnName)) //Look up the record to update based on the specified column name. { whereClause.Append(string.Format("[{0}] = @{0}", columnName)); } sqlUpdateCommand.Append(whereClause); try { if (connection == null) { connection = new SQLiteConnection(_connectionString); } if (connection.State != ConnectionState.Open) { connection.Open(); } string commandText = sqlUpdateCommand.ToString(); using (SQLiteCommand command = new SQLiteCommand(commandText, connection)) { if (transaction != null) { command.Transaction = transaction; } parameters.ForEach(p => command.Parameters.Add(p)); result = command.ExecuteNonQuery(); if (result < 0) { if (string.IsNullOrEmpty(columnName)) { throw new Exception(string.Format("Could not update {0} on database against key columns.", entityType.Name)); } else { object columnValue = EntityReaderGeneric <object> .GetPropertyValue(columnName, e, true); throw new Exception(string.Format("Could not update {0} on database with value {1} on column {2}.", entityType.Name, columnValue, columnName)); } } } } finally { if (disposeConnectionAfterExecute && connection != null & connection.State != ConnectionState.Closed) { connection.Dispose(); } } return(result); }