Example #1
0
        /// <summary>
        /// 获得实时数据的table表
        /// </summary>
        /// <param name="dataSetInformations"></param>
        /// <returns></returns>
        private DataTable GetDataItemTable(IEnumerable <DataSetInformation> dataSetInformations)
        {
            IDictionary <string, List <FieldInformation> > feildInfor = new Dictionary <string, List <FieldInformation> >();

            foreach (var item in dataSetInformations)
            {
                string           key   = item.TableName;
                FieldInformation value = new FieldInformation
                {
                    FeildName    = item.FieldName,
                    VariableName = item.ViewId
                };
                if (feildInfor.Keys.Contains(key))
                {
                    feildInfor[key].Add(value);
                }
                else
                {
                    feildInfor.Add(key, new List <FieldInformation>());
                    feildInfor[key].Add(value);
                }
            }
            string queryString = EnergyContrast.EnergyContrastHelper.GetSqlString(feildInfor);

            DataTable table = _dataFactory.Query(queryString);

            return(table);
        }
Example #2
0
        public void AnalyseModelIsNullTest()
        {
            // Arrange
            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(FieldType.Text)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.Text, nameof(DynamicFieldValue.ValueString), "Let's get dangerous")
                }
            };

            // Act
            var result = _classUnderTest.Analyse(null, fieldInformation);

            // Assert
            result.Result.Should().HaveCount(1);
            result.Result.ContainsKey(nameof(FieldType.Text) + "Assignment").Should().BeTrue();
        }
Example #3
0
        public EditorField(EditorSession session, FieldInformation field, JProperty json)
        {
            Session = session;
            Field   = field;

            if (field.Type != "JObject")
            {
                FieldType = session.Manifest.GetTypeInformation(field.Type);
                if (FieldType == null)
                {
                    throw new InvalidOperationException($"Failed to find type for {field.Type}");
                }
            }
            else
            {
                string typeName = json.Parent["Type"].ToString();
                FieldType = session.Manifest.GetTypeInformation(typeName);
                if (FieldType == null)
                {
                    throw new InvalidOperationException($"Failed to find type for {typeName}");
                }
            }

            this.json = json;
            features  = new List <object>();

            valueInternal = session.CreateValue(FieldType, field.Wrapper, json.Value);
        }
Example #4
0
        public void AnalyseDuplicateAssignmentTest()
        {
            // Arrange
            var alpha = new Alpha
            {
                FieldValues = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.Text, nameof(DynamicFieldValue.ValueString), "Let's get dangerous")
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(FieldType.Text)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text),
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = alpha.FieldValues
            };

            // Act
            var result = _classUnderTest.Analyse(alpha, fieldInformation);

            // Assert
            result.Result[nameof(FieldType.Text) + "Assignment"].Id.Should().Be(nameof(FieldType.Text) + "Value");
            result.Result[nameof(FieldType.Text) + "Assignment"].Value.Should().Be("Let's get dangerous");
            result.Result[nameof(FieldType.Text) + "Assignment"].Type.Should().Be(typeof(string));
        }
Example #5
0
        public IEnumerable <ValidationPropertyInfo> CalculateValidationRules(FieldInformation <FD, FA, FV, T, D> fieldInformation)
        {
            var validationProperties = new List <ValidationPropertyInfo>();

            foreach (var assignment in fieldInformation.Assignments)
            {
                var definition = fieldInformation.Definitions.Single(d => d.Id.Equals(assignment.DefinitionId));

                if (definition.FieldType == FieldType.None || definition.FieldType == FieldType.DynamicCode)
                {
                    continue;
                }

                var validationProperty = new ValidationPropertyInfo
                {
                    PropertyName   = definition.Id.ToString(),
                    JsonName       = definition.Id.ToString(),
                    IsDynamicField = true,
                    Rules          = new List <ValidationRule>()
                };

                SetDataType(definition, validationProperty);
                AddValidationRules(definition, validationProperty);

                validationProperties.Add(validationProperty);
            }

            return(validationProperties);
        }
        public void CalculateValidationRuleNoRulesTest(FieldType fieldType)
        {
            // Arrange
            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(fieldType)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(fieldType)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(fieldType)
                }
            };

            // Act
            var rules = _classUnderTest.CalculateValidationRules(fieldInformation);

            // Assert
            rules.Should().HaveCount(0);
        }
        public void CalculateValidationRuleDataTypeTest(FieldType fieldType)
        {
            // Arrange
            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(fieldType)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(fieldType)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(fieldType)
                }
            };

            // Act
            var rules = _classUnderTest.CalculateValidationRules(fieldInformation);

            // Assert
            rules.Should().HaveCount(1);

            rules.Single().PropertyName.Should().Be(fieldType.ToString());
            rules.Single().JsonName.Should().Be(fieldType.ToString());
            rules.Single().IsDynamicField.Should().BeTrue();
            rules.Single().Rules.Should().HaveCount(0);
        }
Example #8
0
        public void AnalyseMissingFieldValueTest()
        {
            // Arrange
            var alpha = new Alpha
            {
                FieldValues = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.TextMultiline, nameof(DynamicFieldValue.ValueString), "Let's get dangerous")
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(FieldType.Text)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = alpha.FieldValues
            };

            // Act
            var result = _classUnderTest.Analyse(alpha, fieldInformation);

            // Assert
            result.Result.ContainsKey(nameof(FieldType.Text) + "Assignment").Should().BeFalse();
        }
Example #9
0
 public void Init(FieldInformation field)
 {
     FData = new FieldData(field)
     {
         entity = this
     };
     FieldManager.Instance.Reclaim(FData);
 }
Example #10
0
        /**
         * Given the title (/T) of a reference, return the associated reference
         * @param name a string containing the path
         * @return a reference to the field, or null
         */
        public PRIndirectReference GetRefByName(String name)
        {
            FieldInformation fi = (FieldInformation)fieldByName[name];

            if (fi == null)
            {
                return(null);
            }
            return(fi.Ref);
        }
Example #11
0
 public FieldInfoForm(FieldInformation fieldInfo)
 {
     InitializeComponent();
     if (fieldInfo != null)
     {
         columnInfos = new List <ColumnInfo>();
         GetPropertyNameAndValue(fieldInfo);
     }
     this.dataGridView1.DataSource = columnInfos;
 }
Example #12
0
        /// <summary>
        ///     Resolve the value from a field.
        /// </summary>
        public object ResolveField(ResolveFieldContext context, FieldInformation field)
        {
            var classObject = ServiceProvider.GetService(field.Method.DeclaringType);
            var parameters  = context.Parameters(field);
            var result      = field.Method.Invoke(classObject, parameters);

            //todo async support.

            return(result);
        }
Example #13
0
        /**
         * Given the title (/T) of a reference, return the associated reference
         * @param name a string containing the path
         * @return a reference to the field, or null
         */
        virtual public PRIndirectReference GetRefByName(String name)
        {
            FieldInformation fi = GetField(name);

            if (fi == null)
            {
                return(null);
            }
            return(fi.Ref);
        }
Example #14
0
        public void AnalyseInvalidFieldInformationTest()
        {
            // Arrange
            var alpha = new Alpha
            {
                FieldValues = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.Text, nameof(DynamicFieldValue.ValueString), "Let's get dangerous")
                }
            };

            var fieldInformationNoDefinitions = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>(),
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = alpha.FieldValues
            };
            var fieldInformationNoAssignments = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(FieldType.Text)
                },
                Assignments = new List <DynamicFieldAssignment>(),
                Values      = alpha.FieldValues
            };
            var fieldInformationNoFieldValues = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(FieldType.Text)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = new List <DynamicFieldValue>()
            };


            // Act
            var resultNoDefinitions = _classUnderTest.Analyse(alpha, fieldInformationNoDefinitions);
            var resultNoAssignments = _classUnderTest.Analyse(alpha, fieldInformationNoAssignments);
            var resultNoFieldValues = _classUnderTest.Analyse(alpha, fieldInformationNoFieldValues);

            // Assert
            resultNoDefinitions.Result.Should().HaveCount(2);
            resultNoAssignments.Result.Should().HaveCount(2);
            resultNoFieldValues.Result.Should().HaveCount(2);
        }
        public void CalculateValidationRulesNotEqualsToDataRowTest(FieldType fieldType, string propertyValueName, object defaultValue)
        {
            // Arrange
            var fieldDefinition = ConfigurationHelper.CreateDefinition(fieldType, null);

            fieldDefinition.Configurations = new List <DynamicFieldConfiguration>
            {
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.NotEqualsTo, ValueString = "DarkwingDuck"
                },
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.NotEqualsTo, ValueString = "LaunchpadMcQuack"
                },
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.NotEqualsDefault
                }
            };

            typeof(DynamicFieldConfiguration).GetProperty(propertyValueName).SetValue(fieldDefinition.Configurations.Last(), defaultValue);

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    fieldDefinition
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(fieldType)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(fieldType)
                }
            };

            // Act
            var rules = _classUnderTest.CalculateValidationRules(fieldInformation);

            // Assert
            rules.Should().HaveCount(1);

            var rule = rules.Single();

            rule.PropertyName.Should().Be(fieldType.ToString());
            rule.JsonName.Should().Be(fieldType.ToString());
            rule.IsDynamicField.Should().BeTrue();

            rule.Rules.First(r => r.Rule == "NotEqualsTo").PropertyName.Should().Be("DarkwingDuck");
            rule.Rules.First(r => r.Rule == "NotEqualsTo").DefaultValue.Should().Be(defaultValue?.ToString());
            rule.Rules.Last(r => r.Rule == "NotEqualsTo").PropertyName.Should().Be("LaunchpadMcQuack");
            rule.Rules.Last(r => r.Rule == "NotEqualsTo").DefaultValue.Should().Be(defaultValue?.ToString());
        }
Example #16
0
        public EditorField(EditorSession session, JToken json, string name, FieldInformation info)
        {
            Session = session;
            Name    = name;
            Field   = info;
            Json    = json;

            Type = session.GetTypeInformation(info.Type);

            if (Json.Type == JTokenType.Object &&
                Field?.Format != FieldFormat.Dictionary)
            {
                PopulateMissing((JObject)Json, Type);
            }

            Children = new Dictionary <string, EditorField> ();
            if (Field.Format == FieldFormat.Dictionary)
            {
                if (Json.Type != JTokenType.Null)
                {
                    foreach (var property in ((JObject)Json).Properties())
                    {
                        Children.Add(property.Name, new EditorField(Session, property.Value, property.Name, Field.ValueFormat));
                    }
                }
            }
            else
            {
                if (Type.Fields != null)
                {
                    foreach (var field in Type.Fields)
                    {
                        var property = Json[field.Key];

                        if (field.Value.Type == "JObject")
                        {
                            var type = Json["Type"];


                            Children.Add(field.Key, new EditorField(Session, property, field.Key, new FieldInformation()
                            {
                                Type   = type.ToObject <string> (),
                                Format = FieldFormat.Object
                            }));
                        }
                        else
                        {
                            Children.Add(field.Key, new EditorField(Session, property, field.Key, field.Value));
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Adds the file.
        /// </summary>
        /// <param name="targetUrl">The local path.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="documentLibrary">The document library.</param>
        /// <returns>The ID of the file in SharePoint</returns>
        public string AddFile(string targetUrl, string fileName, string documentLibrary, ProcessLog p)
        {
            string itemId = string.Empty;

            TraceManager.TraceInformation("\tWSSVC:AddFile:Adding file <{0}> to SharePoint {1}", fileName, targetUrl);
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("\t\tCannot find file to upload", fileName);
            }

            FieldInformation[] fields = new FieldInformation[] { new FieldInformation() };

            byte[]       fileContents    = File.ReadAllBytes(fileName);
            string[]     destinationUrls = { targetUrl };
            CopyResult[] results;

            using (Copy copyWebService = new Copy())
            {
                copyWebService.Url         = string.Format(CultureInfo.CurrentCulture, "{0}/_vti_bin/copy.asmx", this.ServerUrl);
                copyWebService.Credentials = this.Credentials;
                copyWebService.CopyIntoItems(targetUrl, destinationUrls, fields, fileContents, out results);

                foreach (CopyResult result in results)
                {
                    if (result.ErrorCode != CopyErrorCode.Success)
                    {
                        throw new Exception(string.Format("Failed to upload file {0} to SharePoint. Message: {1}", targetUrl, result.ErrorMessage));
                    }

                    using (Lists listsWebService = new Lists())
                    {
                        listsWebService.Url         = string.Format(CultureInfo.CurrentCulture, "{0}/_vti_bin/lists.asmx", this.ServerUrl);
                        listsWebService.Credentials = this.Credentials;
                        XNamespace rowsetSchemaNameSpace = "#RowsetSchema";

                        XDocument sharePointListItems = XDocument.Parse(listsWebService.GetListItems(documentLibrary, string.Empty, SharePointHelpers.QueryXmlNode, SharePointHelpers.ViewFieldsXmlNode, "0", SharePointHelpers.QueryOptionsXmlNode, string.Empty).OuterXml);
                        XElement  fileElement         = (from row in sharePointListItems.Descendants(rowsetSchemaNameSpace + "row")
                                                         where (row.Attribute("ows__CopySource") != null) &&
                                                         (row.Attribute("ows__CopySource").Value == targetUrl)
                                                         select row).First();

                        itemId = fileElement.Attribute("ows_ID").Value;
                        p.Add(new Item()
                        {
                            EncodedAbsUrl = fileElement.Attribute("ows_EncodedAbsUrl").Value, Version = fileElement.Attribute("ows_owshiddenversion").Value, Workspace = this.Workspace
                        });
                    }
                }
            }

            return(itemId);
        }
Example #18
0
        public EditorSession(BehaviourManifest manifest, JObject instance, string type, JsonSerializer jsonSerializer)
        {
            Manifest       = manifest;
            JsonSerializer = jsonSerializer;
            Instance       = instance;

            var rootField = new FieldInformation()
            {
                Type = type
            };

            Root = new EditorField(this, instance, "root", rootField);
        }
Example #19
0
        /**
         * After reading, we index all of the fields. Recursive.
         * @param fieldlist An array of fields
         * @param fieldDict the last field dictionary we encountered (recursively)
         * @param parentPath the pathname of the field, up to this point or null
         */
        virtual protected void IterateFields(PdfArray fieldlist, PRIndirectReference fieldDict, String parentPath)
        {
            foreach (PRIndirectReference refi in fieldlist.ArrayList)
            {
                PdfDictionary dict = (PdfDictionary)PdfReader.GetPdfObjectRelease(refi);

                // if we are not a field dictionary, pass our parent's values
                PRIndirectReference myFieldDict = fieldDict;
                String    fullPath    = parentPath;
                PdfString tField      = (PdfString)dict.Get(PdfName.T);
                bool      isFieldDict = tField != null;

                if (isFieldDict)
                {
                    myFieldDict = refi;
                    if (parentPath == null)
                    {
                        fullPath = tField.ToString();
                    }
                    else
                    {
                        fullPath = parentPath + '.' + tField.ToString();
                    }
                }

                PdfArray kids = (PdfArray)dict.Get(PdfName.KIDS);
                if (kids != null)
                {
                    PushAttrib(dict);
                    IterateFields(kids, myFieldDict, fullPath);
                    stack.RemoveAt(stack.Count - 1); // pop
                }
                else                                 // leaf node
                {
                    if (myFieldDict != null)
                    {
                        PdfDictionary mergedDict = (PdfDictionary)stack[stack.Count - 1];
                        if (isFieldDict)
                        {
                            mergedDict = MergeAttrib(mergedDict, dict);
                        }

                        mergedDict.Put(PdfName.T, new PdfString(fullPath));
                        FieldInformation fi = new FieldInformation(fullPath, mergedDict, myFieldDict);
                        fields.Add(fi);
                        fieldByName[fullPath] = fi;
                    }
                }
            }
        }
        /// <summary>
        /// After reading, we index all of the fields. Recursive.
        /// </summary>
        /// <param name="fieldlist">An array of fields</param>
        /// <param name="fieldDict">the last field dictionary we encountered (recursively)</param>
        /// <param name="title">the pathname of the field, up to this point or null</param>
        protected void IterateFields(PdfArray fieldlist, PrIndirectReference fieldDict, string title)
        {
            foreach (PrIndirectReference refi in fieldlist.ArrayList)
            {
                PdfDictionary dict = (PdfDictionary)PdfReader.GetPdfObjectRelease(refi);

                // if we are not a field dictionary, pass our parent's values
                PrIndirectReference myFieldDict = fieldDict;
                string    myTitle     = title;
                PdfString tField      = (PdfString)dict.Get(PdfName.T);
                bool      isFieldDict = tField != null;

                if (isFieldDict)
                {
                    myFieldDict = refi;
                    if (title == null)
                    {
                        myTitle = tField.ToString();
                    }
                    else
                    {
                        myTitle = title + '.' + tField;
                    }
                }

                PdfArray kids = (PdfArray)dict.Get(PdfName.Kids);
                if (kids != null)
                {
                    PushAttrib(dict);
                    IterateFields(kids, myFieldDict, myTitle);
                    Stack.RemoveAt(Stack.Count - 1);   // pop
                }
                else
                {          // leaf node
                    if (myFieldDict != null)
                    {
                        PdfDictionary mergedDict = (PdfDictionary)Stack[Stack.Count - 1];
                        if (isFieldDict)
                        {
                            mergedDict = MergeAttrib(mergedDict, dict);
                        }

                        mergedDict.Put(PdfName.T, new PdfString(myTitle));
                        FieldInformation fi = new FieldInformation(myTitle, mergedDict, myFieldDict);
                        fields.Add(fi);
                        FieldByName[myTitle] = fi;
                    }
                }
            }
        }
Example #21
0
        public void AnalyseValidationIgnoreTest()
        {
            // Arrange
            var alpha = new Alpha
            {
                Beta    = "Darkwing Duck",
                Gamma   = "MegaVolt",
                Epsilon = new Alpha
                {
                    Beta  = "beta",
                    Gamma = "gamme",
                    Delta = new Omega
                    {
                        Stigma = 666
                    }
                },
                FieldValues = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.Text, nameof(DynamicFieldValue.ValueString), "Let's get dangerous")
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(FieldType.Text)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = alpha.FieldValues
            };

            // Act
            var result = _classUnderTest.Analyse(alpha, fieldInformation);

            // Assert
            result.Result.Should().HaveCount(3);
            result.Result.ContainsKey(nameof(FieldType.Text) + "Assignment").Should().BeTrue();

            result.Result[nameof(Alpha.Beta)].Id.Should().Be(nameof(Alpha.Beta));
            result.Result[nameof(Alpha.Beta)].Value.Should().Be(alpha.Beta);
            result.Result[nameof(Alpha.Beta)].Type.Should().Be(typeof(string));

            result.Result[nameof(Alpha.Gamma)].Id.Should().Be(nameof(Alpha.Gamma));
            result.Result[nameof(Alpha.Gamma)].Value.Should().Be(alpha.Gamma);
            result.Result[nameof(Alpha.Gamma)].Type.Should().Be(typeof(string));
        }
        /// <summary>
        ///     Generate the parameters for the field.
        /// </summary>
        /// <param name="type">Extension.</param>
        /// <param name="field">Field information.</param>
        /// <returns></returns>
        public static object[] Parameters(this ResolveFieldContext <object> type, FieldInformation field)
        {
            if (field == null)
            {
                return(null);
            }

            var routeArguments = new List <object>();

            foreach (var parameter in field.Method.GetParameters())
            {
                if (!type.Arguments.ContainsKey(parameter.Name))
                {
                    continue;
                }

                var arg = type.Arguments[parameter.Name];

                if (arg == null)
                {
                    routeArguments.Add(null);
                    continue;
                }

                if (typeof(IDictionary <string, object>).IsAssignableFrom(arg.GetType()) ||
                    typeof(IEnumerable <object>).IsAssignableFrom(arg.GetType())
                    )
                {
                    try
                    {
                        var json = JsonConvert.SerializeObject(arg);
                        arg = JsonConvert.DeserializeObject(json, parameter.ParameterType);
                    }
                    catch
                    {
                        var json = JsonConvert.SerializeObject(arg, new DeepDictionaryRequest());
                        arg = JsonConvert.DeserializeObject(json, parameter.ParameterType);
                    }
                }
                else if (parameter.ParameterType == typeof(char))
                {
                    arg = arg.ToString()[0];
                }

                routeArguments.Add(arg);
            }

            return(routeArguments.Any() ? routeArguments.ToArray() : null);
        }
        public void CalculateValidationRulesEqualsToTest()
        {
            // Arrange
            var fieldDefinition = ConfigurationHelper.CreateDefinition(FieldType.Text, null);

            fieldDefinition.Configurations = new List <DynamicFieldConfiguration>
            {
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.EqualsTo, ValueString = "DarkwingDuck"
                },
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.EqualsTo, ValueString = "LaunchpadMcQuack"
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    fieldDefinition
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.Text)
                }
            };

            // Act
            var rules = _classUnderTest.CalculateValidationRules(fieldInformation);

            // Assert
            rules.Should().HaveCount(1);

            var rule = rules.Single();

            rule.PropertyName.Should().Be(nameof(FieldType.Text));
            rule.JsonName.Should().Be(nameof(FieldType.Text));
            rule.IsDynamicField.Should().BeTrue();
            rule.Rules.Should().HaveCount(2);
            rule.Rules[0].Rule.Should().Be("EqualsTo");
            rule.Rules[0].PropertyName.Should().Be("DarkwingDuck");
            rule.Rules[1].Rule.Should().Be("EqualsTo");
            rule.Rules[1].PropertyName.Should().Be("LaunchpadMcQuack");
        }
        public void CalculateValidationRulesRangeTest()
        {
            // Arrange
            var fieldDefinition = ConfigurationHelper.CreateDefinition(FieldType.NumberInteger, null);

            fieldDefinition.Configurations = new List <DynamicFieldConfiguration>
            {
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.Minimum, ValueInteger = 5
                },
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.Maximum, ValueInteger = 10
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    fieldDefinition
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.NumberInteger)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.NumberInteger)
                }
            };

            // Act
            var rules = _classUnderTest.CalculateValidationRules(fieldInformation);

            // Assert
            rules.Should().HaveCount(1);

            rules.Single().PropertyName.Should().Be("NumberInteger");
            rules.Single().JsonName.Should().Be("NumberInteger");
            rules.Single().IsDynamicField.Should().BeTrue();
            rules.Single().Rules.Should().HaveCount(3);
            rules.Single().Rules[0].Rule.Should().Be("Number");
            rules.Single().Rules[1].Rule.Should().Be("DecimalPlaces");
            rules.Single().Rules[1].Value.Should().Be(0);
            rules.Single().Rules[2].Rule.Should().Be("Range");
            rules.Single().Rules[2].Minimum.Should().Be(5);
            rules.Single().Rules[2].Maximum.Should().Be(10);
        }
        /// <summary>
        ///     Create field definitions based off a type.
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        public IEnumerable <FieldDefinition> CreateDefinitions(params Type[] types)
        {
            var definitions = new List <FieldDefinition>();

            foreach (var type in types)
            {
                foreach (var method in type.GetMethods())
                {
                    var graphRoute = method.GetCustomAttributes(typeof(GraphRouteAttribute), true)
                                     .OfType <GraphRouteAttribute>()
                                     .FirstOrDefault();

                    if (graphRoute == null)
                    {
                        continue;
                    }

                    var parameters = method.GetParameters();
                    var arguments  = CreateArguments(parameters);
                    var response   = method.ReturnType;

                    if (response.IsGenericType && response.GetGenericTypeDefinition() == typeof(Task <>))
                    {
                        response = response.GenericTypeArguments.First();
                    }

                    var field = new FieldInformation
                    {
                        IsMutation = graphRoute.IsMutation,
                        Arguments  = arguments,
                        Name       =
                            !string.IsNullOrWhiteSpace(graphRoute.Name)
                            ? graphRoute.Name
                            : StringHelper.ConvertToCamelCase(method.Name),
                        Response       = response,
                        Method         = method,
                        ObsoleteReason = TypeHelper.GetDeprecationReason(method)
                    };

                    var definition = new FieldDefinition(field, context => ResolveField(context, field));

                    definitions.Add(definition);
                }
            }

            return(definitions);
        }
        public void CalculateValidationRulesStringLengthTest()
        {
            // Arrange
            var fieldDefinition = ConfigurationHelper.CreateDefinition(FieldType.Text, null);

            fieldDefinition.Configurations = new List <DynamicFieldConfiguration>
            {
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.MinLength, ValueInteger = 5
                },
                new DynamicFieldConfiguration {
                    ConfigurationType = FieldConfigurationType.MaxLength, ValueInteger = 10
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    fieldDefinition
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(FieldType.Text)
                },
                Values = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(FieldType.Text)
                }
            };

            // Act
            var rules = _classUnderTest.CalculateValidationRules(fieldInformation);

            // Assert
            rules.Should().HaveCount(1);

            rules.Single().PropertyName.Should().Be("Text");
            rules.Single().JsonName.Should().Be("Text");
            rules.Single().IsDynamicField.Should().BeTrue();
            rules.Single().Rules.Should().HaveCount(2);
            rules.Single().Rules.First().Rule.Should().Be("MinLength");
            rules.Single().Rules.First().Value.Should().Be(5);
            rules.Single().Rules.Last().Rule.Should().Be("MaxLength");
            rules.Single().Rules.Last().Value.Should().Be(10);
        }
Example #27
0
        public EditorSession(BehaviourManifest manifest, object instance, JsonSerializer jsonSerializer)
        {
            Manifest       = manifest;
            JsonSerializer = jsonSerializer;

            var    rootJson = JObject.FromObject(instance, JsonSerializer);
            string type     = instance.GetType().FullName;

            Instance = rootJson;

            var rootField = new FieldInformation()
            {
                Type = type
            };

            Root = new EditorField(this, rootJson, "root", rootField);
        }
Example #28
0
        public void AnalyseDataTypesDataRowTest(FieldType fieldType, string valuePropertyName, Type type, object value)
        {
            // Arrange
            var alpha = new Alpha
            {
                Beta        = "Darkwing Duck",
                Gamma       = "MegaVolt",
                FieldValues = new List <DynamicFieldValue>
                {
                    ConfigurationHelper.CreateField(fieldType, valuePropertyName, value)
                }
            };

            var fieldInformation = new FieldInformation <DynamicFieldDefinition, DynamicFieldAssignment, DynamicFieldValue, string, int>
            {
                Definitions = new List <DynamicFieldDefinition>
                {
                    ConfigurationHelper.CreateDefinition(fieldType)
                },
                Assignments = new List <DynamicFieldAssignment>
                {
                    ConfigurationHelper.CreateAssignment(fieldType)
                },
                Values = alpha.FieldValues
            };

            // Act
            var result = _classUnderTest.Analyse(alpha, fieldInformation);

            // Assert
            result.Result.Should().HaveCount(3);

            result.Result[nameof(Alpha.Beta)].Id.Should().Be(nameof(Alpha.Beta));
            result.Result[nameof(Alpha.Beta)].Value.Should().Be(alpha.Beta);
            result.Result[nameof(Alpha.Beta)].Type.Should().Be(typeof(string));

            result.Result[nameof(Alpha.Gamma)].Id.Should().Be(nameof(Alpha.Gamma));
            result.Result[nameof(Alpha.Gamma)].Value.Should().Be(alpha.Gamma);
            result.Result[nameof(Alpha.Gamma)].Type.Should().Be(typeof(string));

            result.Result[fieldType.ToString() + "Assignment"].Id.Should().Be(fieldType.ToString() + "Value");
            result.Result[fieldType.ToString() + "Assignment"].Value.Should().Be(value);
            result.Result[fieldType.ToString() + "Assignment"].Type.Should().Be(type);
        }
Example #29
0
        private void updateTime(RegionalRecord rec)
        {
            FieldInformation fi6058    = FieldInformation.GetFieldInformation(6058);
            Field            field6058 = rec.GetField(fi6058);

            if (field6058 != null)
            {
                time = field6058.TimeValue.ToString();
            }

            /*
             * FieldInformation fiREGIONAL_ASK_TIME = FieldInformation.GetFieldInformation("REGIONAL_ASK_TIME");
             * Field fieldREGIONAL_ASK_TIME = data.GetField(fiREGIONAL_ASK_TIME);
             * if (fieldREGIONAL_ASK_TIME != null)
             * {
             *  Console.WriteLine("REGIONAL_ASK_TIME = {0}", fieldREGIONAL_ASK_TIME.TimeValue.ToString());
             * }
             */
        }
Example #30
0
    public Deck(Gameplay game)
    {
        cards = new List<Card>();
        fieldInfo = new FieldInformation();
        CardSelectedVector = new List<CardIdentifier>();

        initialPositionShowDeck = new Vector3(-15.43038f, 3.943099f, -18.63872f);
        deltaPositionShowDeck   = new Vector3(0.625f, 0.0f, 0.001f);

        Cursor = GameObject.FindGameObjectWithTag("Cursor");

        bShowingDeck = false;
        currentCard = 0;

        ViewBackground = Resources.Load ("ViewCardBackground") as Texture2D;

        CardsWatching = new List<Game2DCard>();
        TotalCards = new List<Game2DCard>();
        _Game = game;
    }
        /// <summary>
        ///     Resolve the value from a field.
        /// </summary>
        public object ResolveField(ResolveFieldContext <object> context, FieldInformation field)
        {
            var classObject = ServiceProvider.GetService(field.Method.DeclaringType);
            var parameters  = context.Parameters(field);

            if (classObject == null)
            {
                throw new Exception($"Can't resolve class from: {field.Method.DeclaringType}");
            }

            try
            {
                var result = field.Method.Invoke(classObject, parameters);

                return(result);
            }
            catch (Exception ex)
            {
                var stringParams = parameters?.ToList().Select(t => string.Concat(t.ToString(), ":"));

                throw new Exception($"Cant invoke {field.Method.DeclaringType} with parameters {stringParams}", ex);
            }
        }
Example #32
0
 /// <remarks/>
 public System.IAsyncResult BeginCopyIntoItems(string SourceUrl, string[] DestinationUrls, FieldInformation[] Fields, byte[] Stream, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("CopyIntoItems", new object[] {
             SourceUrl,
             DestinationUrls,
             Fields,
             Stream}, callback, asyncState);
 }
Example #33
0
    public Field(Gameplay game)
    {
        CriticalLeft = GameObject.FindGameObjectWithTag("CriticalFrontLeft");
        CriticalVanguard = GameObject.FindGameObjectWithTag("CriticalVanguard");
        CriticalRight = GameObject.FindGameObjectWithTag("CriticalFrontRight");
        returnList = new List<Card>();
        CallEffect = GameObject.FindGameObjectWithTag("CallEffect");

        fieldInfo = new FieldInformation();
        Soul      = new List<Card>();
        Vanguard  = null;
        Left_Rear = null;
        Left_Front = null;
        Center_Rear = null;
        Right_Rear = null;
        Left_Rear = null;
        delta     = new Vector3(0.0f, 0.06f, 0.0f);

        VanguardPower   = (TextMesh)GameObject.FindGameObjectWithTag("VanguardPowerText").GetComponent("TextMesh");
        FrontRightPower = (TextMesh)GameObject.FindGameObjectWithTag("FrontRightPowerText").GetComponent("TextMesh");
        FrontLeftPower  = (TextMesh)GameObject.FindGameObjectWithTag("FrontLeftPowerText").GetComponent("TextMesh");
        RearRightPower  = (TextMesh)GameObject.FindGameObjectWithTag("RearRightPowerText").GetComponent("TextMesh");
        RearLeftPower   = (TextMesh)GameObject.FindGameObjectWithTag("RearLeftPowerText").GetComponent("TextMesh");
        RearCenterPower = (TextMesh)GameObject.FindGameObjectWithTag("RearCenterPowerText").GetComponent("TextMesh");
        VC  = (TextMesh)GameObject.FindGameObjectWithTag("VC").GetComponent("TextMesh");
        FRC = (TextMesh)GameObject.FindGameObjectWithTag("FRC").GetComponent("TextMesh");
        FLC = (TextMesh)GameObject.FindGameObjectWithTag("FLC").GetComponent("TextMesh");
        RRC = (TextMesh)GameObject.FindGameObjectWithTag("RRC").GetComponent("TextMesh");
        RLC = (TextMesh)GameObject.FindGameObjectWithTag("RLC").GetComponent("TextMesh");
        RCC = (TextMesh)GameObject.FindGameObjectWithTag("RCC").GetComponent("TextMesh");
        VC.text = "";
        FRC.text = "";
        FLC.text = "";
        RRC.text = "";
        RLC.text = "";
        RCC.text = "";

        VanguardPower.text    = "";
        FrontRightPower.text  = "";
        FrontLeftPower.text   = "";
        RearRightPower.text   = "";
        RearLeftPower.text    = "";
        RearCenterPower.text  = "";

        DamageZone = new List<Card>();
        DropZone   = new List<Card>();
        BindZone   = new List<Card>();

        VanguardPower.renderer.material.color   = Color.yellow;
        FrontRightPower.renderer.material.color = Color.yellow;
        FrontLeftPower.renderer.material.color  = Color.yellow;
        RearRightPower.renderer.material.color  = Color.yellow;
        RearLeftPower.renderer.material.color   = Color.yellow;
        RearCenterPower.renderer.material.color = Color.yellow;

        ViewBackground = Resources.Load ("ViewCardBackground") as Texture2D;

        CardsWatching = new List<Game2DCard>();
        TotalCards = new List<Game2DCard>();

        _Game = game;

        CardSelectedVector = new List<CardIdentifier>();
        fieldWatcher = new FieldWatcher(game);
        HelpZone = new List<Card>();

        exitBtnStyle.normal.background = Resources.Load("GUI/exit") as Texture2D;
        exitBtnStyle.hover.background  = Resources.Load("GUI/exit_hover") as Texture2D;

        leftArrowBtnStyle.normal.background = Resources.Load("GUI/left_arrow") as Texture2D;
        leftArrowBtnStyle.hover.background  = Resources.Load("GUI/left_arrow_hover") as Texture2D;

        rightArrowBtnStyle.normal.background = Resources.Load("GUI/right_arrow") as Texture2D;
        rightArrowBtnStyle.hover.background  = Resources.Load("GUI/right_arrow_hover") as Texture2D;
    }
Example #34
0
    // Use this for initialization
    void Start()
    {
        gameplay = this;

        _MainCamera = (Camera)gameObject.GetComponent("Camera");

        _SelectionListWindow = new SelectionListWindow(Screen.width / 2, Screen.height / 2 + 100);

        _AbilityManagerList = new SelectionListGenericWindow(Screen.width / 2, Screen.height / 2 + 100);

        _SelectionCardNameWindow = new SelectionCardNameWindow(Screen.width / 2 - 50, Screen.height / 2);
        _SelectionCardNameWindow.CreateCardList();
        _SelectionCardNameWindow.SetGame(this);

        _DecisionWindow = new DecisionWindow(Screen.width / 2, Screen.height / 2 + 100);
        _DecisionWindow.SetGame(this);

        _NotificationWindow = new NotificacionWindow(Screen.width / 2, Screen.height / 2 + 100);
        _NotificationWindow.SetGame(this);

        FromHandToBindList = new List<Card>();

        AttackedList = new List<Card>();

        UnitsCalled = new List<Card>();

        EnemySoulBlastQueue = new List<Card>();

        _PopupNumber = new PopupNumber();

        _MouseHelper = new MouseHelper(this);
        GameChat = new Chat();

        opponent = PlayerVariables.opponent;

        playerHand = new PlayerHand();
        enemyHand = new EnemyHand();

        field = new Field(this);
        enemyField = new EnemyField(this);
        guardZone = new GuardZone();
        guardZone.SetField(field);
        guardZone.SetEnemyField(enemyField);
        guardZone.SetGame(this);

        fieldInfo = new FieldInformation();
        EnemyFieldInfo = new EnemyFieldInformation();

        Data = new CardDataBase();
        List<CardInformation> tmpList = Data.GetAllCards();
        for(int i = 0; i < tmpList.Count; i++)
        {
            _SelectionCardNameWindow.AddNewNameToTheList(tmpList[i]);
        }

        //camera = (CameraPosition)GameObject.FindGameObjectWithTag("MainCamera").GetComponent("CameraPosition");
        //camera.SetLocation(CameraLocation.Hand);

        LoadPlayerDeck();
        LoadEnemyDeck();

        gamePhase = GamePhase.CHOOSE_VANGUARD;

        bDrawing = true;
        bIsCardSelectedFromHand = false;
        bPlayerTurn = false;

        bDriveAnimation = false;
        bChooseTriggerEffects = false;
        DriveCard = null;

        //Texture showed above a card when this is selected for an action (An attack, for instance)
        CardSelector = GameObject.FindGameObjectWithTag("CardSelector");
        _CardMenuHelper = (CardHelpMenu)GameObject.FindGameObjectWithTag("CardMenuHelper").GetComponent("CardHelpMenu");
        _GameHelper = (GameHelper)GameObject.FindGameObjectWithTag("GameHelper").GetComponent("GameHelper");

        bPlayerTurn = PlayerVariables.bFirstTurn;

        //ActivePopUpQuestion(playerDeck.DrawCard());
        _CardMenu = new CardMenu(this);

        _AbilityManager = new AbilityManager(this);
        _AbilityManagerExt = new AbilityManagerExt();

        _GameHelper.SetChat(GameChat);
        _GameHelper.SetGame(this);

        EnemyTurnStackedCards = new List<Card>();

        dummyUnitObject = new UnitObject();
        dummyUnitObject.SetGame(this);

        stateDynamicText = new DynamicText();
    }
 public MouseHelper(Gameplay game)
 {
     _Game = game;
     _FieldInfo = new FieldInformation();
     _Camera = (Camera)GameObject.FindGameObjectWithTag("MainCamera").GetComponent("Camera");
 }
Example #36
0
 /// <remarks/>
 public void CopyIntoItemsAsync(string SourceUrl, string[] DestinationUrls, FieldInformation[] Fields, byte[] Stream, object userState)
 {
     if ((this.CopyIntoItemsOperationCompleted == null))
     {
         this.CopyIntoItemsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCopyIntoItemsOperationCompleted);
     }
     this.InvokeAsync("CopyIntoItems", new object[] {
             SourceUrl,
             DestinationUrls,
             Fields,
             Stream}, this.CopyIntoItemsOperationCompleted, userState);
 }
Example #37
0
 /// <remarks/>
 public uint EndGetItem(System.IAsyncResult asyncResult, out FieldInformation[] Fields, out byte[] Stream)
 {
     object[] results = this.EndInvoke(asyncResult);
     Fields = ((FieldInformation[])(results[1]));
     Stream = ((byte[])(results[2]));
     return ((uint)(results[0]));
 }
Example #38
0
 /**
 * After reading, we index all of the fields. Recursive.
 * @param fieldlist An array of fields
 * @param fieldDict the last field dictionary we encountered (recursively)
 * @param parentPath the pathname of the field, up to this point or null
 */
 virtual protected void IterateFields(PdfArray fieldlist, PRIndirectReference fieldDict, String parentPath) {
     foreach (PRIndirectReference refi in fieldlist.ArrayList) {
         PdfDictionary dict = (PdfDictionary) PdfReader.GetPdfObjectRelease(refi);
         
         // if we are not a field dictionary, pass our parent's values
         PRIndirectReference myFieldDict = fieldDict;
         String fullPath = parentPath;
         PdfString tField = (PdfString)dict.Get(PdfName.T);
         bool isFieldDict = tField != null;
         
         if (isFieldDict) {
             myFieldDict = refi;
             if (parentPath == null) {
                 fullPath = tField.ToString();
             } else {
                 fullPath = parentPath + '.' + tField.ToString();
             }
         }
         
         PdfArray kids = (PdfArray)dict.Get(PdfName.KIDS);
         if (kids != null) {
             PushAttrib(dict);
             IterateFields(kids, myFieldDict, fullPath);
             stack.RemoveAt(stack.Count - 1);   // pop
         }
         else {          // leaf node
             if (myFieldDict != null) {
                 PdfDictionary mergedDict = (PdfDictionary)stack[stack.Count - 1];
                 if (isFieldDict)
                     mergedDict = MergeAttrib(mergedDict, dict);
                 
                 mergedDict.Put(PdfName.T, new PdfString(fullPath));
                 FieldInformation fi = new FieldInformation(fullPath, mergedDict, myFieldDict);
                 fields.Add(fi);
                 fieldByName[fullPath] = fi;
             }
         }
     }
 }
Example #39
0
 /// <remarks/>
 public void CopyIntoItemsAsync(string SourceUrl, string[] DestinationUrls, FieldInformation[] Fields, byte[] Stream)
 {
     this.CopyIntoItemsAsync(SourceUrl, DestinationUrls, Fields, Stream, null);
 }