/// <summary> /// Editing name of directory /// </summary> /// <param name="de">Edited directory</param> private void EditFolder(DirectoryEndpoint de) { try { Logger.Info("Starting edit a Directory"); using (var sc = new POCServiceClient("NetTcpBinding_IPOCService")) { var data = JsonConvert.SerializeObject(de); sc.EditFolder(EncryptionHelper.EncryptString(data, KeyEncryption)); } Logger.Info("Ended editing name of directory"); } catch (Exception ex) { //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { var dn = new DirectoryNode { IsFolder = true, NodeId = de.FolderId }; MakeTreeNode(dn, false, true); var messageDialog = _view.MessageDialogContentControl.Content as MessageDialog; messageDialog.ShowMessageDialog( "Cannot edit a new directory due to exception occured, please see the log file under the Logs for more information", "Message"); })); Logger.Error(ex.StackTrace); } }
/// <summary> /// Edit directory name /// </summary> /// <param name="data">directory data</param> public void EditDirectoryAction(DirectoryEndpoint data) { var editFolderBackgroundWorker = new BackgroundWorker(); editFolderBackgroundWorker.DoWork += EditFolderBackgroundWorker_DoWork; editFolderBackgroundWorker.RunWorkerCompleted += EditFolderBackgroundWorker_RunWorkerCompleted; editFolderBackgroundWorker.RunWorkerAsync(data); ApplicationContext.FolderListAll.Where(r => r.FolderId == data.FolderId) .ToList() .ForEach(r => r.FolderName = data.Name); ApplicationContext.FolderListTree.Where(r => r.FolderId == data.FolderId) .ToList() .ForEach(r => r.FolderName = data.Name); ApplicationContext.IsAddNode = false; ApplicationContext.IsEditNode = true; ApplicationContext.IsDeleteNode = false; //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { var dn = new DirectoryNode { IsFolder = true, NodeId = data.FolderId }; SelectCurrentTreeNode(dn); })); }
/// <summary> /// Adding a new endpoint /// </summary> private void AddComputer() { try { Logger.Info("Starting Add a new Endpoint"); //create a new computer var newComputer = new DirectoryEndpoint { FolderId = _nodeSeleted, Name = _labelName, Mac = _mac }; using (var sc = new POCServiceClient("NetTcpBinding_IPOCService")) { var data = JsonConvert.SerializeObject(newComputer); var cstr = sc.SaveDirectoryEndpoint(EncryptionHelper.EncryptString(data, KeyEncryption)); var com = JsonConvert.DeserializeObject <EndPointData>(EncryptionHelper.DecryptRijndael(cstr, KeyEncryption)); var endp = new EndPoint(com); _endpointIdAdded = endp; } Logger.Info("Ended adding a new endpoint"); } catch (Exception ex) { ApplicationContext.IsBusy = false; //refresh tree data _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { MakeTreeNode(0, true, true); })); Logger.Error(ex); } }
/// <summary> /// Save the node name edited /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataTree_NodeExitedEditMode(object sender, NodeEventArgs e) { var mainViewModel = PageNavigatorHelper.GetMainModel(); var nodedata = e.Node.Data as DirectoryNode; if (DataTree.Equals(sender)) { if (nodedata != null && !string.IsNullOrWhiteSpace(nodedata.Title.Trim())) { if (nodedata != null && nodedata.IsFolder) { if (nodedata.Title.Length > 200) { var mdialog = PageNavigatorHelper._MainWindow.MessageDialogView; mdialog.ShowMessageDialog("Name's length must be less than 200 letters", "Message"); nodedata.Title = _originalTitle; } else { DataTree.SelectionSettings.NodeSelection = TreeSelectionType.None; var ed = new DirectoryEndpoint { Name = nodedata.Title, FolderId = nodedata.NodeId }; if (mainViewModel != null) { mainViewModel.EditDirectoryAction(ed); } } } if (nodedata != null && !nodedata.IsFolder) { if (nodedata.Title.Length > 250) { var mdialog = PageNavigatorHelper._MainWindow.MessageDialogView; mdialog.ShowMessageDialog("Name's length must be less than 250 letters", "Message"); nodedata.Title = _originalTitle; } else { DataTree.SelectionSettings.NodeSelection = TreeSelectionType.None; var ed = new DirectoryEndpoint { Name = nodedata.Title, FolderId = nodedata.NodeId }; if (mainViewModel != null) { mainViewModel.EditEndpointAction(ed); } } } } else { if (nodedata != null) { nodedata.Title = _originalTitle; } } } else if (SoftwareDataTree.Equals(sender)) { if (nodedata != null && !string.IsNullOrWhiteSpace(nodedata.SourceName.Trim())) { if (nodedata.SourceName.Length > 200) { var mdialog = PageNavigatorHelper._MainWindow.MessageDialogView; mdialog.ShowMessageDialog("the length of SourceName must be less than 200 letters", "Message"); nodedata.Title = _originalTitle; nodedata.SourceName = _originalSourceName; return; } var updSource = ApplicationContext.UpdateSourceList.Find(r => r.Id == nodedata.NodeId); if (updSource != null) { updSource.SourceName = nodedata.Title; } Model.BuilSoftwareTree(); var editSoftwareBg = new BackgroundWorkerHelper(); editSoftwareBg.AddDoWork(SaveBackgroundWorker_DoWork).DoWork(updSource); } else { if (nodedata != null) { nodedata.Title = _originalTitle; nodedata.SourceName = _originalSourceName; } } } ApplicationContext.IsBusy = false; }