Example #1
0
        public static void Create(Database database, string name)
        {
            if (database == null)
                throw new ArgumentNullException("database", "database is null.");
            if (name == null)
                throw new ArgumentNullException("name", "name is null.");
            if (Exists(database, name))
                throw new ArgumentException(string.Format("Workflow with the name \"{0}\" already exists.", name), "name");

            var workflow = new Workflow(name);
            database.WorkflowsLock.EnterWriteLock();
            try
            {
                workflow.WorkflowLock.EnterWriteLock();
                try
                {
                    database.WorkflowNames.Add(workflow.Name, workflow.Id);
                    database.Workflows.Add(workflow.Id, workflow);
                }
                finally
                {
                    workflow.WorkflowLock.ExitWriteLock();
                }
            }
            finally
            {
                database.WorkflowsLock.ExitWriteLock();
            }
        }