public void Extend() { var option = new BuilderOption { Pure = true, Extend = true, BaseClass = "Object, Ixx{name}", ClassNameTemplate = "Extend{name}", ModelNameForCopy = "Extend{name}", }; var builder = new ClassBuilder { Table = _table, Option = option, }; builder.Execute(); var rs = builder.ToString(); Assert.NotEmpty(rs); var target = ReadTarget("Code\\class_user_extend.cs", rs); Assert.Equal(target, rs); }
public void Extend2() { var option = new BuilderOption { Pure = true, Extend = true, BaseClass = null, ClassNameTemplate = "Extend{name}2", DisplayNameTemplate = "{displayName}模型", }; option.Excludes.Add("UpdateUser"); option.Excludes.Add("UpdateUserID"); option.Excludes.Add("UpdateIP"); option.Excludes.Add("UpdateTime"); var builder = new ClassBuilder { Table = _table, Option = option, }; builder.Execute(); var rs = builder.ToString(); Assert.NotEmpty(rs); var target = File.ReadAllText("Code\\class_user_extend2.cs".GetFullPath()); Assert.Equal(target, rs); }
public importHouseUODataRequest Build(BuilderOption option, HouseData dto) { switch (dto.Value.Type) { case HouseTypes.Apartment: return(new importHouseUODataRequest { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), importHouseUORequest = new importHouseUORequest { Id = RequestID, Item = dto.Value.MapToApartmentHouseUO(option.Command) } }); case HouseTypes.Living: return(new importHouseUODataRequest { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), importHouseUORequest = new importHouseUORequest { Id = RequestID, Item = dto.Value.MapToLivingHouseUO(option.Command) } }); default: throw new NotImplementedException(); } }
private HttpClientHandler Handler(BuilderOption Option, Action <HttpClientHandler> action = null) { HttpClientHandler Handler = new HttpClientHandler(); if (Container != null) { Handler.AllowAutoRedirect = true; Handler.UseCookies = true; Handler.CookieContainer = Container; } if (Proxy != null) { Handler.Proxy = Proxy; } if (Option.UseHttps) { Handler.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; Handler.ServerCertificateCustomValidationCallback = (Message, Certificate, Chain, Error) => true; } if (Option.UseZip) { Handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } action?.Invoke(Handler); return(Handler); }
public void Interface() { var option = new BuilderOption { Interface = true, BaseClass = "NewLife.Data.IExtend", ClassNameTemplate = "Ixx{name}", }; option.Excludes.Add("UpdateUser"); option.Excludes.Add("UpdateUserID"); option.Excludes.Add("UpdateIP"); option.Excludes.Add("UpdateTime"); var builder = new ClassBuilder { Table = _table, Option = option, }; builder.Execute(); var rs = builder.ToString(); Assert.NotEmpty(rs); var target = File.ReadAllText("Code\\class_user_interface.cs".GetFullPath()); Assert.Equal(target, rs); }
public void Pure() { var option = new BuilderOption { Pure = true, Partial = true, ClassNameTemplate = "Pure{name}", BaseClass = "Object, Ixx{name}", ModelNameForCopy = "Ixx{name}", }; var builder = new ClassBuilder { Table = _table, Option = option, }; builder.Execute(); var rs = builder.ToString(); Assert.NotEmpty(rs); var target = File.ReadAllText("Code\\class_user_pure.cs".GetFullPath()); Assert.Equal(target, rs); }
/// <summary>测试序列化</summary> private static void Test12() { var option = new BuilderOption(); var tables = ClassBuilder.LoadModels("../../NewLife.Cube/CubeDemoNC/Areas/School/Models/Model.xml", option, out var atts); EntityBuilder.BuildTables(tables, option); }
public EntityBuilderTests() { _option = new BuilderOption(); var tables = ClassBuilder.LoadModels(@"..\..\XCode\Membership\Member.xml", _option, out _); _table = tables.FirstOrDefault(e => e.Name == "User"); }
public IHttpMultiClient Build(Action <BuilderOption> action = null, Action <HttpClientHandler> handle = null) { BuilderOption Option = new BuilderOption(); action?.Invoke(Option); CacheSecond = Option.CacheTime; return(BuildProvider(Option, handle)); }
public exportNsiListRequest1 Build(BuilderOption option) { return(new exportNsiListRequest1 { ISRequestHeader = Create <ISRequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportNsiListRequest = new exportNsiListRequest { Id = RequestID, ListGroupSpecified = false } }); }
public exportDataProviderNsiItemRequest1 Build(BuilderOption option) { return(new exportDataProviderNsiItemRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportDataProviderNsiItemRequest = new exportDataProviderNsiItemRequest { Id = RequestID, RegistryNumber = exportDataProviderNsiItemRequestRegistryNumber.Item1 } }); }
public importSupplierNotificationsOfOrderExecutionRequest1 Build(BuilderOption option, OrderData data) { return(new importSupplierNotificationsOfOrderExecutionRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), importSupplierNotificationsOfOrderExecutionRequest = new importSupplierNotificationsOfOrderExecutionRequest { Id = RequestID, SupplierNotificationOfOrderExecution = getOrders(data.Values) } }); }
public exportMeteringDeviceHistoryRequest1 Build(BuilderOption option) { return(new exportMeteringDeviceHistoryRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportMeteringDeviceHistoryRequest = new exportMeteringDeviceHistoryRequest { Id = RequestID, FIASHouseGuid = option.Get(ParametrType.FIASHouseGUID).ToGisString() } }); }
public exportHouseDataRequest Build(BuilderOption option) { return(new exportHouseDataRequest { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportHouseRequest = new exportHouseRequest { Id = RequestID, FIASHouseGuid = option.Params[ParametrType.FIASHouseGUID].ToGisString() } }); }
public exportNsiItemRequest1 Build(BuilderOption option) { return(new exportNsiItemRequest1 { ISRequestHeader = Create <ISRequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportNsiItemRequest = new exportNsiItemRequest { Id = RequestID, RegistryNumber = option.Get(ParametrType.RegistryNumber).ToString() } }); }
public void Add <TRequest, TBuilder>(BuilderOption option) { if (_container.Any(x => x.Key.RequestType == typeof(TRequest) && x.Key.Option.Equals(option))) { return; } _container.Add(new KeyContainer { RequestType = typeof(TRequest), Option = option }, typeof(TBuilder)); }
private void bt_GenTable_Click(Object sender, EventArgs e) { SaveConfig(); if (cbTableList.SelectedValue == null) { return; } var table = cbTableList.SelectedValue as IDataTable; if (table == null) { return; } sw.Reset(); sw.Start(); try { //var ss = Engine.Render(table); //var builder = new EntityBuilder(); var cfg = Config; var option = new BuilderOption { BaseClass = cfg.BaseClass, ConnName = cfg.EntityConnName, Namespace = cfg.NameSpace, Output = cfg.OutputPath, }; var rs = EntityBuilder.BuildTables(new[] { table }, option); MessageBox.Show("生成" + table + "成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } //catch (TemplateException ex) //{ // MessageBox.Show(ex.Message, "模版错误", MessageBoxButtons.OK, MessageBoxIcon.Error); //} catch (Exception ex) { MessageBox.Show(ex.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } sw.Stop(); lb_Status.Text = "生成 " + cbTableList.Text + " 完成!耗时:" + sw.Elapsed; }
public importAdditionalServicesRequest1 Build(BuilderOption option, AdditionalServiceData dto) { return(new importAdditionalServicesRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgGUID)), importAdditionalServicesRequest = new importAdditionalServicesRequest { Id = RequestID, ImportAdditionalServiceType = dto.Values.Select(x => new importAdditionalServicesRequestImportAdditionalServiceType { AdditionalServiceTypeName = x.Name, TransportGUID = x.TransportGuid, ItemElementName = ItemChoiceType.OKEI, Item = x.Unit.OKEI }).ToArray() } }); }
public exportSupplyResourceContractDataRequest Build(BuilderOption option) { return(new exportSupplyResourceContractDataRequest { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportSupplyResourceContractRequest = new exportSupplyResourceContractRequest { Id = RequestID, ItemsElementName = new ItemsChoiceType19[] { ItemsChoiceType19.FIASHouseGuid }, Items = new object[] { option.Params[ParametrType.FIASHouseGUID].ToGisString() } } }); }
public exportMeteringDeviceDataRequest1 Build(BuilderOption option) { return(new exportMeteringDeviceDataRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportMeteringDeviceDataRequest = new exportMeteringDeviceDataRequest { Id = RequestID, ItemsElementName = new ItemsChoiceType3[] { ItemsChoiceType3.FIASHouseGuid, }, Items = new object[] { option.Params[ParametrType.FIASHouseGUID].ToGisString() } } }); }
public exportLicenseRequest1 Build(BuilderOption option) { return(new exportLicenseRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Params[ParametrType.OrgPPAGUID]), exportLicenseRequest = new exportLicenseRequest { Id = RequestID, Items = new object[] { new exportLicenseRequestLicenseOrganization { ItemElementName = ItemChoiceType.OGRN, Item = option.Params[ParametrType.OGRN].ToGisString() } } } }); }
public importMeteringDeviceDataRequest1 Build(BuilderOption option, CounterData data) { if (data.Values.Count() > LIMIT_BY_REQUEST) { throw new ArgumentOutOfRangeException("Превышено максимальное кол-во CounterDto для запроса"); } return(new importMeteringDeviceDataRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), importMeteringDeviceDataRequest = new importMeteringDeviceDataRequest { Id = RequestID, FIASHouseGuid = option.Get(ParametrType.FIASHouseGUID).ToGisString(), MeteringDevice = MapMeteringDevices(option.Command, data.Values) } }); }
public void FixModelFile() { // 加载模型文件,得到数据表 var file = @"..\..\XUnitTest.XCode\Code\Member.xml"; var option = new BuilderOption(); var tables = ClassBuilder.LoadModels(file, option, out var atts); EntityBuilder.FixModelFile(file, option, atts, tables); atts["NameFormat"] = "underline"; file = @"..\..\XUnitTest.XCode\Code\Member2.xml"; EntityBuilder.FixModelFile(file, option, atts, tables); var xml = File.ReadAllText(file); Assert.Contains("Name", xml); }
public exportPaymentDocumentDetailsRequest1 Build(BuilderOption option) { return(new exportPaymentDocumentDetailsRequest1 { RequestHeader = Create <RequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)), exportPaymentDocumentDetailsRequest = new exportPaymentDocumentDetailsRequest { Id = RequestID, ItemsElementName = new ItemsChoiceType4[] { ItemsChoiceType4.FIASHouseGuid, ItemsChoiceType4.Year, ItemsChoiceType4.Month }, Items = new object[] { option.Get(ParametrType.FIASHouseGUID).ToGisString(), (short)option.Get(ParametrType.Year), (int)option.Get(ParametrType.Month) } } }); }
private IHttpMultiClient BuildProvider(BuilderOption Option = null, Action <HttpClientHandler> handle = null) { Client = new HttpClient(Handler(Option, handle)) { Timeout = new TimeSpan(0, 0, Option.TimeOut) }; Client.DefaultRequestHeaders.Clear(); if (MultiConfig.HeaderOpt.Count != 0) { MultiConfig.HeaderOpt.ForEach(item => { foreach (var KeyValuePair in item) { Client.DefaultRequestHeaders.Add(KeyValuePair.Key, KeyValuePair.Value); } }); } return(this); }
public void BuildTT() { var dir = ".\\Output\\BuildTT\\"; if (Directory.Exists(dir.GetFullPath())) { Directory.Delete(dir.GetFullPath(), true); } var option = new BuilderOption { Output = dir, ClassNameTemplate = "{name}TT" }; // 测试Built.tt foreach (var item in _tables) { var builder = new ClassBuilder { Table = item, Option = option, }; builder.Execute(); builder.Save(null, true, false); } foreach (var item in _tables) { var file = dir.CombinePath(item.Name + "TT.cs").GetFullPath(); Assert.True(File.Exists(file)); if (item.Name == "User") { var rs = File.ReadAllText(file); var target = File.ReadAllText("Code\\BuildTT\\UserTT.cs".GetFullPath()); Assert.Equal(target, rs); } } // 清理 //Directory.Delete(dir.GetFullPath(), true); }
public void BuildDtos() { var dir = ".\\Output\\Dtos\\"; if (Directory.Exists(dir.GetFullPath())) { Directory.Delete(dir.GetFullPath(), true); } var option = new BuilderOption { Output = dir, ClassNameTemplate = "{name}Dto", }; ClassBuilder.BuildModels(_tables, option); option.ClassNameTemplate = null; ClassBuilder.BuildInterfaces(_tables, option); foreach (var item in _tables) { var file = dir.CombinePath(item.Name + "Dto.cs").GetFullPath(); Assert.True(File.Exists(file)); if (item.Name == "User") { var rs = File.ReadAllText(file); var target = File.ReadAllText("Code\\Dtos\\UserDto.cs".GetFullPath()); Assert.Equal(target, rs); } file = dir.CombinePath("I" + item.Name + ".cs").GetFullPath(); Assert.True(File.Exists(file)); if (item.Name == "User") { var rs = File.ReadAllText(file); var target = File.ReadAllText("Code\\Dtos\\IUser.cs".GetFullPath()); Assert.Equal(target, rs); } } }
public void Exclude() { var option = new BuilderOption { ConnName = "MyConn", Namespace = "Company.MyName", Partial = true, }; option.Usings.Add("NewLife.Remoting"); var builder = new EntityBuilder { Table = _table, Option = option, }; // 数据类 builder.Execute(); var columns = _table.Columns.Where(e => e.Properties["Model"] == "False").ToList(); Assert.Equal(4, columns.Count); var rs = builder.ToString(); Assert.NotEmpty(rs); var target = ReadTarget("Code\\entity_user_normal.cs", rs); Assert.Equal(target, rs); // 业务类 builder.Business = true; builder.Execute(); rs = builder.ToString(); Assert.NotEmpty(rs); target = ReadTarget("Code\\entity_user_normal_biz.cs", rs); Assert.Equal(target, rs); }
public exportOrgRegistryRequest1 Build(BuilderOption option) { return(new exportOrgRegistryRequest1 { ISRequestHeader = Create <ISRequestHeader>(option.IsOperator, option.Params[Enums.ParametrType.OrgPPAGUID]), exportOrgRegistryRequest = new exportOrgRegistryRequest { Id = RequestID, lastEditingDateFromSpecified = false, SearchCriteria = new exportOrgRegistryRequestSearchCriteria[] { new exportOrgRegistryRequestSearchCriteria { ItemsElementName = new ItemsChoiceType3[] { ItemsChoiceType3.OGRN }, Items = new string[] { option.Params[Enums.ParametrType.OGRN].ToString() } } } } }); }
public bool TryBuild <TRequest>(BuilderOption option, out TRequest result) where TRequest : class { result = null; if (_container.Any(x => x.Key.RequestType == typeof(TRequest) && x.Key.Option.Equals(option)) == false) { BuildError?.Invoke(this, new ErrorEventArgs(true, $"При сборке запроса {nameof(TRequest)} произошла ошибка: нет зарегистрированного сборщика запроса")); return(false); } var type = _container.FirstOrDefault(x => x.Key.RequestType == typeof(TRequest) && x.Key.Option.Equals(option)).Value; var instance = Activator.CreateInstance(type); var builder = (IRequestBuilder <TRequest>)instance; try { result = builder.Build(option); return(true); } catch (Exception ex) { BuildError?.Invoke(this, new ErrorEventArgs(true, $"При сборке запроса {nameof(TRequest)} произошла ошибка:{ex.GetChainException()}")); return(false); } }
public ConfigFileBuilder(BuilderOption parameters) : base(parameters) { }
public ProjectBuilder(BuilderOption parameters) : base(parameters, ".csproj") { }
public ClassBuilder(BuilderOption parameters) : base(parameters, ".cs") { }
public SolutionBuilder(BuilderOption parameters) : base(parameters, ".sln") { }