private void DragSource_DragStart(object sender, Infragistics.DragDrop.DragDropStartEventArgs e) { var rightTreeVm = PageNavigatorHelper.GetRightElementViewModel(); rightTreeVm.SetNodeDropable(); var xdt = e.DragSource as Border; var cpr = xdt.TryFindParent <Expander>(); var ep = cpr.DataContext as PolicyElementViewModel; var dragSource = sender as DragSource; DataTemplate cardLayout = new DataTemplate(); cardLayout.DataType = typeof(StackPanel); FrameworkElementFactory cardHolder = new FrameworkElementFactory(typeof(TextBlock)); cardHolder.SetValue(TextBlock.TextProperty, ep.Name); cardHolder.SetValue(TextBlock.ForegroundProperty, (SolidColorBrush)(new BrushConverter().ConvertFrom(ep.ExpanderBackgroundColor))); cardLayout.VisualTree = cardHolder; dragSource.DragTemplate = cardLayout; }
private void EndPointDataGrid_OnSelectedItemsChanged(object sender, SelectedItemsChangedEventArgs e) { var source = e.Source as XamDataGrid; if (source != null) { var ep = source.ActiveDataItem as EndPoint; if (ep != null) { var rightModel = PageNavigatorHelper.GetRightElementViewModel(); Thread.Sleep(500); if (rightModel != null && rightModel.DirectoryPushed) { var dir = ApplicationContext.FolderListAll.Find(r => r.FolderId == ep.FolderId); var listNodes = new List <int>(); GetParentListId(listNodes, dir); PageNavigatorHelper.GetRightElementViewModel().SelectTreeNode(ep.EndpointId, listNodes, TreeViewSelectMode.Endpoint); } else if (rightModel != null && !rightModel.DirectoryPushed) { var nodeSelected = new DirectoryNode { NodeId = ep.EndpointId, IsFolder = false }; foreach (var le in ApplicationContext.LableEndpointDatas) { var endp = le.EndPointDatas.Find(r => r.EndpointId == ep.EndpointId); if (endp != null) { ApplicationContext.LabelExpandedIds.Add(le.Id); break; } } PageNavigatorHelper.GetRightElementViewModel().SelectLabelNodeFromGrid(nodeSelected); } } } }
public void EndPointNavigationClick() { SubDiscoveryVisibility = 0.99; SubSoftwareVisibility = 0.99; SubPolicyVisibility = 0.99; SubReportingVisibility = 0.99; SubEndpointVisibility = SubEndpointVisibility == 1 ? 0.99 : 1; var mainViewModel = PageNavigatorHelper.GetMainModel(); if (mainViewModel != null) { mainViewModel.NavigationIndex = (int)NavigationIndexes.Endpoint; } var righModel = PageNavigatorHelper.GetRightElementViewModel(); if (righModel != null) { if (righModel.DirectoryPushed) { var nodeSelected = ApplicationContext.NodesSelected != null && ApplicationContext.NodesSelected.Count > 0 ? ApplicationContext.NodesSelected[0] : null; if (nodeSelected != null) { SelectCurrentTreeNode(nodeSelected); } } else { var nodeSelected = ApplicationContext.LabelNodesSelected != null && ApplicationContext.LabelNodesSelected.Count > 0 ? ApplicationContext.LabelNodesSelected[0] : null; if (nodeSelected != null) { righModel.SelectLabelNodeFromGrid(nodeSelected); } } } }
/// <summary> /// Move folders and enpoints into another folder /// </summary> /// <param name="margs">parameters that contain folderId list, endpoidId list and taget forderId</param> private void MoveDirectoriesAndEndpoints(MoveFoldersAndEndpointsInputArgs margs) { try { Logger.Info("Starting move directory and endpoint"); using (var sc = new POCServiceClient("NetTcpBinding_IPOCService")) { var data = JsonConvert.SerializeObject(margs); sc.MoveFoldersAndEndpoints(EncryptionHelper.EncryptString(data, KeyEncryption)); //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { PageNavigatorHelper.GetRightElementViewModel().SearchText = string.Empty; ApplicationContext.SearchText = string.Empty; PageNavigatorHelper._MainWindow.RightTreeElement.BackButton.Visibility = Visibility.Collapsed; ApplicationContext.DirSearched = false; var dn = new DirectoryNode { IsFolder = true, NodeId = margs.TargerFolderId }; MakeTreeNode(dn, false, true); })); } Logger.Info("Ended move directory and endpoint"); } catch (Exception ex) { //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { MakeTreeNode(0); var messageDialog = _view.MessageDialogContentControl.Content as MessageDialog; messageDialog.ShowMessageDialog( "Cannot move this tree note due to exception occured, please see the log file under the Logs for more information", "Message"); })); Logger.Error(ex.StackTrace); } }
private void OnPOCAgentNavExecute() { var mainViewModel = PageNavigatorHelper.GetMainModel(); if (mainViewModel != null) { mainViewModel.NavigationIndex = (int)NavigationIndexes.POCAgent; ApplicationContext.IsRebuildTree = true; if (ApplicationContext.FolderPolicyList == null) { Functions.LoadFolderPolicy(); } if (ApplicationContext.EndpointPolicyList == null) { Functions.LoadEndpointPolicy(); } var rightVM = PageNavigatorHelper.GetRightElementViewModel(); rightVM.ReBuildTree(ApplicationContext.NodesSelected); } PageNavigatorHelper.Switch(new POCAgentPage()); }
private void BuildTree(List <DirectoryNode> labelNodesSelected) { _labelTreeDataSource = new List <DirectoryNode>(); foreach (var labelEndPoint in _labelEndPoints) { var directoryNode = CreateDirectoryNode(labelEndPoint.Id, labelEndPoint.Name); directoryNode.DirectoryNodes = new ObservableCollection <DirectoryNode>(CreateChildNodes(labelEndPoint.EndPointDatas)); _labelTreeDataSource.Add(directoryNode); } _labelDataTree.ItemsSource = _labelTreeDataSource; if (_labelTreeDataSource.Count == 0) { _labelDataTree.Width = PageNavigatorHelper._MainWindow.GrdRightElement.ActualWidth; } else { _labelDataTree.Width = ApplicationContext.GridRightOriginalWidth; } PageNavigatorHelper.GetRightElementViewModel().RefreshLabelTreeData(labelNodesSelected); }
/// <summary> /// Editing name of endpoint /// </summary> /// <param name="de">Edited Endpoint</param> private void EditEndpoint(DirectoryEndpoint de) { try { Logger.Info("Starting edit an endpoint"); using (var sc = new POCServiceClient("NetTcpBinding_IPOCService")) { var data = JsonConvert.SerializeObject(de); sc.EditEndpoint(EncryptionHelper.EncryptString(data, KeyEncryption)); //refresh labels tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { var rightViewModel = PageNavigatorHelper.GetRightElementViewModel(); rightViewModel.LoadLabelView(true); })); } Logger.Info("Ended editing name of endpoint"); } catch (Exception ex) { //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { var dn = new DirectoryNode { IsFolder = false, NodeId = de.FolderId }; MakeTreeNode(dn, false, true); var messageDialog = _view.MessageDialogContentControl.Content as MessageDialog; messageDialog.ShowMessageDialog( "Cannot edit a new endpoint due to exception occured, please see the log file under the Logs for more information", "Message"); })); Logger.Error(ex.StackTrace); } }
public void ReBuildTree(List <DirectoryNode> nodeSelected) { var mainVm = PageNavigatorHelper.GetMainModel(); var isPocAgent = mainVm.NavigationIndex == (int)NavigationIndexes.POCAgent; var rootId = ApplicationContext.FolderListTree == null || (ApplicationContext.FolderListTree != null && ApplicationContext.FolderListTree.Count == 0) ? ApplicationContext.FolderListAll.Find(r => r.FolderId == ApplicationContext.FolderListAll.Min(m => m.FolderId)).FolderId : ApplicationContext.FolderListTree.Min(r => r.FolderId); var rootName = ApplicationContext.FolderListTree == null || (ApplicationContext.FolderListTree != null && ApplicationContext.FolderListTree.Count == 0) ? ApplicationContext.FolderListAll.Find(r => r.FolderId == ApplicationContext.FolderListAll.Min(m => m.FolderId)).FolderName : ApplicationContext.FolderListTree.Find(r => r.FolderId == rootId).FolderName; var guid = ApplicationContext.FolderListTree == null || (ApplicationContext.FolderListTree != null && ApplicationContext.FolderListTree.Count == 0) ? ApplicationContext.FolderListAll.Find(r => r.FolderId == ApplicationContext.FolderListAll.Min(m => m.FolderId)).Guid : ApplicationContext.FolderListTree.Find(r => r.FolderId == rootId).Guid; var rootPolicy = isPocAgent ? ApplicationContext.FolderPolicyList.Find(r => r.ObjectId == rootId) : null; // create root, build subtree and return it var node = new DirectoryNode { NodeId = rootId, Title = rootName, IsFolder = true, NodeWidth = ApplicationContext.GridRightOriginalWidth, Guid = guid, NodeHoverWidth = isPocAgent?0:ApplicationContext.GridRightOriginalWidth, NodeSelectedWidth = isPocAgent? ApplicationContext.GridRightOriginalWidth : 0, NodePolicyColor = isPocAgent? (rootPolicy != null?rootPolicy.Color: UIConstant.PolicyDefaultColor) : "", ChildrenPolicyColor = isPocAgent? GetChildPolicyAssign(new Directory { FolderId = rootId }): null }; MakeSubTree(node, isPocAgent); var listNode = new ObservableCollection <DirectoryNode>(); listNode.Add(node); var rightViewModel = PageNavigatorHelper.GetRightElementViewModel(); if (rightViewModel != null) { rightViewModel.EndEditingTree(); rightViewModel.TreeDataSource = listNode; rightViewModel.RefreshTreeData(nodeSelected); } }
public void DeleteNodes(List <DirectoryNode> nodes) { var rightViewModel = PageNavigatorHelper.GetRightElementViewModel(); var listNode = new ObservableCollection <DirectoryNode>(); var dirTreeRootId = rightViewModel.TreeDataSource.First().NodeId; if (nodes.Find(r => r.NodeId == dirTreeRootId && r.IsFolder) != null) { rightViewModel.TreeDataSource.First().DirectoryNodes = new ObservableCollection <DirectoryNode>(); foreach (var node in nodes) { RemoveOrEditLabelNode(node, false); } } else { foreach (var node in nodes) { RemoveNode(node, rightViewModel.TreeDataSource, listNode); RemoveOrEditLabelNode(node, false); } } }
/// <summary> /// Add new Computer /// </summary> /// <param name="dir">parent node. if dir==null than add computer from adding button, else than adding computer from other</param> private void AddComputerAction(DirectoryNode dir = null) { try { var isPocAgent = NavigationIndex == (int)NavigationIndexes.POCAgent; var dn = new DirectoryNode { IsFolder = false, Title = _labelName, ComputerType = 2, PowerState = 1, IsNoAgent = true, NodeColor = CommonConstants.GREEN_OFFLINE_COLOR, NodeWidth = ApplicationContext.GridRightOriginalWidth, Guid = _guid, NodeHoverWidth = isPocAgent ? 0 : ApplicationContext.GridRightOriginalWidth, NodeSelectedWidth = isPocAgent ? ApplicationContext.GridRightOriginalWidth : 0, NodePolicyColor = isPocAgent ? UIConstant.PolicyDefaultColor : "" }; _newNode = dn; var addBackgroundWorker = new BackgroundWorker(); addBackgroundWorker.DoWork += AddBackgroundWorker_DoWork; addBackgroundWorker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { var rightViewModel = PageNavigatorHelper.GetRightElementViewModel(); if (dir == null) { _newNode.NodeId = _endpointIdAdded.EndpointId; _newNode.NodeColor = _endpointIdAdded.Color; var enp = ApplicationContext.EndPointListTree.Find(r => r.Guid == _guid); if (enp != null) { enp.GUIID = _endpointIdAdded.GUIID; enp.EndpointId = _endpointIdAdded.EndpointId; enp.Color = _endpointIdAdded.Color; enp.AgentText = _endpointIdAdded.AgentText; enp.ComputerType = _endpointIdAdded.ComputerType; enp.Domain = _endpointIdAdded.Domain; enp.FolderId = _endpointIdAdded.FolderId; enp.HDDCapacity = _endpointIdAdded.HDDCapacity; enp.ID = _endpointIdAdded.ID; enp.IPv4 = _endpointIdAdded.IPv4; enp.IPv6 = _endpointIdAdded.IPv6; enp.LastSync = _endpointIdAdded.LastSync; enp.LastSyncDayText = _endpointIdAdded.LastSyncDayText; enp.MACAddress = _endpointIdAdded.MACAddress; enp.OSName = _endpointIdAdded.OSName; enp.PowerState = _endpointIdAdded.PowerState; enp.Processor = _endpointIdAdded.Processor; enp.ProductVersion = _endpointIdAdded.ProductVersion; enp.SystemManufacturer = _endpointIdAdded.SystemManufacturer; enp.SystemModel = _endpointIdAdded.SystemModel; enp.SystemName = _endpointIdAdded.SystemName; enp.SystemType = _endpointIdAdded.SystemType; enp.TotalPhysicalMemory = _endpointIdAdded.TotalPhysicalMemory; enp.UserName = _endpointIdAdded.UserName; } } else { var snode = new DirectoryNode { IsFolder = false, NodeId = _endpointIdAdded.EndpointId }; MakeTreeNode(snode, false, true); } //refresh labels tree data rightViewModel.LoadLabelView(true); ApplicationContext.IsError = false; }; addBackgroundWorker.RunWorkerAsync(); ApplicationContext.IsAddNode = true; ApplicationContext.IsDeleteNode = false; //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { if (!ApplicationContext.ExpandedIds.Contains(_nodeSeleted)) { ApplicationContext.ExpandedIds.Add(_nodeSeleted); } var endp = new EndPoint { Guid = _guid, FolderId = _nodeSeleted }; var ec = ApplicationContext.EndPointListAll.Count; ApplicationContext.EndPointListTree.Add(endp); if (ec == ApplicationContext.EndPointListAll.Count) { ApplicationContext.EndPointListAll.Add(endp); } AddNodeToCurrentTree(dn, true, dir); if (dir == null && ApplicationContext.NodeEditting != null) { _view.RightTreeElement.Model.TreeEnterEditMode(_view.RightTreeElement.DataTree.Nodes); } })); } catch (Exception ex) { ApplicationContext.IsBusy = false; //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { MakeTreeNode(0, true, true); })); Logger.Error(ex.Message, ex); } }
private void RefreshTreeRight(int folderId) { //Refresh Right Tree PageNavigatorHelper.GetRightElementViewModel().UpdateTree(folderId); }
private void OnSyncNowCommand(object arg) { using (var sc = new POCServiceClient("NetTcpBinding_IPOCService")) { var fids = new List <int>(); var eids = new List <int>(); var endplst = new List <EndPoint>(); var rightVm = PageNavigatorHelper.GetRightElementViewModel(); if (rightVm.DirectoryPushed) { //Select all endpoint in selected folders and selected endpoints foreach (var cnode in ApplicationContext.NodesSelected) { if (cnode != null) { if (cnode.IsFolder) { fids.Add(cnode.NodeId); } else { eids.Add(cnode.NodeId); } } } foreach (var fid in fids) { GetAllEndpointOfFolder(endplst, fid); } foreach (var eid in eids) { var endpoint = ApplicationContext.EndPointListAll.Find(e => e.EndpointId == eid); if (!endplst.Select(ep => ep.EndpointId).Contains(endpoint.EndpointId)) { endplst.Add(endpoint); } } } else { //Select all endpoint in selected labels and selected endpoints foreach (var cnode in ApplicationContext.LabelNodesSelected) { if (cnode != null) { if (cnode.IsFolder) { fids.Add(cnode.NodeId); } else { eids.Add(cnode.NodeId); } } } var endpointDatas = new List <LabelEndPointsData>(); foreach (var id in fids) { var listEndpoints = ApplicationContext.LableEndpointDatas.Where(r => r.Id == id).ToList(); endpointDatas.AddRange(listEndpoints); } foreach (var le in endpointDatas) { foreach (var en in le.EndPointDatas) { if (!endplst.Select(r => r.EndpointId).Contains(en.EndpointId)) { var endpoint = new EndPoint(en); endplst.Add(endpoint); } } } foreach (var eid in eids) { var endpoint = ApplicationContext.EndPointListAll.Find(e => e.EndpointId == eid); if (!endplst.Select(ep => ep.EndpointId).Contains(endpoint.EndpointId)) { endplst.Add(endpoint); } } } if (endplst.Count == 0) { var messageDialog = PageNavigatorHelper._MainWindow.MessageDialogContentControl.Content as MessageDialog; messageDialog.ShowMessageDialog("You must select at least one Endpoint to sync", "Sync Action"); return; } var requestObj = new StringAuthenticateObject { StringAuth = "OK", StringValue = string.Join(",", endplst.Select(r => r.EndpointId).ToList()) }; var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(requestObj), KeyEncryption); try { sc.SyncNow(requestData); } catch (Exception ex) { } } }
/// <summary> /// Called when [navigator selected]. /// </summary> /// <param name="btn">The BTN.</param> private void OnNavigatorCommand(Button btn) { var rightVM = PageNavigatorHelper.GetRightElementViewModel(); _view.StSubDiscovery.Visibility = Visibility.Visible; _view.StSubEndpoint.Visibility = Visibility.Visible; _view.StSubSoftware.Visibility = Visibility.Visible; _view.StSubPolicies.Visibility = Visibility.Visible; _view.StSubReporting.Visibility = Visibility.Visible; var mainViewModel = PageNavigatorHelper.GetMainModel(); var previousIndex = mainViewModel.NavigationIndex; switch (btn.Name) { case "BtnEndPoint": EndPointNavigationClick(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "SubBtnLabel": OnLabelNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "SubBtnColor": CanTabSelected(btn); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "SubBtnAssignments": OnAssignmentNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "BtnDiscovery": OnDiscoveryNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "SubBtnNeighborhood": OnNeighborhoodNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "SubBtnLDAP": OnLDAPNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; if (rightVM.DirectoryPushed) { mainViewModel.AddDeleteButtonVisible = true; } } break; case "BtnSoftware": OnSoftwareNavExecute(); if (rightVM != null) { rightVM.BuilSoftwareTree(); rightVM.DirectoryTreeVisible = false; rightVM.SoftwareTreeVisible = true; mainViewModel.AddDeleteButtonVisible = false; } break; case "SubBtnDownload": OnDownloadNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = false; rightVM.SoftwareTreeVisible = true; mainViewModel.AddDeleteButtonVisible = false; } break; case "SubBtnTransfer": OnTransferNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = false; rightVM.SoftwareTreeVisible = true; mainViewModel.AddDeleteButtonVisible = false; } break; case "BtnLicense": OnLicenseNavExecute(); break; case "BtnPolicy": OnPolicyNavExecute(); break; case "SubBtnPOCAgent": OnPOCAgentNavExecute(); if (rightVM != null) { rightVM.DirectoryTreeVisible = true; rightVM.SoftwareTreeVisible = false; mainViewModel.AddDeleteButtonVisible = false; } break; case "SubBtnEndpointPatron": break; case "BtnReporting": OnReportingNavExecute(); break; case "SubBtnQuarantine": OnQuarantineNavExecute(); break; case "BtnNotification": OnNotificationNavExecute(); break; case "BtnSetting": OnSettingNavExecute(); break; } if (btn.Name != "SubBtnPOCAgent" && previousIndex == (int)NavigationIndexes.POCAgent) { ApplicationContext.IsRebuildTree = true; rightVM.ReBuildTree(ApplicationContext.NodesSelected); } }
private void DragSource_OnDragEnd(object sender, DragDropEventArgs e) { var rightTreeVm = PageNavigatorHelper.GetRightElementViewModel(); rightTreeVm.SetNodeDropableOrNot(); }