public static async Task <EsentSession> CreateReadOnlySession(IEsentSession parentSession, IDisposeWaiters waiters)
            {
                var dispatcher = new SingleThreadDispatcher();

                try
                {
                    return(await dispatcher.QueueAction(() =>
                    {
                        var session = new Session(parentSession.Instance);
                        try
                        {
                            Api.JetAttachDatabase(session, parentSession.DatabaseFile, AttachDatabaseGrbit.None);
                            JET_DBID dbid;
                            Api.JetOpenDatabase(session, parentSession.DatabaseFile, string.Empty, out dbid, OpenDatabaseGrbit.None);
                            // ReSharper disable once AccessToDisposedClosure
                            return new EsentSession(parentSession.Instance, session, dbid, parentSession.DatabaseFile, waiters, dispatcher, true);
                        }
                        catch
                        {
                            session.Dispose();
                            throw;
                        }
                    }));
                }
                catch
                {
                    dispatcher.Dispose();
                    throw;
                }
            }
        private async Task CreateCachedInstance()
        {
            var dispatcher = new SingleThreadDispatcher();

            try
            {
                // ReSharper disable once AccessToDisposedClosure
                var mainSession = await dispatcher.QueueAction(() => CreateInstance(dispatcher));

                var newSession = new MainSessionObj()
                {
                    MainSession = mainSession,
                    Waiters     = this
                };
                await newSession.CreateReservedSessions();

                var old = Interlocked.Exchange(ref _cachedSession, newSession);
                if (old != null)
                {
                    await old.DisposeAsync();
                }
            }
            catch
            {
                dispatcher.Dispose();
                throw;
            }
        }
 public EsentSession(Instance instance, Session session, JET_DBID dbid, string databasePath, IDisposeWaiters waiters, SingleThreadDispatcher dispatcher, bool isSecondary)
 {
     Instance           = instance;
     _databasePath      = databasePath;
     _waiters           = waiters;
     _session           = session;
     _database          = dbid;
     IsSecondarySession = isSecondary;
     _dispatcher        = dispatcher;
 }
Example #4
0
 public FileLogWriter(string type)
 {
     Type     = type;
     mLogPath = System.IO.Directory.GetCurrentDirectory() +
                System.IO.Path.DirectorySeparatorChar + "logs" + System.IO.Path.DirectorySeparatorChar;
     if (!System.IO.Directory.Exists(mLogPath))
     {
         System.IO.Directory.CreateDirectory(mLogPath);
     }
     mDispatcher = new SingleThreadDispatcher <LogItem>(OnWriteLog);
 }
Example #5
0
 private RequestBuilder(string controllerName, string actionName, object routeValues)
 {
     _controllerName = controllerName;
     _actionName = actionName;
     _routeValues = new RouteValueDictionary(routeValues);
     NavigationService = new Mock<INavigationService>();
     Navigator = new Mock<INavigator>();
     Route = new Mock<IRoute>();
     Controller = new Mock<IController>();
     Path = "TestPath";
     ProgressListeners = new List<INavigationProgressListener>();
     Dispatcher = new SingleThreadDispatcher();
 }
Example #6
0
 private RequestBuilder(string controllerName, string actionName, object routeValues)
 {
     _controllerName   = controllerName;
     _actionName       = actionName;
     _routeValues      = new RouteValueDictionary(routeValues);
     NavigationService = new Mock <INavigationService>();
     Navigator         = new Mock <INavigator>();
     Route             = new Mock <IRoute>();
     Controller        = new Mock <IController>();
     Path = "TestPath";
     ProgressListeners = new List <INavigationProgressListener>();
     Dispatcher        = new SingleThreadDispatcher();
 }
        private IEsentSession CreateInstance(SingleThreadDispatcher dispatcher)
        {
            var databasePath = GetEdbFilePath();
            var instance     = DoCreateInstance();

            try
            {
                IEsentSession result;
                if (!File.Exists(databasePath))
                {
                    var session1 = new Session(instance);
                    try
                    {
                        JET_DBID database;

                        Api.JetCreateDatabase(session1, databasePath, null, out database, CreateDatabaseGrbit.None);
                    }
                    finally
                    {
                        session1.Dispose();
                    }
                }
                var session = new Session(instance);
                try
                {
                    JET_DBID database;

                    Api.JetAttachDatabase(session, databasePath, AttachDatabaseGrbit.None);
                    Api.OpenDatabase(session, databasePath, out database, OpenDatabaseGrbit.None);
                    result = new EsentSession(instance, session, database, databasePath, this, dispatcher, false);
                }
                catch
                {
                    session.Dispose();
                    throw;
                }
                return(result);
            }
            catch
            {
                instance.Dispose();
                throw;
            }
        }
Example #8
0
 public static void Initialize()
 {
     // initialize store
     if (StoreOnMemoryObjectPersistence.IsPersistentDataExisted("users"))
     {
         _store = new PersistentDataStore<long, TwitterUser>
             (_ => _.Id, Path.Combine(App.DataStorePath, "users"), ChunkCount,
             manageData: StoreOnMemoryObjectPersistence.GetPersistentData("users"));
     }
     else
     {
         _store = new PersistentDataStore<long, TwitterUser>
             (_ => _.Id, Path.Combine(App.DataStorePath, "users"), ChunkCount);
     }
     _dispatcher = new SingleThreadDispatcher<TwitterUser>(_store.Store);
     LoadScreenNameResolverCache();
     App.ApplicationFinalize += Shutdown;
 }
Example #9
0
 public static void Initialize()
 {
     // initialize
     if (StoreOnMemoryObjectPersistence.IsPersistentDataExisted("statuses"))
     {
         _store = new PersistentDataStore<long, TwitterStatus>
             (_ => _.Id, Path.Combine(App.DataStorePath, "statuses"), ChunkCount, new IdReverseComparer(),
             StoreOnMemoryObjectPersistence.GetPersistentData("statuses"));
     }
     else
     {
         _store = new PersistentDataStore<long, TwitterStatus>
             (_ => _.Id, Path.Combine(App.DataStorePath, "statuses"), ChunkCount, new IdReverseComparer());
     }
     _dispatcher = new SingleThreadDispatcher<TwitterStatus>(_store.Store);
     App.ApplicationFinalize += Shutdown;
 }