Exemplo n.º 1
0
 public static void ToEntity(DT.SlaveGroup source, SlaveGroup target)
 {
     if ((source != null) && (target != null))
     {
         target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
     }
 }
Exemplo n.º 2
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");
         }
     }
 }
Exemplo n.º 3
0
        private void btnAddGroup_Click(object sender, EventArgs e)
        {
            SlaveGroup newGroup = new SlaveGroup();

            newGroup.Name        = "New Group";
            newGroup.OwnerUserId = UserInformation.Instance.User.Id;
            Content.Add(newGroup);
        }
Exemplo n.º 4
0
        public static SlaveGroup ToEntity(DT.SlaveGroup source)
        {
            if (source == null)
            {
                return(null);
            }
            var entity = new SlaveGroup(); ToEntity(source, entity);

            return(entity);
        }
Exemplo n.º 5
0
 public static DT.SlaveGroup ToDto(SlaveGroup source)
 {
     if (source == null)
     {
         return(null);
     }
     return(new DT.SlaveGroup {
         Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId
     });
 }
Exemplo n.º 6
0
        private void btnAddGroup_Click(object sender, EventArgs e)
        {
            var parentResourceId = selectedResource is SlaveGroup ? selectedResource.Id : (Guid?)null;

            var group = new SlaveGroup {
                Name             = "New Group",
                OwnerUserId      = UserInformation.Instance.User.Id,
                ParentResourceId = parentResourceId
            };

            SelectedResource = group;
            Content.Add(group);
        }
Exemplo n.º 7
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     foreach (Resource res in Content)
     {
         if (res is SlaveGroup && res.Id == Guid.Empty)
         {
             SlaveGroup slaveGroup = (SlaveGroup)res;
             slaveGroup.Store();
         }
         else if (res.Id != Guid.Empty && res.Modified)
         {
             res.Store();
         }
     }
 }
Exemplo n.º 8
0
        public DataSet GenerateSQL(Guid DataViewListID, out MetricTrac.Bll.DataViewList.Extend dv, out List <MasterGroup> MasterGroupList)
        {
            MasterGroupList = new List <MasterGroup>();
            dv = MetricTrac.Bll.DataViewList.Get(DataViewListID);
            string sql = SqlSelet.Replace("@InstanceId", "'" + dv.InstanceId.ToString() + "'");

            List <string> TotalOrderBy = new List <string>();
            List <string> TotalSelect  = new List <string>();

            List <ReferenceEntity.UseField> MasterGroupByFieldList = GetGroupByFieldList(ref sql, TotalOrderBy, TotalSelect, dv.GroupByList);
            List <ReferenceEntity.UseField> MasterSelectFieldList  = GetSelectFieldList(ref sql, TotalOrderBy, TotalSelect, dv.SelectList);

            List <ReferenceEntity.UseField> SlaveGroupByFieldList = GetGroupByFieldList(ref sql, TotalOrderBy, TotalSelect, dv.GroupBySlaveList);
            List <ReferenceEntity.UseField> SlaveSelectFieldList  = GetSelectFieldList(ref sql, TotalOrderBy, TotalSelect, dv.SelectSlaveList);

            if (MasterSelectFieldList.Count == 0 && SlaveSelectFieldList.Count == 0)
            {
                return(null);
            }

            DataSet                ds = MetricTrac.Bll.LinqMicajahDataContext.Execute(sql);
            DataTable              dt = ds.Tables[0];
            List <string>          PrevMasterGroupValue = new List <string>();
            List <MasterGroupNode> PrevMasterGroupNode  = new List <MasterGroupNode>();

            for (int i = 0; i < MasterGroupByFieldList.Count + SlaveGroupByFieldList.Count; i++)
            {
                PrevMasterGroupValue.Add(null);
                PrevMasterGroupNode.Add(null);
            }
            MasterGroup  mg = null;
            MasterRecord mr = null;
            MasterHeader mh = null;

            foreach (DataRow r in dt.Rows)
            {
                string OrgLocationRootColumnName = "en_FullName";
                if (dt.Columns.Contains(OrgLocationRootColumnName))
                {
                    object o = r[OrgLocationRootColumnName];
                    if (o is string && ((string)o) == "Organization Location")
                    {
                        r[OrgLocationRootColumnName] = MetricTrac.Bll.LinqMicajahDataContext.OrganizationName;
                    }
                }

                //Fill Master Group
                bool   isNewMasterGroup = false;
                string alias;
                string GroupValue;
                List <MasterGroupNode> GroupTree = null;

                for (int i = 0; i < MasterGroupByFieldList.Count; i++)
                {
                    alias      = GetAlias(MasterGroupByFieldList[i]);
                    GroupValue = r[alias].ToString();
                    if (PrevMasterGroupValue[i] != GroupValue && !isNewMasterGroup)
                    {
                        GroupTree        = new List <MasterGroupNode>();
                        isNewMasterGroup = true;
                        for (int k = 0; k < i; k++)
                        {
                            PrevMasterGroupNode[k].HeaderCount++;
                        }
                    }
                    PrevMasterGroupValue[i] = GroupValue;

                    string GroupHeader = MasterGroupByFieldList[i].Entity.ReadableName;
                    if (MasterGroupByFieldList[i].ReadableName != "Name")
                    {
                        GroupHeader += " " + MasterGroupByFieldList[i].ReadableName;
                    }

                    if (isNewMasterGroup)
                    {
                        MasterGroupNode n = new MasterGroupNode()
                        {
                            Header      = GroupHeader,
                            Value       = GroupValue,
                            HeaderCount = 1
                        };
                        GroupTree.Add(n);

                        for (int k = 0; k < i; k++)
                        {
                            PrevMasterGroupNode[k].SubGroupCount++;
                        }
                        PrevMasterGroupNode[i] = n;
                    }
                }
                if (isNewMasterGroup)
                {
                    mg = new MasterGroup()
                    {
                        GroupTree = GroupTree,

                        MasterHeaderList = new List <MasterHeader>(),
                        MasterRecordList = new List <MasterRecord>(),
                        SlaveGroupList   = new List <SlaveGroup>()
                    };
                    MasterGroupList.Add(mg);

                    foreach (var s in MasterSelectFieldList)
                    {
                        mh = new MasterHeader()
                        {
                            Header = s.Entity.ReadableName + (s.ReadableName == "Name" ? "" : (" " + s.ReadableName))
                        };
                        mg.MasterHeaderList.Add(mh);
                    }
                }

                //Fill Master Record
                bool         isNewMasterRecord = isNewMasterGroup;
                MasterRecord PrevMasterRecord  = mg.MasterRecordList.Count == 0 ? null : mg.MasterRecordList[mg.MasterRecordList.Count - 1];
                mr = new MasterRecord()
                {
                    MasterValueList = new List <MasterValue>(),
                    SlaveRecordList = new List <SlaveRecord>()
                };

                for (int i = 0; i < MasterSelectFieldList.Count; i++)
                {
                    var         s  = MasterSelectFieldList[i];
                    MasterValue mv = new MasterValue()
                    {
                        Value = GetValue(s, r)// r[GetAlias(s)].ToString()
                    };
                    mr.MasterValueList.Add(mv);
                    if (PrevMasterRecord == null || mv.Value != PrevMasterRecord.MasterValueList[i].Value)
                    {
                        isNewMasterRecord = true;
                    }
                }
                if (isNewMasterRecord)
                {
                    mg.MasterRecordList.Add(mr);
                    for (int k = 0; k < MasterGroupByFieldList.Count; k++)
                    {
                        PrevMasterGroupNode[k].RecordCount++;
                    }
                }
                else
                {
                    mr = mg.MasterRecordList[mg.MasterRecordList.Count - 1];
                }

                //Fill Slave Group
                if (mg.MasterRecordList.Count == 1)
                {
                    for (int i = 0; i < SlaveGroupByFieldList.Count; i++)
                    {
                        var        sg = SlaveGroupByFieldList[i];
                        SlaveGroup g  = new SlaveGroup()
                        {
                            Group = r[GetAlias(sg)].ToString()
                        };
                        mg.SlaveGroupList.Add(g);
                    }
                }


                //Fill Slave Records
                SlaveRecord sr = new SlaveRecord()
                {
                    SlaveValueList = new List <SlaveValue>()
                };
                mr.SlaveRecordList.Add(sr);
                for (int i = 0; i < SlaveSelectFieldList.Count; i++)
                {
                    var column = SlaveSelectFieldList[i];
                    //object v = r[GetAlias(column)];
                    SlaveValue sv = new SlaveValue()
                    {
                        Value = GetValue(column, r)//v == null ? null : v.ToString()
                    };
                    sr.SlaveValueList.Add(sv);
                }
            }

            /*for (int i = 0; i < MasterGroupList.Count; i++)
             * {
             *  var MG = MasterGroupList[i];
             *
             *  for (int k = i + 1; k < MasterGroupList.Count; k++)
             *  {
             *      if (MG.GroupTree.Count <= ChildMG.GroupTree.Count) break;
             *  }
             * }*/


            return(ds);
        }
Exemplo n.º 9
0
 private void btnAddGroup_Click(object sender, EventArgs e) {
   SlaveGroup newGroup = new SlaveGroup();
   newGroup.Name = "New Group";
   newGroup.OwnerUserId = UserInformation.Instance.User.Id;
   Content.Add(newGroup);
 }
Exemplo n.º 10
0
    protected override void OnContentChanged() {
      base.OnContentChanged();
      if (Content == null) {
        slaveView.Content = null;
        scheduleView.Content = null;
        permissionView.Content = null;
        permissionView.FetchSelectedUsers = null;
        treeSlaveGroup.Nodes.Clear();
      } else {
        permissionView.Content = Access.AccessClient.Instance;
        treeSlaveGroup.Nodes.Clear();

        //rebuild
        TreeNode ungrp = new TreeNode(UngroupedGroupName);
        ungrp.ImageIndex = slaveGroupImageIndex;
        ungrp.SelectedImageIndex = ungrp.ImageIndex;
        var newGroup = new SlaveGroup();
        newGroup.Name = UngroupedGroupName;
        newGroup.Id = Guid.NewGuid();
        newGroup.Description = "Contains slaves which are in no group";
        ungrp.Tag = newGroup;

        foreach (Resource g in Content) {
          if (g.GetType() == typeof(SlaveGroup)) {
            //root node
            if (g.ParentResourceId == null) {
              TreeNode tn = new TreeNode();
              tn.ImageIndex = slaveGroupImageIndex;
              tn.SelectedImageIndex = tn.ImageIndex;

              tn.Tag = g;
              tn.Text = g.Name;
              if (g.OwnerUserId == Access.UserInformation.Instance.User.Id) tn.BackColor = ownedResourceColor;

              BuildSlaveGroupTree(g, tn);
              treeSlaveGroup.Nodes.Add(tn);
            }
          } else if (g.GetType() == typeof(Slave)) {
            if (g.ParentResourceId == null) {
              var stn = new TreeNode(g.Name);
              stn.ImageIndex = slaveImageIndex;
              stn.SelectedImageIndex = stn.ImageIndex;
              stn.Tag = g;
              if (g.OwnerUserId == Access.UserInformation.Instance.User.Id) stn.BackColor = ownedResourceColor;
              ungrp.Nodes.Add(stn);
            }
          }
        }
        treeSlaveGroup.Nodes.Add(ungrp);
      }
    }
Exemplo n.º 11
0
        private void treeSlaveGroup_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                Point    pt       = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                TreeNode destNode = ((TreeView)sender).GetNodeAt(pt);
                TreeNode newNode  = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");

                if (destNode.TreeView == newNode.TreeView)
                {
                    if (destNode.Text == UngroupedGroupName || (destNode.Parent != null && destNode.Parent.Text == UngroupedGroupName))
                    {
                        MessageBox.Show(string.Format("You can't drag items to the group \"{0}\".{1}This group only contains slaves which haven't yet been assigned to a real group.",
                                                      UngroupedGroupName, Environment.NewLine), "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    SlaveGroup sgrp       = null;
                    TreeNode   parentNode = null;
                    if (destNode.Tag != null && destNode.Tag is SlaveGroup)
                    {
                        sgrp       = (SlaveGroup)destNode.Tag;
                        parentNode = destNode;
                    }
                    else if (destNode.Parent != null && destNode.Parent.Tag is SlaveGroup)
                    {
                        sgrp       = (SlaveGroup)destNode.Parent.Tag;
                        parentNode = destNode.Parent;
                    }

                    if (newNode.Tag is SlaveGroup && CheckParentsEqualsMovedNode(parentNode, newNode))
                    {
                        return;
                    }

                    SlaveGroup parent = (SlaveGroup)parentNode.Tag;

                    if (parent.OwnerUserId != null && !IsAuthorized(parent))
                    {
                        MessageBox.Show(string.Format("You don't have the permissions to drag items to the group \"{0}\".", ((Resource)parentNode.Tag).Name),
                                        "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (sgrp != null && newNode.Tag != null)
                    {
                        //save parent group to get an id
                        if (sgrp.Id == Guid.Empty)
                        {
                            sgrp.Store();
                        }

                        if (newNode.Tag is Slave)
                        {
                            Slave slave = (Slave)newNode.Tag;
                            if (slave.ParentResourceId == null || (slave.ParentResourceId != null && slave.ParentResourceId != sgrp.Id))
                            {
                                slave.ParentResourceId = sgrp.Id;
                                newNode.Remove();
                                parentNode.Nodes.Clear();
                                BuildSlaveGroupTree(sgrp, parentNode);
                            }
                        }
                        else if (newNode.Tag is SlaveGroup)
                        {
                            SlaveGroup slaveGroup = (SlaveGroup)newNode.Tag;
                            if (slaveGroup.ParentResourceId == null || (slaveGroup.ParentResourceId != null && slaveGroup.ParentResourceId != sgrp.Id))
                            {
                                slaveGroup.ParentResourceId = sgrp.Id;
                                newNode.Remove();
                                parentNode.Nodes.Clear();
                                BuildSlaveGroupTree(sgrp, parentNode);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        protected override void OnContentChanged()
        {
            base.OnContentChanged();
            if (Content == null)
            {
                slaveView.Content                 = null;
                scheduleView.Content              = null;
                permissionView.Content            = null;
                permissionView.FetchSelectedUsers = null;
                treeSlaveGroup.Nodes.Clear();
            }
            else
            {
                permissionView.Content = Access.AccessClient.Instance;
                treeSlaveGroup.Nodes.Clear();

                //rebuild
                TreeNode ungrp = new TreeNode(UngroupedGroupName);
                ungrp.ImageIndex         = slaveGroupImageIndex;
                ungrp.SelectedImageIndex = ungrp.ImageIndex;
                var newGroup = new SlaveGroup();
                newGroup.Name        = UngroupedGroupName;
                newGroup.Id          = Guid.NewGuid();
                newGroup.Description = "Contains slaves which are in no group";
                ungrp.Tag            = newGroup;

                foreach (Resource g in Content)
                {
                    if (g.GetType() == typeof(SlaveGroup))
                    {
                        //root node
                        if (g.ParentResourceId == null)
                        {
                            TreeNode tn = new TreeNode();
                            tn.ImageIndex         = slaveGroupImageIndex;
                            tn.SelectedImageIndex = tn.ImageIndex;

                            tn.Tag  = g;
                            tn.Text = g.Name;
                            if (g.OwnerUserId == Access.UserInformation.Instance.User.Id)
                            {
                                tn.BackColor = ownedResourceColor;
                            }

                            BuildSlaveGroupTree(g, tn);
                            treeSlaveGroup.Nodes.Add(tn);
                        }
                    }
                    else if (g.GetType() == typeof(Slave))
                    {
                        if (g.ParentResourceId == null)
                        {
                            var stn = new TreeNode(g.Name);
                            stn.ImageIndex         = slaveImageIndex;
                            stn.SelectedImageIndex = stn.ImageIndex;
                            stn.Tag = g;
                            if (g.OwnerUserId == Access.UserInformation.Instance.User.Id)
                            {
                                stn.BackColor = ownedResourceColor;
                            }
                            ungrp.Nodes.Add(stn);
                        }
                    }
                }
                treeSlaveGroup.Nodes.Add(ungrp);
            }
        }