示例#1
0
        private static void _onSchemaWasChanged(object sender, SchemaWasChangedEventArgs schemaWasChangedEventArgs)
        {
            var processId = schemaWasChangedEventArgs.ProcessId;
            var currentActivity = Runtime.GetCurrentActivityName(processId);
            var currentState = Runtime.GetCurrentStateName(processId);
            var newScheme = Runtime.GetProcessScheme(processId);

            ActivityDefinition oldActivity = null;
            try
            {
                oldActivity = newScheme.FindActivity(currentActivity);
            }
            catch (ActivityNotFoundException)
            {
            }

            //Если в новой схеме есть активити в которой находился наш процесс то ничего не делаем
            if (oldActivity != null)
                return;

            //Если в новой схеме есть состояние в котором мы находились то производим установку в него
            if (
                newScheme.Activities.Any(
                    a =>
                        !string.IsNullOrEmpty(a.State) &&
                        a.State.Equals(currentState, StringComparison.InvariantCultureIgnoreCase)))
            {
                var param = new Dictionary<string, object>
                {
                    {"Comment", "Automatic synchronization of the status, due to changing in the route of the document."}
                };
                _runtime.SetState(processId, null, null, currentState, param);
                return;
            }

            //Ставим в начальный статус
            if (!string.IsNullOrEmpty(newScheme.InitialActivity.State))
            {
                var param = new Dictionary<string, object>
                {
                    {"Comment", string.Format("Process was set in initial state, due to state with name {0} was not found in new route.",currentState)}
                };
                Runtime.SetState(processId, null, null, newScheme.InitialActivity.State, param);
                return;
            }
        }
示例#2
0
 private void BindProcessToNewScheme(ProcessInstance processInstance, ProcessDefinition updatedProcessScheme, List<SchemaWasChangedEventArgs> changes)
 {
     bool ısSchemeObsolete = processInstance.IsSchemeObsolete;
     bool ısDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged;
     processInstance.SchemeId = updatedProcessScheme.Id;
     processInstance.IsSchemeObsolete = false;
     processInstance.IsDeterminingParametersChanged = false;
     processInstance.ProcessScheme = updatedProcessScheme;
     this.PersistenceProvider.BindProcessToNewScheme(processInstance, true);
     SchemaWasChangedEventArgs schemaWasChangedEventArg = new SchemaWasChangedEventArgs()
     {
         DeterminingParametersWasChanged = ısDeterminingParametersChanged,
         ProcessId = processInstance.ProcessId,
         SchemeId = processInstance.SchemeId,
         SchemaWasObsolete = ısSchemeObsolete
     };
     changes.Add(schemaWasChangedEventArg);
     processInstance.SchemeId = updatedProcessScheme.Id;
     processInstance.IsSchemeObsolete = false;
     processInstance.IsDeterminingParametersChanged = false;
     processInstance.ProcessScheme = updatedProcessScheme;
     this.PersistenceProvider.BindProcessToNewScheme(processInstance, true);
 }