Exemple #1
0
        private static void LogToDB(LogRequest request)
        {
            Serilog.Log.Write(
                ConvertTo_SerilogLogLevel(request.Level),
                "{source}{timestamp}{level}{method}{machineName}{message}{exception}{parameters}{activityId}",

                request.Source,
                request.TimeStamp,
                request.Level,
                request.Method,
                request.MachineName,
                request.Message,
                request.Exception,
                ParametersSerializer.Serialize(request.Parameters),
                request.ActivityId);

            LogEventLevel ConvertTo_SerilogLogLevel(string logLevel)
            {
                switch (logLevel.ToLower())
                {
                case "info": return(LogEventLevel.Information);

                default:
                    throw new NotImplementedException($"Mapping for {logLevel} is not implemented.");
                }
            }
        }
Exemple #2
0
        public void SavePersistenceParameters(ProcessInstance processInstance)
        {
            var parametersToPersistList =
                processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence)
                .Select(ptp =>
            {
                if (ptp.Type == typeof(UnknownParameterType))
                {
                    return new { Parameter = ptp, SerializedValue = (string)ptp.Value }
                }
                ;
                return(new { Parameter = ptp, SerializedValue = ParametersSerializer.Serialize(ptp.Value, ptp.Type) });
            })
                .ToList();

            using (var session = Store.OpenSession())
            {
                var process = session.Load <WorkflowProcessInstance>(processInstance.ProcessId);
                if (process != null && process.Persistence != null)
                {
                    var persistedParameters = process.Persistence.ToList();

                    foreach (var parameterDefinitionWithValue in parametersToPersistList)
                    {
                        var persistence =
                            persistedParameters.SingleOrDefault(
                                pp => pp.ParameterName == parameterDefinitionWithValue.Parameter.Name);

                        {
                            if (persistence == null)
                            {
                                if (parameterDefinitionWithValue.SerializedValue != null)
                                {
                                    persistence = new WorkflowProcessInstancePersistence
                                    {
                                        ParameterName = parameterDefinitionWithValue.Parameter.Name,
                                        Value         = parameterDefinitionWithValue.SerializedValue
                                    };
                                    process.Persistence.Add(persistence);
                                }
                            }
                            else
                            {
                                if (parameterDefinitionWithValue.SerializedValue != null)
                                {
                                    persistence.Value = parameterDefinitionWithValue.SerializedValue;
                                }
                                else
                                {
                                    process.Persistence.Remove(persistence);
                                }
                            }
                        }
                    }
                }
                session.SaveChanges();
            }
        }
Exemple #3
0
        public void SavePersistenceParameters(ProcessInstance processInstance)
        {
            var parametersToPersistList =
                processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence)
                .Select(ptp =>
            {
                if (ptp.Type == typeof(UnknownParameterType))
                {
                    return new { Parameter = ptp, SerializedValue = (string)ptp.Value }
                }
                ;
                return(new { Parameter = ptp, SerializedValue = ParametersSerializer.Serialize(ptp.Value, ptp.Type) });
            })
                .ToList();

            var cache =
                Store.GetOrCreateCache <Guid, WorkflowProcessInstance>(IgniteConstants.WorkflowProcessInstanceCacheName);
            var process = cache.Get(processInstance.ProcessId);

            if (process != null && process.Persistence != null)
            {
                var persistedParameters = process.Persistence.ToList();

                foreach (var parameterDefinitionWithValue in parametersToPersistList)
                {
                    var persistence =
                        persistedParameters.SingleOrDefault(
                            pp => pp.ParameterName == parameterDefinitionWithValue.Parameter.Name);
                    {
                        if (persistence == null)
                        {
                            if (parameterDefinitionWithValue.SerializedValue != null)
                            {
                                persistence = new WorkflowProcessInstancePersistence
                                {
                                    ParameterName = parameterDefinitionWithValue.Parameter.Name,
                                    Value         = parameterDefinitionWithValue.SerializedValue
                                };
                                process.Persistence.Add(persistence);
                            }
                        }
                        else
                        {
                            if (parameterDefinitionWithValue.SerializedValue != null)
                            {
                                persistence.Value = parameterDefinitionWithValue.SerializedValue;
                            }
                            else
                            {
                                process.Persistence.Remove(persistence);
                            }
                        }
                    }
                }

                cache.Put(process.Id, process);
            }
        }
Exemple #4
0
        public void SavePersistenceParameters(ProcessInstance processInstance)
        {
            var parametersToPersistList =
                processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence)
                .Select(ptp =>
            {
                if (ptp.Type == typeof(UnknownParameterType))
                {
                    return new { Parameter = ptp, SerializedValue = (string)ptp.Value }
                }
                ;
                return(new { Parameter = ptp, SerializedValue = ParametersSerializer.Serialize(ptp.Value, ptp.Type) });
            })
                .ToList();

            var dbcoll  = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName);
            var process = dbcoll.Find(x => x.Id == processInstance.ProcessId).FirstOrDefault();

            if (process != null && process.Persistence != null)
            {
                var persistedParameters = process.Persistence.ToList();

                foreach (var parameterDefinitionWithValue in parametersToPersistList)
                {
                    var persistence =
                        persistedParameters.SingleOrDefault(
                            pp => pp.ParameterName == parameterDefinitionWithValue.Parameter.Name);
                    {
                        if (persistence == null)
                        {
                            if (parameterDefinitionWithValue.SerializedValue != null)
                            {
                                persistence = new WorkflowProcessInstancePersistence
                                {
                                    ParameterName = parameterDefinitionWithValue.Parameter.Name,
                                    Value         = parameterDefinitionWithValue.SerializedValue
                                };
                                process.Persistence.Add(persistence);
                            }
                        }
                        else
                        {
                            if (parameterDefinitionWithValue.SerializedValue != null)
                            {
                                persistence.Value = parameterDefinitionWithValue.SerializedValue;
                            }
                            else
                            {
                                process.Persistence.Remove(persistence);
                            }
                        }
                    }
                }

                Save(dbcoll, process, doc => doc.Id == process.Id);
            }
        }
Exemple #5
0
        public void SavePersistenceParameters(ProcessInstance processInstance)
        {
            var parametersToPersistList =
                processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence)
                .Select(ptp =>
            {
                if (ptp.Type == typeof(UnknownParameterType))
                {
                    return new { Parameter = ptp, SerializedValue = (string)ptp.Value }
                }
                ;
                return(new { Parameter = ptp, SerializedValue = ParametersSerializer.Serialize(ptp.Value, ptp.Type) });
            })
                .ToList();

            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                var persistedParameters = WorkflowProcessInstancePersistence.SelectByProcessId(connection, processInstance.ProcessId).ToList();

                foreach (var parameterDefinitionWithValue in parametersToPersistList)
                {
                    var persistence =
                        persistedParameters.SingleOrDefault(
                            pp => pp.ParameterName == parameterDefinitionWithValue.Parameter.Name);
                    {
                        if (persistence == null)
                        {
                            if (parameterDefinitionWithValue.SerializedValue != null)
                            {
                                persistence = new WorkflowProcessInstancePersistence()
                                {
                                    Id            = Guid.NewGuid(),
                                    ProcessId     = processInstance.ProcessId,
                                    ParameterName = parameterDefinitionWithValue.Parameter.Name,
                                    Value         = parameterDefinitionWithValue.SerializedValue
                                };
                                persistence.Insert(connection);
                            }
                        }
                        else
                        {
                            if (parameterDefinitionWithValue.SerializedValue != null)
                            {
                                persistence.Value = parameterDefinitionWithValue.SerializedValue;
                                persistence.Update(connection);
                            }
                            else
                            {
                                WorkflowProcessInstancePersistence.Delete(connection, persistence.Id);
                            }
                        }
                    }
                }
                WorkflowProcessInstancePersistence.Commit(connection);
            }
        }
Exemple #6
0
        /// <summary>
        /// Saves persisted <see cref="ParameterPurpose.Persistence"/> parameters of the process to store
        /// </summary>
        /// <param name="processInstance">Instance of the process</param>
        public void SavePersistenceParameters(ProcessInstance processInstance)
        {
            var parametersToSave = processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence && ptp.Value != null)
                                   .ToDictionary(ptp => ptp.Name, ptp =>
            {
                if (ptp.Type == typeof(UnknownParameterType))
                {
                    return((string)ptp.Value);
                }
                return(ParametersSerializer.Serialize(ptp.Value, ptp.Type));
            });

            var parametersToRemove =
                processInstance.ProcessParameters.Where(ptp => ptp.Purpose == ParameterPurpose.Persistence && ptp.Value == null).Select(ptp => ptp.Name).ToList();

            if (!parametersToSave.Any() && !parametersToRemove.Any())
            {
                return;
            }

            var db = _connector.GetDatabase();

            var key = GetKeyForProcessPersistence(processInstance.ProcessId);

            var oldPrarmetersValue = db.StringGet(key);

            if (!oldPrarmetersValue.HasValue)
            {
                if (parametersToSave.Any())
                {
                    db.StringSet(key, JsonConvert.SerializeObject(parametersToSave));
                }
            }
            else
            {
                var existingParameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(oldPrarmetersValue);

                parametersToRemove.ForEach(p => existingParameters.Remove(p));

                foreach (var ptsKey in parametersToSave.Keys)
                {
                    if (existingParameters.ContainsKey(ptsKey))
                    {
                        existingParameters[ptsKey] = parametersToSave[ptsKey];
                    }
                    else
                    {
                        existingParameters.Add(ptsKey, parametersToSave[ptsKey]);
                    }
                }

                if (existingParameters.Any())
                {
                    db.StringSet(key, JsonConvert.SerializeObject(existingParameters));
                }
                else
                {
                    db.KeyDelete(key);
                }
            }
        }