예제 #1
0
        public OldApplicationModel()
        {
            Tables = new TableEntityCollection();
            //WorkFlowManager = new WorkflowManager();

            //ExecutionItems = new ExecutionItemCollection();
            //SelectedExecutionItem = ExecutionItems.FirstOrDefault();

            ConnectionString = SQLDataProducerSettings.Default.ConnectionString;

            // TODO: Move plugin folder to some other folder. Configure where it is? Or hardcode
            _availablePlugins = PluginLoader.LoadPluginsFromFolder(Environment.CurrentDirectory);

            _executionItemsWithWarningsSource = new CollectionViewSource {
                Source = ExecutionItems
            };
            ExecutionItemsWithWarningsView        = _executionItemsWithWarningsSource.View;
            ExecutionItemsWithWarningsView.Filter = new Predicate <object>(obj =>
            {
                ExecutionNode t = obj as ExecutionNode;
                if (t != null)
                {
                    return(t.HasWarning);
                }
                return(true);
            });
        }
        public void ShouldAddParentNodeToNode()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");

            string expected =
                @"-Customer
--Order";

            Assert.That(customer.getDebugString(), Is.EqualTo(expected));

            order.AddParent(1, "CustomerGroup");
            expected =
                @"Root
-Customer
--CustomerGroup
---Order";
            Assert.That(root.getDebugString(), Is.EqualTo(expected));
            customer.AddParent(1, "Country");
            expected =
                @"Root
-Country
--Customer
---CustomerGroup
----Order";
            Assert.That(root.getDebugString(), Is.EqualTo(expected));
        }
예제 #3
0
    ResolveFieldContext GetContext(ExecutionContext context, ExecutionNode node)
    {
        var argumentValues = ExecutionHelper.GetArgumentValues(context.Schema,
                                                               node.FieldDefinition.Arguments, node.Field.Arguments, context.Variables);
        var dictionary = ExecutionHelper.SubFieldsFor(context, node.FieldDefinition.ResolvedType, node.Field);

        return(new ResolveFieldContext
        {
            FieldName = node.Field.Name,
            FieldAst = node.Field,
            FieldDefinition = node.FieldDefinition,
            ReturnType = node.FieldDefinition.ResolvedType,
            ParentType = node.GetParentType(context.Schema),
            Arguments = argumentValues,
            Source = node.Source,
            Schema = context.Schema,
            Document = context.Document,
            Fragments = context.Fragments,
            RootValue = context.RootValue,
            UserContext = context.UserContext,
            Operation = context.Operation,
            Variables = context.Variables,
            CancellationToken = context.CancellationToken,
            Metrics = context.Metrics,
            Errors = context.Errors,
            Path = node.Path,
            SubFields = dictionary
        });
    }
예제 #4
0
        protected override async Task <ExecutionNode> ExecuteNodeAsync(
            ExecutionContext context, ExecutionNode node)
        {
            try
            {
                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var resultNode = await base.ExecuteNodeAsync(context, node);

                    scope.Complete();
                    return(resultNode);
                }
            }
            catch (AuthorizationPolicyViolationException)
            {
                node.Result = null;
                return(node);
            }
            catch (Exception err)
            {
                node.Result = null;
                context.Errors.Add(new ExecutionError(err.Message));
                return(node);
            }
        }
        public void ShouldSimulateCompleteWorkflow()
        {
            DataAccess.TableEntityDataAccess tda = new DataAccess.TableEntityDataAccess(Connection());
            var person       = tda.GetTableAndColumns("Person", "NewPerson");
            var personDetail = tda.GetTableAndColumns("Person", "AnotherTable");

            personDetail.Columns.First().Generator = new ValueFromOtherColumnIntGenerator(personDetail.Columns.First().ColumnDataType);
            personDetail.Columns.First().Generator.GeneratorParameters.ValueFromOtherColumn.Value = person.Columns.First();

            ExecutionNode node = ExecutionNode.CreateLevelOneNode(100, "Root");

            node.AddTable(person);
            node.AddTable(personDetail);

            var consumerMeta   = PluginLoader.GetMetaDataOfType(typeof(InsertConsumer));
            var wrapper        = new DataConsumerPluginWrapper(consumerMeta.ConsumerName, typeof(InsertConsumer), consumerMeta.OptionsTemplate);
            ExecutionResultBuilder builder = new ExecutionResultBuilder();

            WorkflowManager manager = new WorkflowManager();

            manager.RunWorkFlow(Connection(), wrapper, builder, options, node);
            var result = builder.Build();

            Assert.That(result.InsertCount, Is.EqualTo(200));
            Assert.That(result.Errors.Count, Is.EqualTo(0));
            Assert.That(result.Duration, Is.GreaterThan(new TimeSpan(1)));
        }
예제 #6
0
        public void ShouldReturnTablesInCorrectOrder()
        {
            // Scenario: Make 2 customers, for each customer make two accounts and do one deposit and one withdraw for each account
            string[] requestedOrder = { "Customer", "Account", "Deposit", "Withdraw", "Account", "Deposit", "Withdraw",
                                        "Customer", "Account", "Deposit", "Withdraw", "Account", "Deposit", "Withdraw", };

            // 2 Customers
            ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer");

            customer.AddTable(new TableEntity("dbo", "Customer"));

            // Make 2 accounts
            var accounts = customer.AddChild(2, "Accounts");

            accounts.AddTable(new TableEntity("dbo", "Account"));

            // make one one Deposit and one WithDraw
            var accountTransactions = accounts.AddChild(1, "AccountTransactions");

            accountTransactions.AddTable(new TableEntity("dbo", "Deposit"));
            accountTransactions.AddTable(new TableEntity("dbo", "Withdraw"));


            NodeIterator it = new NodeIterator(customer);

            var actual =
                new List <TableEntity>(it.GetTablesRecursive().Select(x => x.Table));

            for (int i = 0; i < requestedOrder.Length; i++)
            {
                Console.WriteLine(actual[i].TableName);
                Assert.That(requestedOrder[i], Is.EqualTo(actual[i].TableName));
            }
        }
        public void shouldAddChildNodesToNode()
        {
            ExecutionNode node = ExecutionNode.CreateLevelOneNode(1);

            node.AddChild(100);
            Assert.AreEqual(1, node.Children.Count(), "Number of children");

            node.AddChild(1);
            node.AddChild(1);
            Assert.AreEqual(3, node.Children.Count(), "Number of children");
            foreach (var item in node.Children)
            {
                Assert.That(item.Level, Is.GreaterThan(1));
                Console.WriteLine(item.Level);

                for (int i = 0; i < 3; i++)
                {
                    item.AddChild(1);
                }

                foreach (var child in item.Children)
                {
                    Assert.That(item.Level, Is.LessThan(child.Level));
                }
            }
        }
예제 #8
0
    public void EvaluateTree()
    {
        if (companion == null)
        {
            companion = GetComponent <Companion>();
        }
        BehaviourNode currentNode = rootNode.childNode;

        while (currentNode is ControlNode)
        {
            ControlNode c = currentNode as ControlNode;

            MethodInfo method = this.GetType().GetMethod(c.methodName);
            bool       result = (bool)method.Invoke(this, null);

            if (result)
            {
                currentNode = c.positive;
            }
            else
            {
                currentNode = c.negative;
            }
        }
        if (currentNode is ExecutionNode)
        {
            ExecutionNode e = currentNode as ExecutionNode;

            if (e.methodName != current)
            {
                Invoke(e.methodName, 0);
                current = e.methodName;
            }
        }
    }
예제 #9
0
        public void ShouldGetZeroTotalExpectedInsertedRowWhenThereIsNoTable()
        {
            ExecutionNode customer            = ExecutionNode.CreateLevelOneNode(2, "No tables");
            NodeIterator  it                  = new NodeIterator(customer);
            long          actualExpectedCount = it.GetExpectedInsertCount();

            Assert.That(actualExpectedCount, Is.EqualTo(0));
        }
 public void MergeNodeWithParentNode(ExecutionNode nodeToMergeWithParent)
 {
     if (nodeToMergeWithParent != null)
     {
         var parentNode = nodeToMergeWithParent.MergeWithParent();
         _projectViewModel.SelectedExecutionNode = parentNode;
     }
 }
예제 #11
0
 public ExecutionNode BuildExecutionNode(ExecutionNode node, IGraphType resolvedType, Field nodeField, FieldType fieldType)
 {
     return(ExecutionStrategy.BuildExecutionNode(
                node,
                resolvedType,
                nodeField,
                fieldType));
 }
 public void RemoveNode(ExecutionNode nodeToRemove)
 {
     if (nodeToRemove != null)
     {
         var parentNode = nodeToRemove.RemoveNode();
         _projectViewModel.SelectedExecutionNode = parentNode;
     }
 }
 public void AddParentNode(ExecutionNode nodeToManipulate)
 {
     if (nodeToManipulate != null)
     {
         var newNode = nodeToManipulate.AddParent(1);
         _projectViewModel.SelectedExecutionNode = newNode;
     }
 }
예제 #14
0
 internal ReadonlyResolveFieldContext Reset(ExecutionNode node, ExecutionContext context)
 {
     _executionNode    = node;
     _executionContext = context;
     _arguments        = null;
     _subFields        = null;
     return(this);
 }
        public void shouldCreateExecutionNodeBySettingRepeatCount()
        {
            int           numberOfRepeats = 10;
            ExecutionNode node            = ExecutionNode.CreateLevelOneNode(numberOfRepeats);

            Assert.NotNull(node);
            Assert.That(node.RepeatCount, Is.EqualTo(numberOfRepeats));
        }
        public void ShouldNotBeAbleToRemoveRootNode()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");

            var someNode = root.RemoveNode();

            Assert.That(someNode, Is.EqualTo(root));
        }
예제 #17
0
 private static ExecutionNode BuildReleaseNode(RunContext context, ReleaseConfig release)
 {
     var node = new ExecutionNode(string.Format("Begin release {0}", release.Name), string.Format("End release {0}", release.Name));
     foreach (var feature in release.Features)
     {
         node.AddChild(BuildFeatureNode(context, feature));
     }
     return node;
 }
예제 #18
0
 protected override void ValidateNodeResult(ExecutionContext context, ExecutionNode node)
 {
     try {
         var result = this.AuthorizeAsync(context, node).ConfigureAwait(false).GetAwaiter().GetResult();
         result.PostProcess(context, node).ConfigureAwait(false).GetAwaiter().GetResult();
     } catch (AuthorizationPolicyViolationException err)
     {
         throw err;
     }
 }
예제 #19
0
        public override IAuthorizationPolicy <T> BuildCopy(ExecutionContext context, ExecutionNode node)
        {
            var copy = new ShortCircuitPolicy <T>()
            {
                Rules = Rules
            };

            copy.BuildContext(context, node);
            return(copy);
        }
        public void ShouldNotBeAbleToAddSameTableTwice()
        {
            ExecutionNode node1         = ExecutionNode.CreateLevelOneNode(1);
            TableEntity   customerTable = new TableEntity("dbo", "Customer");

            node1.AddTable(customerTable);
            node1.AddTable(customerTable);
            node1.AddTable(customerTable);
            Assert.That(node1.Tables.Count(), Is.EqualTo(1));
        }
        public void ShouldNotBeAbleToMergeRootNodeWithParent()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer").AddTable(new TableEntity("dbo", "Customer"));

            var merged = root.MergeWithParent();

            Assert.That(merged, Is.EqualTo(root));
            Assert.That(merged.Tables, Is.Empty);
        }
        public void ShouldHaveParentIfItIsChild()
        {
            ExecutionNode root = ExecutionNode.CreateLevelOneNode(1);

            Assert.That(root.HasChildren, Is.False);

            var child = root.AddChild(1);

            Assert.That(root.HasChildren, Is.True);
            Assert.That(child.Parent, Is.EqualTo(root));
        }
 private void WriteExecutionNode(JsonWriter writer, ExecutionNode node, JsonSerializer serializer)
 {
     if (node is ValueExecutionNode valueExecutionNode)
     {
         serializer.Serialize(writer, valueExecutionNode.ToValue());
     }
     else if (node is ObjectExecutionNode objectExecutionNode)
     {
         if (objectExecutionNode.SubFields == null)
         {
             writer.WriteNull();
         }
         else
         {
             writer.WriteStartObject();
             foreach (var childNode in objectExecutionNode.SubFields)
             {
                 var propName = childNode.Name;
                 if (_namingStrategy != null)
                 {
                     propName = _namingStrategy.GetPropertyName(propName, false);
                 }
                 writer.WritePropertyName(propName);
                 WriteExecutionNode(writer, childNode, serializer);
             }
             writer.WriteEndObject();
         }
     }
     else if (node is ArrayExecutionNode arrayExecutionNode)
     {
         var items = arrayExecutionNode.Items;
         if (items == null)
         {
             writer.WriteNull();
         }
         else
         {
             writer.WriteStartArray();
             foreach (var childNode in items)
             {
                 WriteExecutionNode(writer, childNode, serializer);
             }
             writer.WriteEndArray();
         }
     }
     else if (node == null || node is NullExecutionNode)
     {
         writer.WriteNull();
     }
     else
     {
         serializer.Serialize(writer, node.ToValue());
     }
 }
 private static void WriteExecutionNode(Utf8JsonWriter writer, ExecutionNode node, JsonSerializerOptions options)
 {
     if (node is ValueExecutionNode valueExecutionNode)
     {
         WriteValue(writer, valueExecutionNode.ToValue(), options);
     }
     else if (node is ObjectExecutionNode objectExecutionNode)
     {
         if (objectExecutionNode.SubFields == null)
         {
             writer.WriteNullValue();
         }
         else
         {
             writer.WriteStartObject();
             foreach (var childNode in objectExecutionNode.SubFields)
             {
                 var propertyName = childNode.Name;
                 if (options.PropertyNamingPolicy != null)
                 {
                     propertyName = options.PropertyNamingPolicy.ConvertName(propertyName);
                 }
                 writer.WritePropertyName(propertyName);
                 WriteExecutionNode(writer, childNode, options);
             }
             writer.WriteEndObject();
         }
     }
     else if (node is ArrayExecutionNode arrayExecutionNode)
     {
         var items = arrayExecutionNode.Items;
         if (items == null)
         {
             writer.WriteNullValue();
         }
         else
         {
             writer.WriteStartArray();
             foreach (var childNode in items)
             {
                 WriteExecutionNode(writer, childNode, options);
             }
             writer.WriteEndArray();
         }
     }
     else if (node == null || node is NullExecutionNode)
     {
         writer.WriteNullValue();
     }
     else
     {
         WriteValue(writer, node.ToValue(), options);
     }
 }
예제 #25
0
 protected void BuildContext(ExecutionContext context, ExecutionNode node)
 {
     Context     = context;
     Node        = node;
     AuthContext = new AuthorizationContext <T>
     {
         Subject          = node.Result as T,
         Viewer           = GetViewer(context, node),
         ExecutionContext = context,
         ExecutionNode    = node
     };
 }
        public void ShouldHaveNoNullValuesAfterInitialization()
        {
            ExecutionNode node = ExecutionNode.CreateLevelOneNode(1);

            Assert.That(node, Is.Not.Null);
            Assert.That(node.NodeName, Is.Not.Null);
            Assert.That(node.Level, Is.Not.Null);
            Assert.That(node.NodeId, Is.Not.Null);
            Assert.That(node.Tables, Is.Not.Null);
            Assert.That(node.Children, Is.Not.Null);
            Assert.That(node.RepeatCount, Is.Not.Null);
        }
예제 #27
0
        public void ShouldInstantiateWorkflowManager()
        {
            builder = new ExecutionResultBuilder().Begin();
            ExecutionNode rootNode = ExecutionNode.CreateLevelOneNode(1, "Root");

            manager.RunWorkFlow(connectionString, wrapper, builder, options, rootNode);

            var result = builder.Build();

            Assert.That(result.Errors.Count, Is.EqualTo(0), "error count");
            Assert.That(result.InsertCount, Is.EqualTo(0), "insert count");
        }
        public void ShouldRemoveNode()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");
            var           recall   = order.AddChild(1, "Recall");

            var someNode = order.RemoveNode();

            Assert.That(someNode, Is.EqualTo(customer), "When removing a node, the parent node should be returned");
            Assert.That(customer.Children.Contains(order), Is.Not.True);
        }
        public void ShouldNotBeAbleToAddParentToRoot()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");

            string beforeAddingParent = root.getDebugString();

            var returnNode = root.AddParent(1, "Nono");

            Assert.That(returnNode, Is.EqualTo(root));
            Assert.That(root.getDebugString(), Is.EqualTo(beforeAddingParent));
        }
예제 #30
0
        public void ShouldRunWorkflowAsync()
        {
            builder = new ExecutionResultBuilder().Begin();
            ExecutionNode rootNode = ExecutionNode.CreateLevelOneNode(1, "Root");

            rootNode.AddTable(new TableEntity("dbo", "Customer"));

            manager.RunWorkFlowAsync(connectionString, wrapper, builder, options, rootNode);
            Thread.Sleep(10); // give some time for the async method to complete
            var result = builder.Build();

            Assert.That(result.Errors.Count, Is.EqualTo(0));
            Assert.That(result.InsertCount, Is.EqualTo(1));
        }
 public override IViewer GetViewer(ExecutionContext context, ExecutionNode node)
 {
     if (context.UserContext is IProvideClaimsPrincipal userContextWithClaimsPrincipal)
     {
         return(new Viewer
         {
             User = userContextWithClaimsPrincipal.User
         });
     }
     else
     {
         throw new Exception("ExecutionContext.UserContext does not correctly implement IProvideClaimsPrincipal interface");
     }
 }
예제 #32
0
        private static ExecutionNode BuildFeatureNode(string featureName, DeployContext context)
        {
            FeatureConfig feature;
            if (!context.FeaturesConfig.TryGet(featureName, out feature))
                throw new SoftFailureException(string.Format("Cannot find feature {0}", featureName));

            var node = new ExecutionNode(string.Format("Begin feature {0}", featureName), string.Format("End feature {0}", featureName));
            foreach (var taskConfig in feature.Recipe)
            {
                var task = context.TaskManager.CreateTask(taskConfig);
                var replacer = new VariableReplacer(context.ApplicationContext, feature, taskConfig);
                node.AddChild(new ExecutionNode(task, new TaskExecutionContext(context.RunContext, feature, taskConfig, replacer)));
            }

            return node;
        }
예제 #33
0
 private static ExecutionNode BuildRestoreDatabasesNode(DatabaseBackupInfo[] databases, DeployContext context)
 {
     var node = new ExecutionNode("Restoring databases...", "All databases restored!");
     node.AddChild(new ExecutionNode(new RestoreDatabasesTransform(context.ApplicationContext.UserConfig.Databases.Connection, databases)));
     return node;
 }
예제 #34
0
            public Tuple<ExecutionNode, StateHash, bool, StateHash> Calculate(DeployContext context, StateHash hash, StateHash startingHash, ICacheManager cacheManager)
            {
                if (mTransform != null)
                {
                    hash = mTransform.CalculateTransform(hash);
                    if (hash == startingHash)
                        return Tuple.Create((ExecutionNode)null, hash, true, (StateHash)null);

                    var backups = GetCachedBackups(cacheManager, hash, context.ApplicationContext.ProjectConfig.Databases);
                    if (backups != null)
                    {
                        var node = new ExecutionNode("Restoring state from cache...", "Cache restored");
                        node.AddChild(new ExecutionNode(new RestoreDatabasesTransform(context.ApplicationContext.UserConfig.Databases.Connection, backups, hash)));

                        return Tuple.Create(node, hash, true, hash);
                    }
                }
                else if (mChildren.Count > 0)
                {
                    var result = new ExecutionNode(mLogPre, mLogPost);
                    var changed = false;
                    StateHash cacheHash = null;

                    foreach (var child in mChildren)
                    {
                        var calc = child.Calculate(context, hash, startingHash, cacheManager);
                        if (calc.Item3)
                        {
                            changed = true;
                            result.mChildren.Clear();
                        }

                        if (calc.Item1 != null)
                            result.mChildren.Add(calc.Item1);

                        hash = calc.Item2;
                        if (calc.Item4 != null)
                            cacheHash = calc.Item4;
                    }

                    if (result.mChildren.Count == 0)
                        result = null;

                    return Tuple.Create(result, hash, changed, cacheHash);
                }

                return Tuple.Create(this, hash, false, (StateHash)null);
            }
예제 #35
0
            public void AddChild(ExecutionNode node)
            {
                if (mTransform != null)
                    throw new InvalidOperationException("Cannot add child nodes to an action-initialized execution node");

                mChildren.Add(node);
            }
예제 #36
0
        private static void RunCore(DeployContext context)
        {
            Beep(context, "start");

            var plan = ActionPlan.Build(context.RunContext);

            var root = new ExecutionNode("Begin deploy", "Deploy completed");
            root.AddChild(BuildRestoreDatabasesNode(plan.Databases, context));

            foreach (var release in plan.Releases)
            {
                var releaseNode = BuildReleaseNode(release, context);
                root.AddChild(releaseNode);
            }

            var hash = StateHash.Empty;
            try
            {
                StateHash startingHash = null;
                if (context.Resume)
                {
                    startingHash = LoadResumeHash(context);
                }

                var improved = root.Calculate(context, hash, startingHash, context.CacheManager);
                if (improved.Item3)
                {
                    root = improved.Item1;
                    if (improved.Item4 != null)
                    {
                        context.CacheManager.UpdateHits(context.ApplicationContext.ProjectConfig.Databases.Select(x => Tuple.Create(x, improved.Item4)));
                    }
                }

                var sink = new CheckingRequirementSink(context.ApplicationContext.Log);
                root.GetRequirements(sink);
                if (sink.Finish())
                    throw new SoftFailureException("Command aborted due to unmet requirements.");

                root.Run(context, startingHash ?? hash, context.CacheManager);

                if (!context.DryRun)
                    CleanResumeHash(context);
            }
            catch (SoftFailureException ex)
            {
                Beep(context, "error");
                throw new SoftFailureException("Blocking error detected", ex);
            }

            Beep(context, "success");
        }
예제 #37
0
        private static void RunCore(RunContext context)
        {
            var plan = ActionPlan.Build(context);

            var root = new ExecutionNode(string.Format("Running '{0}' action", context.Action), "Success!");
            foreach (var release in plan.Releases)
            {
                root.AddChild(BuildReleaseNode(context, release));
            }

            var sink = new CheckingRequirementSink(context.ApplicationContext.Log);
            root.GetRequirements(sink);
            if (sink.Finish())
                throw new SoftFailureException("Command aborted due to unmet requirements.");

            root.Run(context);
        }