void IListener <ObjectSetChangedMessage> .Handle(ObjectSetChangedMessage message)
        {
            if (message.ObjectName != ObjectName)
            {
                return;
            }
            IObjectSpace objectSpace = new ODataObjectSpace();

            _chartView.Context.BindingSource.DataSource = objectSpace.GetObjects("Project").AsQueryable().OrderBy("name asc").ToArrayList();
        }
        void IListener <FilterChangedMessage> .Handle(FilterChangedMessage message)
        {
            if (message.ObjectName != ObjectName)
            {
                return;
            }
            IObjectSpace objectSpace = new ODataObjectSpace();

            _chartView.Context.BindingSource.DataSource = objectSpace.GetObjects("Project", message.Filter, null);
        }
示例#3
0
        private void ShowRelatedView(string relatedObjectName, string objectName, object selectedEntity)
        {
            var relationshipRoles = MetadataRepository.EntityRelationshipRoles.Where(role => role.Entity.PhysicalName == objectName && role.NavPanelDisplayOption == 1);
            EntityRelationship entityRelationship = relationshipRoles.Where(c =>
                                                                            c.EntityRelationship.EntityRelationshipRoles
                                                                            .FirstOrDefault(r => r != c &&
                                                                                            r.RelationshipRoleType != (int)RelationshipRoleType.Relationship &&
                                                                                            r.Entity.PhysicalName == relatedObjectName) != null).FirstOrDefault().EntityRelationship;
            EntityRelationshipType relationshipType = (EntityRelationshipType)entityRelationship.EntityRelationshipType;
            IObjectSpace           objectSpace      = new ODataObjectSpace();
            var    currentEntityRelationRole        = entityRelationship.EntityRelationshipRoles.Single(r => r.Entity.PhysicalName == objectName);
            string relationTitle = GetLocationCaption(currentEntityRelationRole.Entity.PhysicalName) + "-";

            if (relationshipType == EntityRelationshipType.OneToMany)
            {
                var roleType     = (RelationshipRoleType)currentEntityRelationRole.RelationshipRoleType;
                var relationship = entityRelationship.EntityRelationshipRelationships.Single().Relationship;
                if (roleType == RelationshipRoleType.OneToMany)
                {
                    var desiredEntityName   = relationship.ReferencingEntity.PhysicalName;
                    var entityId            = objectSpace.GetObjectId(objectName, selectedEntity);
                    CriteriaOperator filter = new BinaryOperator(relationship.ReferencingAttribute.Name, entityId, BinaryOperatorType.Equal);
                    var result = objectSpace.GetObjects(desiredEntityName, filter, null);
                    if (result.Count > 0)
                    {
                        var parameters = new ActionParameters(relatedObjectName, Guid.Empty, ViewShowType.Show)
                        {
                            { "FixedFilter", filter }
                        };
                        App.Instance.Invoke(relatedObjectName, "List", parameters);
                    }
                    else
                    {
                        XtraMessageBox.Show(GetLocationCaption("NoRelatedData"), GetLocationCaption("Katrin"),
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    var    entityName          = relationship.ReferencedEntity.PhysicalName;
                    string desiredPropertyName = relationship.ReferencingAttribute.PhysicalName;
                    Guid   currentId           = objectSpace.GetObjectId(objectName, selectedEntity);
                    var    currentObject       = objectSpace.GetOrNew(objectName, currentId, null);
                    var    propertyInfo        = currentObject.GetType().GetProperty(desiredPropertyName);
                    var    id = propertyInfo.GetValue(currentObject, null);
                    if (id != null)
                    {
                        var relatedObject = objectSpace.GetOrNew(this.Parameter, (Guid)id, string.Empty);
                        if (relatedObject == null)
                        {
                            MessageService.ShowMessage(GetLocationCaption("NoRelatedData"));
                            return;
                        }
                        string detail     = "Detail";
                        var    parameters = new ActionParameters(relatedObjectName, (Guid)id, ViewShowType.Show)
                        {
                            { "WorkingMode", EntityDetailWorkingMode.View }
                        };
                        App.Instance.Invoke(relatedObjectName, detail, parameters);
                    }
                    else
                    {
                        XtraMessageBox.Show(GetLocationCaption("NoRelatedData"),
                                            GetLocationCaption("Katrin"),
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                var relationshipRole = entityRelationship.EntityRelationshipRoles
                                       .Single(r => (RelationshipRoleType)r.RelationshipRoleType == RelationshipRoleType.Relationship);
                var desiredEntityRole = entityRelationship.EntityRelationshipRoles
                                        .Single(r => r != relationshipRole && r != currentEntityRelationRole);
                var desiredEntityPropertyName =
                    entityRelationship.EntityRelationshipRelationships.Select(r => r.Relationship)
                    .Single(r => r.ReferencedEntity.EntityId == desiredEntityRole.Entity.EntityId).
                    ReferencedAttribute.PhysicalName;
                var knownPropertyName = entityRelationship.EntityRelationshipRelationships.Select(r => r.Relationship)
                                        .Single(r => r.ReferencedEntity.EntityId == currentEntityRelationRole.Entity.EntityId).
                                        ReferencedAttribute.PhysicalName;

                CriteriaOperator filter = new BinaryOperator(knownPropertyName, objectSpace.GetObjectId(objectName, selectedEntity));
                var relationships       = objectSpace.GetObjects(relationshipRole.Entity.PhysicalName, filter, null);

                List <object>    desiredEntityIds = new List <object>();
                CriteriaOperator relatedFilter    = null;
                for (int index = 0; index < relationships.Count; index++)
                {
                    var relatedObject   = relationships[index];
                    var propertyInfo    = relatedObject.GetType().GetProperty(desiredEntityPropertyName);
                    var desiredEntityId = propertyInfo.GetValue(relatedObject, null);
                    desiredEntityIds.Add(desiredEntityId);
                    relatedFilter |= new BinaryOperator(desiredEntityPropertyName, desiredEntityId);
                }
                if (desiredEntityIds.Any())
                {
                    if (desiredEntityIds.Count == 1)
                    {
                        string detail     = "Detail";
                        var    parameters = new ActionParameters(relatedObjectName, (Guid)desiredEntityIds[0], ViewShowType.Show)
                        {
                            { "WorkingMode", EntityDetailWorkingMode.View }
                        };
                        App.Instance.Invoke(desiredEntityRole.Entity.PhysicalName, detail, parameters);
                    }
                    else
                    {
                        var parameters = new ActionParameters(desiredEntityRole.Entity.PhysicalName, Guid.Empty, ViewShowType.Show)
                        {
                            { "FixedFilter", relatedFilter }
                        };
                        App.Instance.Invoke(desiredEntityRole.Entity.PhysicalName, "List", parameters);
                    }
                }
                else
                {
                    XtraMessageBox.Show(GetLocationCaption("NoRelatedData"),
                                        GetLocationCaption("Katrin"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
示例#4
0
        private void VarifyUser(UserLoginResult result)
        {
            if (result.Parameter.ServerName == "")
            {
                result.Message = "Please input the server name.";
                return;
            }
            string serverUrl = string.Empty;

            if (result.Parameter.ServiceName != "")
            {
                serverUrl = result.Parameter.ServerName + "/" + result.Parameter.ServiceName;
            }
            else
            {
                serverUrl = result.Parameter.ServerName;
            }
            serverUrl = AppandProtocal(serverUrl);
            Uri serverUri;

            if (!Uri.TryCreate(serverUrl, UriKind.Absolute, out serverUri))
            {
                result.Message = "The server or service you entered is incorrect.";
                return;
            }
            bool isServerReachable = CheckConnection(serverUri);

            if (!isServerReachable)
            {
                result.Message = "The server or service you entered is not available.";
                return;
            }

            string loginPageUrl      = serverUrl + (serverUrl.EndsWith("/") ? "" : "/") + "Login.aspx";
            bool   isLogiPageAvaible = IsUrlReachable(loginPageUrl);

            if (!isLogiPageAvaible)
            {
                result.Message = "The server or service you entered is not available.";
                return;
            }


            UpdateSetting(ServerUrlSettingName, serverUrl);

            //LoadMetadata();

            string userName = result.Parameter.UserName;
            string password = result.Parameter.Password;
            var    provider = (ClientFormsAuthenticationMembershipProvider)Membership.Provider;

            provider.ServiceUri = ConfigurationManager.AppSettings["ServerUrl"] + "/Authentication_JSON_AppService.axd";
            try
            {
                if (!Membership.ValidateUser(userName, password))
                {
                    result.Message = "The username or password you entered is incorrect.";
                    return;
                }


                IObjectSpace     objectSpace    = new ODataObjectSpace();
                CriteriaOperator userNameFilter = new BinaryOperator("UserName", userName);
                var user =
                    objectSpace.GetObjects("User", userNameFilter, null)._First();

                var userId       = (Guid)user.GetType().GetProperty("UserId").GetValue(user, null);
                var fullName     = (string)user.GetType().GetProperty("FullName").GetValue(user, null);
                var extraColumns = new Dictionary <string, string> {
                    { "Role", "Role" }
                };
                var         userRoles      = objectSpace.GetObjects("UserRole", new BinaryOperator("UserId", userId), extraColumns);
                var         currentRoles   = userRoles.AsQueryable().Select("Role").ToArrayList();
                var         userPrivileges = new List <Privilege>();
                List <Guid> roleIds        = new List <Guid>();
                foreach (var roleObject in currentRoles)
                {
                    var role = (Katrin.Domain.Impl.Role)roleObject;
                    if (!roleIds.Contains(role.RoleId))
                    {
                        roleIds.Add(role.RoleId);
                    }
                    else
                    {
                        continue;
                    }
                    objectSpace.LoadProperty(role, "RolePrivileges");

                    var rolePrivileges = role.RolePrivileges;
                    foreach (var rolePrivilege in rolePrivileges)
                    {
                        objectSpace.LoadProperty(rolePrivilege, "Privilege");
                        var privilege = rolePrivilege.Privilege;
                        var name      = (string)privilege.Name;
                        objectSpace.LoadProperty(privilege, "PrivilegeEntities");
                        var privilegeEntities = privilege.PrivilegeEntities;
                        userPrivileges.AddRange(from object privilegeEntity in privilegeEntities
                                                select(string) privilegeEntity.GetType().GetProperty("EntityName")
                                                .GetValue(privilegeEntity, null)
                                                into entityName
                                                select new Privilege()
                        {
                            EntityName = entityName, Name = name
                        });
                    }
                }

                var identity  = new CustomIdentity(userId, userName, fullName);
                var principal = new CustomPrincipal(identity, userPrivileges.ToArray());
                AppDomain.CurrentDomain.SetThreadPrincipal(principal);
                result.Result = true;
                _loginSuccess = true;
            }
            catch (ThreadAbortException)
            {
                //There just catch the abort exception and then leave this catch block.
            }
            catch (Exception ex)
            {
                //result.Message = BuildExceptionString(ex);
                result.Message = ex.Message;
                MessageService.ShowException(ex);
            }
        }