Beispiel #1
0
        public async Task <bool> ResumeWorkflow(string workflowId)
        {
            if (LockProvider.AcquireLock(workflowId).Result)
            {
                bool requeue = false;
                try
                {
                    var wf = await PersistenceStore.GetWorkflowInstance(workflowId);

                    if (wf.Status == WorkflowStatus.Suspended)
                    {
                        wf.Status = WorkflowStatus.Runnable;
                        await PersistenceStore.PersistWorkflow(wf);

                        requeue = true;
                        return(true);
                    }
                    return(false);
                }
                finally
                {
                    await LockProvider.ReleaseLock(workflowId);

                    if (requeue)
                    {
                        await QueueProvider.QueueForProcessing(workflowId);
                    }
                }
            }
            return(false);
        }
        public async Task <bool> SuspendWorkflow(string workflowId)
        {
            if (await LockProvider.AcquireLock(workflowId, new CancellationToken()))
            {
                try
                {
                    var wf = await PersistenceStore.GetWorkflowInstance(workflowId);

                    if (wf.Status == WorkflowStatus.Runnable)
                    {
                        wf.Status = WorkflowStatus.Suspended;
                        await PersistenceStore.PersistWorkflow(wf);

                        return(true);
                    }

                    return(false);
                }
                finally
                {
                    await LockProvider.ReleaseLock(workflowId);
                }
            }

            return(false);
        }
        public async Task PublishEvent(string eventName, string eventKey, object eventData, DateTime?effectiveDate = null)
        {
            if (_shutdown)
            {
                throw new Exception("Host is not running");
            }

            Logger.LogDebug("Creating event {0} {1}", eventName, eventKey);
            Event evt = new Event();

            if (effectiveDate.HasValue)
            {
                evt.EventTime = effectiveDate.Value.ToUniversalTime();
            }
            else
            {
                evt.EventTime = DateTime.Now.ToUniversalTime();
            }

            evt.EventData   = eventData;
            evt.EventKey    = eventKey;
            evt.EventName   = eventName;
            evt.IsProcessed = false;
            string eventId = await PersistenceStore.CreateEvent(evt);

            await QueueProvider.QueueWork(eventId, QueueType.Event);
        }
Beispiel #4
0
        public async Task IsUsernameRegisteredAsync_TestUser_Exists()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.Users.IsUsernameRegisteredAsync(TestBase.ValidUser.Username);

            Assert.IsTrue(result);
        }
Beispiel #5
0
        public async Task IsUsernameRegisteredAsync_NonExistentUser_DoesNotExist()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.Users.IsUsernameRegisteredAsync(TestBase.ValidUser.Username + Guid.NewGuid().ToString());

            Assert.IsFalse(result);
        }
        public async Task IsIdentityRegisteredAsync_NonexistentCredentialAndSecret_NoRecord()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserAuthentications.IsIdentityRegisteredAsync(ValidUserAuthentications.First().CredentialType, ValidUserAuthentications.First().Secret + " xyz");

            Assert.IsFalse(result);
        }
Beispiel #7
0
        public async Task CreateAsync_ValidUser_GetsNewSession()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserSessions.CreateAsync(ValidUserId, DateTime.UtcNow);

            Assert.AreEqual(TestBase.ValidUser.Id, result.UserId);
        }
        public async Task GetBySecretAsync_ValidCredentialAndSecret_GetsRecord()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserAuthentications.GetBySecretAsync(ValidUserAuthentications.First().CredentialType, ValidUserAuthentications.First().Secret);

            Assert.IsNotNull(result);
        }
        public async Task GetByUserAsync_nonexistentId_NoRecord()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserAuthentications.GetAsync(Guid.NewGuid());

            Assert.IsNull(result);
        }
        public async Task GetAsync_ValidId_GetsRecord()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserAuthentications.GetAsync(ValidUserAuthentications.First().Id);

            Assert.IsNotNull(result);
        }
        public async Task GetByUserAsync_ValidUserEmptyCredential_GetsEmptyList()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserAuthentications.GetByUserAsync(CredentialType.Twitter, ValidUserId);

            Assert.AreEqual(0, result.Count);
        }
        public async Task GetByUserAsync_ValidUserCredentialPair_GetsRecords()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.UserAuthentications.GetByUserAsync(ValidUserAuthentications.First().CredentialType, ValidUserId);

            Assert.AreEqual(ValidUserAuthentications.Count(), result.Count);
        }
Beispiel #13
0
        public async Task GetAsync_TestCustomer_GetsCustomerRecord()
        {
            var database = new PersistenceStore(ConnectionString);

            var result = await database.Customers.GetAsync(TestBase.ValidCustomerId);

            Assert.AreEqual(TestBase.ValidCustomer.Id, result.Id);
            Assert.AreEqual(TestBase.ValidCustomer.DisplayName, result.DisplayName);
        }
Beispiel #14
0
        public async Task SubscribeEvent(string workflowId, int stepId, string eventName, string eventKey)
        {
            Logger.LogDebug("Subscribing to event {0} {1} for workflow {2} step {3}", eventName, eventKey, workflowId, stepId);
            EventSubscription subscription = new EventSubscription();

            subscription.WorkflowId = workflowId;
            subscription.StepId     = stepId;
            subscription.EventName  = eventName;
            subscription.EventKey   = eventKey;

            await PersistenceStore.CreateEventSubscription(subscription);
        }
Beispiel #15
0
        public void Start()
        {
            _shutdown = false;
            PersistenceStore.EnsureStoreExists();
            QueueProvider.Start().Wait();
            LockProvider.Start().Wait();

            Logger.LogInformation("Starting backgroud tasks");

            foreach (var task in _backgroundTasks)
            {
                task.Start();
            }
        }
Beispiel #16
0
        private async Task StashUnpublishedEvents()
        {
            if (!_shutdown)
            {
                var pub = await QueueProvider.DequeueForPublishing();

                while (pub != null)
                {
                    await PersistenceStore.CreateUnpublishedEvent(pub);

                    pub = await QueueProvider.DequeueForPublishing();
                }
            }
        }
Beispiel #17
0
        public async Task GetAsync_CreateViewAsync_ProducesNewView()
        {
            var    database          = new PersistenceStore(ConnectionString);
            string originalAccessKey = "abc-123";
            var    view = new ViewDTO(null, ValidCustomerId, originalAccessKey, new ViewCustomizationDTO("url", "logo", "title", new List <ViewCustomizationHeaderLinkDTO>(), "copyright"), new List <ViewColumnDTO>()
            {
            });

            var result = await database.Views.CreateNewAsync(view);

            Assert.AreEqual(originalAccessKey, result.AccessKey);
            Assert.AreNotEqual(originalAccessKey, view.AccessKey);
            Assert.AreEqual(view.CustomerId, result.CustomerId);
            Assert.IsNotNull(result.Id);
        }
        public async Task <string> StartWorkflow <TData>(string workflowId, int?version, TData data = null)
            where TData : class
        {
            if (_shutdown)
            {
                throw new InvalidOperationException("Host is not running");
            }

            var def = Registry.GetDefinition(workflowId, version);

            if (def == null)
            {
                throw new WorkflowNotRegisteredException(workflowId, version);
            }

            var wf = new WorkflowInstance
            {
                WorkflowDefinitionId = workflowId,
                Version       = def.Version,
                Data          = data,
                Description   = def.Description,
                NextExecution = 0,
                CreateTime    = DateTime.Now.ToUniversalTime(),
                Status        = WorkflowStatus.Runnable
            };

            if ((def.DataType != null) && (data == null))
            {
                wf.Data = def.DataType.GetConstructor(new Type[] { }).Invoke(null);
            }

            wf.ExecutionPointers.Add(new ExecutionPointer
            {
                Id       = Guid.NewGuid().ToString(),
                StepId   = 0,
                Active   = true,
                StepName = def.Steps.First(x => x.Id == 0).Name
            });

            string id = await PersistenceStore.CreateNewWorkflow(wf);

            await QueueProvider.QueueWork(id, QueueType.Workflow);

            return(id);
        }
Beispiel #19
0
        public async Task <string> StartWorkflow <TData>(string workflowId, int?version, TData data = null)
            where TData : class
        {
            if (_shutdown)
            {
                throw new Exception("Host is not running");
            }

            var def = Registry.GetDefinition(workflowId, version);

            if (def == null)
            {
                throw new Exception(String.Format("Workflow {0} version {1} is not registered", workflowId, version));
            }

            var wf = new WorkflowInstance();

            wf.WorkflowDefinitionId = workflowId;
            wf.Version       = def.Version;
            wf.Data          = data;
            wf.Description   = def.Description;
            wf.NextExecution = 0;
            wf.CreateTime    = DateTime.Now.ToUniversalTime();
            wf.Status        = WorkflowStatus.Runnable;

            if ((def.DataType != null) && (data == null))
            {
                wf.Data = def.DataType.GetConstructor(new Type[] { }).Invoke(null);
            }

            wf.ExecutionPointers.Add(new ExecutionPointer()
            {
                Id             = Guid.NewGuid().ToString(),
                StepId         = def.InitialStep,
                Active         = true,
                ConcurrentFork = 1,
                StepName       = def.Steps.First(x => x.Id == def.InitialStep).Name
            });
            string id = await PersistenceStore.CreateNewWorkflow(wf);

            await QueueProvider.QueueForProcessing(id);

            return(id);
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _shutdown = false;
            PersistenceStore.EnsureStoreExists();
            await QueueProvider.Start();

            await LockProvider.Start();

            await _lifeCycleEventHub.Start();

            await _searchIndex.Start();

            Logger.LogInformation("Starting background tasks");

            foreach (var task in _backgroundTasks)
            {
                task.Start();
            }
        }
Beispiel #21
0
        public async Task <bool> TerminateWorkflow(string workflowId)
        {
            if (LockProvider.AcquireLock(workflowId).Result)
            {
                try
                {
                    var wf = await PersistenceStore.GetWorkflowInstance(workflowId);

                    wf.Status = WorkflowStatus.Terminated;
                    await PersistenceStore.PersistWorkflow(wf);

                    return(true);
                }
                finally
                {
                    await LockProvider.ReleaseLock(workflowId);
                }
            }
            return(false);
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _shutdown = false;
            PersistenceStore.EnsureStoreExists();
            await QueueProvider.Start();

            await LockProvider.Start();

            await _lifeCycleEventHub.Start();

            await _searchIndex.Start();

            // Event subscriptions are removed when stopping the event hub.
            // Add them when starting.
            AddEventSubscriptions();

            Logger.LogInformation("Starting background tasks");

            foreach (var task in _backgroundTasks)
            {
                task.Start();
            }
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var activity = WorkflowActivity.StartHost();

            try
            {
                _shutdown = false;
                PersistenceStore.EnsureStoreExists();
                await QueueProvider.Start();

                await LockProvider.Start();

                await _lifeCycleEventHub.Start();

                await _searchIndex.Start();

                // Event subscriptions are removed when stopping the event hub.
                // Add them when starting.
                AddEventSubscriptions();

                Logger.LogInformation("Starting background tasks");

                foreach (var task in _backgroundTasks)
                {
                    task.Start();
                }
            }
            catch (Exception ex)
            {
                activity.RecordException(ex);
                throw;
            }
            finally
            {
                activity?.Dispose();
            }
        }
Beispiel #24
0
        public async Task PublishEvent(string eventName, string eventKey, object eventData)
        {
            if (_shutdown)
            {
                throw new Exception("Host is not running");
            }

            Logger.LogDebug("Publishing event {0} {1}", eventName, eventKey);
            var subs = await PersistenceStore.GetSubcriptions(eventName, eventKey);

            foreach (var sub in subs.ToList())
            {
                EventPublication pub = new EventPublication();
                pub.Id         = Guid.NewGuid();
                pub.EventData  = eventData;
                pub.EventKey   = eventKey;
                pub.EventName  = eventName;
                pub.StepId     = sub.StepId;
                pub.WorkflowId = sub.WorkflowId;
                await QueueProvider.QueueForPublishing(pub);

                await PersistenceStore.TerminateSubscription(sub.Id);
            }
        }
Beispiel #25
0
 private static CacheManager GetCacheManager(PersistenceStore store)
 {
     return CacheFactory.GetCacheManager(Enum.GetName(typeof(PersistenceStore), store)) as CacheManager;
 }
 /// <summary>
 /// Construct a new index term for the specified persistence store.
 /// </summary>
 /// <param name="PersistenceStore">Store to add index term to.</param>
 public MeshIndexTerm(PersistenceStore PersistenceStore) {
     this.PersistenceStore = PersistenceStore;
     UserProfilesByAccount = PersistenceStore.GetIndex(KeyUserProfile);
     IndexUniqueID = PersistenceStore.GetIndex(UniqueID);
     }
Beispiel #27
0
 /// <summary>
 /// 캐시를 지원하는 <c>IDacHelper</c>를 구현하는 클래스의 새 인스턴스를 돌려줍니다.
 /// </summary>
 /// <param name="dbHelper">쿼리를 수행하는데 사용되는 <c>SqlDbHelper</c>입니다.</param>
 /// <param name="connectionStringName">연결문자열입니다.</param>
 /// <param name="store">캐시 저장 메카니즘의 종류 입니다.</param>
 /// <param name="slidingExpiration">캐시의 폐기 시간 입니다.</param>
 /// <returns>캐시를 지원하는 <c>IDacHelper</c>를 구현하는 클래스의 새 인스턴스입니다.</returns>
 public static IDacHelper CreateCacheable(SqlDbHelper dbHelper, string connectionStringName, PersistenceStore store, TimeSpan slidingExpiration)
 {
     return new CacheableDacHelper(dbHelper, connectionStringName, GetCacheManager(store), slidingExpiration);
 }
        /// <summary>
        /// Construct a persistence store for the specified domain, with the
        /// specified store and portal stores.
        /// </summary>
        /// <param name="Domain">Domain name of the service</param>
        /// <param name="Store">store name for the profile persistence store.</param>
        /// <param name="Portal">Store name for the portal persistence store.</param>
        public Mesh(string Domain, string Store, string Portal) {
            this.Domain = Domain;
            MeshStore = new LogPersistenceStore(Store, StoreType, StoreComment);
            PortalStore = new LogPersistenceStore(Portal, PortalType, PortalComment);

            //Accounts are kept in the portal store and indexed by 
            //the account
            PortalByPrimary = PortalStore.ObjectIndex;

            //Profiles are kept in the Mesh and are indexed by the UDF of the 
            //master signature key.
            IndexUniqueID = MeshStore.ObjectIndex;
            }