Ejemplo n.º 1
0
        private void delToolStripMenuItem_Click(object sender, EventArgs e)
        {
            VPNEntity entity = new VPNEntity();

            entity.ConnectionAddr  = this.listView_VPNSourceList.SelectedItems[0].SubItems[0].Text;
            entity.AccountName     = this.listView_VPNSourceList.SelectedItems[0].SubItems[1].Text;
            entity.AccountPassword = this.listView_VPNSourceList.SelectedItems[0].SubItems[2].Text;
            entity.DialType        = this.listView_VPNSourceList.SelectedItems[0].SubItems[3].Text;
            entity.Key             = this.listView_VPNSourceList.SelectedItems[0].SubItems[4].Text;
            entity.Supplementary   = this.listView_VPNSourceList.SelectedItems[0].SubItems[5].Text;



            controler.DelVpnEntityFromSource(entity);
            controler.SaveVPNSourceToFile();
            controler.RefreshVPNListToView();


            if (listView_VPNSourceList.Items.Count <= 0)
            {
                this.contextMenuStrip_Edit.Items[0].Enabled = true;
                this.contextMenuStrip_Edit.Items[1].Enabled = false;
                this.contextMenuStrip_Edit.Items[2].Enabled = false;

                this.editToolStripMenuItem.DropDownItems[0].Enabled = true;
                this.editToolStripMenuItem.DropDownItems[1].Enabled = false;
                this.editToolStripMenuItem.DropDownItems[2].Enabled = false;
            }
        }
Ejemplo n.º 2
0
 public void RemoveVPN(VPNEntity entity)
 {
     if (vpnList.Contains(entity))
     {
         vpnList.Remove(entity);
     }
 }
Ejemplo n.º 3
0
 public void AddVPN(VPNEntity entity)
 {
     if (!vpnList.Contains(entity))
     {
         vpnList.Add(entity);
     }
 }
Ejemplo n.º 4
0
        public void ModifyVPN(VPNEntity oEntity, VPNEntity mEntity)
        {
            int index = vpnList.IndexOf(oEntity);

            if (index != -1)
            {
                vpnList[index] = mEntity;
            }
        }
Ejemplo n.º 5
0
        public void SetFormByVPNEntity(VPNEntity entity)
        {
            this.InputAddress         = entity.ConnectionAddr;
            this.InputAccountName     = entity.AccountName;
            this.InputAccountPassword = entity.AccountPassword;

            this.InputDialType      = entity.DialType;
            this.InputKey           = entity.Key;
            this.InputSupplementary = entity.Supplementary;
        }
Ejemplo n.º 6
0
        public bool LoadFromFile(String filePath)
        {
            XmlDocument       xmlDoc   = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;
            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(filePath, settings);
                xmlDoc.Load(reader);

                XmlNode     root       = xmlDoc.SelectSingleNode("Source");
                XmlNodeList sourceList = root.ChildNodes;

                vpnList.Clear();

                foreach (XmlNode xn in sourceList)
                {
                    VPNEntity entity = new VPNEntity();

                    XmlElement  vpnEntity = (XmlElement)xn;
                    XmlNodeList vpnAttrs  = vpnEntity.ChildNodes;
                    entity.ConnectionAddr  = vpnAttrs.Item(0).InnerText;
                    entity.AccountName     = vpnAttrs.Item(1).InnerText;
                    entity.AccountPassword = vpnAttrs.Item(2).InnerText;
                    entity.DialType        = vpnAttrs.Item(3).InnerText;
                    entity.Key             = vpnAttrs.Item(4).InnerText;
                    entity.Supplementary   = vpnAttrs.Item(5).InnerText;

                    vpnList.Add(entity);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditEntityForm addEntityForm = new EditEntityForm();

            addEntityForm.Text = "Add new entity";
            if (addEntityForm.ShowDialog(this) == DialogResult.OK)
            {
                VPNEntity entity = new VPNEntity();
                entity.ConnectionAddr  = addEntityForm.InputAddress;
                entity.AccountName     = addEntityForm.InputAccountName;
                entity.AccountPassword = addEntityForm.InputAccountPassword;
                entity.DialType        = addEntityForm.InputDialType;
                entity.Key             = addEntityForm.InputKey;
                entity.Supplementary   = addEntityForm.InputSupplementary;

                this.controler.AddVpnEntityToSource(entity);
                this.controler.SaveVPNSourceToFile();
                this.controler.RefreshVPNListToView();
            }
        }
Ejemplo n.º 8
0
        private void modifyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditEntityForm modifyEntityForm = new EditEntityForm();

            modifyEntityForm.Text = "Modify entity";

            VPNEntity originalEntity = new VPNEntity();

            originalEntity.ConnectionAddr  = this.listView_VPNSourceList.SelectedItems[0].SubItems[0].Text;
            originalEntity.AccountName     = this.listView_VPNSourceList.SelectedItems[0].SubItems[1].Text;
            originalEntity.AccountPassword = this.listView_VPNSourceList.SelectedItems[0].SubItems[2].Text;
            originalEntity.DialType        = this.listView_VPNSourceList.SelectedItems[0].SubItems[3].Text;
            originalEntity.Key             = this.listView_VPNSourceList.SelectedItems[0].SubItems[4].Text;
            originalEntity.Supplementary   = this.listView_VPNSourceList.SelectedItems[0].SubItems[5].Text;

            modifyEntityForm.SetFormByVPNEntity(originalEntity);


            if (modifyEntityForm.ShowDialog(this) == DialogResult.OK)
            {
                VPNEntity modifiedEntity = new VPNEntity();
                modifiedEntity.ConnectionAddr  = modifyEntityForm.InputAddress;
                modifiedEntity.AccountName     = modifyEntityForm.InputAccountName;
                modifiedEntity.AccountPassword = modifyEntityForm.InputAccountPassword;
                modifiedEntity.DialType        = modifyEntityForm.InputDialType;
                modifiedEntity.Key             = modifyEntityForm.InputKey;
                modifiedEntity.Supplementary   = modifyEntityForm.InputSupplementary;

                if (originalEntity.Equals(modifiedEntity))
                {
                    return;
                }
                else
                {
                    controler.ModifyVpnEntityInSource(originalEntity, modifiedEntity);
                    controler.SaveVPNSourceToFile();
                    controler.RefreshVPNListToView();
                }
            }
        }
Ejemplo n.º 9
0
        public override bool Equals(object obj)
        {
            if (!(obj is VPNEntity))
            {
                return(false);
            }

            VPNEntity entity = obj as VPNEntity;

            if (entity.ConnectionAddr.Equals(this.connectionAddr) &&
                entity.AccountName.Equals(this.accountName) &&
                entity.AccountPassword.Equals(this.accountPassword) &&
                entity.DialType.Equals(this.dialType) &&
                entity.Key.Equals(this.key) &&
                entity.Supplementary.Equals(this.supplementary))

            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
 public void ModifyVpnEntityInSource(VPNEntity oEntity, VPNEntity mEntity)
 {
     vpnResource.ModifyVPN(oEntity, mEntity);
 }
Ejemplo n.º 11
0
 public void DelVpnEntityFromSource(VPNEntity entity)
 {
     vpnResource.RemoveVPN(entity);
 }
Ejemplo n.º 12
0
 public void AddVpnEntityToSource(VPNEntity entity)
 {
     vpnResource.AddVPN(entity);
 }