コード例 #1
0
ファイル: ClassBuilderTests.cs プロジェクト: qaz734913414/X
        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);
        }
コード例 #2
0
ファイル: ClassBuilderTests.cs プロジェクト: zeroyou/X
        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);
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
ファイル: HttpMultiClient.cs プロジェクト: EmilyEdna/Synctool
        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);
        }
コード例 #5
0
ファイル: ClassBuilderTests.cs プロジェクト: zeroyou/X
        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);
        }
コード例 #6
0
ファイル: ClassBuilderTests.cs プロジェクト: zeroyou/X
        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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
ファイル: EntityBuilderTests.cs プロジェクト: zeroyou/X
        public EntityBuilderTests()
        {
            _option = new BuilderOption();
            var tables = ClassBuilder.LoadModels(@"..\..\XCode\Membership\Member.xml", _option, out _);

            _table = tables.FirstOrDefault(e => e.Name == "User");
        }
コード例 #9
0
ファイル: HttpMultiClient.cs プロジェクト: EmilyEdna/Synctool
        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));
        }
コード例 #10
0
 public exportNsiListRequest1 Build(BuilderOption option)
 {
     return(new exportNsiListRequest1 {
         ISRequestHeader = Create <ISRequestHeader>(option.IsOperator, option.Get(ParametrType.OrgPPAGUID)),
         exportNsiListRequest = new exportNsiListRequest {
             Id = RequestID,
             ListGroupSpecified = false
         }
     });
 }
コード例 #11
0
 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
         }
     });
 }
コード例 #12
0
 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)
         }
     });
 }
コード例 #13
0
 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()
         }
     });
 }
コード例 #14
0
 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()
         }
     });
 }
コード例 #15
0
 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()
         }
     });
 }
コード例 #16
0
        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));
        }
コード例 #17
0
ファイル: FrmMain.cs プロジェクト: NewLifeX/XCoder
        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;
        }
コード例 #18
0
 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()
         }
     });
 }
コード例 #19
0
 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()
             }
         }
     });
 }
コード例 #20
0
 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()
             }
         }
     });
 }
コード例 #21
0
 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()
                 }
             }
         }
     });
 }
コード例 #22
0
        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)
                }
            });
        }
コード例 #23
0
        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);
        }
コード例 #24
0
 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)
             }
         }
     });
 }
コード例 #25
0
ファイル: HttpMultiClient.cs プロジェクト: EmilyEdna/Synctool
 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);
 }
コード例 #26
0
ファイル: ClassBuilderTests.cs プロジェクト: zeroyou/X
        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);
        }
コード例 #27
0
ファイル: ClassBuilderTests.cs プロジェクト: zeroyou/X
        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);
                }
            }
        }
コード例 #28
0
        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);
        }
コード例 #29
0
 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()
                     }
                 }
             }
         }
     });
 }
コード例 #30
0
        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);
            }
        }
コード例 #31
0
 public ConfigFileBuilder(BuilderOption parameters)
     : base(parameters)
 {
 }
コード例 #32
0
ファイル: ProjectBuilder.cs プロジェクト: feihuobuke/xCoder
 public ProjectBuilder(BuilderOption parameters)
     : base(parameters, ".csproj")
 {
 }
コード例 #33
0
ファイル: ClassBuilder.cs プロジェクト: feihuobuke/xCoder
 public ClassBuilder(BuilderOption parameters)
     : base(parameters, ".cs")
 {
 }
コード例 #34
0
ファイル: SolutionBuilder.cs プロジェクト: feihuobuke/xCoder
 public SolutionBuilder(BuilderOption parameters)
     : base(parameters, ".sln")
 {
 }