Esempio n. 1
0
        private void ExecuteTemplateApi(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos)
        {
            var pathOutput = PathOutput.PathOutputApi(tableInfo, configContext);

            if (File.Exists(pathOutput) && tableInfo.CodeCustomImplemented)
            {
                return;
            }

            var pathTemplateClass  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "api");
            var pathTemplateApiGet = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "api.get");

            if (!File.Exists(pathTemplateClass))
            {
                return;
            }

            var textTemplateClass  = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder);
            var TextTemplateApiGet = Read.AllText(tableInfo, pathTemplateApiGet, this._defineTemplateFolder);

            var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass);

            var classBuilderApiGet = string.Empty;

            if (!tableInfo.IsCompositeKey && tableInfo.Keys.IsNotNull())
            {
                classBuilderApiGet = TextTemplateApiGet;
                classBuilderApiGet = classBuilderApiGet.Replace("<#className#>", tableInfo.ClassName);
                classBuilderApiGet = classBuilderApiGet.Replace("<#KeyName#>", tableInfo.Keys.FirstOrDefault());
                classBuilderApiGet = classBuilderApiGet.Replace("<#KeyType#>", tableInfo.KeysTypes.FirstOrDefault());
            }

            classBuilder = classBuilder.Replace("<#ApiGet#>", classBuilderApiGet);

            using (var stream = new StreamWriter(pathOutput))
            {
                stream.Write(classBuilder);
            }
        }
Esempio n. 2
0
        private void ExecuteTemplateApi(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos)
        {
            var pathOutput = PathOutput.PathOutputApi(tableInfo, configContext);

            if (!tableInfo.MakeApi)
            {
                return;
            }

            if (File.Exists(pathOutput) && tableInfo.CodeCustomImplemented)
            {
                return;
            }

            if (File.Exists(pathOutput) && Convert.ToBoolean(ConfigurationManager.AppSettings["GerarApiExistentes"]) == false)
            {
                return;
            }


            var pathTemplateClass  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.ApiBase(tableInfo));
            var pathTemplateApiGet = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.ApiGet(tableInfo));

            if (!File.Exists(pathTemplateClass))
            {
                return;
            }

            var textTemplateClass  = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder);
            var TextTemplateApiGet = Read.AllText(tableInfo, pathTemplateApiGet, this._defineTemplateFolder);

            var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass);

            var classBuilderApiGet = string.Empty;

            if (!tableInfo.IsCompositeKey && tableInfo.Keys.IsAny())
            {
                classBuilderApiGet = TextTemplateApiGet;
                classBuilderApiGet = classBuilderApiGet.Replace("<#className#>", tableInfo.ClassName);
                classBuilderApiGet = classBuilderApiGet.Replace("<#namespace#>", configContext.Namespace);
                classBuilderApiGet = classBuilderApiGet.Replace("<#inheritClassName#>", tableInfo.InheritClassName);
                classBuilderApiGet = classBuilderApiGet.Replace("<#KeyName#>", tableInfo.Keys.FirstOrDefault());
                classBuilderApiGet = classBuilderApiGet.Replace("<#KeyType#>", tableInfo.KeysTypes.FirstOrDefault());
            }
            classBuilder = classBuilder.Replace("<#ApiGet#>", classBuilderApiGet);

            var pathTemplateCustoMethod = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.ApiCustomMethod(tableInfo));

            classBuilder = this.CustomMethods(tableInfo, configContext, classBuilder, pathTemplateCustoMethod);

            if (!tableInfo.Authorize)
            {
                classBuilder = classBuilder.Replace("[Authorize]", string.Empty);
            }


            using (var stream = new HelperStream(pathOutput).GetInstance())
            {
                stream.Write(classBuilder);
            }
        }