Exemplo n.º 1
0
        private int AddPocAgentToDb(POCAgent pocAgent)
        {
            var resultDeserialize = ServiceManager.Invoke(sc => RequestResponseUtils.GetData <DataResponse>(
                                                              sc.AddPolicy, pocAgent));

            return(resultDeserialize.Result);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        private void DuplicateCurrentPolicy()
        {
            try
            {
                ApplicationContext.IsBusy = true;
                var selectedElement  = ApplicationContext.PoliciesList.FirstOrDefault();
                var selectedPocAgent = ApplicationContext.POCAgentList.Find(p => p.Id == selectedElement.Id);
                if (selectedPocAgent != null)
                {
                    var labelName = String.Format("{0} copy", selectedPocAgent.Name);
                    var maxCount  = FindPolicyIndexByTitle(labelName, labelName.ToUpper());
                    if (maxCount >= 1)
                    {
                        labelName += " (" + maxCount + ")";
                    }
                    var policy = CreatePolicyElementByName(labelName);
                    _view.PnlPolicyContainer.Children.Add(policy);
                    PolicyColorExisted.Add(policy.Model.ExpanderBackgroundColor);

                    var pocAgent = new POCAgent
                    {
                        POCServer         = selectedPocAgent.POCServer,
                        Key               = selectedPocAgent.Key,
                        Port              = selectedPocAgent.Port,
                        Name              = labelName,
                        NeighborhoodWatch = selectedPocAgent.NeighborhoodWatch,
                        ActiveTransfer    = selectedPocAgent.ActiveTransfer,
                        UpdateSource      = selectedPocAgent.UpdateSource,
                        SyncInterval      = selectedPocAgent.SyncInterval,
                        TransferInterval  = selectedPocAgent.TransferInterval,
                        Color             = policy.Model.ExpanderBackgroundColor
                    };

                    policy.Model.Id = Id = AddPocAgentToDb(pocAgent);
                    pocAgent.Id     = Id;
                    ApplicationContext.POCAgentList.Add(pocAgent);
                    policy.ActiveCurrentExpander();
                    BtnSaveVisible = true;
                }
            }
            catch (Exception e)
            {
                ApplicationContext.IsBusy = false;
                Logger.Error(e.Message, e);
            }
        }
Exemplo n.º 4
0
        private void UpdatePocAgent(POCAgent pa)
        {
            var pocAgent = ApplicationContext.POCAgentList.Find(r => r.Id == pa.Id);

            if (pocAgent != null)
            {
                pocAgent.POCServer         = pa.POCServer;
                pocAgent.Port              = pa.Port;
                pocAgent.Key               = pa.Key;
                pocAgent.NeighborhoodWatch = pa.NeighborhoodWatch;
                pocAgent.Name              = pa.Name;
                pocAgent.UpdateSource      = pa.UpdateSource;
                pocAgent.ActiveTransfer    = pa.ActiveTransfer;
                pocAgent.SyncInterval      = pa.SyncInterval;
                pocAgent.TransferInterval  = pa.TransferInterval;
            }
        }
Exemplo n.º 5
0
        private void AddNewPolicy()
        {
            try
            {
                ApplicationContext.IsBusy = true;
                var labelName = "New Policy";
                var maxCount  = FindPolicyIndex();
                if (maxCount >= 2)
                {
                    labelName += " (" + maxCount + ")";
                }
                var policy = CreatePolicyElementByName(labelName);
                _view.PnlPolicyContainer.Children.Add(policy);
                PolicyColorExisted.Add(policy.Model.ExpanderBackgroundColor);

                Uri myUri    = new Uri(ApplicationContext.ServerAddress);
                var pocAgent = new POCAgent
                {
                    POCServer         = myUri.Host,
                    Key               = KeyEncryption,
                    Port              = myUri.Port,
                    Name              = labelName,
                    NeighborhoodWatch = true,
                    ActiveTransfer    = ActiveTransfer,
                    UpdateSource      = UpdateSource,
                    SyncInterval      = 60,
                    TransferInterval  = 30,
                    Color             = policy.Model.ExpanderBackgroundColor
                };

                policy.Model.Id = Id = AddPocAgentToDb(pocAgent);
                pocAgent.Id     = Id;
                ApplicationContext.POCAgentList.Add(pocAgent);
                policy.ActiveCurrentExpander();
                BtnSaveVisible = true;
            }
            catch (Exception e)
            {
                ApplicationContext.IsBusy = false;
                Logger.Error(e.Message, e);
            }
        }