public static void UpdateScheduledTask(int scheduledTaskId, int statusId)
 {
     using (var context = new CloudCoreDB())
     {
         context.Cloudcore_ScheduledTaskUpdateStatus(scheduledTaskId, statusId);
     }
 }
Exemple #2
0
		public void Search()
        {
			var db = new CloudCoreDB();

			var result = (from a in db.Cloudcore_User 
                                select new { a.UserId, a.Email });

			SearchResult = result;
		}
Exemple #3
0
		public void GetResults()
        {
			var db = new CloudCoreDB();

			var result = (from a in db.Cloudcore_User 
                                select new { a.UserId, a.Email });

			ListResult = result;
		}
        public void Init()
        {
            db = new CloudCoreDB { ObjectTrackingEnabled = true };

            //CleanCostLedgerTable();

            WorkflowTests.DeployProcess();
            WorkflowTests.DeployProcessTestData();

            cloudCostingActivityTestClass = new CloudCostingActivityTestClass();
        }
 public void LoadAccessPools()
 {
     var db = new CloudCoreDB();
     AccessPools = (from ap in db.Cloudcore_AccessPool
                    join aa in db.Cloudcore_ActivityAllocation on ap.AccessPoolId equals aa.AccessPoolId
                    where aa.ActivityId == ActiveActivityDetails.ActivityId
                    select new AccessPoolItem
                    {
                        AccessPoolId = ap.AccessPoolId,
                        AccessPoolName = ap.AccessPoolName
                    });
 }
 public void AddSystemValue()
 {
     try
     {
         CloudCoreDB db = new CloudCoreDB();
         int? systemval = 0;
         db.Cloudcore_SystemValueCreate(this.CategoryId, this.ValueName, this.ValueData, this.ValueDescription, ref systemval);
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
 public void CreateCategory()
 {
     try
     {
         CloudCoreDB db = new CloudCoreDB();
         int? _categoryId = null;
         db.Cloudcore_SystemValueCategoryCreate(CategoryName, ref _categoryId);
         this.CategoryId = _categoryId.Value;
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
        public virtual List<Cloudcore_ResetRunningOutdatedWorkflowItemsResult> ResetOutdatedWorkflowItems()
        {
            var tasks = new List<Cloudcore_ResetRunningOutdatedWorkflowItemsResult>();

            OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
            {
                var db = new CloudCoreDB();
                tasks = db.Cloudcore_ResetRunningOutdatedWorkflowItems(
                    KeepAliveSettings.Instance.TimeOutInSeconds,
                    WorkItemStatus.Running.Id,
                    WorkItemStatus.Retry.Id,
                    WorkItemStatus.Pending.Id).ToList();
            });

            return tasks;
        }
Exemple #9
0
        public override void InvokeHandler(CommandSetState state)
        {
            CleanLists();

            ConnectionStringBuilderPopup form = new ConnectionStringBuilderPopup();
            form.MyConnectionString = "Data Source=localhost; Integrated Security=True; Initial Catalog=CloudCoreDB;";
            form.ShowDialog();

            if (form.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                CloudCoreDB db = new CloudCoreDB(form.MyConnectionString);
                var store = state.CurrentDocView.CurrentDiagram.Store;
                var showscript = true;

                Architect.CustomCode.Helpers.ArchitectDte.Instance.Store = store;
                var dte = Architect.CustomCode.Helpers.ArchitectDte.Dte;
                var project = dte.ActiveWindow.Project;

                string AssemblyName = project.Properties.Item("AssemblyName").Value.ToString();
                string SystemModuleGuid = project.Properties.Item("AssemblyGuid").Value.ToString();

                Architect.ProcessOverview.Process process = store.ElementDirectory.AllElements.OfType<Architect.ProcessOverview.Process>().First();

                getDiagramSubProcess(store, process, project);
                getDatabaseSubProcesses(db, new Guid(process.VisioId));

                // Do List Comparison
                myActivities.FindAll(a => !(a.activity is FromProcessConnector) && !(a.activity is ToProcessConnector)).ForEach(act => act.DoCreate = !dbActivities.Any(a => a.activity.ActivityGuid == new Guid(act.activity.VisioId)));
                dbActivities.ForEach(act => act.DoDelete = !myActivities.FindAll(a => !(a.activity is FromProcessConnector) && !(a.activity is ToProcessConnector)).Any(a => new Guid(a.activity.VisioId) == act.activity.ActivityGuid));

                if (dbActivities.Any(a => a.DoDelete))
                {
                    showscript = getReplacementIds();
                }

                string script = GenerateScript(AssemblyName, SystemModuleGuid, new Guid(process.VisioId), process.ProcessName, db, migrateItemList, mySubProcesses, myActivities, myFlows);

                CleanLists();

                if (showscript)
                {
                    ViewScriptForm scriptform = new ViewScriptForm(script);
                    scriptform.ShowDialog();
                }
            }
        }
Exemple #10
0
        public void LoadInstanceHistory()
        {
            var db = new CloudCoreDB();
            var result = (from af in db.Cloudcore_ActivityFailureHistory
                          join am in db.Cloudcoremodel_ActivityModel on af.ActivityModelId equals am.ActivityModelId
                          join a in db.Cloudcore_Activity on am.ActivityModelId equals a.ActivityModelId
                          join w in db.Cloudcore_Worklist on new { af.KeyValue, a.ActivityId } equals new { w.KeyValue, w.ActivityId }
                          where w.InstanceId == InstanceId
                          orderby af.FailedAt descending
                          select new FailedActivityHistory
                          {
                              DateFailed = af.FailedAt,
                              Reason = af.Reason,
                              ActivityName = am.ActivityName
                          });

            InstanceFailedHistory = result.OrderByDescending(x => x.DateFailed);
        }
Exemple #11
0
        public OpenWorkItem OpenWorkItemByInstance( Int64 instanceId)
        {

            CloudCoreDB db = new CloudCoreDB();
            Int64? keyvalue = null;
            Guid? activityGuid = null;
            Guid? subProcessGuid = null;

            db.Cloudcore_WorkItemStartByInstance(CloudCoreIdentity.UserId, instanceId, ref keyvalue, ref activityGuid, ref subProcessGuid);
            if ((activityGuid != null) && (subProcessGuid != null))
            {
                return new OpenWorkItem() { InstanceId = instanceId, KeyValue = keyvalue.Value, Action = "_" + activityGuid.Value.ToString().Replace("-", "_"), Controller = "_" + subProcessGuid.Value.ToString().Replace("-", "_") };

            }
            else
            {
                return null;
            }
        }
        public void LoadScheduledTaskGroupScheduledTasks(int scheduledTaskGroupId)
        {
            var context = new CloudCoreDB();
            var data = context.Cloudcore_ScheduledTasksPerGroupId(scheduledTaskGroupId);

            ScheduledTasks = new List<ScheduledTaskModelEnableDisable>();

            foreach (var item in data)
            {
                var task = new ScheduledTaskModelEnableDisable
                {
                    ScheduledTaskId = item.ScheduledTaskId ?? 0,
                    ScheduledTaskName = item.ScheduledTaskName,
                    IsRunning = item.StatusId == 0 || item.StatusId == 1
                };
                ScheduledTasks.Add(task);
            }

            context.Dispose();
        }
        public void CanDelayWorkItem()
        {
            const int minutesToDelay = 5;
            const double marginInMilliseconds = 100; // for approximation (we don't care if it's out by mere milliseconds)
            const int millisecondsToDelay = minutesToDelay * 60 * 1000;

            WorklistItem workListItem = cloudParkedActivityTestClass.GetWorkListItem();

            var timeBeforeDelay = DateTime.Now;

            cloudParkedActivityTestClass.OnVirtualWork();

            var db = new CloudCoreDB();

            var newActivateTimeFromDb = db.Cloudcore_VwWorklistEx.Single(w => w.InstanceId == workListItem.InstanceId).Activate;
            var millisecondDifference = (newActivateTimeFromDb - timeBeforeDelay).TotalMilliseconds;
            double millisecondDifferenceWithMargin = millisecondDifference + marginInMilliseconds;

            Assert.IsTrue(millisecondDifferenceWithMargin >= millisecondsToDelay); // approximately 5 minutes
        }
        public void GetApplicationActivities()
        {
            CloudCoreDB db = new CloudCoreDB();
            var query = (from appact in db.Cloudcore_SystemApplicationAllocation
                         join act in db.Cloudcore_Activity on appact.ActivityId equals act.ActivityId
                         join actmod in db.Cloudcoremodel_ActivityModel on new { act.ProcessRevisionId, act.ActivityModelId } equals new { actmod.ProcessRevisionId, actmod.ActivityModelId }
                         join mod in db.Cloudcore_SystemModule on act.SystemModuleId equals mod.SystemModuleId
                         join subp in db.Cloudcoremodel_SubProcess on new { act.SubProcessGuid, act.ProcessRevisionId } equals new { subp.SubProcessGuid, subp.ProcessRevisionId }
                         join pro in db.Cloudcoremodel_ProcessModel on act.ProcessGuid equals pro.ProcessGuid
                         where appact.ApplicationId == this.ApplicationId
                         select new SystemApplicationActivity
                         {
                             ActivityId = appact.ActivityId,
                             ActivityName = actmod.ActivityName,
                             ModuleName = mod.AssemblyName,
                             SubProcessName = subp.SubProcessName,
                             ProcessName = pro.ProcessName
                         });

            this.ApplicationActivities = query.Distinct().ToList();
        }
Exemple #15
0
        public override void InvokeHandler(CommandSetState state)
        {
            CleanLists();
            var store = state.CurrentDocView.CurrentDiagram.Store;
            var showscript = true;

            ConnectionStringBuilderPopup form = new ConnectionStringBuilderPopup();
            form.MyConnectionString = "Data Source=localhost; Integrated Security=True; Initial Catalog=CloudCoreDB;";
            form.ShowDialog();

            if (form.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                CloudCoreDB db = new CloudCoreDB(form.MyConnectionString);
                EnvDTE._DTE dte = new ScheduledTasks.VsEnvironment.ScheduledTaskDte(store).Dte;
                var project = dte.ActiveWindow.Project;

                Group group = getDiagramTasks(store, project);
                getDatabaseTasks(db, group.Id);

                string AssemblyName = project.Properties.Item("AssemblyName").Value.ToString();
                string AssemblyGuid = project.Properties.Item("AssemblyGuid").Value.ToString();

                // Do List Comparison
                scheduledtasks.ForEach(task => task.DoCreate = !dbscheduledtasks.Any(a => a.ScheduledTask.ScheduledTaskGuid == task.ScheduledTask.Id));
                dbscheduledtasks.ForEach(task => task.DoDelete = !scheduledtasks.Any(a => a.ScheduledTask.Id == task.ScheduledTask.ScheduledTaskGuid));

                string script = GenerateScript(AssemblyName, AssemblyGuid, group.Id, group.GroupName, scheduledtasks, dbscheduledtasks);

                CleanLists();

                if (showscript)
                {
                    ViewScriptForm scriptform = new ViewScriptForm(script);
                    scriptform.ShowDialog();
                }
            }
        }
        public void Execute()
        {
            try
            {
                StartKeepAlive(_scheduledTaskid);

                if (TaskTypeIsCSharp())
                {
                    _cSharpScheduledTask.Execute();
                }
                else
                {
                    using (var database = new CloudCoreDB())
                    {
                        database.CommandTimeout = 240;
                        database.ExecuteCommand(string.Format("exec {0}", _storedProcedureName));
                    }
                }
            }
            finally
            {
                StopKeepAlive();
            }
        }
 protected override WorklistItem GetWorklistItem(CloudCoreDB db)
 {
     return worklistItem;
 }
        protected WorklistItem GetLocationAwareWorklistItem(WorkItemStatus workflowStatusType)
        {
            long? instanceId = null;
            int? activityId = null;
            Guid? activityGuid = null;
            long? keyValue = null;
            int? maxRetries = null;
            int? currentRetries = null;
            string activityName = String.Empty;

            OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
            {
                using (var database = new CloudCoreDB())
                {
                    database.Cloudcore_WorkItemStartFromVirtualWorkerByLocation(
                        Core.Modules.Environment.ApplicationId,
                        (int)workflowStatusType.Id,
                        KeepAliveSettings.Instance.TimeOutInSeconds,
                        ref activityGuid,
                        ref activityId,
                        ref instanceId,
                        ref keyValue,
                        LocationConfig.Latitude,
                        LocationConfig.Longitude,
                        LocationConfig.RadiusInMeters,
                        ref maxRetries,
                        ref currentRetries,
                        ref activityName);
                }
            });

            return new WorklistItem(activityId, activityGuid, activityName, maxRetries, currentRetries)
            {
                InstanceId = instanceId,
                KeyValue = keyValue
            };
        }
        protected virtual void UpdateFailureOutcome(long instanceId, string message, WorkItemStatus outcomeStatus)
        {
            try
            {
                OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
                {
                    using (var database = new CloudCoreDB())
                    {
                        database.Cloudcore_WorkItemFail(instanceId, message, (byte)outcomeStatus.Id);
                    }
                });
            }
            catch (DataThreadDeadlockException ex)
            {
                Logger.Fatal(String.Format("Unable to update workflow final failure status after execution (ID {0}). Exiting...", instanceId),
                             ex, OperationContext.LoggingCategory);

                ExitStrategy.Quitting = true;
                throw;
            }
        }
 public virtual void SendKeepAliveHeartBeat(long instanceId, CloudCoreDB database)
 {
     OperationContext.ThreadSafeDataAccess.DataAccessOperation(() => database.Cloudcore_WorkflowKeepAlive(instanceId));
 }
 private void DashboardTaskFailed(DashboardItemInfo dashboardTaskInfo, string failureReason)
 {
     using (var database = new CloudCoreDB())
     {
         database.Cloudcore_DashboardFailed(dashboardTaskInfo.DashboardId, failureReason, (byte)DashboardTaskStatus.Failed);
     }
 }
Exemple #22
0
        private void getDatabaseFlows(CloudCoreDB db, Guid ActivityGuid)
        {
            var dbtasks = (from a in db.Cloudcoremodel_FlowModel
                           join b in db.Cloudcoremodel_ActivityModel on a.FromActivityModelId equals b.ActivityModelId
                           where b.ActivityGuid == ActivityGuid
                           select a).ToList();

            dbtasks.ForEach(a => dbFlows.Add(a));
        }
        protected virtual void UpdateFailureOutcome(int scheduledTaskId, string message, ScheduledTaskStatusId outcomeStatus)
        {
            try
            {
                OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
                {
                    using (var database = new CloudCoreDB())
                    {
                        database.Cloudcore_ScheduledTaskUpdateOutcome(scheduledTaskId, (byte)outcomeStatus, message);
                    }
                });
            }
            catch (DataThreadDeadlockException ex)
            {
                Logger.Fatal(string.Format("Unable to update scheduled task final failure outcome after execution (ID {0}). Exiting...", scheduledTaskId),
                             ex, OperationContext.LoggingCategory);

                ExitStrategy.Quitting = true;
                throw;
            }
        }
 private void RescheduleTask(ScheduledTaskExecutionInfo scheduledTaskInfo)
 {
     OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
     {
         using (var database = new CloudCoreDB())
         {
             database.Cloudcore_ScheduledTaskUpdateOutcome(
                 scheduledTaskInfo.ScheduledTaskId,
                 (int)ScheduledTaskStatusId.Pending,
                 reason: string.Empty);
         }
     });
 }
        private List<DashboardItemInfo> GetDashboardTasksToRun()
        {
            var dashboardTasksToRun = new List<DashboardItemInfo>();

            OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
            {
                using (var database = new CloudCoreDB())
                {
                    dashboardTasksToRun = (from t in database.Cloudcore_DashboardTasksToRun()
                                           let dashboardId = t.DashboardId
                                           where dashboardId.HasValue
                                           let dashboardGuid = t.DashboardGuid
                                           where dashboardGuid.HasValue
                                           let systemModuleId = t.SystemModuleId
                                           where systemModuleId.HasValue
                                           let title = t.Title
                                           where !String.IsNullOrWhiteSpace(title) 
                                           let description = t.Description
                                           where !String.IsNullOrWhiteSpace(description)
                                           select new DashboardItemInfo
                                           {
                                               DashboardId = dashboardId.Value,
                                               DashboardGuid = dashboardGuid.Value,
                                               SystemModuleId = systemModuleId.Value,
                                               Title = title,
                                               Description = description
                                           }).ToList();
                }
            });

            return dashboardTasksToRun;
        }
 protected override WorkflowStatusType HandleWorklistFailure(CloudCoreDB db, long instanceId, int? activityId, string msg, int maxRetries, int retries)
 {
     StatusResult = base.HandleWorklistFailure(db, instanceId, activityId, msg, maxRetries, retries);
     return StatusResult;
 }
Exemple #27
0
        private void getDatabaseTasks(CloudCoreDB db, Guid groupGuid)
        {
            var dbtasks = (from a in db.Cloudcore_ScheduledTask 
                           join b in db.Cloudcore_ScheduledTaskGroup on a.ScheduledTaskGroupId equals b.ScheduledTaskGroupId
                           where b.ScheduledTaskGroupGuid == groupGuid 
                           select a).ToList();

            dbtasks.ForEach(a => dbscheduledtasks.Add(new DBScheduledTask { ScheduledTask = a }));
        }
        private void KeepWorkflowItemAlive(long instanceId)
        {
            Logger.Debug(String.Format("Keep-Alive session has started for Workflow Item Instance ID {0}.", instanceId),
                OperationContext.LoggingCategory);

            using (var database = new CloudCoreDB())
            {
                while (ShouldKeepAlive && !ExitStrategy.Quitting)
                {
                    SendKeepAliveHeartBeat(instanceId, database);
                    OnWorkflowKeptAlive(instanceId);
                    Sleep(KeepAliveSettings.Instance.CheckIntervalInSeconds);
                }
            }

            Logger.Debug(String.Format("Keep-Alive session has ended for Workflow Item Instance ID {0}.", instanceId),
                OperationContext.LoggingCategory);
        }
        protected List<ScheduledTaskExecutionInfo> GetScheduledTasksToRun(ScheduledTaskStatusId scheduledTaskStatusId)
        {
            var scheduledTasksToRun = new List<ScheduledTaskExecutionInfo>();

            OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
            {
                using (var database = new CloudCoreDB())
                {
                    scheduledTasksToRun = (from t in database.Cloudcore_ScheduledTasksToRun((int)scheduledTaskStatusId, KeepAliveSettings.Instance.TimeOutInSeconds)
                                           let scheduledTaskId = t.ScheduledTaskId
                                           where scheduledTaskId.HasValue
                                           let scheduledTaskGuid = t.ScheduledTaskGuid
                                           where scheduledTaskGuid.HasValue
                                           let retries = t.Retries
                                           where retries.HasValue
                                           let maxRetries = t.MaxRetries
                                           where maxRetries.HasValue
                                           let scheduledTaskTypeId = t.ScheduledTaskTypeId
                                           where scheduledTaskTypeId != null
                                           select new ScheduledTaskExecutionInfo
                                           {
                                               ScheduledTaskId = scheduledTaskId.Value,
                                               ScheduledTaskGuid = scheduledTaskGuid.Value,
                                               ScheduledTaskName = t.ScheduledTaskName,
                                               ScheduledTaskType = (ExecutionType)scheduledTaskTypeId.Value,
                                               CurrentRetries = retries.Value,
                                               MaximumRetries = maxRetries.Value
                                           }).ToList();
                }
            });

            return scheduledTasksToRun;
        }
 private void UpdateDashboardTask(DashboardItemInfo dashboardTaskInfo, DashboardTaskStatus status)
 {
     OperationContext.ThreadSafeDataAccess.DataAccessOperation(() =>
     {
         using (var database = new CloudCoreDB())
         {
             database.Cloudcore_DashboardTaskUpdate(
                 dashboardTaskInfo.DashboardId,
                 (byte)status);
         }
     });
 }