Esempio n. 1
0
 protected override void OnContentChanged()
 {
     base.OnContentChanged();
     if (Content == null)
     {
         ShowSlaveUI(true);
         txtName.Clear();
         txtCPU.Clear();
         txtDetailsDescription.Clear();
         txtMemory.Clear();
         txtOS.Clear();
         txtSlaveState.Clear();
         txtLastHeartbeat.Clear();
         txtFreeMemory.Clear();
         txtId.Clear();
         txtHbIntervall.Clear();
         cbxDisposable.Checked = false;
         cbxPublic.Checked     = false;
     }
     else
     {
         if (Content.GetType() == typeof(Slave))
         {
             ShowSlaveUI(true);
             Slave ct         = (Slave)Content;
             bool  authorized = UserInformation.Instance.UserExists && (ct.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
             txtName.Text              = ct.Name;
             txtHbIntervall.Text       = ct.HbInterval.ToString();
             cbxPublic.Enabled         = authorized;
             cbxPublic.CheckedChanged -= new EventHandler(cbxPublic_CheckedChanged);
             cbxPublic.Checked         = ct.OwnerUserId == null;
             cbxPublic.CheckedChanged += new EventHandler(cbxPublic_CheckedChanged);
             txtCPU.Text = string.Format("{0} Cores @ {1} Mhz, Arch.: {2}", ct.Cores.ToString(), ct.CpuSpeed.ToString(), ct.CpuArchitecture.ToString());
             txtDetailsDescription.Text = ct.Description;
             txtMemory.Text             = ct.Memory.ToString();
             txtOS.Text            = ct.OperatingSystem;
             txtSlaveState.Text    = ct.SlaveState.ToString();
             txtLastHeartbeat.Text = ct.LastHeartbeat.ToString();
             txtFreeMemory.Text    = ct.FreeMemory.ToString();
             txtId.Text            = ct.Id.ToString();
             cbxDisposable.Enabled = authorized;
             cbxDisposable.Checked = ct.IsDisposable.GetValueOrDefault();
         }
         else if (Content.GetType() == typeof(SlaveGroup))
         {
             SlaveGroup ct = (SlaveGroup)Content;
             txtName.Text              = ct.Name;
             txtHbIntervall.Text       = ct.HbInterval.ToString();
             cbxPublic.Enabled         = ct.Name != "UNGROUPED" && HiveRoles.CheckAdminUserPermissions();
             cbxPublic.CheckedChanged -= new EventHandler(cbxPublic_CheckedChanged);
             cbxPublic.Checked         = ct.OwnerUserId == null;
             cbxPublic.CheckedChanged += new EventHandler(cbxPublic_CheckedChanged);
             ShowSlaveUI(false);
         }
         else
         {
             throw new Exception("Unknown Resource in SlaveView");
         }
     }
 }
Esempio n. 2
0
 private bool IsAuthorized(Resource resource)
 {
     return(resource != null &&
            resource.Name != UngroupedGroupName &&
            resource.Id != Guid.Empty &&
            UserInformation.Instance.UserExists &&
            (resource.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions()));
 }
Esempio n. 3
0
 public override void Execute()
 {
     if (HiveRoles.CheckHiveUserPermissions())
     {
         MainFormManager.MainForm.ShowContent(HiveClient.Instance);
     }
     else if (!UserInformation.Instance.UserExists)
     {
         MessageBox.Show(
             "Couldn't fetch user information from the server." + Environment.NewLine +
             "Please verify that you have an existing user and that your user name and password is correct.",
             "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         MessageBox.Show(
             "You do not seem to have the permissions to use the Hive Job Manager." + Environment.NewLine +
             "If that's not the case or you have any questions please write an email to [email protected]",
             "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 4
0
 private bool IsAdmin()
 {
     return(HiveRoles.CheckAdminUserPermissions());
 }
Esempio n. 5
0
        private Resource BuildResourceTree()
        {
            treeView.Nodes.Clear();

            treeView.BeforeCheck -= treeView_BeforeCheck;
            treeView.AfterCheck  -= treeView_AfterCheck;

            var resources = GetAvailableResourcesForProjectAdministration(Content.Id);

            var disabledParentResources = HiveAdminClient.Instance.DisabledParentResources;
            var mainResources           = new HashSet <Resource>(resources.OfType <SlaveGroup>().Where(x => x.ParentResourceId == null));
            //var parentedMainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>()
            //  .Where(x => x.ParentResourceId.HasValue && !resources.Select(y => y.Id).Contains(x.ParentResourceId.Value)));
            //mainResources.UnionWith(parentedMainResources);
            var mainDisabledParentResources = new HashSet <Resource>(disabledParentResources.Where(x => x.ParentResourceId == null || x.ParentResourceId == Guid.Empty));

            mainResources.UnionWith(mainDisabledParentResources);
            var subResources = new HashSet <Resource>(resources.Union(disabledParentResources).Except(mainResources).OrderByDescending(x => x.Name));

            var stack = new Stack <Resource>(mainResources.OrderByDescending(x => x.Name));

            Resource top = null;

            //bool nodeSelected = false;
            if (detailsViewHost != null && detailsViewHost.Content != null && detailsViewHost.Content is Resource)
            {
                var resourceId = ((Resource)detailsViewHost.Content).Id;
                top = resources.Where(x => x.Id == resourceId).FirstOrDefault();
            }


            TreeNode currentNode     = null;
            Resource currentResource = null;

            var addedAssignments   = newAssignedResources.Except(assignedResources);
            var removedAssignments = assignedResources.Except(newAssignedResources);
            var addedIncludes      = newIncludedResources.Except(includedResources);
            var removedIncludes    = includedResources.Except(newIncludedResources);

            while (stack.Any())
            {
                var newResource = stack.Pop();
                var newNode     = new TreeNode(newResource.Name)
                {
                    Tag = newResource
                };

                if (top == null && !disabledParentResources.Contains(newResource))
                {
                    top = newResource;
                }

                //if(!nodeSelected && top != null && newResource.Id == top.Id) {
                //  newNode.BackColor = selectedBackColor;
                //  newNode.ForeColor = selectedForeColor;
                //  nodeSelected = true;
                //}

                // search for parent node of newNode and save in currentNode
                // necessary since newNodes (stack top items) might be siblings
                // or grand..grandparents of previous node (currentNode)
                while (currentNode != null && newResource.ParentResourceId != currentResource.Id)
                {
                    currentNode     = currentNode.Parent;
                    currentResource = currentNode == null ? null : (Resource)currentNode.Tag;
                }

                if (currentNode == null)
                {
                    treeView.Nodes.Add(newNode);
                }
                else
                {
                    currentNode.Nodes.Add(newNode);
                }

                if (disabledParentResources.Contains(newResource))
                {
                    newNode.Checked   = false;
                    newNode.ForeColor = grayTextColor;
                }
                else if (newAssignedResources.Contains(newResource))
                {
                    newNode.Checked = true;
                    if (!HiveRoles.CheckAdminUserPermissions())
                    {
                        if (!HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id) ||
                            !HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).Any() ||
                            projectExclusiveResources.Contains(newResource))
                        {
                            newNode.ForeColor = SystemColors.GrayText;
                            newNode.Text     += IMMUTABLE_TAG;
                        }
                    }
                }
                else if (newIncludedResources.Contains(newResource))
                {
                    newNode.Checked   = true;
                    newNode.ForeColor = SystemColors.GrayText;
                }

                if (includedResources.Contains(newResource) && newIncludedResources.Contains(newResource))
                {
                    newNode.Text += INCLUDED_TAG;
                }
                else if (addedIncludes.Contains(newResource))
                {
                    newNode.BackColor = addedIncludeColor;
                    newNode.ForeColor = SystemColors.GrayText;
                    newNode.Text     += ADDED_INCLUDE_TAG;
                }
                else if (removedIncludes.Contains(newResource))
                {
                    newNode.BackColor = removedIncludeColor;
                    newNode.Text     += REMOVED_INCLUDE_TAG;
                }

                if (addedAssignments.Contains(newResource))
                {
                    newNode.BackColor = addedAssignmentColor;
                    newNode.ForeColor = SystemColors.ControlText;
                    newNode.Text     += ADDED_ASSIGNMENT_TAG;
                }
                else if (removedAssignments.Contains(newResource))
                {
                    newNode.BackColor = removedAssignmentColor;
                    newNode.ForeColor = SystemColors.ControlText;
                    newNode.Text     += REMOVED_ASSIGNMENT_TAG;
                }

                if (newResource is Slave)
                {
                    newNode.ImageIndex = slaveImageIndex;
                }
                else
                {
                    newNode.ImageIndex = slaveGroupImageIndex;

                    var childResources = subResources.Where(x => x.ParentResourceId == newResource.Id);
                    if (childResources.Any())
                    {
                        foreach (var resource in childResources.OrderByDescending(x => x.Name))
                        {
                            subResources.Remove(resource);
                            stack.Push(resource);
                        }
                        currentNode     = newNode;
                        currentResource = newResource;
                    }
                }
                newNode.SelectedImageIndex = newNode.ImageIndex;
            }

            ExpandResourceNodesOfInterest(treeView.Nodes);

            bool expandUngroupedGroupNode = false;
            var  ungroupedSlaves          = subResources.OfType <Slave>().OrderBy(x => x.Name);

            if (ungroupedSlaves.Any())
            {
                ungroupedGroupNode = new TreeNode(UNGROUPED_GROUP_NAME)
                {
                    ForeColor = SystemColors.GrayText,
                    Tag       = new SlaveGroup()
                    {
                        Name        = UNGROUPED_GROUP_NAME,
                        Description = UNGROUPED_GROUP_DESCRIPTION
                    }
                };

                foreach (var slave in ungroupedSlaves)
                {
                    var slaveNode = new TreeNode(slave.Name)
                    {
                        Tag = slave
                    };
                    if (newAssignedResources.Contains(slave))
                    {
                        slaveNode.Checked        = true;
                        expandUngroupedGroupNode = true;
                    }

                    if (!HiveRoles.CheckAdminUserPermissions())
                    {
                        slaveNode.ForeColor = SystemColors.GrayText;
                        slaveNode.Text     += IMMUTABLE_TAG;
                    }
                    else
                    {
                        if (addedAssignments.Contains(slave))
                        {
                            slaveNode.BackColor = addedAssignmentColor;
                            slaveNode.ForeColor = SystemColors.ControlText;
                            slaveNode.Text     += ADDED_ASSIGNMENT_TAG;
                        }
                        else if (removedAssignments.Contains(slave))
                        {
                            slaveNode.BackColor      = removedAssignmentColor;
                            slaveNode.ForeColor      = SystemColors.ControlText;
                            slaveNode.Text          += REMOVED_ASSIGNMENT_TAG;
                            expandUngroupedGroupNode = true;
                        }
                    }
                    ungroupedGroupNode.Nodes.Add(slaveNode);
                }

                if (expandUngroupedGroupNode)
                {
                    ungroupedGroupNode.Expand();
                }
                treeView.Nodes.Add(ungroupedGroupNode);
            }
            else if (ungroupedGroupNode != null)
            {
                ungroupedGroupNode.Nodes.Clear();
            }

            treeView.BeforeCheck += treeView_BeforeCheck;
            treeView.AfterCheck  += treeView_AfterCheck;

            return(top);
        }