Ejemplo n.º 1
0
        public async Task <string> GetStatusChangeTextAsync(InitiativeStatus status, bool isPastTense = false)
        {
            TemplateKey key = new TemplateKey()
            {
                Category = StringTemplateCategory.StatusDescription,
                Key      = string.Concat(status.ToString(), isPastTense ? "_past" : "_present")
            };
            string template = _stringTemplateCache.ContainsKey(key) ? _stringTemplateCache[key] : null;

            if (string.IsNullOrWhiteSpace(template))
            {
                template = await _ideaContext.StringTemplates
                           .Where(x => x.Category == key.Category && x.Key == key.Key)
                           .Select(x => x.Text)
                           .FirstOrDefaultAsync();

                if (string.IsNullOrWhiteSpace(template))
                {
                    throw new KeyNotFoundException($"Unable to find a StringTemplate with category {key.Category} and key {key.Key}");
                }

                _stringTemplateCache[key] = template;
            }

            return(template);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 文件保存
        /// </summary>
        /// <param name="path"></param>
        /// <param name="result"></param>
        private static void Save(string folder, string filename, string input, TemplateKey key)
        {
            byte[] result = System.Text.Encoding.GetEncoding("utf-8").GetBytes(input);
            switch (key)
            {
            case TemplateKey.Entity:
                folder += @"\entity";
                break;

            case TemplateKey.Dao:
                folder += @"\dao";
                break;

            case TemplateKey.Service:
                folder += @"\service";
                break;
            }
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            using (FileStream fileStream = new FileStream(Path.Combine(folder, filename), FileMode.Create))
            {
                for (int i = 0; i < result.Length; i++)
                {
                    fileStream.WriteByte(result[i]);
                }
            }
        }
Ejemplo n.º 3
0
        public OpenContentSettings(IDictionary moduleSettings)
        {
            var template = moduleSettings["template"] as string;    //templatepath+file  or  //manifestpath+key

            FirstTimeInitialisation = string.IsNullOrEmpty(template);
            if (!FirstTimeInitialisation)
            {
                var templateUri = new FileUri(template);
                TemplateKey = new TemplateKey(templateUri);
                TemplateManifest templateManifest;
                Manifest = ManifestUtils.GetManifest(TemplateKey, out templateManifest);
                Template = templateManifest;
            }

            var sTabId    = moduleSettings["tabid"] as string;
            var sModuleId = moduleSettings["moduleid"] as string;

            TabId    = -1;
            ModuleId = -1;
            if (sTabId != null && sModuleId != null)
            {
                TabId    = int.Parse(sTabId);
                ModuleId = int.Parse(sModuleId);
            }

            Data   = moduleSettings["data"] as string;
            _query = moduleSettings["query"] as string;
            var sDetailTabId = moduleSettings["detailtabid"] as string;

            DetailTabId = -1;
            if (!string.IsNullOrEmpty(sDetailTabId))
            {
                DetailTabId = int.Parse(sDetailTabId);
            }
        }
Ejemplo n.º 4
0
        // Token: 0x0600237C RID: 9084 RVA: 0x000AD4B8 File Offset: 0x000AB6B8
        internal override object GetDictionaryKey(BamlRecord startRecord, ParserContext parserContext)
        {
            object     obj        = null;
            int        num        = 0;
            BamlRecord bamlRecord = startRecord;
            short      num2       = 0;

            while (bamlRecord != null)
            {
                if (bamlRecord.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord bamlElementStartRecord = bamlRecord as BamlElementStartRecord;
                    if (++num != 1)
                    {
                        break;
                    }
                    num2 = bamlElementStartRecord.TypeId;
                }
                else if (bamlRecord.RecordType == BamlRecordType.Property && num == 1)
                {
                    BamlPropertyRecord bamlPropertyRecord = bamlRecord as BamlPropertyRecord;
                    short              num3;
                    string             a;
                    BamlAttributeUsage bamlAttributeUsage;
                    parserContext.MapTable.GetAttributeInfoFromId(bamlPropertyRecord.AttributeId, out num3, out a, out bamlAttributeUsage);
                    if (num3 == num2)
                    {
                        if (a == "TargetType")
                        {
                            obj = parserContext.XamlTypeMapper.GetDictionaryKey(bamlPropertyRecord.Value, parserContext);
                        }
                        else if (a == "DataType")
                        {
                            object    dictionaryKey = parserContext.XamlTypeMapper.GetDictionaryKey(bamlPropertyRecord.Value, parserContext);
                            Exception ex            = TemplateKey.ValidateDataType(dictionaryKey, null);
                            if (ex != null)
                            {
                                this.ThrowException("TemplateBadDictionaryKey", parserContext.LineNumber, parserContext.LinePosition, ex);
                            }
                            obj = new DataTemplateKey(dictionaryKey);
                        }
                    }
                }
                else if (bamlRecord.RecordType == BamlRecordType.PropertyComplexStart || bamlRecord.RecordType == BamlRecordType.PropertyIListStart || bamlRecord.RecordType == BamlRecordType.ElementEnd)
                {
                    break;
                }
                bamlRecord = bamlRecord.Next;
            }
            if (obj == null)
            {
                this.ThrowException("StyleNoDictionaryKey", parserContext.LineNumber, parserContext.LinePosition, null);
            }
            return(obj);
        }
 public OpenContentSettings(string template, int tabId, int moduleId, string templateSettings = "", string filterSettings = "", int detailTabId = -1)
 {
     // template = //templatepath+file  or  //manifestpath+key
     FirstTimeInitialisation = string.IsNullOrEmpty(template);
     if (!FirstTimeInitialisation)
     {
         TemplateKey = new TemplateKey(new FileUri(template));
         TemplateManifest templateManifest;
         Manifest = ManifestUtils.GetManifest(TemplateKey, out templateManifest);
         Template = templateManifest;
     }
     TabId       = tabId;
     ModuleId    = moduleId;
     Data        = templateSettings;
     _query      = filterSettings;
     DetailTabId = detailTabId;
 }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public MustacheTemplate Parse(string text, Tags startingTags = null, int lineIndent = 0, ParserPipeline pipeline = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            var key     = new TemplateKey(text, startingTags, lineIndent);
            var success = Cache.TryGetValue(key, out MustacheTemplate template);

            if (!success)
            {
                template = Cache[key] = MustacheParser.Parse(text, startingTags, lineIndent, pipeline);
            }

            return(template);
        }
Ejemplo n.º 7
0
        public OpenContentSettings(ComponentSettingsInfo moduleSettings)
        {
            FirstTimeInitialisation = string.IsNullOrEmpty(moduleSettings.Template);
            if (!FirstTimeInitialisation)
            {
                TemplateKey = new TemplateKey(new FileUri(moduleSettings.Template));
                TemplateManifest templateManifest;
                Manifest = ManifestUtils.GetManifest(TemplateKey, out templateManifest);
                Template = templateManifest;
            }
            TabId    = moduleSettings.TabId;
            ModuleId = moduleSettings.ModuleId;

            Data   = moduleSettings.Data;
            _query = moduleSettings.Query;

            DetailTabId = moduleSettings.DetailTabId;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 输出到文件
        /// </summary>
        /// <param name="template">模板文本</param>
        /// <param name="table">表数据</param>
        private static void FileOutput(string template, Table table, TemplateKey key, string filename)
        {
            var    model  = table;
            string suffix = filename.Substring(filename.LastIndexOf("."));
            string result = string.Empty;

            try
            {
                result = Engine.Razor.RunCompile(template, key.ToString("G") + suffix, null, model);
            }
            catch (FormatException e)
            {
                throw new TemplateSyntaxErrorException(
                          "模板文件可能有问题,请确保您没有擅自修改,或者修改后没有出现违反Razor Engine语法的问题。\n" +
                          "如果是不小心修改了模板文件,您可以到下面的地址重新获取模板文件。\n" +
                          "https://github.com/AyakuraYuki/CodErator \n\n" +
                          "如果需要自定义模板内容,请参考Razor Engine的语法规范。", e);
            }
            Save(optionHelper.OutputPath, filename, result, key);
        }
Ejemplo n.º 9
0
        /*
         * public TemplateInfo Response
         * {
         *  get { return this; }
         * }
         */
        #endregion

        // override object.GetHashCode
        public override int GetHashCode()
        {
            return(TemplateKey.GetHashCode());
        }
Ejemplo n.º 10
0
 public bool Equals(TemplateKey other)
 {
     return(TemplateType == other.TemplateType &&
            Name == other.Name);
 }
 void SetDefaultXaml()
 {
     Xaml = templateProvider.GetTemplateXamlFor(TemplateKey.Replace("Template", string.Empty));
 }
Ejemplo n.º 12
0
 public static string Parse(TemplateKey templateKey, string template, object model, DynamicViewBag viewbag)
 {
     var result = Engine.Razor.RunCompile(template, templateKey.ToString("G"), null, model, (DynamicViewBag)viewbag);
     return result;
 }
        /// <summary>
        ///   If the Template represented by a group of baml records is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed
        ///   collection of baml records.  For ControlTemplate, this is the styleTargetType.
        ///   For DataTemplate, this is the DataTemplateKey containing the DataType.
        /// </summary>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
        internal override object GetDictionaryKey(BamlRecord startRecord, ParserContext parserContext)
        {
            object     key = null;
            int        numberOfElements = 0;
            BamlRecord record           = startRecord;
            short      ownerTypeId      = 0;

            while (record != null)
            {
                if (record.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord elementStart = record as BamlElementStartRecord;
                    if (++numberOfElements == 1)
                    {
                        // save the type ID of the first element (i.e. <ControlTemplate>)
                        ownerTypeId = elementStart.TypeId;
                    }
                    else
                    {
                        // We didn't find the key before a reading the
                        // VisualTree nodes of the template
                        break;
                    }
                }
                else if (record.RecordType == BamlRecordType.Property && numberOfElements == 1)
                {
                    // look for the TargetType property on the <ControlTemplate> element
                    // or the DataType property on the <DataTemplate> element
                    BamlPropertyRecord propertyRecord = record as BamlPropertyRecord;
                    short              attributeOwnerTypeId;
                    string             attributeName;
                    BamlAttributeUsage attributeUsage;
                    parserContext.MapTable.GetAttributeInfoFromId(propertyRecord.AttributeId, out attributeOwnerTypeId, out attributeName, out attributeUsage);
                    if (attributeOwnerTypeId == ownerTypeId)
                    {
                        if (attributeName == TargetTypePropertyName)
                        {
                            key = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                        }
                        else if (attributeName == DataTypePropertyName)
                        {
                            object    dataType = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                            Exception ex       = TemplateKey.ValidateDataType(dataType, null);
                            if (ex != null)
                            {
                                ThrowException(SRID.TemplateBadDictionaryKey,
                                               parserContext.LineNumber,
                                               parserContext.LinePosition,
                                               ex);
                            }
                            //
                            key = new DataTemplateKey(dataType);
                        }
                    }
                }
                else if (record.RecordType == BamlRecordType.PropertyComplexStart ||
                         record.RecordType == BamlRecordType.PropertyIListStart ||
                         record.RecordType == BamlRecordType.ElementEnd)
                {
                    // We didn't find the targetType before a complex property like
                    // FrameworkTemplate.VisualTree or the </ControlTemplate> tag or
                    // TableTemplate.Tree or the </TableTemplate> tag
                    break;
                }
                record = record.Next;
            }

            if (key == null)
            {
                ThrowException(SRID.StyleNoDictionaryKey,
                               parserContext.LineNumber,
                               parserContext.LinePosition,
                               null);
            }

            return(key);
        }
Ejemplo n.º 14
0
        public static string Parse(TemplateKey templateKey, string template, object model)
        {
            var result = Engine.Razor.RunCompile(template, templateKey.ToString("G"), null, model);

            return(result);
        }
Ejemplo n.º 15
0
        public static string Parse(TemplateKey templateKey, string template, object model, DynamicViewBag viewbag)
        {
            var result = Engine.Razor.RunCompile(template, templateKey.ToString("G"), null, model, (DynamicViewBag)viewbag);

            return(result);
        }
Ejemplo n.º 16
0
 public TemplateKey(TemplateKey templateKey, string shortKey, string extension = "")
 {
     _folder   = templateKey.Folder;
     ShortKey  = shortKey;
     Extention = extension == "" ? templateKey.Extention : extension;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取模板消息的id
        /// </summary>
        /// <param name="templateKey"></param>
        /// <returns></returns>
        string GetTemplateMessageId(string templateKey)
        {
            var appid     = _settingManager.GetSettingValue(AppSettings.Weixin.AppId);
            var appsecret = _settingManager.GetSettingValue(AppSettings.Weixin.AppSecret);

            if (!AccessTokenContainer.CheckRegistered(appid))
            {
                AccessTokenContainer.Register(appid, appsecret);
            }



            //生成获取 template id
            try
            {
                var tempInfo = _templateKeyRepository.FirstOrDefault(t => t.TempMsgKey == templateKey);
                if (tempInfo != null && !string.IsNullOrEmpty(tempInfo.TempMsgId))
                {
                    return(tempInfo.TempMsgId);
                }

                #region 设置行业(调用频率限制)

                try
                {
                    var temps = TemplateApi.GetIndustry(appid);
                    if (temps.primary_industry.first_class == "IT科技" && temps.primary_industry.second_class == "互联网|电子商务" &&
                        temps.secondary_industry.first_class == "房地产" && temps.secondary_industry.second_class == "物业")
                    {
                    }
                    else
                    {
                        TemplateApi.SetIndustry(appid, IndustryCode.IT科技_互联网_电子商务, IndustryCode.房地产_物业);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("初始化模板消息", ex);
                }

                #endregion

                var addResult = TemplateApi.Addtemplate(appid, templateKey);
                if (tempInfo != null)
                {
                    tempInfo.TempMsgId = addResult.template_id;
                    _templateKeyRepository.Update(tempInfo);
                }
                else
                {
                    tempInfo            = new TemplateKey();
                    tempInfo.TempMsgKey = templateKey;
                    tempInfo.TempMsgId  = addResult.template_id;
                    _templateKeyRepository.Insert(tempInfo);
                }
                return(tempInfo.TempMsgId);
            }
            catch (Exception ex)
            {
                _logger.Error("获取模板ID失败", ex);
                throw new UserFriendlyException("获取模板ID失败" + Environment.NewLine + ex.Message, ex);
            }
        }