Exemplo n.º 1
0
 public static void GenerateCodeForInvalidData(InvalidDataInfo info, ICodeBuilder codeBuilder)
 {
     if (!info.FilterType.EndsWith("NewerThanCurrentEntry") && !info.FilterType.EndsWith("OlderThanHistoryEntries"))
     {
         codeBuilder.InsertCode(InvalidCodeSnippet(info), DataStructureCodeGenerator.InvalidDataTag, info.Source);
     }
 }
Exemplo n.º 2
0
        private static string InvalidCodeSnippet(InvalidDataInfo info)
        {
            string       result       = "";
            const string detectEscape = @"""{\d+}""";

            info.ErrorMessage = Regex.Replace(info.ErrorMessage, detectEscape, delegate(Match m) {
                return(m.Value.Replace("\"", ""));
            });
            if (info.ErrorMessage.Length == 0)
            {
                result = string.Format(@"{{ name:"" {0} "", filter: ""{1}.{0}"" }},
            ",
                                       info.FilterType.Contains(".") ? info.FilterType.Split('.')[1] : info.FilterType,
                                       info.Source.Module.Name);
            }
            else
            {
                result = string.Format(@"{{ name:"" {0} "", filter: ""{1}.{0}"", message: ""{2}"" }},
            ",
                                       info.FilterType.Contains(".") ? info.FilterType.Split('.')[1] : info.FilterType,
                                       info.Source.Module.Name,
                                       info.ErrorMessage);
            }
            return(result);
        }
Exemplo n.º 3
0
        public void GetErrorMessageMethodName()
        {
            var tests = new ListOfTuples <string, string, string>()
            {
                { "Mod.Ent", "Filt", "GetErrorMessage_Filt" },
                { "Mod.Ent", "Mod.Filt", "GetErrorMessage_Filt" },
                { "Mod.Ent", "Mod2.Filt", "GetErrorMessage_Mod2_2E_Filt" },
                { "Mod.Ent", "Dictionary<List<System.Guid>, object[]>", "GetErrorMessage_Dictionary_3C_List_3C_System_2E_Guid_3E__2C__20_object_5B__5D__3E_" },
            };

            foreach (var test in tests)
            {
                Console.WriteLine("Input: " + test.Item1 + ", " + test.Item2 + ".");
                var dataStructureParts = test.Item1.Split('.');
                var invalidData        = new InvalidDataInfo
                {
                    Source = new DataStructureInfo {
                        Module = new ModuleInfo {
                            Name = dataStructureParts[0]
                        }, Name = dataStructureParts[1]
                    },
                    FilterType   = test.Item2,
                    ErrorMessage = "[Test]"
                };
                Assert.AreEqual(test.Item3, invalidData.GetErrorMessageMethodName());
            }
        }
Exemplo n.º 4
0
        private static string CheckInvalidItemsSnippet(InvalidDataInfo info)
        {
            return(string.Format(
                       @"            if (insertedNew.Count() > 0 || updatedNew.Count() > 0)
            {{
                {0}[] changedItems = inserted.Concat(updated).ToArray();
                var invalidItems = _domRepository.{0}.Filter(this.Query(changedItems.Select(item => item.ID)), new {1}());
                if (invalidItems.Count() > 0)
                    throw new Rhetos.UserException({2}, ""DataStructure:{0},ID:"" + invalidItems.First().ID.ToString(){3});
            }}
",
                       info.Source.GetKeyProperties(),
                       info.FilterType,
                       CsUtility.QuotedString(info.ErrorMessage),
                       UserMessageAppend.Evaluate(info)));
        }
Exemplo n.º 5
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            InvalidDataInfo info = (InvalidDataInfo)conceptInfo;

            PropertyCodeGeneratorHelper.GenerateCodeForInvalidData(info, codeBuilder);
        }
Exemplo n.º 6
0
 public static void GenerateCodeForInvalidData(InvalidDataInfo info, ICodeBuilder codeBuilder)
 {
     codeBuilder.InsertCode(InvalidCodeSnippet(info), DataStructureCodeGenerator.InvalidDataTag, info.Source);
 }