public void TestPatchElementMapFieldTypeOptionSet() { var patch = new PatchElement(); var expectedOperator = "op"; var expectedPath = "path"; var expectedValue = new OptionSet { Value = 1000 }; var field = new Field { Type = FieldType.OptionSet, Name = "fieldName", Value = expectedValue }; var mapped = FieldMapHelper.TryMapField("fieldName", field, expectedOperator, expectedPath, (op, path, value) => { patch.Operator = op; patch.Path = path; patch.Value = value; }); //Assert.IsTrue(mapped); //Assert.IsNotNull(patch); //Assert.AreEqual(expectedOperator, patch.Operator); //Assert.AreEqual(expectedPath, patch.Path); //Assert.AreEqual(expectedValue, patch.Value); }
public void TestPatchElementMapFieldMatchFieldName() { var patch = new PatchElement(); var expectedOperator = "op"; var expectedPath = "path"; var expectedValue = "fieldValue"; var field = new Field { Name = "fieldName", Type = FieldType.String, Value = expectedValue }; var mapped = FieldMapHelper.TryMapField("fieldName", field, expectedOperator, expectedPath, (op, path, value) => { patch.Operator = op; patch.Path = path; patch.Value = value; }); Assert.IsTrue(mapped); Assert.IsNotNull(patch); Assert.AreEqual(expectedOperator, patch.Operator); Assert.AreEqual(expectedPath, patch.Path); Assert.AreEqual(expectedValue, patch.Value); mapped = FieldMapHelper.TryMapField("fieldName1", field, expectedOperator, expectedPath, (op, path, value) => { patch.Operator = op; patch.Path = path; patch.Value = value; }); Assert.IsFalse(mapped); }
private static Action <string, string, string> UpdateElement(PatchElement element, System.Type type) { return((op, path, value) => { element.Operator = op; element.Path = path; element.Value = EnumHelper.MapOptionSet(value, type).ToString(); }); }
private static Action <string, string, string> UpdateElement(PatchElement element) { return((op, path, value) => { element.Operator = op; element.Path = path; element.Value = value; }); }
/// <inheritdoc /> /// <summary> /// Creates Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer class and fills properties required to update request /// </summary> /// <param name="model">Customer record entity model</param> /// <returns>mapped Tc.Crm.Common.IntegrationLayer.Model.Schema.Customer</returns> public object Map(EntityModel model) { List <PatchElement> elements = null; foreach (var field in model.Fields) { var element = new PatchElement(); var mapped = ////////////////////////////////////////CustomerIdentity////////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.Salutation, field, $"{Replace}", $"{Identity}/salutation", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.FirstName, field, $"{Replace}", $"{Identity}/firstName", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.LastName, field, $"{Replace}", $"{Identity}/lastName", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Language, field, $"{Replace}", $"{Identity}/language", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Birthdate, field, $"{Replace}", $"{Identity}/birthdate", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.AcademicTitle, field, $"{Replace}", $"{Identity}/academicTitle", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.MiddleName, field, $"{Replace}", $"{Identity}/middleName", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Gender, field, $"{Replace}", $"{Identity}/gender", UpdateElement(element, typeof(Model.Schema.Gender))) || ////////////////////////////////////////CustomerIdentifier/////////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.SourceMarket, field, $"{Replace}", $"{Identifier}/sourceMarket", UpdateElement(element)) || ////////////////////////////////////////CustomerGeneral/////////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.StatusCode, field, $"{Replace}", $"{General}/customerStatus", UpdateElement(element, typeof(Model.Schema.CustomerStatus))) || ////////////////////////////////////////Company////////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.Name, field, $"{Replace}", $"{Company}/companyName", UpdateElement(element)) || ////////////////////////////////////////Additional/////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.Segment, field, $"{Replace}", $"{Company}/segmentadditional", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.DateOfDeath, field, $"{Replace}", $"{Additional}/dateOfDeath", UpdateElement(element)) || ////////////////////////////////////////Address1///////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.Address1AdditionaInformation, field, $"{Replace}", $"{Address1}/additionalAddressInfo", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1FlatOrUnitNumber, field, $"{Replace}", $"{Address1}/flatNumberUnit", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1Street, field, $"{Replace}", $"{Address1}/street", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1Town, field, $"{Replace}", $"{Address1}/town", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1County, field, $"{Replace}", $"{Address1}/county", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1CountryId, field, $"{Replace}", $"{Address1}/country", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1PostalCode, field, $"{Replace}", $"{Address1}/postalCode", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address1HouseNumberOrBuilding, field, $"{Replace}", $"{Address1}/houseNumberBuilding", UpdateElement(element)) || ////////////////////////////////////////Address2///////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.Address2AdditionaInformation, field, $"{Replace}", $"{Address2}/additionalAddressInfo", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2FlatOrUnitNumber, field, $"{Replace}", $"{Address2}/flatNumberUnit", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2Street, field, $"{Replace}", $"{Address2}/street", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2Town, field, $"{Replace}", $"{Address2}/town", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2County, field, $"{Replace}", $"{Address2}/county", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2CountryId, field, $"{Replace}", $"{Address2}/country", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2PostalCode, field, $"{Replace}", $"{Address2}/postalCode", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Address2HouseNumberOrBuilding, field, $"{Replace}", $"{Address2}/houseNumberBuilding", UpdateElement(element)) || //////////////////////////////////////////Phone//////////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.Telephone1, field, $"{Replace}", $"{Phone1}/number", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Telephone1Type, field, $"{Replace}", $"{Phone1}/type", UpdateElement(element, typeof(Model.Schema.PhoneType))) || FieldMapHelper.TryMapField(Attributes.Customer.Telephone2, field, $"{Replace}", $"{Phone2}/number", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Telephone2Type, field, $"{Replace}", $"{Phone2}/type", UpdateElement(element, typeof(Model.Schema.PhoneType))) || FieldMapHelper.TryMapField(Attributes.Customer.Telephone3, field, $"{Replace}", $"{Phone3}/number", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.Telephone3Type, field, $"{Replace}", $"{Phone3}/type", UpdateElement(element, typeof(Model.Schema.PhoneType))) || ////////////////////////////////////////Email//////////////////////////////////////////////////// FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress1, field, $"{Replace}", $"{Email1}/number", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress1Type, field, $"{Replace}", $"{Email1}/type", UpdateElement(element, typeof(Model.Schema.EmailType))) || FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress2, field, $"{Replace}", $"{Email2}/number", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress2Type, field, $"{Replace}", $"{Email2}/type", UpdateElement(element, typeof(Model.Schema.EmailType))) || FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress3, field, $"{Replace}", $"{Email3}/number", UpdateElement(element)) || FieldMapHelper.TryMapField(Attributes.Customer.EmailAddress3Type, field, $"{Replace}", $"{Email3}/type", UpdateElement(element, typeof(Model.Schema.EmailType))); if (mapped) { if (elements == null) { elements = new List <PatchElement> { element } } ; else { elements.Add(element); } } } return(elements); }
/// <summary> /// 2. 创建补丁清单文件到输出目录 /// </summary> private void CreatePatchManifestFile(AssetBundleManifest unityManifest, List <AssetInfo> buildMap, List <string> encryptList) { string[] allAssetBundles = unityManifest.GetAllAssetBundles(); // 创建DLC管理器 DLCManager dlcManager = new DLCManager(); dlcManager.LoadAllDLC(); // 加载旧补丁清单 PatchManifest oldPatchManifest = LoadPatchManifestFile(); // 创建新补丁清单 PatchManifest newPatchManifest = new PatchManifest(); // 写入版本信息 newPatchManifest.ResourceVersion = BuildVersion; // 写入所有AssetBundle文件的信息 for (int i = 0; i < allAssetBundles.Length; i++) { string bundleName = allAssetBundles[i]; string path = $"{OutputDirectory}/{bundleName}"; string md5 = HashUtility.FileMD5(path); uint crc32 = HashUtility.FileCRC32(path); long sizeBytes = EditorTools.GetFileSize(path); int version = BuildVersion; string[] assetPaths = GetBundleAssetPaths(buildMap, bundleName); string[] depends = unityManifest.GetDirectDependencies(bundleName); string[] dlcLabels = dlcManager.GetAssetBundleDLCLabels(bundleName); // 创建标记位 bool isEncrypted = encryptList.Contains(bundleName); bool isCollected = IsCollectBundle(buildMap, bundleName); int flags = PatchElement.CreateFlags(isEncrypted, isCollected); // 注意:如果文件没有变化使用旧版本号 if (oldPatchManifest.Elements.TryGetValue(bundleName, out PatchElement oldElement)) { if (oldElement.MD5 == md5) { version = oldElement.Version; } } PatchElement newElement = new PatchElement(bundleName, md5, crc32, sizeBytes, version, flags, assetPaths, depends, dlcLabels); newPatchManifest.ElementList.Add(newElement); } // 写入所有变体信息 { Dictionary <string, List <string> > variantInfos = GetVariantInfos(allAssetBundles); foreach (var pair in variantInfos) { if (pair.Value.Count > 0) { string bundleName = $"{pair.Key}.{ PatchDefine.AssetBundleDefaultVariant}"; List <string> variants = pair.Value; newPatchManifest.VariantList.Add(new PatchVariant(bundleName, variants)); } } } // 创建新文件 string filePath = OutputDirectory + $"/{PatchDefine.PatchManifestFileName}"; Log($"创建补丁清单文件:{filePath}"); PatchManifest.Serialize(filePath, newPatchManifest); }