예제 #1
0
        /// <summary>
        /// Deletes the profile.
        /// </summary>
        public static void DeleteProfile(NetworkProfile profile = null)
        {
            if (profile == null)
            {
                profile = DataModel.SelectedNetworkProfile;

                if (profile == null)
                {
                    MyMessageBox.ShowMessage("No profile selected!");
                    return;
                }
            }

            // check if it is possibile to do operation
            if (UseCaseApplication.CheckIsOperationNotAllowedNow())
            {
                return;
            }

            bool res = MyMessageBox.Ask("Do you want to delete profile " + profile.Name + "?");

            if (res)
            {
                UseCaseLogger.ShowInfo("Remove profile [" + profile.Name + "]");
                DataModel.NetworkProfileList.Remove(profile);
                DataModel.SelectedNetworkProfile = null;
                UseCaseView.FindAndCloseProfile(profile);
                UseCaseProfile.Refresh();
            }
        }
예제 #2
0
        /// <summary>
        /// Saves the current profile.
        /// </summary>
        public static void SaveProfile(NetworkProfile profile = null)
        {
            if (profile == null)
            {
                FormProfile viewProfile = ViewModel.SelectedView as FormProfile;

                if (viewProfile == null)
                {
                    MyMessageBox.ShowAlert("No profile selected!");
                    return;
                }

                // ANS-10: check if any nic is selected
                if (viewProfile.SelectedNetworkCard == null)
                {
                    MyMessageBox.ShowAlert("No network card is selected, profile is not saved!");
                    return;
                }

                // check if it is possibile do operation
                if (UseCaseApplication.CheckIsOperationNotAllowedNow())
                {
                    return;
                }


                viewProfile.StoreFormOnData();
                profile = viewProfile.Profile;
            }
            if (profile.IsNew)
            {
                profile.Id = CreateNewProfileId();
                // if not exist add it
                DataModel.NetworkProfileList.Add(profile);
            }
            else
            {
                // save profile
                for (int i = 0; i < DataModel.NetworkProfileList.Count; i++)
                {
                    if (profile.Id == DataModel.NetworkProfileList[i].Id)
                    {
                        // found e replace
                        DataModel.NetworkProfileList[i] = profile;
                        break;
                    }
                }
            }
            // list refresh
            Refresh();
        }
예제 #3
0
        /// <summary>
        /// Shows the new profile.
        /// </summary>
        public static void ShowNewProfile()
        {
            // check if it is possibile to do operation
            if (UseCaseApplication.CheckIsOperationNotAllowedNow())
            {
                return;
            }

            NetworkProfile profile = new NetworkProfile();

            profile.Name = UseCaseProfile.NEW_NIC_NAME;

            ShowProfile(profile);
        }
예제 #4
0
        /// <summary>
        /// Runs current profile.
        /// </summary>
        public static void Run()
        {
            // check if it is possibile to do operation
            if (UseCaseApplication.CheckIsOperationNotAllowedNow())
            {
                return;
            }

            if (DataModel.SelectedNetworkProfile == null)
            {
                MyMessageBox.ShowMessage("No profile selected!");
                return;
            }

            if (MyMessageBox.Ask("Do you want to run the profile " + DataModel.SelectedNetworkProfile.Name + "?"))
            {
                ViewModel.MainView.backgroundWorker.RunWorkerAsync(DataModel.SelectedNetworkProfile);
            }
        }
예제 #5
0
        /// <summary>
        /// Duplicates the profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public static void DuplicateProfile(NetworkProfile profile)
        {
            // check if it is possibile to do operation
            if (UseCaseApplication.CheckIsOperationNotAllowedNow())
            {
                return;
            }

            NetworkProfile newProfile = new NetworkProfile();

            newProfile = NetworkProfile.Copy(profile);

            newProfile.Id   = UseCaseProfile.CreateNewProfileId();
            newProfile.Name = "Copy of " + newProfile.Name;

            DataModel.NetworkProfileList.Add(newProfile);

            Refresh();
        }
예제 #6
0
        /// <summary>
        /// Disables the network card.
        /// </summary>
        public static void DisableNetworkCard()
        {
            if (DataModel.SelectedNetworkCard == null)
            {
                MyMessageBox.ShowMessage("No network card selected!");
                return;
            }

            // check if it is possibile to do operation
            if (UseCaseApplication.CheckIsOperationNotAllowedNow())
            {
                return;
            }

            if (MyMessageBox.Ask("Do you want to disable network card " + DataModel.SelectedNetworkCard.Name + "?"))
            {
                SetStatusCard(false);
            }
        }
예제 #7
0
        /// <summary>
        /// Refreshes the specified refresh list view.
        /// </summary>
        /// <param name="refreshListView">if set to <c>true</c> [refresh list view].</param>
        public static void Refresh(bool refreshListView = true)
        {
            RibbonButton rButton = null;

            ViewModel.MainView.rbtnProfilesList.DropDownItems.Clear();
            ObjectListView listView = ViewModel.ProfilesView.listView;

            if (refreshListView)
            {
                listView.ClearObjects();

                // if last order is defined, we reset it
                if (listView.LastSortColumn != null)
                {
                    listView.LastSortOrder  = SortOrder.None;
                    listView.LastSortColumn = null;
                }
            }

            // can not  use context menu in windows form so we create it programmatically
            NotifyIcon       ni  = ViewModel.MainView.notifyIcon;
            ContextMenuStrip cms = new ContextMenuStrip();
            //ToolStripMenuItem tsi = new ToolStripMenuItem("Open window", null, null, "mnuOpenWindow");
            //cms.Items.Add(tsi);
            ToolStripMenuItem tsi;

            ni.ContextMenuStrip = cms;

            // if there are no profile define, no separator.
            if (DataModel.NetworkProfileList.Count > 0)
            {
                tsi        = new ToolStripMenuItem("Run Autodetect");
                tsi.Click += new System.EventHandler(ViewModel.MainView.rbtnProfileAutorun_Click);
                cms.Items.Add(tsi);

                ToolStripSeparator tss = new ToolStripSeparator();
                cms.Items.Add(tss);
            }


            foreach (NetworkProfile item in DataModel.NetworkProfileList)
            {
                // 1 - refresh the profileView
                if (refreshListView)
                {
                    listView.AddObject(item);
                }

                // 2 - refresh the ribbonPanel in mainView
                rButton = new RibbonButton();

                rButton.Text         = item.Name;
                rButton.ToolTip      = item.Name;
                rButton.ToolTipTitle = item.Name;

                rButton.SmallImage = UseCaseApplication.GetImage(item.ImageName);
                rButton.Tag        = item;
                //rButton.Image = global::Argon.Windows.Forms.Properties.Resources.profile_0_48x48;
                rButton.Image = UseCaseApplication.GetImage(item.ImageName);
                //rButton.SmallImage = UseCaseApplication.GetImage(item.ImageName);
                rButton.Click += new System.EventHandler(ViewModel.MainView.btnRunProfile_Click);

                ViewModel.MainView.rbtnProfilesList.DropDownItems.Add(rButton);

                tsi        = new ToolStripMenuItem("Run " + item.Name, UseCaseApplication.GetImage(item.ImageName));
                tsi.Tag    = item;
                tsi.Click += new System.EventHandler(ViewModel.MainView.btnRunProfile_Click);
                cms.Items.Add(tsi);
            }

            // if there are no profile define, no separator.
            if (DataModel.NetworkProfileList.Count > 0)
            {
                ToolStripSeparator tss = new ToolStripSeparator();
                cms.Items.Add(tss);
            }

            tsi        = new ToolStripMenuItem("Close program");
            tsi.Click += new System.EventHandler(ViewModel.MainView.btnClose_Click);
            cms.Items.Add(tsi);


            // bug on ribbon: if i don't do it, buttons are not display untill change tab
            ViewModel.MainView.Width += 1;
            ViewModel.MainView.Width -= -1;
        }