static void Main(string[] args) { var assemblyName = @"D:\DEV\repos\DeltaX-Community\DeltaX\Bin\DeltaX.TagRuleToDatabase\DeltaX.Database.dll"; var className = "DeltaX.Database.DbConnectionFactory"; Console.WriteLine($"Load {assemblyName}!"); var asl = new AssemblyLoader(Path.GetDirectoryName(assemblyName)); var res1 = asl.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(assemblyName))); // PrintTypes(res1); var t1 = InstanceCreator.GetType(assemblyName, className); var inst = Activator.CreateInstance(t1, new object[] { null, null, null }); assemblyName = @"D:\DEV\repos\DeltaX-Community\DeltaX\Bin\DeltaX.TagRuleToDatabase\MySqlConnector.dll"; className = "MySqlConnector.MySqlConnection"; Console.WriteLine($"Load {assemblyName}!"); var res2 = asl.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(assemblyName))); // PrintTypes(res2); var t2 = InstanceCreator.GetType(assemblyName, className); var inst2 = Activator.CreateInstance(t2, new object[] { }); }
internal static void DoTestOnModelBuilder <T>(bool useSql, Action <ModelBuilder> checkMethod, Action <T> checkContext = null, [CallerMemberName] string memberName = null) where T : VisitableDbContext { var optionsBuilder = new DbContextOptionsBuilder <T>(); optionsBuilder = useSql ? optionsBuilder.UseSqlServer(GetSqlConnectionString(memberName)) : optionsBuilder.UseInMemoryDatabase(nameof(T02_ShouldHaveUniqueIndex)); var options = optionsBuilder.Options; var count = 0; using (var context = InstanceCreator.CreateInstance <T>(EmptyShamanLogger.Instance, options)) { context.ExternalCheckModel = b => { count++; checkMethod?.Invoke(b); }; if (useSql) { Console.WriteLine("Migration"); context.Database.Migrate(); } // var tmp = context.Settings.ToArray(); // enforce to create model var model = context.Model; if (model == null) // enforce to create model { throw new NullReferenceException(); } if (checkContext != null) { checkContext(context); } } if (count == 0) { throw new Exception("checkMethod has not been invoked"); } }
public virtual void ReadFrom(XElement xE) { BiddingScheme = null; Id = null; Name = null; Status = null; Type = null; SystemStatus = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "biddingScheme") { BiddingScheme = InstanceCreator.CreateBiddingScheme(xItem); BiddingScheme.ReadFrom(xItem); } else if (localName == "id") { Id = long.Parse(xItem.Value); } else if (localName == "name") { Name = xItem.Value; } else if (localName == "status") { Status = SharedBiddingStrategyBiddingStrategyStatusExtensions.Parse(xItem.Value); } else if (localName == "type") { Type = BiddingStrategyTypeExtensions.Parse(xItem.Value); } else if (localName == "systemStatus") { SystemStatus = BiddingStrategySystemStatusExtensions.Parse(xItem.Value); } } }
public virtual void ReadFrom(XElement xE) { TrialId = null; AsyncError = null; TrialCampaignId = null; TrialAdGroupId = null; BaseCampaignId = null; BaseAdGroupId = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "trialId") { TrialId = long.Parse(xItem.Value); } else if (localName == "asyncError") { AsyncError = InstanceCreator.CreateApiError(xItem); AsyncError.ReadFrom(xItem); } else if (localName == "trialCampaignId") { TrialCampaignId = long.Parse(xItem.Value); } else if (localName == "trialAdGroupId") { TrialAdGroupId = long.Parse(xItem.Value); } else if (localName == "baseCampaignId") { BaseCampaignId = long.Parse(xItem.Value); } else if (localName == "baseAdGroupId") { BaseAdGroupId = long.Parse(xItem.Value); } } }
public virtual void ReadFrom(XElement xE) { CampaignId = null; AdGroupId = null; Criterion = null; BidModifier = null; BaseAdGroupId = null; BidModifierSource = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "campaignId") { CampaignId = long.Parse(xItem.Value); } else if (localName == "adGroupId") { AdGroupId = long.Parse(xItem.Value); } else if (localName == "criterion") { Criterion = InstanceCreator.CreateCriterion(xItem); Criterion.ReadFrom(xItem); } else if (localName == "bidModifier") { BidModifier = double.Parse(xItem.Value); } else if (localName == "baseAdGroupId") { BaseAdGroupId = long.Parse(xItem.Value); } else if (localName == "bidModifierSource") { BidModifierSource = BidModifierSourceExtensions.Parse(xItem.Value); } } }
public virtual void ReadFrom(XElement xE) { Entries = null; TotalNumEntries = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "entries") { if (Entries == null) { Entries = new List <Media>(); } var entriesItem = InstanceCreator.CreateMedia(xItem); entriesItem.ReadFrom(xItem); Entries.Add(entriesItem); } else if (localName == "totalNumEntries") { TotalNumEntries = int.Parse(xItem.Value); } } }
public virtual void ReadFrom(XElement xE) { SharedSetId = null; Criterion = null; Negative = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "sharedSetId") { SharedSetId = long.Parse(xItem.Value); } else if (localName == "criterion") { Criterion = InstanceCreator.CreateCriterion(xItem); Criterion.ReadFrom(xItem); } else if (localName == "negative") { Negative = bool.Parse(xItem.Value); } } }
public void DoNotPopulateCollectionTest() { var options = InstanceCreator.CreateInstanceOptions <TestModel>() .PopulateCollectionMembers(false); var actual = options.Complete() .CreateInstance(); actual.MyIntList.Should() .BeEmpty(); actual.MyStringList.Should() .BeEmpty(); actual.MyIntArray.Should() .BeEmpty(); actual.MyStringArray.Should() .BeEmpty(); actual.MyInt32Enumerable.Should() .BeEmpty(); actual.MyStringEnumerable.Should() .BeEmpty(); }
public virtual void ReadFrom(XElement xE) { Extensions = null; PlatformRestrictions = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "extensions") { if (Extensions == null) { Extensions = new List <ExtensionFeedItem>(); } var extensionsItem = InstanceCreator.CreateExtensionFeedItem(xItem); extensionsItem.ReadFrom(xItem); Extensions.Add(extensionsItem); } else if (localName == "platformRestrictions") { PlatformRestrictions = ExtensionSettingPlatformExtensions.Parse(xItem.Value); } } }
public ProcessingResult ProcessQuery(MethodCallExpression query, ProcessingResult parentResult, DataContext context) { var items = parentResult.GetItems(); var enumerator = items.GetEnumerator(); if (enumerator.MoveNext()) { return(new ProcessingResult(true, parentResult.Result)); } var elementType = QueryProcessingHelper.GetSourceParameterType(query); var hasDefaultValue = query.Arguments.Count > 1; var defaultValue = hasDefaultValue ? ((ConstantExpression)query.Arguments[1]).Value : InstanceCreator.GetDefaultValue(elementType); var resultList = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType)); resultList.Add(defaultValue); return(new ProcessingResult(true, resultList)); }
public void CreateTypes(int count, Random rndGen) { var uniqueName = InstanceCreator.CreateInstanceOf<Guid>(rndGen).ToString("N"); AssemblyName assemblyName = new AssemblyName(uniqueName); AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder mb = ab.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".dll"); for (int i = 0; i < count; i++) { Type type = null; var choice = rndGen.Next(10); if (choice < 6) { // Entity type type = CreateEntityType(mb, rndGen, i.ToString()); CreateClientEntityType(mb, rndGen, type); CreateControllerType(mb, type); } else if (choice < 7) { // Enum type type = CreateEnumType(mb, rndGen, i.ToString()); } else { // Complex Type type = CreateCompexType(mb, rndGen, i.ToString()); } } this.Assembly = ab; }
public override void ReadFrom(XElement xE) { base.ReadFrom(xE); PartitionType = null; ParentCriterionId = null; CaseValue = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "partitionType") { PartitionType = ProductPartitionTypeExtensions.Parse(xItem.Value); } else if (localName == "parentCriterionId") { ParentCriterionId = long.Parse(xItem.Value); } else if (localName == "caseValue") { CaseValue = InstanceCreator.CreateProductDimension(xItem); CaseValue.ReadFrom(xItem); } } }
//Lista 10 public void RegisterInstance <T>(T instance) where T : class { creators[typeof(T)] = new InstanceCreator(instance); }
private CompiledQuery CreateAndRunVirtualMachine(string script) { return(InstanceCreator.Create(script, new DiskSchemaProvider())); }
public T SelectOne <T>(InstanceCreator <T> creator) where T : class { return(SelectOne(PreparedStatement, creator, null)); }
/// <summary> /// Selects the many. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="creator">The creator.</param> /// <returns></returns> public IEnumerable <T> SelectMany <T>(InstanceCreator <T> creator) where T : class { return(SelectMany(PreparedStatement, creator)); }
private CompiledQuery CreateAndRunVirtualMachine(string script) { return(InstanceCreator.CompileForExecution(script, new FlatFileSchemaProvider())); }
private CompiledQuery CreateAndRunVirtualMachine(string script) { return InstanceCreator.CompileForExecution(script, Guid.NewGuid().ToString(), new JsonSchemaProvider()); }
public static IEnumerable <Product> CreateRandomProducts() { int seed = RandomSeedGenerator.GetRandomSeed(); var r = new Random(seed); var products = new List <Product>(); try { for (int i = 0; i < r.Next(5000); i++) { products.Add(new Product { ID = r.Next(1000), Name = InstanceCreator.CreateInstanceOf <string>(r), Price = InstanceCreator.CreateInstanceOf <Decimal>(r), Rating = r.Next(5), PublishDate = InstanceCreator.CreateInstanceOf <DateTimeOffset>(r), ReleaseDate = InstanceCreator.CreateInstanceOf <DateTimeOffset?>(r), Date = InstanceCreator.CreateInstanceOf <DateTime>(r), NullableDate = r.Next(9) % 3 == 0 ? (Date?)null : InstanceCreator.CreateInstanceOf <DateTime>(r), TimeOfDay = InstanceCreator.CreateInstanceOf <DateTimeOffset>(r).TimeOfDay, NullableTimeOfDay = r.Next(19) % 3 == 0 ? (TimeOfDay?)null : InstanceCreator.CreateInstanceOf <DateTimeOffset>(r).TimeOfDay, Taxable = InstanceCreator.CreateInstanceOf <bool?>(r) }); if (r.NextDouble() > .7) { products.Last().Supplier = new Supplier { ID = r.Next(1000), Name = InstanceCreator.CreateInstanceOf <string>(r), Address = new Address { City = InstanceCreator.CreateInstanceOf <string>(r), State = InstanceCreator.CreateInstanceOf <string>(r) } }; products.Last().Supplier.Products.Add(products.Last()); } else if (r.NextDouble() > .3) { products.Last().Supplier = new Supplier { ID = r.Next(1000), Name = InstanceCreator.CreateInstanceOf <string>(r), Address = null }; products.Last().Supplier.Products.Add(products.Last()); } } } catch (Exception e) { Console.WriteLine(e.Message); } return(products); }
public static void AddFilter <T>(this IList <MagicOnionServiceFilterDescriptor> filters) where T : MagicOnionFilterAttribute { var obj = InstanceCreator.Create <T>(); filters.Add(new MagicOnionServiceFilterDescriptor(obj)); }
protected IRunnable CreateAndRunVirtualMachine <T>(string script, IDictionary <string, IEnumerable <T> > sources) where T : BasicEntity { return(InstanceCreator.Create(script, new SchemaProvider <T>(sources))); }
public virtual void ReadFrom(XElement xE) { AdGroupId = null; Ad = null; Status = null; ApprovalStatus = null; Trademarks = null; DisapprovalReasons = null; TrademarkDisapproved = null; Labels = null; BaseCampaignId = null; BaseAdGroupId = null; ForwardCompatibilityMap = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "adGroupId") { AdGroupId = long.Parse(xItem.Value); } else if (localName == "ad") { Ad = InstanceCreator.CreateAd(xItem); Ad.ReadFrom(xItem); } else if (localName == "status") { Status = AdGroupAdStatusExtensions.Parse(xItem.Value); } else if (localName == "approvalStatus") { ApprovalStatus = AdGroupAdApprovalStatusExtensions.Parse(xItem.Value); } else if (localName == "trademarks") { if (Trademarks == null) { Trademarks = new List <string>(); } Trademarks.Add(xItem.Value); } else if (localName == "disapprovalReasons") { if (DisapprovalReasons == null) { DisapprovalReasons = new List <string>(); } DisapprovalReasons.Add(xItem.Value); } else if (localName == "trademarkDisapproved") { TrademarkDisapproved = bool.Parse(xItem.Value); } else if (localName == "labels") { if (Labels == null) { Labels = new List <Label>(); } var labelsItem = InstanceCreator.CreateLabel(xItem); labelsItem.ReadFrom(xItem); Labels.Add(labelsItem); } else if (localName == "baseCampaignId") { BaseCampaignId = long.Parse(xItem.Value); } else if (localName == "baseAdGroupId") { BaseAdGroupId = long.Parse(xItem.Value); } else if (localName == "forwardCompatibilityMap") { if (ForwardCompatibilityMap == null) { ForwardCompatibilityMap = new List <String_StringMapEntry>(); } var forwardCompatibilityMapItem = new String_StringMapEntry(); forwardCompatibilityMapItem.ReadFrom(xItem); ForwardCompatibilityMap.Add(forwardCompatibilityMapItem); } } }
public T GetNewItem(params object[] parameters) { var returnVal = InstanceCreator.CreateInstance <T>(parameters); return(returnVal); }
private (byte[] DllFile, byte[] PdbFile) CreateForStore(string script) { return(InstanceCreator.CompileForStore(script, new SystemSchemaProvider())); }
private CompiledQuery CreateAndRunVirtualMachine(string script, IEnumerable <TestEntity> source, Action <object[]> onGetTableOrRowSource, WhenCheckedParameters whenChecked) { return(InstanceCreator.CompileForExecution(script, new TestSchemaProvider(source, onGetTableOrRowSource, whenChecked))); }
protected CompiledQuery CreateAndRunVirtualMachine <T>(string script, IDictionary <string, IEnumerable <T> > sources) where T : BasicEntity { return(InstanceCreator.CompileForExecution(script, new SchemaProvider <T>(sources))); }
public static T CreateInstance <T>() where T : class { return(InstanceCreator <T> .CreateInstance()); }
public void TestApplyPatchOnIndividualProperty() { // clear respository this.ClearRepository("DeltaTests_Todoes"); this.Client.GetStringAsync(this.BaseAddress + "/$metadata").Wait(); Random r = new Random(RandomSeedGenerator.GetRandomSeed()); var s = new CreatorSettings() { NullValueProbability = 0.0, MaxArrayLength = 100 }; // post new entity to repository var todo = InstanceCreator.CreateInstanceOf <DeltaTests_TodoClient>(r, s); todo.NullableBool = true; todo.NullableInt = 100000; todo.Enum = "One"; todo.Estimation = new DeltaTests_Estimation() { CompletedBy = new DateTime(2012, 10, 18), EstimatedTime = TimeSpan.FromDays(1) }; todo.XElement = @"<a><b/></a>"; DataServiceContext ctx = WriterClient(new Uri(this.BaseAddress), DataServiceProtocolVersion.V3); ctx.ResolveName = ResolveName; ctx.ResolveType = ResolveType; ctx.AddObject("DeltaTests_Todoes", todo); ctx.SaveChanges(); int id = todo.ID; todo.ID = InstanceCreator.CreateInstanceOf <int>(r, s); todo.Name = InstanceCreator.CreateInstanceOf <string>(r, s); todo.Enum = "Two"; todo.NullableBool = null; todo.Items = InstanceCreator.CreateInstanceOf <DeltaTests_TodoItems>(r, s); todo.Tags = InstanceCreator.CreateInstanceOf <List <DeltaTests_TodoTag> >(r, s); todo.Estimation.CompletedBy = new DateTime(2012, 11, 18); todo.NullableInt = 999999; todo.Bool = InstanceCreator.CreateInstanceOf <bool>(r, s); todo.Byte = InstanceCreator.CreateInstanceOf <Byte>(r, s); todo.ByteArray = InstanceCreator.CreateInstanceOf <byte[]>(r, s); todo.DateTime = InstanceCreator.CreateInstanceOf <DateTime>(r, s); todo.DateTimeOffset = InstanceCreator.CreateInstanceOf <DateTimeOffset>(r, s); todo.Decimal = InstanceCreator.CreateInstanceOf <Decimal>(r, s); todo.Double = InstanceCreator.CreateInstanceOf <Double>(r, s); todo.Float = InstanceCreator.CreateInstanceOf <float>(r, s); todo.Guid = InstanceCreator.CreateInstanceOf <Guid>(r, s); todo.Integer = InstanceCreator.CreateInstanceOf <Int32>(r, s); todo.Long = InstanceCreator.CreateInstanceOf <long>(r, s); todo.Short = InstanceCreator.CreateInstanceOf <short>(r, s); todo.String = InstanceCreator.CreateInstanceOf <string>(r, s); todo.TimeSpan = InstanceCreator.CreateInstanceOf <TimeSpan>(r, s); todo.XElement = @"<b><a/></b>"; ctx.UpdateObject(todo); ctx.SaveChanges(); ctx = ReaderClient(new Uri(this.BaseAddress), DataServiceProtocolVersion.V3); ctx.ResolveName = ResolveName; ctx.ResolveType = ResolveType; var actual = ctx.CreateQuery <DeltaTests_TodoClient>("DeltaTests_Todoes").Where(t => t.ID == id).First(); //Assert.Equal(id, actual.ID); Assert.Equal(todo.Name, actual.Name); Assert.Equal(todo.Estimation.CompletedBy, actual.Estimation.CompletedBy); Assert.Equal(todo.Estimation.EstimatedTime, actual.Estimation.EstimatedTime); Assert.Equal(todo.NullableBool, actual.NullableBool); Assert.Equal(todo.NullableInt, actual.NullableInt); Assert.Equal(todo.Bool, actual.Bool); Assert.Equal(todo.Byte, actual.Byte); Assert.Equal(todo.ByteArray, actual.ByteArray); Assert.Equal(todo.DateTime, actual.DateTime); Assert.Equal(todo.DateTimeOffset, actual.DateTimeOffset); Assert.Equal(todo.Decimal, actual.Decimal); Assert.Equal(todo.Double, actual.Double); Assert.Equal(todo.Float, actual.Float); Assert.Equal(todo.Guid, actual.Guid); Assert.Equal(todo.Integer, actual.Integer); Assert.Equal(todo.Long, actual.Long); Assert.Equal(todo.Short, actual.Short); Assert.Equal(todo.String, actual.String); Assert.Equal(todo.TimeSpan, actual.TimeSpan); Assert.Equal(todo.XElement, actual.XElement.Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty)); // clear respository this.ClearRepository("DeltaTests_Todoes"); }
public ObjectActivatorWithTracking(InstanceCreator instanceCreator, List <IObjectActivator> argumentActivators, List <IMemberBinder> memberBinders, int?checkNullOrdinal, IDbContext dbContext) : base(instanceCreator, argumentActivators, memberBinders, checkNullOrdinal) { this._dbContext = dbContext; }
private bool GenerateRandomDataForClient( Type clientType, Type serverType, Random rand, out object value, int?depth = null, CreatorSettings settings = null) { if (clientType == serverType) { value = InstanceCreator.CreateInstanceOf(clientType, rand, settings); return(true); } else if (this.EntityClientTypes.Contains(clientType) || this.ComplexClientTypes.Contains(clientType)) { value = GenerateClientStructureRandomData( clientType, serverType, rand, depth); return(true); } else if (serverType.IsEnum) { value = InstanceCreator.CreateInstanceOf(serverType, rand).ToString(); return(true); } else if (clientType.IsGenericType) { if (clientType.GetGenericTypeDefinition() == typeof(ObservableCollection <>)) { var values = Activator.CreateInstance(clientType); if (depth <= 2) { var addMethod = clientType.GetMethod("Add"); Type elementType = clientType.GetGenericArguments()[0]; Type serverElementType = serverType.GetGenericArguments()[0]; int length = rand.Next(10); for (int j = 0; j < length; j++) { object elementValue; if (GenerateRandomDataForClient(elementType, serverElementType, rand, out elementValue, depth, new CreatorSettings() { NullValueProbability = 0.0 })) { addMethod.Invoke(values, new object[] { elementValue }); } } } value = values; return(true); } } else if (this.primitiveTypes.Contains(clientType)) { if (serverType == typeof(ushort) || serverType == typeof(uint) || serverType == typeof(ulong)) { value = InstanceCreator.CreateInstanceOf <ushort>(rand); return(true); } else if (serverType == typeof(char)) { value = InstanceCreator.CreateInstanceOf <char>(rand).ToString(); return(true); } } value = null; return(false); }