コード例 #1
0
        public static WorkerRoleWebPortal CreateNew(IWorkerRole workerInstance, Func <IRebuilderPerfCounter> rebuildReadModel, Func <IRebuilderPerfCounter> rebuildEventStore, IPortalTaskCoordinator coordinator)
        {
            if (instance == null)
            {
                lock (coordinator.LockObject)
                {
                    if (instance == null)
                    {
                        instance = new WorkerRoleWebPortal();


                        if (worker != null)
                        {
                            throw new InvalidOperationException("You should only start one instance!");
                        }


                        WorkerRoleWebPortal.coordinator = coordinator;
                        WorkerRoleWebPortal.coordinator.SetWorkerIsNotWorking();
                        worker = workerInstance;
                        WorkerRoleWebPortal.rebuildReadModel  = rebuildReadModel;
                        WorkerRoleWebPortal.rebuildEventStore = rebuildEventStore;
                    }
                }
            }

            return(instance);
        }
        public static EventStoreRebuilderWebPortal CreateNew(IEventStoreRebuilder rebuilderInstance, IPortalTaskCoordinator coordinator)
        {
            try
            {
                lock (coordinator.LockObject)
                {
                    if (rebuilder != null)
                    {
                        throw new InvalidOperationException("Can not create new instance of EventStoreRebuilderWebPortal. You should only start one instance!");
                    }

                    if (coordinator.PortalIsRebuilding)
                    {
                        throw new InvalidOperationException("Can not create new instance of EventStoreRebuilderWebPortal. Is already rebuilding");
                    }

                    instance = new EventStoreRebuilderWebPortal();

                    EventStoreRebuilderWebPortal.coordinator = coordinator;
                    EventStoreRebuilderWebPortal.coordinator.SetPortalIsNotRebuilding();
                    rebuilder = rebuilderInstance;
                }

                return(instance);
            }
            catch (Exception ex)
            {
                WorkerRoleWebPortal.Instance.WorkerRole.Tracer.Notify(ex.Message);
                throw;
            }
        }