Example #1
0
        /// <summary>
        ///     Adding a new directory
        /// </summary>
        private void AddFolder()
        {
            try
            {
                Logger.Info("Starting Add a new Directory");

                //create a new folder
                var newFolder = new Folder
                {
                    FolderName = _labelName,
                    ParentId   = _nodeSeleted
                };
                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var data = JsonConvert.SerializeObject(newFolder);
                    var fstr = sc.SaveNewFolder(EncryptionHelper.EncryptString(data, KeyEncryption));
                    var fol  = JsonConvert.DeserializeObject <Directory>(EncryptionHelper.DecryptRijndael(fstr,
                                                                                                          KeyEncryption));
                    _dirIdAdded = fol;
                }

                Logger.Info("Ended adding a new Directory");
            }
            catch (Exception ex)
            {
                //refresh tree data
                _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    MakeTreeNode(0, true, true);
                }));
                Logger.Error(ex.StackTrace);
            }
        }
Example #2
0
        /// <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);
            }
        }
Example #3
0
 public static List <LastUpdated> GetLastUpdateData()
 {
     try
     {
         if (pocClientServiceForAutoRefresh == null)
         {
             pocClientServiceForAutoRefresh = new POCServiceClient("NetTcpBinding_IPOCService");
         }
         if (pocClientServiceForAutoRefresh.ChannelFactory.State == CommunicationState.Faulted ||
             pocClientServiceForAutoRefresh.ChannelFactory.State == CommunicationState.Closed)
         {
             pocClientServiceForAutoRefresh.Close();
             pocClientServiceForAutoRefresh = null;
             pocClientServiceForAutoRefresh = new POCServiceClient("NetTcpBinding_IPOCService");
         }
         var lastUpdate     = pocClientServiceForAutoRefresh.GetLastUpdateData();
         var decryptionData = lastUpdate;
         var lupds          = JsonConvert.DeserializeObject <List <LastUpdated> >(decryptionData);
         return(lupds);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw;
     }
 }
Example #4
0
        public static void Invoke(ServiceClientHandler handler)
        {
            var sc = new POCServiceClient("NetTcpBinding_IPOCService");

            try
            {
                _log.Info("ServiceClientHandler: " + handler.Method);
                handler(sc);
            }
            catch (TimeoutException ex)
            {
                _log.Error("Timeout error: {0}" + ex.Message, ex);
                sc.Abort();
            }
            catch (FaultException fe)
            {
                _log.Error("Timeout error: {0}" + fe.Message, fe);
                sc.Abort();
            }
            catch (CommunicationException ce)
            {
                _log.Error("Timeout error: {0}" + ce.Message, ce);
                sc.Abort();
            }
            finally
            {
                if (sc.State != CommunicationState.Closed)
                {
                    sc.Close();
                }
            }
        }
Example #5
0
        /// <summary>
        ///     Deleting directories and endpoints that selected
        /// </summary>
        /// <param name="data">a collection of directoryId</param>
        private void DeleteDirectoriesAndEndpoints(List <DeleteDirectoryFolderRequest> data)
        {
            try
            {
                Logger.Info("Starting delete directory and endpoint");

                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var directtoryData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(data), KeyEncryption);

                    sc.DeleteDirectoryComputer(directtoryData);
                }

                Logger.Info("Ended delete directory and endpoint");
            }
            catch (Exception ex)
            {
                //refresh tree data
                _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    MakeTreeNode(0, true, true);
                    var messageDialog = _view.MessageDialogContentControl.Content as MessageDialog;
                    messageDialog.ShowMessageDialog(
                        "Cannot delete this tree nodes due to exception occured, please see the log file under the Logs for more information",
                        "Message");
                }));
                Logger.Error(ex.StackTrace);
            }
        }
 private void AddOrRemoveConfirmed(NeighborhoodWatch cust)
 {
     using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
     {
         var data = JsonConvert.SerializeObject(cust);
         sc.SaveNeighborhoodWatchConfirmed(EncryptionHelper.EncryptString(data, KeyEncryption));
     }
 }
Example #7
0
 public void AssignPolicy(List <PolicyAssign> lpa)
 {
     using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
     {
         var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(lpa),
                                                          KeyEncryption);
         sc.AssignPolicy(requestData);
     }
 }
Example #8
0
 public static void DeleteDirectoryAssignmentRuleCriteria(int lcid)
 {
     using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
     {
         var request = new DataRequest(lcid);
         var datareq = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(request),
                                                      Key);
         sc.DeleteAssignRuleCriteria(datareq);
     }
 }
Example #9
0
 public static int AddLabelCriteria(LabelCriteria lc)
 {
     using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
     {
         var datareq = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(lc),
                                                      Key);
         var rs = sc.AddLabelCriteria(datareq);
         ApplicationContext.IsRebuildTree = true;
         return(EncryptionHelper.DecryptStringToInt(rs, Key));
     }
 }
Example #10
0
        private void OnSavePolicyCommand(object arg)
        {
            if (string.IsNullOrWhiteSpace(POCServer) || string.IsNullOrWhiteSpace(Key) || Port == null)
            {
                _messageDialog.ShowMessageDialog("Server information (POCServer, Port, Key) cannot be null", "Message");
                return;
            }
            if (SynchronizationInterval == null || TransferInterval == null ||
                (SynchronizationInterval != null && SynchronizationInterval <= 0) ||
                (TransferInterval != null && TransferInterval <= 0))
            {
                _messageDialog.ShowMessageDialog("Time interval cannot be null or less than 0", "Message");
                return;
            }
            var pocAgent = new POCAgent
            {
                POCServer         = POCServer,
                Key               = Key,
                Port              = Port.Value,
                Name              = Name,
                NeighborhoodWatch = NeighborhoodWatch,
                ActiveTransfer    = ActiveTransfer,
                UpdateSource      = UpdateSource,
                SyncInterval      = SynchronizationInterval.Value,
                TransferInterval  = TransferInterval.Value,
                Color             = PolicyColor,
                Id = Id
            };

            if (pocServerOrigin != POCServer || portOrigin != Port.Value || keyOrigin != Key)
            {
                var confirmDlg = new ConfirmDialog("Are you sure you want to save these informations?", "Save policy");
                if (confirmDlg.ShowDialog() == true)
                {
                    using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                    {
                        var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(pocAgent),
                                                                         KeyEncryption);
                        sc.EditPolicy(requestData);
                        UpdatePocAgent(pocAgent);
                    }
                }
            }
            else
            {
                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(pocAgent),
                                                                     KeyEncryption);
                    sc.EditPolicy(requestData);
                    UpdatePocAgent(pocAgent);
                }
            }
        }
Example #11
0
 public static void DeleteLabelCriteria(int lcid)
 {
     using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
     {
         var request = new StringAuthenticateObject {
             StringValue = lcid.ToString(), StringAuth = "OK"
         };
         var datareq = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(request),
                                                      Key);
         sc.DeleteLabelCriteria(datareq);
         ApplicationContext.IsRebuildTree = true;
     }
 }
        public List <Directory> GetAllFolders()
        {
            try
            {
                var folderListAll = new List <Directory>();
                Logger.Info("Start get all folders");
                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var result            = sc.GetAllFolders(EncryptionHelper.EncryptString("OK", KeyEncryption));
                    var resultDeserialize =
                        JsonConvert.DeserializeObject <List <Directory> >(EncryptionHelper.DecryptRijndael(result,
                                                                                                           KeyEncryption));
                    if (resultDeserialize == null)
                    {
                        PageNavigatorHelper._MainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                        {
                            var messageDialog = PageNavigatorHelper._MainWindow.MessageDialogContentControl.Content as MessageDialog;

                            messageDialog.ShowMessageDialog("Data is null", "Message");
                        }));
                        return(null);
                    }

                    foreach (var folder in resultDeserialize)
                    {
                        var fol = new Directory
                        {
                            FolderId   = folder.FolderId,
                            FolderName = folder.FolderName,
                            ParentId   = folder.ParentId,
                            Guid       = Guid.NewGuid()
                        };
                        folderListAll.Add(fol);
                    }
                }
                Logger.Info("End getting folder datas");
                return(folderListAll);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                PageNavigatorHelper._MainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    var messageDialog = PageNavigatorHelper._MainWindow.MessageDialogContentControl.Content as MessageDialog;

                    messageDialog.ShowMessageDialog("Cannot get directory due to exception occured, please see the log file under the Logs for more information", "Message");
                }));
                return(null);
            }
        }
Example #13
0
        private void MoveDiscoveryBk_DoWork(object sender, DoWorkEventArgs e)
        {
            var strAuth        = new StringAuthenticateObject();
            var xmlDataBuilder = new StringBuilder();

            xmlDataBuilder.Append("<DataSet>");
            var indexName = GetFolderIndexAdd();

            foreach (var neighborhood in _selectedData)
            {
                var nname = neighborhood.Computer;
                if (string.IsNullOrWhiteSpace(neighborhood.Computer))
                {
                    nname = "New Computer";
                    if (indexName >= 2)
                    {
                        nname += " (" + indexName + ")";
                        indexName++;
                    }
                }
                xmlDataBuilder.Append("<Endpont>");
                xmlDataBuilder.Append("<SystemName>" + nname + "</SystemName>");
                xmlDataBuilder.Append("<FolderId>" + ApplicationContext.NodeTargetId + "</FolderId>");
                xmlDataBuilder.Append("<MacAddress>" + neighborhood.MAC + "</MacAddress>");
                xmlDataBuilder.Append("</Endpont>");
            }
            xmlDataBuilder.Append("</DataSet>");
            strAuth.StringAuth  = "OK";
            strAuth.StringValue = xmlDataBuilder.ToString();
            using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
            {
                var data     = JsonConvert.SerializeObject(strAuth);
                var result   = sc.AddNewEndpointsFromDiscovery(EncryptionHelper.EncryptString(data, KeyEncryption));
                var rsDeser  = JsonConvert.DeserializeObject <List <EndPointData> >(EncryptionHelper.DecryptRijndael(result, KeyEncryption));
                var listData = new List <EndPoint>();
                foreach (var ed in rsDeser)
                {
                    var enp = new EndPoint(ed);
                    listData.Add(enp);
                }
                var ec = ApplicationContext.EndPointListAll.Count;
                ApplicationContext.EndPointListTree.RemoveAll(r => r.FolderId == ApplicationContext.NodeTargetId);
                ApplicationContext.EndPointListTree.AddRange(listData);
                if (ec == ApplicationContext.EndPointListAll.Count)
                {
                    ApplicationContext.EndPointListAll.RemoveAll(r => r.FolderId == ApplicationContext.NodeTargetId);
                    ApplicationContext.EndPointListAll.AddRange(listData);
                }
            }
        }
Example #14
0
        private void ClearUnmanagedNeighborhoodDb(List <int> nids)
        {
            var nidsJoin = string.Join(",", nids);
            var strAuth  = new StringAuthenticateObject
            {
                StringAuth  = "OK",
                StringValue = nidsJoin
            };

            using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
            {
                var data = JsonConvert.SerializeObject(strAuth);
                sc.DeleteNeighborhoodWatch(EncryptionHelper.EncryptString(data, KeyEncryption));
            }
        }
        public List <EndPoint> GetDirectoryEndpoints(int folderId, string searchKey = "")
        {
            try
            {
                var endPointListAll = new List <EndPoint>();

                Logger.Info("Start getting Endpoint datas in a folder with folderId =" + folderId);
                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var searchObj = new EndpointSearch {
                        FolderId = folderId, SearchKey = searchKey
                    };
                    var result            = sc.GetDirectoryData(EncryptionHelper.EncryptString(JsonConvert.SerializeObject(searchObj), KeyEncryption));
                    var resultDeserialize =
                        JsonConvert.DeserializeObject <List <EndPointData> >(EncryptionHelper.DecryptRijndael(result,
                                                                                                              KeyEncryption));
                    if (resultDeserialize == null)
                    {
                        PageNavigatorHelper._MainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                        {
                            var messageDialog = PageNavigatorHelper._MainWindow.MessageDialogContentControl.Content as MessageDialog;
                            messageDialog.ShowMessageDialog("Data is null", "Message");
                        }));
                        return(null);
                    }

                    foreach (var epd in resultDeserialize)
                    {
                        var ep = new EndPoint(epd);
                        endPointListAll.Add(ep);
                    }
                }
                Logger.Info("End getting EndPoint datas");
                return(endPointListAll);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                PageNavigatorHelper._MainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
                {
                    var messageDialog = PageNavigatorHelper._MainWindow.MessageDialogContentControl.Content as MessageDialog;

                    messageDialog.ShowMessageDialog("Cannot get endpoint due to exception occured, please see the log file under the Logs for more information", "Message");
                }));
                return(null);
            }
        }
Example #16
0
        private void DeletePolicy()
        {
            var confirmDlg = new ConfirmDialog("Are you sure you want to delete these informations?", "Delete policy");

            if (confirmDlg.ShowDialog() == true)
            {
                if (ApplicationContext.PoliciesList != null)
                {
                    var listId = ApplicationContext.PoliciesList.Select(r => r.Id).ToList();

                    var requestObj = new StringAuthenticateObject
                    {
                        StringAuth  = "OK",
                        StringValue = string.Join(",", listId)
                    };
                    using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                    {
                        var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(requestObj),
                                                                         KeyEncryption);
                        sc.DeletePolicy(requestData);
                    }

                    foreach (var policyElementViewModel in ApplicationContext.PoliciesList)
                    {
                        //policyElementViewModel.IsActived = true;
                        _view.PnlPolicyContainer.Children.Remove(policyElementViewModel._view);
                    }
                    ApplicationContext.POCAgentList.RemoveAll(
                        r => ApplicationContext.PoliciesList.Select(r2 => r2.Id).Contains(r.Id));
                    ApplicationContext.PoliciesList.Clear();

                    if (_view.PnlPolicyContainer.Children.Count > 0 && ApplicationContext.POCAgentList.Count > 0)
                    {
                        var item = ApplicationContext.POCAgentList.FirstOrDefault(i => i.Id == Id);
                        if (item == null)
                        {
                            Id = ApplicationContext.POCAgentList.FirstOrDefault().Id;
                            BuildPage();
                        }
                    }
                    else
                    {
                        BtnSaveVisible = false;
                    }
                }
            }
        }
 private void SaveBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
     {
         var keyEncryption = Functions.GetConfig("MESSAGE_KEY", "");
         var updSource = e.Argument as UpdateSource;
         if (updSource != null)
         {
             using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
             {
                 var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(updSource),
                                                                  keyEncryption);
                 sc.EditUpdateSource(requestData);
             }
         }
     }));
 }
Example #18
0
 private void ChangeUpdSourceBg_DoWork(object sender, DoWorkEventArgs e)
 {
     _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                  (Action)(() =>
     {
         var usschedule = new AddOrDeleteUpdateSourceScheduling
         {
             UpdateSourceId = Id,
             SchedulingId = ApplicationContext.TransferScheduleId,
             IsAdding = IsSelected
         };
         using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
         {
             var data = JsonConvert.SerializeObject(usschedule);
             sc.AddOrDeleteUpdateSourceScheduling(EncryptionHelper.EncryptString(data, KeyEncryption));
         }
     }));
 }
 private void SaveScheduleBg_DoWork(object sender, DoWorkEventArgs e)
 {
     _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                  (Action)(() =>
     {
         var tscheduling = new TransferSchedule
         {
             Id = TransferScheduleId,
             TransferEveryHours = TransferEveryHours,
             CanTransferAfterNewContent = CanTransferAfterNewContent,
             CanTransferEveryHours = CanTransferEveryHours
         };
         using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
         {
             var data = JsonConvert.SerializeObject(tscheduling);
             sc.EditTransferScheduling(EncryptionHelper.EncryptString(data, KeyEncryption));
         }
     }));
 }
        private void DeleteBg_DoWork(object sender, DoWorkEventArgs e)
        {
            var ldapId = (int)e.Argument;

            _view.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
            {
                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var stringAuth = new StringAuthenticateObject
                    {
                        StringAuth = "OK",
                        StringValue = ldapId.ToString()
                    };
                    var request = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(stringAuth),
                                                                 KeyEncryption);
                    sc.DeleteLDAP(request);
                    DomainName = string.Empty;
                }
            }));
        }
Example #21
0
        /// <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 DeleteContent()
        {
            var selectedIds   = ViewList.Where(r => r.IsSelected).Select(r => r.Id).ToList();
            var filesToDelete = ViewList.Where(r => r.IsSelected).Select(r => r.Name).ToList();
            var requestObj    = new StringAuthenticateObject
            {
                StringAuth  = "OK",
                StringValue = string.Join(",", selectedIds)
            };

            using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
            {
                var requestData = EncryptionHelper.EncryptString(JsonConvert.SerializeObject(requestObj),
                                                                 KeyEncryption);
                sc.DeleteContent(requestData);
            }
            ServiceManager.DeleteSoftwareFile(filesToDelete);
            ApplicationContext.SoftwareList.RemoveAll(r => selectedIds.Contains(r.Id));
            ApplicationContext.UpdateSourceSoftwareList.RemoveAll(r => selectedIds.Contains(r.SoftwareId));
            BuidPage();
        }
Example #23
0
        public static void UpdateMainUpdateSourceConfig()
        {
            try
            {
                using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
                {
                    var sourceUrl = RequestResponseUtils.DecryptString(
                        sc.GetMainUpdateSourceUrl()
                        );

                    if (!string.IsNullOrWhiteSpace(sourceUrl))
                    {
                        ApplicationContext.MainUpdateSourceUrl = sourceUrl;
                    }
                    else
                    {
                        var config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
                        var systemServiceModalSectionGroups = config.SectionGroups["system.serviceModel"];

                        var servicesSectionInformation = systemServiceModalSectionGroups.Sections["client"].SectionInformation;
                        var xmlText = servicesSectionInformation.GetRawXml();
                        var xmlDoc  = new XmlDocument();
                        xmlDoc.LoadXml(xmlText);

                        var endpointNode =
                            xmlDoc.SelectSingleNode(
                                "/client/endpoint[@name='BasicHttpBinding_IMainUpdateSourceService']");
                        if (endpointNode != null)
                        {
                            ApplicationContext.MainUpdateSourceUrl = endpointNode.Attributes["address"].Value;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("UpdateMainUpdateSourceConfig: {0}" + ex.Message, ex);
                DialogHelper.Error("Unable get MainUpdateSource service url");
            }
        }
        /// <summary>
        /// Get searched data
        /// </summary>
        /// <param name="searchKey"></param>
        public void GetSearchedData(string searchKey)
        {
            using (var sc = new POCServiceClient("NetTcpBinding_IPOCService"))
            {
                var jsonSearchkey          = JsonConvert.SerializeObject(searchKey);
                var encryptedJsonSearchkey = EncryptionHelper.EncryptString(jsonSearchkey, KeyEncryption);
                var jsonResult             = sc.SearchEndPoint(encryptedJsonSearchkey);

                var decryptedJsonResult = EncryptionHelper.DecryptRijndael(jsonResult, KeyEncryption);
                var endPointDatas       = JsonConvert.DeserializeObject <List <EndPointData> >(decryptedJsonResult);

                var endPoints = new List <EndPoint>();
                var dirs      = new List <Directory>();

                foreach (var endPointData in endPointDatas)
                {
                    var ep = new EndPoint(endPointData);
                    endPoints.Add(ep);
                    var dir = ApplicationContext.FolderListAll.Find(d => d.FolderId == ep.FolderId);
                    if (dir != null)
                    {
                        GetParentNode(dirs, dir);
                    }
                }

                dirs.Reverse();

                ApplicationContext.EndPointListTree = endPoints;

                if (string.IsNullOrEmpty(searchKey))
                {
                    ApplicationContext.FolderListTree = ApplicationContext.FolderListAll;
                }
                else
                {
                    ApplicationContext.FolderListTree = dirs;
                }
            }
        }
Example #25
0
        /// <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);
            }
        }
Example #26
0
        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)
                {
                }
            }
        }