Exemplo n.º 1
0
        private void Save(InspectionItem inspectionItem, int applicationId, Guid userId, bool isTrainee, bool isReinspection, string currentUser)
        {
            var siteManager       = this.container.GetInstance <SiteManager>();
            var inspectionManager = this.container.GetInstance <InspectionManager>();

            inspectionManager.Save(inspectionItem, applicationId, userId, isTrainee, isReinspection, isTrainee ? inspectionItem.SiteDescription : null, currentUser);

            if (isTrainee)
            {
                return;
            }

            var site = siteManager.GetById(inspectionItem.SiteId);

            if (site == null || site.Description == inspectionItem.SiteDescription)
            {
                return;
            }

            site.Description = inspectionItem.SiteDescription;
            site.UpdatedBy   = currentUser;
            site.UpdatedDate = DateTime.Now;

            siteManager.Save(site);
        }
Exemplo n.º 2
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var type  = (TypeInfo)item;
            var value = (bool)paramValue;

            if (!type.DeclaredConstructors.Any())
            {
                return(InspectionItem.Create(item, true, "This item has no constructors. Skipped"));
            }

            foreach (var constructor in type.DeclaredConstructors)
            {
                if (value && constructor.IsPublic)
                {
                    return(InspectionItem.Ok(item));
                }
                else if (!value && constructor.IsPublic)
                {
                    return(InspectionItem.Create(item, false, $"Type {item.Name} has public constructor"));
                }
            }

            if (!value && type.DeclaredConstructors.All(x => !x.IsPublic))
            {
                return(InspectionItem.Ok(item));
            }

            return(InspectionItem.Create(item, false, $"Type {item.Name} has not valid constructor"));
        }
Exemplo n.º 3
0
    public void InsertItem(string id, string summary, string dialog)
    {
        InspectionItem item = Instantiate(ItemPrefab, Vector3.zero, Quaternion.identity, itemsRootTran);

        item.Init(id, summary, dialog);
        InspectionMgr.items.Add(item);
    }
Exemplo n.º 4
0
        protected InspectionResult InspectUsingParam(MemberInfo member, IParam param)
        {
            var inspectionResult = new InspectionResult();

            if (param == null)
            {
                inspectionResult.AddResult(InspectionItem.Ok(member, "NotSetParam"));
                return(inspectionResult);
            }

            foreach (var item in ((IBuildable)param).Build())
            {
                if (_checkers.ContainsKey(item.Key))
                {
                    var result = _checkers[item.Key].Check(member, item.Value);
                    inspectionResult.AddResult(result);
                }
                else
                {
                    throw new InvalidOperationException("Cannot find checker for type " + item.Key);
                }
            }

            return(inspectionResult);
        }
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var type  = (TypeInfo)item;
            var value = (DefaultConstructorOptions)paramValue;

            if (!type.DeclaredConstructors.Any())
            {
                return(InspectionItem.Create(item, true, "This item has no constructors. Skipped"));
            }

            foreach (var constructor in type.DeclaredConstructors)
            {
                if (constructor.GetParameters().Length == 0)
                {
                    if (value.IncluePrivate || type.IsAbstract)
                    {
                        return(InspectionItem.Ok(item));
                    }

                    if (constructor.IsPublic)
                    {
                        return(InspectionItem.Ok(item));
                    }
                }
            }
            return(InspectionItem.Create(item, false, $"No default constructor found in type {type.Name}"));
        }
        public async Task <ServiceResponse <bool> > SaveAsync(InspectionItem inspectionItem)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                var inspectionFacade = this.Container.GetInstance <InspectionFacade>();

                base.LogMessage("SaveAsync", DateTime.Now - startTime);

                return(new ServiceResponse <bool>
                {
                    Item = await inspectionFacade.SaveAsync(inspectionItem, base.UserId.GetValueOrDefault(), base.Email),
                    Message = "Inspection saved successfully"
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <bool>
                {
                    HasError = true,
                    Message = ex.Message
                });
            }
        }
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (string[])paramValue;

            if (!value.Any(x => item.Name.StartsWith(x)))
            {
                return(InspectionItem.Create(item, false, $"Wrong member name {item.Name} in class {item.DeclaringType}"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 8
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (int)paramValue;

            if (item.Name.Length > value)
            {
                return(InspectionItem.Create(item, false, $"Too long member name {item.Name} in class {item.DeclaringType}"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 9
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value  = (int)paramValue;
            var method = (MethodInfo)item;

            if (method.GetParameters().Any(x => x.Name.Length < value))
            {
                return(InspectionItem.Create(item, false, $"Too short argument name in {item.Name} in class {item.DeclaringType}"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 10
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (bool)paramValue;

            if (value && !char.IsLower(item.Name[0]))
            {
                return(InspectionItem.Create(item, false, $"Wrong member name {item.Name} in class {item.DeclaringType}"));
            }

            return(InspectionItem.Ok(item));
        }
Exemplo n.º 11
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (IEnumerable <Type>)paramValue;
            var type  = (TypeInfo)item;

            if (!value.Any(x => x.IsAssignableFrom(type)))
            {
                return(InspectionItem.Create(item, false, $"Type {item.Name} is not implements all interfaces: {string.Join(", ", value.Select(x => x.Name))}"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 12
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var attributes = (IEnumerable <Type>)paramValue;

            if (item.CustomAttributes.Any(x => attributes.Contains(x.AttributeType)))
            {
                return(InspectionItem.Create(item, false, $"Member {item.Name} in class {item.DeclaringType} has all attributes {string.Join(", ", attributes.Select(x => x.Name))}"));
            }

            return(InspectionItem.Ok(item));
        }
Exemplo n.º 13
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var type  = (TypeInfo)item;
            var value = (int)paramValue;

            if (type.DeclaredMethods.Count() > value)
            {
                return(InspectionItem.Create(item, false, $"Type {item.Name} has too much methods"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 14
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value  = (int)paramValue;
            var method = (MethodInfo)item;

            if (method.GetParameters().Length > value)
            {
                return(InspectionItem.Create(item, false,
                                             $"Too much args in method {method.Name} in class {item.DeclaringType}"));
            }

            return(InspectionItem.Ok(item));
        }
Exemplo n.º 15
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (bool)paramValue;

            if (value)
            {
                string message = item.DeclaringType != null ?
                                 $"Forbidden item {item.Name} in class {item.DeclaringType}" :
                                 $"Forbidden item {item.Name}";

                return(InspectionItem.Create(item, false, message));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 16
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (string[])paramValue;

            if (!value.Any(x => item.Name.EndsWith(x)))
            {
                string message = item.DeclaringType != null ?
                                 $"Wrong member name {item.Name} in class {item.DeclaringType}" :
                                 $"Wrong member name {item.Name}";

                return(InspectionItem.Create(item, false, message));
            }
            return(InspectionItem.Ok(item));
        }
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value  = (bool)paramValue;
            var method = (MethodInfo)item;

            if (value && method.GetParameters().Any(x => !char.IsLower(x.Name[0])))
            {
                return(InspectionItem.Create(item, false, $"Wrong argument name in {item.Name} in class {item.DeclaringType}"));
            }
            else if (!value && method.GetParameters().Any(x => char.IsLower(x.Name[0])))
            {
                return(InspectionItem.Create(item, false, $"Wrong argument name in {item.Name} in class {item.DeclaringType}"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 18
0
    public void ShowDialog(InspectionItem item)
    {
        this.item          = item;
        transform.position = item.transform.position;
        transform.rotation = item.transform.rotation;
        Vector3 targetPose = InspectionUIMgr.Instance.GyroUICamera.forward.normalized * 200f;

        content.text = item.Info;

        Sequence mySque = DOTween.Sequence();

        mySque.Append(curPanel.DOFade(1, .3f).SetEase(Ease.InOutSine));
        mySque.Join(transform.DOLocalMove(targetPose, .3f));
        mySque.Append(transform.DOPunchPosition(Vector3.one * .1f, 1f));
    }
Exemplo n.º 19
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value = (Type)paramValue;
            var type  = (TypeInfo)item;

            if (type.IsInterface)
            {
                return(InspectionItem.Create(item, true, $"Item {value.Name} is interface. Skipped"));
            }

            if (!value.IsAssignableFrom(type))
            {
                return(InspectionItem.Create(item, false, $"Type {item.Name} not inherits {value.Name}"));
            }
            return(InspectionItem.Ok(item));
        }
Exemplo n.º 20
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value  = (bool)paramValue;
            var method = (MethodInfo)item;

            if (value && method.ReturnType.FullName != "System.Void")
            {
                return(InspectionItem.Create(item, false, $"Member {item.Name} in class {item.DeclaringType} is not void"));
            }
            else if (!value && method.ReturnType.FullName == "System.Void")
            {
                return(InspectionItem.Create(item, false, $"Member {item.Name} in class {item.DeclaringType} is void"));
            }

            return(InspectionItem.Ok(item));
        }
    public void MapToInspectionItemDtoCorrectly()
    {
        var expect = new InspectionItem
        {
            InspectionItemId  = 11,
            OrderIndex        = 3,
            InspectionContent = "inspection content",
            InputTypeId       = 2,
        };
        var mapper = CreateMapper();
        var actual = mapper.Map <InspectionItemDto>(expect);

        Assert.Equal(expect.InspectionItemId, actual.InspectionItemId);
        Assert.Equal(expect.OrderIndex, actual.OrderIndex);
        Assert.Equal(expect.InspectionContent, actual.InspectionContent);
        Assert.Equal(expect.InputTypeId, actual.InputTypeId);
    }
Exemplo n.º 22
0
        public InspectionItem Check(MemberInfo item, object paramValue)
        {
            var value    = (PropertyOptions)paramValue;
            var property = (PropertyInfo)item;

            if (value.Value)
            {
                if (property.GetMethod != null)
                {
                    if (value.IncludePrivate)
                    {
                        return(InspectionItem.Ok(property));
                    }

                    if ((property.GetMethod.IsPublic && property.IsPublic()) ||
                        (property.GetMethod.IsAssembly && property.IsInternal()) ||
                        (property.GetMethod.IsFamily && property.IsProtected()))
                    {
                        return(InspectionItem.Ok(property));
                    }
                    return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has has only private getter"));
                }

                return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has no getter"));
            }
            else
            {
                if (property.GetMethod == null)
                {
                    return(InspectionItem.Ok(property));
                }
                else if (property.GetMethod.IsPrivate)
                {
                    if (value.IncludePrivate)
                    {
                        return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has private getter"));
                    }
                    return(InspectionItem.Ok(property));
                }
                else
                {
                    return(InspectionItem.Create(item, false, $"Property {property.Name} in {property.DeclaringType.Name} has getter"));
                }
            }
        }
Exemplo n.º 23
0
        public bool Save(InspectionItem inspectionItem, int applicationId, Guid inspectorId, bool isTrainee, bool isReinspection, string siteDesc, string email)
        {
            LogMessage("Save (InspectionManager)");


            var inspection = this.GetInspection(inspectionItem.ApplicationUniqueId, isTrainee, isReinspection);

            if (inspection == null)
            {
                inspection = new Inspection
                {
                    ApplicationId          = applicationId,
                    CommendablePractices   = inspectionItem.CommendablePractices,
                    OverallImpressions     = inspectionItem.OverallImpressions,
                    TraineeSiteDescription = siteDesc,
                    IsTrainee      = isTrainee,
                    InspectorId    = inspectorId,
                    CreatedBy      = email,
                    CreatedDate    = DateTime.Now,
                    IsReinspection = isReinspection
                };

                base.Repository.Add(inspection);
            }
            else
            {
                if (inspectionItem.IsOverride)
                {
                    inspection.OverridenPractices   = inspection.CommendablePractices;
                    inspection.OverridenImpressions = inspection.OverallImpressions;
                }

                inspection.CommendablePractices   = inspectionItem.CommendablePractices;
                inspection.OverallImpressions     = inspectionItem.OverallImpressions;
                inspection.TraineeSiteDescription = siteDesc;
                inspection.UpdatedBy   = email;
                inspection.UpdatedDate = DateTime.Now;

                base.Repository.Save(inspection);
            }

            return(true);
        }
Exemplo n.º 24
0
        public async Task <bool> SaveAsync(InspectionItem inspectionItem, Guid userId, string currentUser)
        {
            var userManager        = this.container.GetInstance <UserManager>();
            var applicationManager = this.container.GetInstance <ApplicationManager>();

            var app = await applicationManager.GetByUniqueIdAsync(inspectionItem.ApplicationUniqueId);

            if (app == null || !app.ComplianceApplicationId.HasValue)
            {
                throw new Exception("Cannot find application");
            }

            var user = userManager.GetById(userId);

            if (app.SiteId != inspectionItem.SiteId)
            {
                var complianceApplicationManager = this.container.GetInstance <ComplianceApplicationManager>();
                var complianceApplication        = complianceApplicationManager.GetById(app.ComplianceApplicationId.Value);

                var applications = complianceApplication.Applications.Where(x => x.SiteId == inspectionItem.SiteId);

                foreach (var application in applications)
                {
                    var isTrainee = this.IsTrainee(app, user.Id, application.SiteId.GetValueOrDefault());

                    inspectionItem.ApplicationUniqueId = application.UniqueId;
                    inspectionItem.ApplicationId       = application.Id;

                    this.Save(inspectionItem, application.Id, user.Id, isTrainee, this.IsReinspection(application), currentUser);
                }
            }
            else
            {
                var isTrainee = this.IsTrainee(app, user.Id, inspectionItem.SiteId);

                this.Save(inspectionItem, app.Id, user.Id, isTrainee, this.IsReinspection(app), currentUser);
            }

            return(true);
        }
Exemplo n.º 25
0
 //显示对话内容面板
 public void ShowOptionDialog(InspectionItem item)
 {
     dialogBox.ShowDialog(item);
     curUIMode = UIMode.DialogBox;
 }