Exemplo n.º 1
0
        private TItem CreateChangedItem <TItem>(SyncDOEntity syncEntity, ISync xmlObjects, List <string> changedField)
            where TItem : IChangedItem
        {
            var errorMessage = "";
            var changedItem  = default(TItem);

            try
            {
                changedItem            = Activator.CreateInstance <TItem>();
                changedItem.ChangeDate = syncEntity.Date;
                var objectStatus = tState.updated;
                switch (syncEntity.ObjectStatus)
                {
                case ObjectStatus.Deleted:
                    objectStatus = tState.deleted;
                    break;

                case ObjectStatus.Created:
                    objectStatus = tState.created;
                    break;
                }

                changedItem.State = objectStatus;
                var xmlObjType = xmlObjects.GetType();
                var field      = typeof(TItem).GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                 .FirstOrDefault(x => x.FieldType == xmlObjType);
                if (field != null)
                {
                    field.SetValue(changedItem, xmlObjects);
                }
                else
                {
                    errorMessage = $"Не найдено свойство типа {xmlObjType.FullName} в объекте {typeof(TItem).FullName}";
                }

                if (changedField != null && changedField.Any())
                {
                    changedItem.СhangedAttributes = new List <AttributeDefinition>();
                    changedItem.СhangedAttributes.AddRange(changedField.Select(x => new AttributeDefinition(x)));
                }
            }
            catch (Exception ex)
            {
                errorMessage = $"{ex.Message}";
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new Exception(
                          $"Ошибка: не удалось создать ChangedItem типа {typeof(TItem).Name}{Environment.NewLine}{errorMessage}");
            }

            return(changedItem);
        }
Exemplo n.º 2
0
		static NamesValuesPair DumpSyncTrait(ISync sync)
		{
			var type = sync.GetType();
			TypeInfo typeInfo;
			lock (typeInfoCache)
				typeInfo = typeInfoCache[type];
			var values = new object[typeInfo.Names.Length];
			var index = 0;

			foreach (var func in typeInfo.SerializableCopyOfMemberFunctions)
				values[index++] = func(sync);

			return Pair.New(typeInfo.Names, values);
		}
Exemplo n.º 3
0
		static NamesValuesPair DumpSyncTrait(ISync sync)
		{
			var type = sync.GetType();
			TypeInfo typeInfo;
			lock (typeInfoCache)
				typeInfo = typeInfoCache[type];
			var values = new object[typeInfo.Names.Length];
			var index = 0;

			foreach (var func in typeInfo.SerializableCopyOfMemberFunctions)
				values[index++] = func(sync);

			return Pair.New(typeInfo.Names, values);
		}
Exemplo n.º 4
0
        static (string[] Names, Values Values) DumpSyncTrait(ISync sync)
        {
            var      type = sync.GetType();
            TypeInfo typeInfo;

            lock (typeInfoCache)
                typeInfo = typeInfoCache[type];
            var values = new Values(typeInfo.Names.Length);
            var index  = 0;

            foreach (var func in typeInfo.SerializableCopyOfMemberFunctions)
            {
                values[index++] = func(sync);
            }

            return(typeInfo.Names, values);
        }
Exemplo n.º 5
0
        static NamesValuesPair DumpSyncTrait(ISync sync)
        {
            var      type = sync.GetType();
            TypeInfo typeInfo;

            lock (typeInfoCache)
                typeInfo = typeInfoCache[type];
            var values = new string[typeInfo.Names.Length];
            var index  = 0;

            foreach (var func in typeInfo.MemberToStringFunctions)
            {
                values[index++] = func(sync);
            }

            return(Pair.New(typeInfo.Names, values));
        }
Exemplo n.º 6
0
 internal static Func <object, int> GetHashFunction(ISync sync)
 {
     return(HashFunctions[sync.GetType()]);
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Получить настройки по входящему типу.
        /// </summary>
        /// <param name="source">входящий объект</param>
        /// <param name="destType">Тип объекта, который был изменён.</param>
        /// <param name="mapper">Маппер для объекта, который был изменён.</param>
        private void GetSyncSettings(ISync source, out Type destType, out IPropertyMapperWithChangedAttrs mapper)
        {
            SyncSetting setting = null;

            destType = null;
            mapper   = null;
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            try
            {
                setting  = SettingService.Current.GetSettings(source).First();
                destType = setting.Destination.ExtractType();
                mapper   = setting.ExtractMapper <IPropertyMapperWithChangedAttrs>();
            }
            catch (Exception ex)
            {
                var text = "Ошибка: не удалось";
                if (setting == null)
                {
                    text = $"{text} загрузить настройки SyncSettings для входящего типа = {source.GetType().FullName}.";
                }
                else if (destType == null)
                {
                    text = $"{text} получить исходящий тип из настройки SyncSettings.PK - {setting.__PrimaryKey}.";
                }
                else if (mapper == null)
                {
                    text = $"{text} получить маппер из настройки SyncSettings.PK - {setting.__PrimaryKey}.";
                }

                throw new Exception($"{text}{Environment.NewLine}{ex.Message}");
            }
        }