Пример #1
0
        public static void AddOrIgnore(TemplateBlockJustTextModel template)
        {
            if (template == null)
            {
                throw new NullReferenceException(nameof(template));
            }

            var elem = Templates.FirstOrDefault(x => x.TriggerGroupName == template.TriggerGroupName && x.TriggerName == template.TriggerName);

            if (elem == null)
            {
                Templates.Add(template);
                Update(Templates);
            }
        }
        private static Dictionary <string, string> GetPropertyDictionary(TemplateBlockJustTextModel x, TemplateCodeInitDataOptions opts)
        {
            var dict = new Dictionary <string, string>
            {
                ["Name"]            = $"{opts.ResourcesClassName}.{TemplatesBlockExtensions.ToTemplateNameResourceKey(x.TriggerName)}",
                ["InteractionType"] = PropertyToGeneratedString.ToString(opts.InteractionType),
                ["MessageType"]     = "MessageType.NotSet",
                ["Header"]          = $"{opts.ResourcesClassName}.{TemplatesBlockExtensions.ToTemplateHeaderResourceKey(x.TriggerName)}",
                ["Body"]            = $"{opts.ResourcesClassName}.{TemplatesBlockExtensions.ToTemplateBodyResourceKey(x.TriggerName)}",
                ["Uid"]             = GetTriggerUidProperty(opts.TemplateSchemaName, x.TriggerName)
            };

            if (x is TemplateBlock t)
            {
                dict[nameof(TemplateBlock.AnyTimeAllowed)]  = PropertyToGeneratedString.ToString(t.AnyTimeAllowed);
                dict[nameof(TemplateBlock.AllowedFromHour)] = PropertyToGeneratedString.ToString(t.AllowedFromHour);
                dict[nameof(TemplateBlock.AllowedToHour)]   = PropertyToGeneratedString.ToString(t.AllowedToHour);
            }

            return(dict);
        }