Exemplo n.º 1
0
        public override void Run()
        {
            if (!(this.Owner is ObjectController))
            {
                return;
            }
            ObjectController objectController = (ObjectController)this.Owner;
            IObjectSpace     objectSpace      = new ODataObjectSpace();
            var selectedId = objectSpace.GetObjectId(objectController.ObjectName, objectController.SelectedObject);
            var parameters = new ActionParameters(objectName, Guid.Empty, ViewShowType.Show)
            {
                { "ProjectId", selectedId },
                { "WorkingMode", workMode }
            };

            if (string.IsNullOrEmpty(objectName))
            {
                objectName = objectController.ObjectName;
                parameters = new ActionParameters(objectName, selectedId, ViewShowType.Show)
                {
                    { "WorkingMode", workMode }
                };
            }
            App.Instance.Invoke(objectName, "Detail", parameters);
        }
Exemplo n.º 2
0
        void View_OnSendSysMessage(object sender, EventArgs e)
        {
            IObjectSpace objectSpace    = new ODataObjectSpace();
            var          notification   = (Katrin.Domain.Impl.Notification)objectSpace.GetOrNew("Notification", Guid.Empty, "NotificationRecipients");
            Guid         notificationId = notification.NotificationId;

            notification.ObjectType = "sysMsg";
            notification.Subject    = _sysMessageData.Subject;
            notification.Body       = _sysMessageData.Body;
            var recipients = notification.NotificationRecipients;

            //Type recipientType = DynamicTypeBuilder.Instance.GetDynamicType("NotificationRecipient");
            foreach (Guid receiverId in _sendView.GetReceiverList())
            {
                if (receiverId == AuthorizationManager.CurrentUserId)
                {
                    continue;
                }
                var recipient = new Katrin.Domain.Impl.NotificationRecipient();
                recipient.NotificationRecipientId = Guid.NewGuid();
                recipient.NotificationId          = notificationId;
                recipient.RecipientId             = receiverId;
                recipient.NotificationStatus      = "NotSend";
                recipients.Add(recipient);
            }
            objectSpace.SaveChanges();
            _sendView.CloseView();
        }
Exemplo n.º 3
0
 public bool CopyAndNew()
 {
     _detailView.PostEditors();
     OnSaving();
     if (!_detailView.ValidateData())
     {
         return(false);
     }
     if (NewEntityId == Guid.Empty)
     {
         _objectSpace = new ODataObjectSpace();
         ObjectId     = NewEntityId;
         var newEntity  = GetEntity();
         var metaEntity = MetadataRepository.Entities.Where(c => c.PhysicalName == ObjectName).FirstOrDefault();
         foreach (var att in metaEntity.Attributes)
         {
             if (att.IsCopyEnabled ?? false)
             {
                 SetProperValue(ObjectEntity, att.TableColumnName, newEntity, att.TableColumnName);
             }
         }
         ObjectEntity = newEntity;
         WorkingMode  = EntityDetailWorkingMode.Add;
         RefreshEntityId(newEntity);
         NewEntityId = ObjectId;
         BindData(ObjectEntity);
     }
     return(true);
 }
Exemplo n.º 4
0
        private object ConvertEntity(object soruceObject, string sourceOjbectName, string targetObjectName)
        {
            IObjectSpace obojectSpace = new ODataObjectSpace();
            var          targetType   = obojectSpace.ResolveType(targetObjectName);
            var          targetObject = Activator.CreateInstance(targetType);

            obojectSpace.SetEntityId(targetObjectName, targetObject, Guid.NewGuid());
            var mappingList = GetMappingList(sourceOjbectName, targetObjectName);

            foreach (var mappingItem in mappingList)
            {
                SetProperValue(soruceObject, mappingItem.SourceAttributeName, targetObject, mappingItem.TargetAttributeName);
            }
            string convertPath = "/ConvertObject/" + targetObjectName;

            if (AddInTree.ExistsTreeNode(convertPath))
            {
                var descriptor = AddInTree.BuildItems <IObjectConvert>(convertPath, null);
                if (descriptor != null && descriptor.Count() > 0)
                {
                    descriptor.First().ConvertObject(soruceObject, targetObject);
                }
            }
            SetFieldValue(targetObject, "CreatedOn", DateTime.Now);
            SetFieldValue(targetObject, "CreatedById", AuthorizationManager.CurrentUserId);
            SetFieldValue(targetObject, "OwnerId", AuthorizationManager.CurrentUserId);
            SetFieldValue(targetObject, "ModifiedOn", DateTime.Now);
            SetFieldValue(targetObject, "ModifiedById", AuthorizationManager.CurrentUserId);
            return(targetObject);
        }
Exemplo n.º 5
0
        private static void DelButtonClick(object sender, AlertButtonClickEventArgs e)
        {
            var notifcation = e.AlertForm.AlertInfo.Tag as NotificationDTO;

            if (notifcation == null)
            {
                return;
            }
            if (notifcation.NotificationRecipientId == Guid.Empty)
            {
                return;
            }
            IObjectSpace objectSpace = new ODataObjectSpace();

            if (e.ButtonName == "DelNotification")
            {
                e.Button.Name = "Deleted";
                var recipent = objectSpace.GetOrNew("NotificationRecipient", notifcation.NotificationRecipientId, null);
                objectSpace.DeleteObject("NotificationRecipient", recipent);
                objectSpace.SaveChanges();
                notifcation.NotificationRecipientId = Guid.Empty;
                timer_Elapsed(null, null);
            }
            else if (e.ButtonName == "MarkReaded")
            {
                e.Button.Name = "Marked";
                MarkReaded(objectSpace, notifcation);
                e.Button.Image = new Bitmap(WinFormsResourceService.GetBitmap("sendsysmsg"), new Size(16, 16));
                timer_Elapsed(null, null);
            }
        }
Exemplo n.º 6
0
        private static List <LookupListItem <Guid?> > GetLookupValues(bool withEmptyRow, EntityAttribute attribute)
        {
            var    lookupValue       = attribute.AttributeLookupValues.First();
            var    lookupValueEntity = lookupValue.Entity;
            string displayMemberName =
                lookupValueEntity.Attributes.First(a => a.AttributeId == lookupValue.DisplayEntityAttributeId).PhysicalName;
            string valueMemberName = lookupValueEntity.Name + "Id";
            var    values          = new ODataObjectSpace().GetObjects(lookupValueEntity.PhysicalName);

            var items = new List <LookupListItem <Guid?> >();

            foreach (var value in values)
            {
                var    item        = new LookupListItem <Guid?>();
                object displayName = value.GetType().GetProperty(displayMemberName).GetValue(value, null);
                if (displayName != null)
                {
                    item.DisplayName = displayName.ToString();
                    item.Value       = (Guid)value.GetType().GetProperty(valueMemberName).GetValue(value, null);
                    items.Add(item);
                }
            }
            if (withEmptyRow)
            {
                items.Insert(0, new LookupListItem <Guid?>());
            }
            return(items);
        }
Exemplo n.º 7
0
        private static void ShowNotifications(IList notificationInfos, RibbonForm form)
        {
            IObjectSpace objectSpace  = new ODataObjectSpace();
            AlertControl alertControl = new AlertControl();

            alertControl.AutoHeight = true;
            AlertButton setReaded = new AlertButton(new Bitmap(WinFormsResourceService.GetBitmap("notification"), new Size(16, 16)));

            setReaded.Style = AlertButtonStyle.CheckButton;
            setReaded.Down  = false;
            setReaded.Hint  = "Mark Readed";
            setReaded.Name  = "MarkReaded";
            alertControl.Buttons.Add(setReaded);
            AlertButton deleteBtn = new AlertButton(new Bitmap(WinFormsResourceService.GetBitmap("overlay_delete"), new Size(16, 16)));

            deleteBtn.Style = AlertButtonStyle.CheckButton;
            deleteBtn.Down  = false;
            deleteBtn.Hint  = "Delete Notification";
            deleteBtn.Name  = "DelNotification";
            alertControl.Buttons.Add(deleteBtn);
            alertControl.ButtonClick    += new AlertButtonClickEventHandler(DelButtonClick);
            alertControl.BeforeFormShow += (sender, e) =>
            {
                e.AlertForm.BackgroundImage       = WinFormsResourceService.GetBitmap("nback");
                e.AlertForm.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;

                int l = 1;
                while (e.AlertForm.AlertInfo.Text.Length > 12 * l)
                {
                    e.AlertForm.AlertInfo.Text = e.AlertForm.AlertInfo.Text.Insert(12 * l, " ");
                    l++;
                }
                e.AlertForm.Size = new System.Drawing.Size(320, 300);
            };
            alertControl.AlertClick += (sender, e) =>
            {
                NotificationDTO data = (NotificationDTO)e.Info.Tag;
                MarkReaded(objectSpace, data);
                e.AlertForm.Tag       = data;
                e.AlertForm.Disposed += AlertForm_Disposed;
                e.AlertForm.Close();
            };

            AlertManage manager = new AlertManage(alertControl, form);

            foreach (var notificationInfo in notificationInfos)
            {
                var pro = notificationInfo.GetType().GetProperty("NotificationRecipientId");
                if (pro == null)
                {
                    continue;
                }
                Guid notificationRecipientId = (Guid)pro.GetValue(notificationInfo, null);
                var  notificationUser        = (Katrin.Domain.Impl.NotificationRecipient)objectSpace.GetOrNew("NotificationRecipient", notificationRecipientId, null);
                notificationUser.NotificationStatus = "Opened";
                manager.ShowAlert((NotificationDTO)notificationInfo);
            }
            objectSpace.SaveChanges();
        }
        public static IList ListData(string entityName, CriteriaOperator criteria)
        {
            var          projections  = GridViewExtension.GetColumnProjections(entityName);
            var          fetchColumns = projections.Select(p => string.Format("{0} AS {1}", p.QueryExpression, p.Projection)).ToArray();
            var          selector     = string.Format("new({0})", string.Join(",", fetchColumns));
            IObjectSpace objectSpace  = new ODataObjectSpace();

            return(objectSpace.GetObjectQuery(entityName, selector, criteria).ToList());
        }
        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();
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        private System.Collections.IList QueryData()
        {
            IObjectSpace objectSpace        = new ODataObjectSpace();
            var          projections        = GridViewExtension.GetColumnProjections(_objectName, _addtionProperties);
            var          propertyDictionary = projections.ToDictionary(cp => cp.Projection, cp => cp.QueryExpression);
            var          fetchColumns       = propertyDictionary.Select(kvp => string.Format("{0} AS {1}", kvp.Value, kvp.Key)).ToArray();
            var          selector           = string.Format("new({0})", string.Join(",", fetchColumns));
            var          list = objectSpace.GetObjectQuery(_objectName, selector, _filter).ToList();

            return(list);
        }
Exemplo n.º 12
0
        public override void Run()
        {
            if (!(this.Owner is ListController))
            {
                return;
            }
            ListController listController = (ListController)this.Owner;
            IObjectSpace   objectSpace    = new ODataObjectSpace();
            var            selectedId     = objectSpace.GetObjectId(listController.ObjectName, listController.SelectedObject);
            var            parameters     = new ActionParameters("ProjectTaskEffort", selectedId, ViewShowType.Show)
            {
                { "WorkingMode", EntityDetailWorkingMode.Edit }
            };

            App.Instance.Invoke("ProjectTaskEffort", "Detail", parameters);
        }
Exemplo n.º 13
0
        public override void Run()
        {
            if (!(Owner is ObjectController))
            {
                return;
            }
            ObjectController objectController = (ObjectController)Owner;
            string           objectName       = objectController.ObjectName;
            Guid             selectedId       = Guid.Empty;
            IObjectSpace     objectSpace      = new ODataObjectSpace();

            selectedId = objectSpace.GetObjectId(objectName, objectController.SelectedObject);
            var parameters = new ActionParameters(objectName, selectedId, ViewShowType.Show);

            App.Instance.Invoke("TimeTrackingDetail", "TimeTrackingAction", parameters);
        }
Exemplo n.º 14
0
        private int GetDataSourceIndex(IList datas, Guid oldguid)
        {
            IObjectSpace objectSpace = new ODataObjectSpace();

            int index = 0;

            foreach (object obj in datas)
            {
                Guid guid = objectSpace.GetObjectId(this.ObjectName, obj);
                if (guid == oldguid)
                {
                    return(index);
                }
                index++;
            }

            return(-1);
        }
Exemplo n.º 15
0
        public void InitData(string objectTypeName)
        {
            treeList1.FocusedNodeChanged -= treeList1_FocusedNodeChanged;
            treeList1.Nodes.Clear();
            ImageList columnImageList = new ImageList();

            columnImageList.Images.Add(WinFormsResourceService.GetIcon("all").ToBitmap());
            columnImageList.Images.SetKeyName(0, string.Empty);
            treeList1.SelectImageList = columnImageList;

            var root = treeList1.AppendNode(new object[] { ResourceService.GetString("All"), string.Empty, 0 }, null);

            root.SetValue(colFilters, string.Empty);
            IObjectSpace objectSpace = new ODataObjectSpace();

            var notificationQuery = (List <NotificationDTO>)AuthorizationManager.NotificationList.List;
            var objectTypes       = notificationQuery.Select(c => c.ObjectTypeEn).Distinct().ToList();

            if (objectTypes.Contains("sysMsg"))
            {
                objectTypes.Remove("sysMsg");
                objectTypes.Insert(0, "sysMsg");
            }

            int           imageIndex = 1;
            List <string> noteType   = new List <string>();

            foreach (var item in objectTypes)
            {
                columnImageList.Images.Add(WinFormsResourceService.GetIcon(item.ToLower()).ToBitmap());
                columnImageList.Images.SetKeyName(imageIndex, string.Empty);
                int ncount = notificationQuery.Where(c => c.ObjectTypeEn == item && c.NotificationStatus == 1).Count();
                var node   = treeList1.AppendNode(new object[] { ResourceService.GetString(item) + "(" + ncount + ")", string.Empty, string.Empty, imageIndex }, root);
                if (item == objectTypeName)
                {
                    node.Selected = true;
                }
                node.SetValue(colFilters, "[ObjectTypeEn] = '" + item + "'");
                node.SetValue(colNodeName, item);
                imageIndex++;
            }
            treeList1.ExpandAll();
            treeList1.FocusedNodeChanged += treeList1_FocusedNodeChanged;
        }
Exemplo n.º 16
0
        public override void Run()
        {
            if (!(Owner is ObjectController))
            {
                return;
            }
            ObjectController objectController = (ObjectController)Owner;
            string           objectName       = objectController.ObjectName;
            Guid             selectedId       = Guid.Empty;
            IObjectSpace     objectSpace      = new ODataObjectSpace();

            selectedId = objectSpace.GetObjectId(objectName, objectController.SelectedObject);
            var parameters = new ActionParameters(objectName, selectedId, ViewShowType.Show);

            if (Owner is NoteController)
            {
                parameters.Add("ParentObjectName", ((NoteController)Owner).ParentObjectName);
            }
            App.Instance.Invoke("NoteDetail", "NoteAction", parameters);
        }
Exemplo n.º 17
0
        public void MoveTaskToIteration(Guid?iterationId)
        {
            IObjectSpace iobjectSpace  = new ODataObjectSpace();
            Guid         projectTaskId = this._objectSpace.GetObjectId(this.ObjectName, this.SelectedObject);
            object       projectTask   = iobjectSpace.GetOrNew(this.ObjectName, projectTaskId, null);

            Katrin.Domain.Impl.ProjectTask task = projectTask as Katrin.Domain.Impl.ProjectTask;
            task.ProjectIterationId = iterationId;
            iobjectSpace.SaveChanges();
            this.BindListData();

            //update detail
            IList <ProjectTaskDetailController> controllers =
                this.Context.AppContext.ControllerFinder.FinController <ProjectTaskDetailController>("ProjectTaskDetail");
            var detailControllers = controllers.Where(p => p.ObjectId == task.TaskId);

            foreach (var controller in detailControllers)
            {
                controller.UpdateIteration(iterationId);
            }
        }
Exemplo n.º 18
0
        public override void Run()
        {
            Guard.ObjectIsInstanceOfType(Owner, typeof(ISelection), "Owner");
            Guard.ObjectIsInstanceOfType(Owner, typeof(IObjectAware), "Owner");
            var selection   = (ISelection)Owner;
            var objectAware = (IObjectAware)Owner;

            IObjectSpace objectSpace = new ODataObjectSpace();
            Guid         selectedId  = Guid.Empty;

            if (_workMode != EntityDetailWorkingMode.Add)
            {
                selectedId = objectSpace.GetObjectId(objectAware.ObjectName, selection.SelectedObject);
            }
            var parameters = new ActionParameters(objectAware.ObjectName, selectedId, ViewShowType.Show)
            {
                { "WorkingMode", _workMode }
            };
            var controllerName = objectAware.ObjectName;

            App.Instance.Invoke(controllerName, "Detail", parameters);
        }
Exemplo n.º 19
0
        public override void Run()
        {
            var detailController = this.Owner as IObjectDetailController;

            if (detailController != null)
            {
                IController controller = this.Owner as IController;

                var message = new ActivateViewMessage(controller.WorkSpaceID, "History");
                message.Parameters = new ActionParameters(detailController.ObjectName, detailController.ObjectId, ViewShowType.Show);
                EventAggregationManager.SendMessage(message);
            }
            else
            {
                ObjectController objectController = (ObjectController)this.Owner;
                IObjectSpace     objectSpace      = new ODataObjectSpace();
                var selectedId = objectSpace.GetObjectId(objectController.ObjectName, objectController.SelectedObject);
                var parameters = new ActionParameters(objectController.ObjectName, selectedId, ViewShowType.Show);
                App.Instance.Invoke("History", "List", parameters);
                //message.Parameters = new ActionParameters(objectController.ObjectName,selectedId, ViewShowType.Show);
            }
        }
Exemplo n.º 20
0
        public static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //ReduceMemory();
            IObjectSpace objectSpace = new ODataObjectSpace();

            AuthorizationManager.NotificationList.DataSource = GetListData(objectSpace);
            var notificationInfos = ((List <NotificationDTO>)AuthorizationManager.NotificationList.List).Where(c => c.NotificationStatusName == "NotSend").ToList(); //objectSpace.GetObjects("NotificationRecipient", filter, additionProperties);

            if (notificationInfos.Count <= 0)
            {
                return;
            }
            RibbonForm form = _ribbonForm;

            if (form == null)
            {
                return;
            }
            ShowNotificationDelegate s = new ShowNotificationDelegate(ShowNotifications);

            form.BeginInvoke(s, notificationInfos, form);
        }
Exemplo n.º 21
0
        public static List <ColumnProjection> GetColumnProjections(string entityName, List <string> includingPath)
        {
            var              entity           = MetadataRepository.Entities.Single(e => e.PhysicalName == entityName);
            GridView         gridView         = new GridView();
            ODataObjectSpace objSpace         = new ODataObjectSpace();
            IEdmEntityType   entityType       = objSpace.GetTypeDefinition(entityName);
            string           detailLayout     = string.Empty;
            var              defaultLayoutXml = GetDefaultLayout(entityName, ref detailLayout);

            gridView.RestoreLayoutFromString(defaultLayoutXml);
            var projections = gridView.Columns.Cast <GridColumn>()
                              .Where(column => !string.IsNullOrEmpty(column.FieldName) && entityType.FindProperty(column.FieldName) != null)
                              .Select(column => new ColumnProjection(column.FieldName, entity)).ToList();

            gridView.Dispose();
            gridView = null;

            var keyFeildName = entityType.Key().First().Name;
            ColumnProjection keyColumnProjection = new ColumnProjection(keyFeildName, entity);

            if (!projections.Any(p => p.PropertyPath == keyFeildName))
            {
                projections.Add(keyColumnProjection);
            }
            if (includingPath != null)
            {
                foreach (var includItem in includingPath)
                {
                    ColumnProjection includColumnProjection = new ColumnProjection(includItem, entity);
                    if (!projections.Contains(includColumnProjection))
                    {
                        projections.Add(includColumnProjection);
                    }
                }
            }
            return(projections);
        }
Exemplo n.º 22
0
        public override void Run()
        {
            if (!(this.Owner is ObjectController))
            {
                return;
            }
            ObjectController objectController = (ObjectController)this.Owner;
            IObjectSpace     objectSpace      = new ODataObjectSpace();
            var selectedId = objectSpace.GetObjectId(objectController.ObjectName, objectController.SelectedObject);
            var parameters = new ActionParameters(objectName, Guid.Empty, ViewShowType.Show)
            {
                { "ProjectId", selectedId },
                { "WorkingMode", workMode }
            };

            if (string.IsNullOrEmpty(objectName))
            {
                objectName = objectController.ObjectName;
                parameters = new ActionParameters(objectName, selectedId, ViewShowType.Show)
                {
                    { "WorkingMode", workMode }
                };
            }
            BaseController filterController = objectController.Context.ControllerFinder.FindController <BaseController>("BaseControllerList");

            if (filterController != null)
            {
                Guid?projectId   = filterController.GetSelectedFilterProjectId();
                Guid?memberId    = filterController.GetSelectedMemberId();
                Guid?iterationId = filterController.GetSelectedIterationId();
                parameters.Add("ProjectId", projectId);
                parameters.Add("MemberId", memberId);
                parameters.Add("IterationId", iterationId);
            }
            App.Instance.Invoke(objectName, "Detail", parameters);
        }
Exemplo n.º 23
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);
                }
            }
        }
Exemplo n.º 24
0
        public static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <UIElementAdapterFactoryCatalog>().As <IUIElementAdapterFactoryCatalog>().SingleInstance();
            var container = builder.Build();

            IoC.GetInstance = (t, p) => container.Resolve(t);

            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            SkinManager.EnableFormSkins();
            BonusSkins.Register();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CriteriaOperator.RegisterCustomFunction(new IsDuringDaysFunction());
            CriteriaOperator.RegisterCustomFunction(new IsEarlierNextWeekFunction());
            CriteriaOperator.RegisterCustomFunction(new IsLastMonthFunction());
            CriteriaOperator.RegisterCustomFunction(new IsPriorDaysFunction());

            DevExpress.Utils.AppearanceObject.DefaultFont = System.Drawing.SystemFonts.DefaultFont;

            // The LoggingService is a small wrapper around log4net.
            // Our application contains a .config file telling log4net to write
            // to System.Diagnostics.Trace.
            ICSharpCode.Core.Services.ServiceManager.Instance = new Katrin.AppFramework.WinForms.Services.ServiceManager();
            LoggingService.Info("Application start");

            // Get a reference to the entry assembly (Startup.exe)
            Assembly exe = typeof(Program).Assembly;

            // Set the root path of our application. ICSharpCode.Core looks for some other
            // paths relative to the application root:
            // "data/resources" for language resources, "data/options" for default options
            FileUtility.ApplicationRootPath = Path.GetDirectoryName(exe.Location);

            LoggingService.Info("Starting core services...");

            // CoreStartup is a helper class making starting the Core easier.
            // The parameter is used as the application name, e.g. for the default title of
            // MessageService.ShowMessage() calls.
            CoreStartup coreStartup = new CoreStartup("Katrin");

            // It is also used as default storage location for the application settings:
            // "%Application Data%\%Application Name%", but you can override that by setting c.ConfigDirectory

            // Specify the name of the application settings file (.xml is automatically appended)
            coreStartup.PropertiesName = "AppProperties";

            // Initializes the Core services (ResourceService, PropertyService, etc.)
            coreStartup.StartCoreServices();

            // Registeres the default (English) strings and images. They are compiled as
            // "EmbeddedResource" into Startup.exe.
            // Localized strings are automatically picked up when they are put into the
            // "data/resources" directory.
            ResourceService.RegisterNeutralStrings(new ResourceManager("Katrin.Shell.Resources.StringResources", exe));
            ResourceService.RegisterNeutralImages(new ResourceManager("Katrin.Shell.Resources.ImageResources", exe));

            System.Threading.Thread.CurrentThread.CurrentCulture = CultureManager.CurrentCulture;
            ResourceService.Language = CultureManager.CurrentCulture.Name;

            LoggingService.Info("Looking for AddIns...");
            // Searches for ".addin" files in the application directory.
            coreStartup.AddAddInsFromDirectory(Path.Combine(FileUtility.ApplicationRootPath, "AddIns"));

            // Searches for a "AddIns.xml" in the user profile that specifies the names of the
            // add-ins that were deactivated by the user, and adds "external" AddIns.
            coreStartup.ConfigureExternalAddIns(Path.Combine(PropertyService.ConfigDirectory, "AddIns.xml"));

            // Searches for add-ins installed by the user into his profile directory. This also
            // performs the job of installing, uninstalling or upgrading add-ins if the user
            // requested it the last time this application was running.
            coreStartup.ConfigureUserAddIns(Path.Combine(PropertyService.ConfigDirectory, "AddInInstallTemp"),
                                            Path.Combine(PropertyService.ConfigDirectory, "AddIns"));

            LoggingService.Info("Loading AddInTree...");
            // Now finally initialize the application. This parses the ".addin" files and
            // creates the AddIn tree. It also automatically runs the commands in
            // "/Workspace/Autostart"
            coreStartup.RunInitialization();

            LoggingService.Info("Initializing Workbench...");
            // Workbench is our class from the base project, this method creates an instance
            // of the main form.
            LoginForm loginForm = new LoginForm();

            loginForm.ShowDialog();

            try
            {
                LoggingService.Info("Running application...");
                // Workbench.Instance is the instance of the main form, run the message loop.
                if (SecurityContext.IsLogon)
                {
                    var catalog = IoC.Get <IUIElementAdapterFactoryCatalog>();
                    catalog.RegisterFactory(new XtraNavBarUIAdapterFactory());
                    catalog.RegisterFactory(new XtraBarUIAdapterFactory());
                    catalog.RegisterFactory(new RibbonUIAdapterFactory());
                    catalog.RegisterFactory(new NavigatorCustomButtonUIAdapterFactory());
                    catalog.RegisterFactory(new EditorButtonCollectionUIAdapterFactory());

                    ODataObjectSpace.Initialize();
                    MetadataRepository.Initialize();

                    MainForm mainForm = new MainForm();
                    mainForm.FormClosed += mainForm_FormClosed;
                    mainForm.Show();

                    Application.Run();
                }
            }
            catch (Exception ex)
            {
                MessageService.ShowException(ex, ex.Message);
            }
            finally
            {
                LoadingFormManager.EndLoading();
                try
                {
                    // Save changed properties
                    PropertyService.Save();
                }
                catch (Exception ex)
                {
                    MessageService.ShowException(ex, ex.Message);
                }
            }

            LoggingService.Info("Application shutdown");
        }
Exemplo n.º 25
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);
            }
        }