コード例 #1
0
        public void InitStore(EventStoreTypes type)
        {
            //this.EventStoreType = type.ToString();
            switch (type)
            {
            case EventStoreTypes.None:
                store = new NullEventStore();
                break;

            case EventStoreTypes.Xml:
                storeFile = FsUtil.GetCurrentUserAppDataFolder() + "EventStore.xml";
                store     = new EventStore();
                if (File.Exists(storeFile))
                {
                    FileInfo info = new FileInfo(storeFile);
                    if (info.IsReadOnly)
                    {
                        throw new EventStoreInitializationException(storeFile);
                    }

                    store.Hydrate(storeFile);
                }

                break;

            case EventStoreTypes.MSSql:
                store = new DatabaseEventStore(DaoDbType.MSSql);
                try
                {
                    DatabaseAgent.GetAgent(LogEventData.ContextName, DaoDbType.MSSql).EnsureSchema <EventDefinition>();
                }
                catch
                {
                    // we tried
                }
                break;

            case EventStoreTypes.SQLite:
                store = new DatabaseEventStore(DaoDbType.SQLite);
                try
                {
                    DatabaseAgent.GetAgent(LogEventData.ContextName, DaoDbType.SQLite).EnsureSchema <EventDefinition>();
                }
                catch (UnableToDetermineConnectionStringException utdcse)
                {
                    //AppDb.Current;
                }
                catch
                {
                    //we tried
                }
                break;
            }
        }
コード例 #2
0
        public void LogFatal(string message)
        {
            if (fatalLogger == null)
            {
                fatalLogger = (XmlLogger)CreateLogger(Naizari.Logging.LogType.Xml);
                string folder = FsUtil.GetCurrentUserAppDataFolder();
                fatalLogger.LogLocation = folder;
                fatalLogger.LogName     = FsUtil.GetAssemblyName(this.GetType().Assembly);
            }

            fatalLogger.AddEntry(message);
        }
コード例 #3
0
        private void InitEmbeddedDb()
        {
            if ((this.DbType == DaoDbType.Firebird && !string.IsNullOrEmpty(this.ConnectionString)) ||
                this.DbType == DaoDbType.SQLite && !string.IsNullOrEmpty(this.ConnectionString))
            {
                DbConnectionStringBuilder connectionStringBuilder = this.CreateConnectionStringBuilder();
                connectionStringBuilder.ConnectionString = this.ConnectionString;
                string dbName = "";
                if (this.DbType != DaoDbType.SQLite && connectionStringBuilder["Initial Catalog"] != null)
                {
                    dbName = connectionStringBuilder["Initial Catalog"].ToString();
                }

                if (string.IsNullOrEmpty(dbName) && connectionStringBuilder.ContainsKey("Database") &&
                    connectionStringBuilder["Database"] != null)
                {
                    dbName = connectionStringBuilder["Database"].ToString();
                }

                if (string.IsNullOrEmpty(dbName) && connectionStringBuilder.ContainsKey("Data Source") &&
                    connectionStringBuilder["Data Source"] != null)
                {
                    dbName = connectionStringBuilder["Data Source"].ToString();
                }

                if (string.IsNullOrEmpty(dbName))
                {
                    dbName = "default.db";
                }

                string path = "";
                if (HttpContext.Current == null)
                {
                    path = FsUtil.GetCurrentUserAppDataFolder() + dbName;
                }
                else
                {
                    path = HttpContext.Current.Server.MapPath("~/App_Data/" + dbName);
                }

                if (this.DbType == DaoDbType.Firebird)
                {
                    this.ConnectionString = "Database=" + path + ";ServerType=1;";
                    if (!File.Exists(path))
                    {
                        FbConnection.CreateDatabase(this.ConnectionString);
                    }
                }
                else if (this.DbType == DaoDbType.SQLite)
                {
                    FileInfo file = new FileInfo(path);
                    if (!Directory.Exists(file.DirectoryName))
                    {
                        Directory.CreateDirectory(file.DirectoryName);
                    }

                    connectionStringBuilder["Data Source"] = file.FullName;
                    this.ConnectionString = connectionStringBuilder.ConnectionString;
                }
            }
        }