public void GetValueInXmlForm_ShouldReturnXmlRepresentation() { var person = new Person {IsEnabled = true}; var mapping = new AttributeMapping<Person, bool>(Ns + "Person", x => x.IsEnabled); mapping.GetValueInXmlForm(person).ShouldBe("true"); }
private AttributeMapping CreateAttributeMappingWindow(DbMetadataTable selectedTable) { AttributeMapping attributeMapping = new AttributeMapping(this.configuration, this.dataObject, selectedTable); attributeMapping.SourceTargetMapping.MappingRowAdded += SourceTargetMapping_MappingRowAdded; attributeMapping.SourceTargetMapping.MappingRowDeleted += SourceTargetMapping_MappingRowDeleted; return(attributeMapping); }
public void SetValueFromXmlForm_ShouldSetPropertyValue() { var person = new Person(); var mapping = new AttributeMapping<Person, bool>(Ns + "Person", x => x.IsEnabled); mapping.SetValueFromXmlForm(person, "true"); person.IsEnabled.ShouldBe(true); }
public void CustomSerializer_ShouldSerializeCustomValue() { var person = new Person {Address = new Address {StreetName = "231 Queen Street", City = "Auckland"}}; var mapping = new AttributeMapping<Person, Address>(Ns + "Person", x => x.Address, UnpackAddressFromAttribute, PackAddressForAttribute); var actual = mapping.GetValueInXmlForm(person); actual.ShouldBe("231 Queen Street;Auckland"); }
void bgwEntityChanged_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { this.entityMetadata = ((object[])e.Result)[0] as EntityMetadata; attributeMapping = CreateAttributeMappingWindow(this.entityMetadata); existingCheck = CreateImportSettingsControl(); relationMapping = CreateRelationmappingWindow(this.entityMetadata); ConfigurationContent.Content = new ConfigurationContent(attributeMapping, existingCheck, relationMapping); }
public void CustomDeserializer_ShouldDeserializeCustomValue() { var person = new Person(); var mapping = new AttributeMapping<Person, Address>(Ns + "Person", x => x.Address, UnpackAddressFromAttribute, PackAddressForAttribute); mapping.SetValueFromXmlForm(person, "231 Queen Street;Auckland"); person.Address.StreetName.ShouldBe("231 Queen Street"); person.Address.City.ShouldBe("Auckland"); }
public void TestCustomersIncludeOrdersViaConstructorOnly() { var mapping = new AttributeMapping(typeof(NorthwindX)); var policy = new EntityPolicy(); policy.IncludeWith <CustomerX>(c => c.Orders); NorthwindX nw = new NorthwindX(this.provider.New(policy).New(mapping)); TestQuery( nw.Customers ); }
public void Add(Type type, string member, Attribute attribute) { AttributeMapping item = new AttributeMapping(type, attribute); AttributeKey key = new AttributeKey(attribute.GetType(), member); if (!overrides.TryGetValue(key, out List <AttributeMapping> value)) { value = new List <AttributeMapping>(); overrides.Add(key, value); } else if (value.Contains(item)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Attribute ({2}) already set for Type {0}, Member {1}", type.FullName, member, attribute)); } value.Add(item); }
private void ddTargetTables_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ddTargetTables.SelectedItem == null) { return; } DbMetadataTable selectedTable = ((ComboBoxItem)ddTargetTables.SelectedItem).Tag as DbMetadataTable; this.configuration.TargetTable = selectedTable.TableName; attributeMapping = CreateAttributeMappingWindow(selectedTable); existingCheck = CreateExistingCheckWindow(); relationMapping = CreateRelationmappingWindow(); ConfigurationContent.Content = new ConfigurationContent(attributeMapping, existingCheck, relationMapping); }
/// <summary> /// Adds a Member Attribute Override /// </summary> /// <param name="type">Type</param> /// <param name="member">Class Member</param> /// <param name="attribute">Overriding Attribute</param> public void Add(Type type, string member, Attribute attribute) { var mapping = new AttributeMapping(type, attribute); List <AttributeMapping> mappings; var attributeKey = new AttributeKey(attribute.GetType(), member); if (!overrides.TryGetValue(attributeKey, out mappings)) { mappings = new List <AttributeMapping>(); overrides.Add(attributeKey, mappings); } else if (mappings.Contains(mapping)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Attribute ({2}) already set for Type {0}, Member {1}", type.FullName, member, attribute)); } mappings.Add(mapping); }
public T GetAttribute <T>(Type type, string member) where T : Attribute { if (overrides.TryGetValue(new AttributeKey(typeof(T), member), out List <AttributeMapping> value)) { int num = 0; AttributeMapping attributeMapping = null; foreach (AttributeMapping item in value) { int num2 = item.Matches(type); if (num2 > num) { num = num2; attributeMapping = item; } } if (num > 0) { return((T)attributeMapping.Attribute); } } return((T)null); }
public void TestCustomersIncludeOrdersViaConstructorOnly() { var mapping = new AttributeMapping(typeof(NorthwindX)); var policy = new EntityPolicy(); policy.IncludeWith<CustomerX>(c => c.Orders); NorthwindX nw = new NorthwindX(_provider.New(policy).New(mapping)); var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList(); AssertValue(1, custs.Count); AssertNotValue(null, custs[0].Orders); AssertValue(6, custs[0].Orders.Count); }
public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context) { var sourceDesignModelName = xmlElement.GetStringAttributeValue("src"); var sourceDesignModelNameSet = !string.IsNullOrWhiteSpace(sourceDesignModelName); var destinationDesignModelName = xmlElement.GetStringAttributeValue("dest"); var destinationDesignModelNameSet = !string.IsNullOrWhiteSpace(destinationDesignModelName); if (sourceDesignModelNameSet && destinationDesignModelNameSet) { throw new ParseException(xmlElement.ParseLocation, $"Both 'src' and 'dest' attributes cannot be set."); } if (!sourceDesignModelNameSet && !destinationDesignModelNameSet) { throw new ParseException(xmlElement.ParseLocation, $"Either 'src' or 'dest' attribute must be set."); } var currentDesignModel = context.DesignModel; if (!(currentDesignModel is IClassModel currentClassModel)) { throw new ParseException(xmlElement.ParseLocation, $"Mapping model '{currentDesignModel.FullyQualifiedName}' must be a class-like design model."); } var ns = currentDesignModel.Namespace; var sourceReference = sourceDesignModelNameSet ? _designModelCollection.CreateClassModelReference(ns, xmlElement.ParseLocation, sourceDesignModelName) : currentClassModel.CreateClassModelReference(xmlElement.ParseLocation); var destinationReference = destinationDesignModelNameSet ? _designModelCollection.CreateClassModelReference(ns, xmlElement.ParseLocation, destinationDesignModelName) : currentClassModel.CreateClassModelReference(xmlElement.ParseLocation); var classMapping = new ClassMapping { Name = xmlElement.GetStringAttributeValue("name", null), Source = sourceReference, Destination = destinationReference, MapAttributes = xmlElement.GetBoolAttributeValue("attributes", true), MapRelations = xmlElement.GetBoolAttributeValue("relations", true), AddMissing = xmlElement.GetBoolAttributeValue("add-missing", true), TwoWay = xmlElement.GetBoolAttributeValue("two-way", true), ParseLocation = xmlElement.ParseLocation }; foreach (var attributeElement in xmlElement.GetChildElments("Attribute")) { var mapping = new AttributeMapping { Source = new ClassAttributeReference(attributeElement.GetStringAttributeValue("src"), attributeElement.ParseLocation), Destination = new ClassAttributeReference(attributeElement.GetStringAttributeValue("dest"), attributeElement.ParseLocation), ParseLocation = attributeElement.ParseLocation }; classMapping.AttributeMappings.Add(mapping); } foreach (var relationElement in xmlElement.GetChildElments("Relation")) { var relationMapping = new RelationMapping { Source = new ClassRelationReference(relationElement.GetStringAttributeValue("src"), relationElement.ParseLocation), Destination = new ClassRelationReference(relationElement.GetStringAttributeValue("dest"), relationElement.ParseLocation), MapAttributes = relationElement.GetBoolAttributeValue("attributes", true), AddMissing = relationElement.GetBoolAttributeValue("add-missing", true), TwoWay = relationElement.GetBoolAttributeValue("two-way", true), ParseLocation = relationElement.ParseLocation }; foreach (var attributeElement in relationElement.GetChildElments("Attribute")) { var relationAttributeMapping = new AttributeMapping { Source = new ClassAttributeReference(attributeElement.GetStringAttributeValue("src"), attributeElement.ParseLocation), Destination = new ClassAttributeReference(attributeElement.GetStringAttributeValue("dest"), attributeElement.ParseLocation), ParseLocation = attributeElement.ParseLocation }; relationMapping.AttributeMappings.Add(relationAttributeMapping); } classMapping.RelationMappings.Add(relationMapping); } currentClassModel.SetClassMappingData(classMapping); return(null); }
public override bool Equals(object obj) { AttributeMapping attributeMapping = obj as AttributeMapping; return(attributeMapping != null && RegisteredType.Equals(attributeMapping.RegisteredType) && Attribute.Equals(attributeMapping.Attribute)); }
public static ResponsePom Create_DataSource_Post(string DataSourceName, string ContactlistName, string DataSourceQuery, string databaseDataSourceIPHostName, string databaseDataSourcePort, string databaseDataSourceSchemaName, string databaseDataSourcePassword, string databaseType, string databaseDataSourceUserName, string Uri, string User, string Pass, int TimeSpanSeconds) { try { //HttpClientHandler handler = new HttpClientHandler //{ // UseDefaultCredentials = true //}; //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; //handler.ServerCertificateCustomValidationCallback += CertificateValidationCallBack; using (var client = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; client.BaseAddress = new Uri(Uri); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Add("X-Requested-With", "rest"); client.DefaultRequestHeaders.Add("Accept", "application/json"); client.Timeout = new TimeSpan(0, 0, 0, TimeSpanSeconds); var byteArray = Encoding.Default.GetBytes(User + ":" + Pass); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); DataSource datasource = new DataSource(); datasource.dataSourceType = "database_sql"; datasource.name = DataSourceName; datasource.description = "filedsRest"; datasource.listName = ContactlistName; datasource.emptyContactListBeforeImport = false; datasource.automaticUpdateTimezone = true; datasource.checkRejectPattern = false; datasource.automaticUpdateState = false; datasource.automaticUpdateWireless = false; datasource.checkPhoneFormatRule = false; datasource.checkDNC = false; datasource.ifContactExists = "updateexisting"; datasource.fieldSeparator = ","; datasource.ftpFileType = false; datasource.ftpSecured = false; datasource.ftpIPHostName = null; datasource.ftpPassword = null; datasource.ftpRemoteFilePath = null; datasource.ftpUserName = null; datasource.localFilePathOnServer = null; datasource.customDataSourceClassName = ""; datasource.databaseDataSourceIPHostName = databaseDataSourceIPHostName; datasource.databaseDataSourcePort = databaseDataSourcePort; datasource.databaseDataSourceSchemaName = databaseDataSourceSchemaName; datasource.databaseDataSourcePassword = databaseDataSourcePassword; datasource.databaseDataSourceQuery = DataSourceQuery; datasource.databaseType = databaseType; datasource.databaseDataSourceUserName = databaseDataSourceUserName; AttributeMapping mping = new AttributeMapping(); mping.pomAttributeName = "ID"; mping.remoteDatabaseFieldName = "ID"; AttributeMapping mping1 = new AttributeMapping(); mping1.pomAttributeName = "First Name"; mping1.remoteDatabaseFieldName = "ContactName"; AttributeMapping mping2 = new AttributeMapping(); mping2.pomAttributeName = "Phone 1"; mping2.remoteDatabaseFieldName = "PhoneNumber"; var systemAttributeMappingList = new AttributeMapping[3]; systemAttributeMappingList[0] = mping; systemAttributeMappingList[1] = mping1; systemAttributeMappingList[2] = mping2; datasource.systemAttributeMappingList = systemAttributeMappingList; var customAttributeMappingList = new AttributeMapping[5]; AttributeMapping customMapping1 = new AttributeMapping(); customMapping1.pomAttributeName = "AgentID"; customMapping1.remoteDatabaseFieldName = "AgentID"; AttributeMapping customMapping2 = new AttributeMapping(); customMapping2.pomAttributeName = "PhancongID"; customMapping2.remoteDatabaseFieldName = "PhancongID"; AttributeMapping customMapping3 = new AttributeMapping(); customMapping3.pomAttributeName = "CampaignID"; customMapping3.remoteDatabaseFieldName = "CampaignID"; AttributeMapping customMapping4 = new AttributeMapping(); customMapping4.pomAttributeName = "Telesale_ContactID"; customMapping4.remoteDatabaseFieldName = "ContactID"; AttributeMapping customMapping5 = new AttributeMapping(); customMapping5.pomAttributeName = "PhancongIndex"; customMapping5.remoteDatabaseFieldName = "PhancongIndex"; customAttributeMappingList[0] = customMapping1; customAttributeMappingList[1] = customMapping2; customAttributeMappingList[2] = customMapping3; customAttributeMappingList[3] = customMapping4; customAttributeMappingList[4] = customMapping5; datasource.customAttributeMappingList = customAttributeMappingList; var json = JsonConvert.SerializeObject(datasource); var data = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("datasources", data).Result; if (response.StatusCode == HttpStatusCode.OK) { var responseDataSource = JsonConvert.DeserializeObject <ResponseDataSource>(response.Content.ReadAsStringAsync().Result); return(new ResponsePom() { Code = 0, Message = responseDataSource.dataSourceID }); } else { return(new ResponsePom() { Code = 1, Message = "Call Api Pom Create Data Source Status:" + response.ReasonPhrase.ToString() }); } } } catch (Exception ex) { return(new ResponsePom() { Code = 1, Message = "Call Api Pom Create Data Source Error:" + ex.Message.ToString() }); } }