예제 #1
0
        public void DeleteDomainObject(DomainObject obj, ICheck[] checkList)
        {
            if (obj == null)
            {
                return;
            }

            foreach (ICheck check in checkList)
            {
                bool pass = true;

                try
                {
                    pass = check.Check();
                }
                catch (Exception ex)
                {
                    ExceptionManager.Raise(obj.GetType(), "$Error_Delete_Check", ex);
                    return;
                }

                if (!pass)
                {
                    ExceptionManager.Raise(obj.GetType(), "$Error_Delete_Check");
                    return;
                }
            }

            this.DeleteDomainObject(obj);
        }
예제 #2
0
        //检查是否存在产品
        private bool CheckIfExistItem(DomainObject obj)
        {
            if (AllItemCodeHT == null)
            {
                AllItemCodeHT = this.GetAllItemCode();
            }                                   // 获取MES系统中所有的产品

            bool ifExist = false;               //默认不存在

            if (obj.GetType() == typeof(MO))
            {
                if (AllItemCodeHT.Contains(((MO)obj).ItemCode.Trim()))
                {
                    ifExist = true;
                }
            }
            else if (obj.GetType() == typeof(MOBOM))
            {
                if (AllItemCodeHT.Contains(((MOBOM)obj).ItemCode.Trim()))
                {
                    ifExist = true;
                }                                                                                           //MOBOM 暂时没有产品代码
                ifExist = true;
            }
            else if (obj.GetType() == typeof(SBOM))
            {
                if (AllItemCodeHT.Contains(((SBOM)obj).ItemCode.Trim()))
                {
                    ifExist = true;
                }
            }

            return(ifExist);
        }
예제 #3
0
        private string GetLog(DomainObject obj, JobActionResult importResult)
        {
            string dataType = string.Empty;                     //数据类型
            string dataCode = string.Empty;                     //数据Code

            if (obj.GetType() == typeof(MO))
            {
                dataType = "工单单号";
                dataCode = ((MO)obj).MOCode;
            }
            else if (obj.GetType() == typeof(MOBOM))
            {
                dataType = "工单BOM子阶料号";
                dataCode = ((MOBOM)obj).MOBOMItemCode;
            }
            else if (obj.GetType() == typeof(SBOM))
            {
                dataType = "BOM料号子阶料号";
                dataCode = ((SBOM)obj).SBOMItemCode;
            }

            string returnStr = string.Format("导入结果: {2} {0} 为 {1} 的数据", dataType, dataCode, importResult.ToString());

            return(returnStr);
        }
예제 #4
0
        public void AddDomainObject(DomainObject obj, ICheck[] checkList)
        {
            foreach (ICheck check in checkList)
            {
                bool pass = true;

                try
                {
                    pass = check.Check();
                }
                catch (Exception ex)
                {
                    ExceptionManager.Raise(obj.GetType(), "$Error_Add_Check", ex);

                    return;
                }

                if (!pass)
                {
                    ExceptionManager.Raise(obj.GetType(), "$Error_Add_Check");

                    return;
                }
            }

            try
            {
                try
                {
                    //Laws Lu,2006/11/13 uniform system collect date
                    DBDateTime dbDateTime = FormatHelper.GetNowDBDateTime(_provider);

                    DateTime workDateTime = FormatHelper.ToDateTime(dbDateTime.DBDate, dbDateTime.DBTime);

                    DomainObjectUtility.SetValue(obj, "MaintainDate", FormatHelper.TODateInt(workDateTime));
                    DomainObjectUtility.SetValue(obj, "MaintainTime", FormatHelper.TOTimeInt(workDateTime));
                }
                catch
                {
                }

                this._provider.Insert(obj);
            }
            catch (Exception ex)
            {
                ExceptionManager.Raise(obj.GetType(), "$Error_Add_Domain_Object", ex);
            }
        }
예제 #5
0
        /// <summary>
        /// 在数据层中修改指定对象的数据
        /// </summary>
        /// <param name="obj"></param>
        internal static void Update(DomainObject obj)
        {
            Type objectType = obj.GetType();
            var  model      = DataModel.Create(objectType);

            model.Update(obj);
        }
예제 #6
0
        /// <summary>
        /// 在数据层创建指定对象的数据
        /// </summary>
        /// <param name="obj"></param>
        internal static void Create(DomainObject obj)
        {
            var objectType = obj.GetType();
            var model      = DataModel.Create(objectType);

            model.Insert(obj);
        }
예제 #7
0
        /// <summary>
        /// 删除目标对象<paramref name="parent"/>的成员数据
        /// </summary>
        /// <param name="root"></param>
        /// <param name="parent"></param>
        private void DeleteMembers(DomainObject root, DomainObject parent, DomainObject current)
        {
            //AggregateRoot,由程序员手工调用删除
            var tips = Util.GetPropertyTips(current.GetType());

            foreach (var tip in tips)
            {
                switch (tip.DomainPropertyType)
                {
                case DomainPropertyType.EntityObject:
                case DomainPropertyType.ValueObject:
                {
                    DeleteMemberByPropertyValue(root, parent, current, tip);
                }
                break;

                case DomainPropertyType.EntityObjectList:
                case DomainPropertyType.ValueObjectList:
                {
                    DeleteMembersByPropertyValue(root, parent, current, tip);
                }
                break;

                case DomainPropertyType.AggregateRootList:
                case DomainPropertyType.EntityObjectProList:
                {
                    //仅删除引用关系(也就是中间表数据)
                    DeleteQuotesByMaster(root, current);
                }
                break;
                }
            }
        }
예제 #8
0
        public void PutDomainObject(string key, DomainObject domainObject)
        {
            Type type = domainObject.GetType();

            Dictionary <string, DomainObject> domainDictionary = GetDictionaryForType(type);

            domainDictionary.Add(key, domainObject);
        }
예제 #9
0
 public static bool IsPersistent(DomainObject entity)
 {
     var keyAttributedProps =
         entity.GetType()
             .GetProperties()
             .FirstOrDefault(p => p.GetCustomAttributes(typeof (KeyAttribute), true).Length == 1);
     return (keyAttributedProps != null) && !keyAttributedProps.GetValue(entity, null).ToString().Equals("0");
 }
예제 #10
0
 //预处理对象
 private void DealMOObject(DomainObject obj)
 {
     if (obj.GetType() == typeof(MO))
     {
         //对工单 则删除工单对应的MOBOM
         this.DeleteMOBomByMoCode(((MO)obj).MOCode);
     }
 }
예제 #11
0
파일: IdentityMap.cs 프로젝트: eglimi/storm
 public void unregisterDomainObject(DomainObject domainObject)
 {
     Hashtable typeMap = (Hashtable)m_typeMaps[domainObject.GetType().BaseType];
     if(typeMap == null)
         Debug.Assert(false);
     Debug.Assert(typeMap.Contains(domainObject.Id));
     typeMap.Remove(domainObject.Id);
 }
예제 #12
0
        public void Remove(DomainObject item)
        {
            if(item == Person.None) return;
            if (_domainObjects.Contains(item) == false) return;  // Already exists

            IList bindingList = _bindingLists[item.GetType()];

            bindingList.Remove(item);
            _domainObjects.Remove(item);
        }
예제 #13
0
        /// <summary>
        /// Uses reflection to set the ID of a <see cref="DomainObject{IdT}" />.
        /// </summary>
        public void SetIdOf(DomainObject <IdT> domainObject, IdT id)
        {
            // Set the data property reflectively
            PropertyInfo idProperty = domainObject.GetType().GetProperty(NAME_OF_ID_MEMBER,
                                                                         BindingFlags.Public | BindingFlags.Instance);

            Check.Ensure(idProperty != null, "idProperty could not be found");

            idProperty.SetValue(domainObject, id, null);
        }
예제 #14
0
        public StoredEvent(DomainObject <TObjectId, TBaseEvent> entity, TBaseEvent change)
        {
            this.ObjectId   = entity.Id;
            this.ObjectType = entity.GetType().FullName;

            this.Event = change;

            this.EventId   = Guid.NewGuid();
            this.EventType = change.GetType().FullName;
            this.Timestamp = change.Timestamp;
        }
예제 #15
0

        
예제 #16
0
 public void DeleteDomainObject(DomainObject obj)
 {
     try
     {
         this._provider.Delete(obj);
     }
     catch (Exception ex)
     {
         ExceptionManager.Raise(obj.GetType(), "$Error_Delete_Domain_Object", ex);
         return;
     }
 }
예제 #17
0
파일: IdentityMap.cs 프로젝트: eglimi/storm
 public void registerDomainObject(DomainObject domainObject)
 {
     Type type = domainObject.GetType().BaseType;
     Hashtable typeMap = (Hashtable)m_typeMaps[type];
     if(typeMap == null)
     {
         typeMap = new Hashtable();
         m_typeMaps[type] = typeMap;
     }
     Debug.Assert(typeMap.Contains(domainObject) == false);
     typeMap.Add(domainObject.Id, domainObject);
 }
예제 #18
0
        public static void UpdateRecord(this EntityEntry entity, DomainObject newRecord)
        {
            //DatabaseGenerated
            var props = entity.Properties
                        .Where(p =>
                               p != null &&
                               p.Metadata.PropertyInfo.GetAccessors().All(x => !x.IsVirtual) &&
                               !p.Metadata.IsKey() &&
                               p.Metadata.FieldInfo?.DeclaringType != typeof(DomainObject) &&
                               p.Metadata.PropertyInfo.CanWrite &&
                               p.Metadata.PropertyInfo.CustomAttributes.All(a => a.AttributeType != typeof(DatabaseGeneratedAttribute)));

            // Gather props from complex types
            var members = entity.Members
                          .Where(p =>
                                 p != null &&
                                 p.GetType() == typeof(ReferenceEntry) &&
                                 p.Metadata.PropertyInfo.GetAccessors().All(x => !x.IsVirtual) &&
                                 p.Metadata.FieldInfo?.DeclaringType != typeof(DomainObject) &&
                                 p.Metadata.PropertyInfo.CanWrite &&
                                 p.Metadata.PropertyInfo.CustomAttributes.All(a => a.AttributeType != typeof(DatabaseGeneratedAttribute)));
            var aggregate = props.Concat <Object>(members);

            // Check for and apply changes
            foreach (MemberEntry entityProp in aggregate)
            {
                var modifiedProp = newRecord.GetType().GetProperties()
                                   .FirstOrDefault(p => p.Name == entityProp.Metadata.Name);
                if (modifiedProp == null ||
                    modifiedProp.GetValue(newRecord) == null ||
                    modifiedProp.GetMethod != null &&
                    modifiedProp.GetMethod.ReturnType == typeof(Guid) &&
                    (Guid)modifiedProp.GetValue(newRecord) == Guid.Empty)
                {
                    continue;
                }

                var newValue      = modifiedProp.GetValue(newRecord);
                var existingValue = entityProp.CurrentValue;
                if (existingValue == newValue)
                {
                    continue;
                }

                entityProp.CurrentValue = newValue;
            }
        }
예제 #19
0
        public void Add(DomainObject item)
        {
            if(item == null) return;

            if (_domainObjects.Contains(item)) return;  // Already exists

            IList bindingList = _bindingLists[item.GetType()];

            Movie pet = item as Movie;
            if (pet != null)
            {
                Add(pet.Director);
            }

            bindingList.Add(item);
            _domainObjects.Add(item);
        }
예제 #20
0
    private void SaveEvent(DomainObject <Guid, TBaseEvent> domainObject, TBaseEvent @event)
    {
        var stored = new StoredEvent
        {
            ActivityId = Trace.CorrelationManager.ActivityId,
            ObjectId   = domainObject.Id,
            ObjectType = this.TypeNameConverter.Invoke(domainObject.GetType()),
            EventId    = SequentialGuid.NewGuid(),
            EventType  = this.TypeNameConverter.Invoke(@event.GetType()),
            Timestamp  = @event.Timestamp,
            Payload    = this.Serializer.Serialize(@event),
            RowVersion = DateTimeOffset.UtcNow.UtcTicks,
        };

        this.Events.Add(stored);

        OnSavingEvent(@event, stored);
    }
예제 #21
0
        /// <summary>
        /// 删除目标对象<paramref name="parent"/>的成员数据
        /// </summary>
        /// <param name="root"></param>
        /// <param name="parent"></param>
        private void DeleteMembers(DomainObject root, DomainObject parent, DomainObject current)
        {
            //AggregateRoot,由程序员手工调用删除
            var tips = Util.GetPropertyTips(current.GetType());

            foreach (var tip in tips)
            {
                switch (tip.DomainPropertyType)
                {
                case DomainPropertyType.EntityObject:
                case DomainPropertyType.ValueObject:
                {
                    DeleteMemberByPropertyValue(root, parent, current, tip);
                }
                break;

                case DomainPropertyType.EntityObjectList:
                case DomainPropertyType.ValueObjectList:
                {
                    DeleteMembersByPropertyValue(root, parent, current, tip);
                }
                break;

                case DomainPropertyType.PrimitiveList:
                {
                    //删除老数据
                    var child = GetChildTableByRuntime(this, tip);
                    child.DeleteMiddleByMaster(root, current);
                }
                break;

                case DomainPropertyType.AggregateRootList:
                {
                    //仅删除引用关系(也就是中间表数据),由于不需要删除slave根表的数据,因此直接使用该方法更高效,不需要读取实际集合值
                    DeleteQuotesByMaster(root, current);
                }
                break;
                }
            }
        }
예제 #22
0
 protected virtual void OnSave()
 {
     Repository.Save(DomainObject);
     MessageLog.GetLog().LogMessage($"{DomainObject.GetType().Name} : {DomainObject} saved.");
     ObjectSaved?.Invoke(this, new EventArgs());
 }
예제 #23
0
        public override bool Validate(DomainObject domainObject)
        {
            try
            {
                string propValue1 = domainObject.GetType().GetProperty(PropertyName).GetValue(domainObject, null).ToString();
                string propValue2 = domainObject.GetType().GetProperty(OtherPropertyName).GetValue(domainObject, null).ToString();

                switch(DataType)
                {
                    case ValidationDataType.Integer:

                        int ival1 = int.Parse(propValue1);
                        int ival2 = int.Parse(propValue2);

                        switch(Operator)
                        {
                            case ValidationOperator.Equal: return ival1 == ival2;
                            case ValidationOperator.NotEqual: return ival1 != ival2;
                            case ValidationOperator.GreaterThan: return ival1 > ival2;
                            case ValidationOperator.GreaterThanEqual: return ival1 >= ival2;
                            case ValidationOperator.LessThan: return ival1 < ival2;
                            case ValidationOperator.LessThanEqual: return ival1 <= ival2;
                        }
                        break;

                    case ValidationDataType.Double:

                        double dval1 = double.Parse(propValue1);
                        double dval2 = double.Parse(propValue2);

                        switch(Operator)
                        {
                            case ValidationOperator.Equal: return dval1 == dval2;
                            case ValidationOperator.NotEqual: return dval1 != dval2;
                            case ValidationOperator.GreaterThan: return dval1 > dval2;
                            case ValidationOperator.GreaterThanEqual: return dval1 >= dval2;
                            case ValidationOperator.LessThan: return dval1 < dval2;
                            case ValidationOperator.LessThanEqual: return dval1 <= dval2;
                        }
                        break;

                    case ValidationDataType.Decimal:

                        decimal cval1 = decimal.Parse(propValue1);
                        decimal cval2 = decimal.Parse(propValue2);

                        switch(Operator)
                        {
                            case ValidationOperator.Equal: return cval1 == cval2;
                            case ValidationOperator.NotEqual: return cval1 != cval2;
                            case ValidationOperator.GreaterThan: return cval1 > cval2;
                            case ValidationOperator.GreaterThanEqual: return cval1 >= cval2;
                            case ValidationOperator.LessThan: return cval1 < cval2;
                            case ValidationOperator.LessThanEqual: return cval1 <= cval2;
                        }
                        break;

                    case ValidationDataType.Date:

                        DateTime tval1 = DateTime.Parse(propValue1);
                        DateTime tval2 = DateTime.Parse(propValue2);

                        switch(Operator)
                        {
                            case ValidationOperator.Equal: return tval1 == tval2;
                            case ValidationOperator.NotEqual: return tval1 != tval2;
                            case ValidationOperator.GreaterThan: return tval1 > tval2;
                            case ValidationOperator.GreaterThanEqual: return tval1 >= tval2;
                            case ValidationOperator.LessThan: return tval1 < tval2;
                            case ValidationOperator.LessThanEqual: return tval1 <= tval2;
                        }
                        break;

                    case ValidationDataType.String:

                        int result = string.Compare(propValue1, propValue2, StringComparison.CurrentCulture);

                        switch(Operator)
                        {
                            case ValidationOperator.Equal: return result == 0;
                            case ValidationOperator.NotEqual: return result != 0;
                            case ValidationOperator.GreaterThan: return result > 0;
                            case ValidationOperator.GreaterThanEqual: return result >= 0;
                            case ValidationOperator.LessThan: return result < 0;
                            case ValidationOperator.LessThanEqual: return result <= 0;
                        }
                        break;

                }
                return false;
            }
            catch{ return false; }
        }
예제 #24
0
        public IList GetAllRevisionIds(DomainObject entity)
        {
            IAuditReader auditReader = AuditReaderFactory.Get(Session);

            return(auditReader.GetRevisions(entity.GetType(), entity.id));
        }
예제 #25
0
 /// <summary>
 /// Gets value for given business object's property using reflection.
 /// </summary>
 protected object GetPropertyValue(DomainObject domainObject)
 {
     return domainObject.GetType().GetProperty(PropertyName).GetValue(domainObject, null);
 }
예제 #26
0
        public static bool IsPersistent(DomainObject entity)
        {
            var keyAttributedProps = entity.GetType().GetProperties().FirstOrDefault(p => p.GetCustomAttributes(typeof(KeyAttribute), true).Length == 1);

            return((keyAttributedProps != null) && !keyAttributedProps.GetValue(entity, null).ToString().Equals("0"));
        }