public override IList <DsfForEachItem> GetForEachInputs()
        {
            // ReSharper disable MaximumChainedReferences
            var items = (JsonMappings.Where(c => !string.IsNullOrEmpty(c.SourceName)).Select(c => c.SourceName)).ToArray();

            // ReSharper restore MaximumChainedReferences
            return(GetForEachItems(items));
        }
Exemplo n.º 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (JsonMappings != null ? JsonMappings.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (JsonString != null ? JsonString.GetHashCode() : 0);
         return(hashCode);
     }
 }
        public override void UpdateForEachInputs(IList <Tuple <string, string> > updates)
        {
            if (updates != null)
            {
                foreach (Tuple <string, string> t in updates)
                {
                    // locate all updates for this tuple
                    Tuple <string, string> t1 = t;
                    var items = JsonMappings.Where(c => !string.IsNullOrEmpty(c.SourceName) && c.SourceName.Equals(t1.Item1));

                    // issues updates
                    foreach (var a in items)
                    {
                        a.SourceName = t.Item2;
                    }
                }
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var allErrors = new ErrorResultTO();
            var errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            InitializeDebug(dataObject);
            JsonMappings = JsonMappings.Where(validMapping).ToList();
            // Process if no errors
            try
            {
                if (JsonMappings == null)
                {
                    dataObject.Environment.AddError("Json Mappings supplied to activity is null.");
                }

                // ReSharper disable AssignNullToNotNullAttribute
                if (!dataObject.Environment.Errors.Any() && !JsonMappings.Any())
                // ReSharper restore AssignNullToNotNullAttribute
                {
                    dataObject.Environment.AddError("No Json Mappings supplied to activity.");
                }

                // ReSharper disable AssignNullToNotNullAttribute
                if (!dataObject.Environment.Errors.Any())
                // ReSharper restore AssignNullToNotNullAttribute
                {
                    JsonMappings.ToList().ForEach(m =>
                    {
                        var validationResult = new IsValidJsonCreateMappingInputRule(() => m).Check();
                        if (validationResult != null)
                        {
                            dataObject.Environment.AddError(validationResult.Message);
                        }
                    });
                }

                if (dataObject.IsDebugMode())
                {
                    int j = 0;
                    // ReSharper disable PossibleNullReferenceException
                    foreach (JsonMappingTo a in JsonMappings.Where(to => !String.IsNullOrEmpty(to.SourceName)))
                    // ReSharper restore PossibleNullReferenceException
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams(string.Empty, (++j).ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugEvalResult(a.SourceName, string.Empty, dataObject.Environment, update), debugItem);
                        _debugInputs.Add(debugItem);
                    }
                }
                // TODO: More validation through IRule, IRuleSet to throw out anything not in spec
                if (!dataObject.Environment.Errors.Any())
                {
                    // JsonMappings.Count() is larger than zero
                    var json = new JObject(); // outermost JSON would always be a single JObject, i.e. {'name': value}
                    // ReSharper disable AssignNullToNotNullAttribute
                    List <JsonMappingTo> jsonMappingList = JsonMappings.ToList();
                    // ReSharper restore AssignNullToNotNullAttribute

                    // build the list of JsonMappingCompoundTo - a compound is either a single expression or a comma seperated list of expressions
                    // ReSharper disable MaximumChainedReferences
                    List <JsonMappingCompoundTo> results = jsonMappingList.Where(to => !String.IsNullOrEmpty(to.SourceName)).Select(jsonMapping =>
                                                                                                                                    new JsonMappingCompoundTo(dataObject.Environment, jsonMapping
                                                                                                                                                              )).ToList();
                    // ReSharper restore MaximumChainedReferences



                    // main loop for producing largest list of zipped values

                    results.ForEach(x =>
                    {
                        // if it is not a compound,
                        if (!x.IsCompound)
                        {
                            // add JProperty, with name x.DestinationName, and value eval(x.SourceName)
                            json.Add(new JProperty(
                                         x.DestinationName,
                                         x.EvaluatedResultIndexed(0))
                                     );
                        }
                        else
                        {
                            // if it is a compound,
                            if (!x.EvalResult.IsWarewolfRecordSetResult)
                            {
                                json.Add(new JProperty(
                                             x.DestinationName,
                                             x.ComplexEvaluatedResultIndexed(0))
                                         );
                            }
                            else if (x.EvalResult.IsWarewolfRecordSetResult)
                            {
                                json.Add(
                                    x.ComplexEvaluatedResultIndexed(0));
                            }
                        }
                    }
                                    );


                    dataObject.Environment.Assign(JsonString, json.ToString(Formatting.None), update);

                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugEvalResult(JsonString, string.Empty, dataObject.Environment, update));
                    }

                    /*
                     * var rule = new IsSingleValueRule(() => CountNumber);
                     * var single = rule.Check();
                     * if (single != null)
                     * {
                     *  allErrors.AddError(single.Message);
                     * }
                     * else
                     * {
                     *  var count = 0;
                     *  if (dataObject.Environment.HasRecordSet(RecordsetName))
                     *  {
                     *      count = dataObject.Environment.GetCount(rs);
                     *  }
                     *  var value = count.ToString();
                     *  dataObject.Environment.Assign(CountNumber, value);
                     *  AddDebugOutputItem(new DebugEvalResult(CountNumber, "", dataObject.Environment));
                     * }
                     * */
                }
            }
            catch (Exception e)
            {
                // ReSharper disable AssignNullToNotNullAttribute
                JsonMappings.ToList().ForEach(x =>
                                              // ReSharper restore AssignNullToNotNullAttribute
                {
                    AddDebugInputItem(new DebugItemStaticDataParams("", x.SourceName, "SourceName", "="));
                    AddDebugInputItem(new DebugItemStaticDataParams("", x.DestinationName, "DestinationName"));
                });

                allErrors.AddError(e.Message);
                dataObject.Environment.Assign(JsonString, string.Empty, update);
                AddDebugOutputItem(new DebugItemStaticDataParams(string.Empty, JsonString, "", "="));
            }
            finally
            {
                // Handle Errors
                bool hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfCreateJsonActivity", allErrors);
                    string errorString = allErrors.MakeDataListReady();
                    dataObject.Environment.AddError(errorString);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Exemplo n.º 5
0
#pragma warning disable S1541 // Methods and properties should not be too complex
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            var allErrors = new ErrorResultTO();
            var errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            InitializeDebug(dataObject);
            JsonMappings = JsonMappings.Where(validMapping).ToList();
            // Process if no errors
            try
            {
                if (JsonMappings == null)
                {
                    dataObject.Environment.AddError("Json Mappings supplied to activity is null.");
                }

                if (!dataObject.Environment.Errors.Any() && !JsonMappings.Any())
                {
                    dataObject.Environment.AddError("No JSON Mappings supplied to activity.");
                }

                if (!dataObject.Environment.Errors.Any())
                {
                    JsonMappings.ToList().ForEach(m =>
                    {
                        var validationResult = new IsValidJsonCreateMappingInputRule(() => m).Check();
                        if (validationResult != null)
                        {
                            dataObject.Environment.AddError(validationResult.Message);
                        }
                    });
                }

                if (dataObject.IsDebugMode())
                {
                    var j = 0;

                    foreach (JsonMappingTo a in JsonMappings.Where(to => !String.IsNullOrEmpty(to.SourceName)))
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams(string.Empty, (++j).ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugEvalResult(a.SourceName, string.Empty, dataObject.Environment, update), debugItem);
                        _debugInputs.Add(debugItem);
                    }
                }
                if (!dataObject.Environment.Errors.Any())
                {
                    var json = new JObject();

                    var jsonMappingList = JsonMappings.ToList();
                    var results         = jsonMappingList.Where(to => !String.IsNullOrEmpty(to.SourceName)).Select(jsonMapping =>
                                                                                                                   new JsonMappingCompoundTo(dataObject.Environment, jsonMapping
                                                                                                                                             )).ToList();
                    results.ForEach(x =>
                    {
                        ParseResultsJSON(x, json);
                    });

                    dataObject.Environment.Assign(JsonString, json.ToString(Formatting.None), update);

                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugEvalResult(JsonString, string.Empty, dataObject.Environment, update));
                    }
                }
            }
            catch (Exception e)
            {
                JsonMappings.ToList().ForEach(x =>
                {
                    AddDebugInputItem(new DebugItemStaticDataParams("", x.SourceName, "SourceName", "="));
                    AddDebugInputItem(new DebugItemStaticDataParams("", x.DestinationName, "DestinationName"));
                });

                allErrors.AddError(e.Message);
                dataObject.Environment.Assign(JsonString, string.Empty, update);
                AddDebugOutputItem(new DebugItemStaticDataParams(string.Empty, JsonString, "", "="));
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfCreateJsonActivity", allErrors);
                    var errorString = allErrors.MakeDataListReady();
                    dataObject.Environment.AddError(errorString);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }