예제 #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>
 /// Called when [run status changed handler].
 /// </summary>
 /// <param name="profileSender">The profile sender.</param>
 /// <param name="e">The <see cref="Argon.Common.NotifyEventArgs"/> instance containing the event data.</param>
 public static void OnNotifyHandler(Object sender, NotifyEventArgs e)
 {
     if (!e.Error)
     {
         UseCaseLogger.ShowInfo(e.Description);
     }
     else
     {
         UseCaseLogger.ShowError(e.Description);
     }
 }
예제 #3
0
        /// <summary>
        /// Sets the status card.
        /// </summary>
        /// <param name="enabled">if set to <c>true</c> [enabled].</param>
        private static void SetStatusCard(bool enabled)
        {
            WindowsNetworkCard ni = DataModel.SelectedNetworkCard;

            if (ni != null && ni.HardwareName.Length > 0)
            {
                String label = enabled ? "Enabled" : "Disabled";

                bool status = WindowsNetworkCardHelper.SetDeviceStatus(ni, enabled);
                UseCaseLogger.ShowInfo(label + " Network Card " + ni.HardwareName + " (" + status + ")");

                RefreshNetworkCardListStatus();
            }
        }
예제 #4
0
        /// <summary>
        /// Saves the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="showDialog">if set to <c>true</c> [show dialog].</param>
        /// <returns></returns>
        public static bool Save(string fileName = DEFAULT_FILENAME, bool showDialog = false)
        {
            if (showDialog)
            {
                DialogResult result;
                result = MessageBox.Show("Do you want to save default config?", "Save config", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                switch (result)
                {
                case DialogResult.Cancel:
                    return(false);

                case DialogResult.No:
                    SaveFileDialog dialog = new SaveFileDialog();

                    dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
                    //dialog.InitialDirectory = initialDirectory;
                    dialog.Title = "Select a config file to save";

                    result = dialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        fileName = dialog.FileName;
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case DialogResult.Yes:
                    break;
                }
            }

            bool ret = NetworkProfileHelper.Save(DataModel.NetworkProfileList, fileName);

            UseCaseLogger.ShowInfo("Saved file '" + Path.GetFullPath(fileName) + "'");

            return(ret);
        }
예제 #5
0
        /// <summary>
        /// Refreshes all network card status.
        /// </summary>
        public static void RefreshNetworkCardListStatus()
        {
            // refresh the card list in data model
            DataModel.NetworkCardList = WindowsNetworkCardManager.WindowsNetworkCardList;
            UseCaseLogger.ShowInfo("Refresh network card list status");

            // put datamodel list in listview
            ObjectListView listView = ViewModel.NetworkCardsView.listView;

            listView.ClearObjects();
            listView.AddObjects(DataModel.NetworkCardList);

            // refresh list in every window profile form
            foreach (FormProfile item in ViewModel.ProfileViewList)
            {
                item.RefreshNetworkAdapter();
                // TODO fix me
                // item.ipControl.RefreshWifiCombo();
            }
        }
예제 #6
0
        /// <summary>
        /// Loads the specified form main.
        /// </summary>
        /// <param name="formMain">The form main.</param>
        public static void Load(FormMain formMain)
        {
            Version curVersion = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;

            formMain.Text += " - " + curVersion.Major + "." + curVersion.Minor + "." + curVersion.Build;

            // default value
            DataModel.BlockAllOperation  = false;
            DataModel.NetworkCardList    = new List <WindowsNetworkCard>();
            DataModel.NetworkProfileList = new List <NetworkProfile>();

            // create other forms
            CreateForms(formMain);

            // display form
            DisplayFormsInDefaultPosition();

            UseCaseLogger.ShowInfo("Startup program");

            // set the event handler
            NetworkProfileHelper.NotifyEvent += UseCaseLogger.OnNotifyHandler;

            // load the profiles
            UseCaseConfig.Load();

            // check autodetect
            if (Argon.Windows.Forms.Properties.Settings.Default.AutodetectOnStart)
            {
                UseCaseProfile.RunAutoDetect(false);
            }

            // check autodetect
            if (Argon.Windows.Forms.Properties.Settings.Default.CheckForUpdate)
            {
                // do not check info box if updated
                VerifyUpdate(false);
            }
        }
예제 #7
0
 /// <summary>
 /// Called when [run status changed handler].
 /// </summary>
 /// <param name="profileSender">The profile sender.</param>
 /// <param name="e">The <see cref="Argon.Common.NotifyEventArgs"/> instance containing the event data.</param>
 public static void OnRunStatusChangedHandler(Object profileSender, NotifyEventArgs e)
 {
     UseCaseLogger.ShowInfo(e.Description);
     ViewModel.MainView.backgroundWorker.ReportProgress(e.Percentage);
 }
예제 #8
0
        /// <summary>
        /// Loads the specified file name. If operation is ok, DataModel.NetworkProfileList is filled.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="showDialog">if set to <c>true</c> [show dialog].</param>
        /// <returns></returns>
        public static void Load(string fileName = DEFAULT_FILENAME, bool showDialog = false)
        {
            if (showDialog)
            {
                DialogResult result;
                result = MessageBox.Show("Do you want to load default config?", "Load config", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                switch (result)
                {
                case DialogResult.Cancel:
                    return;

                case DialogResult.No:
                    OpenFileDialog dialog = new OpenFileDialog();

                    dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
                    //dialog.InitialDirectory = initialDirectory;
                    dialog.Title = "Select a config file to load";

                    result = dialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        fileName = dialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case DialogResult.Yes:
                    break;
                }
                ;
            }
            else
            {
                // ASSERT: no dialog to show
                //To get the location the assembly normally resides on disk or the install directory
                string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);


                //once you have the path you get the directory with:
                if (!Path.IsPathRooted(fileName))
                {
                    // ANS-16
                    fileName = Path.Combine(path, fileName);
                    Uri uri = new Uri(fileName);

                    fileName = Uri.UnescapeDataString(uri.AbsolutePath);
                }
            }



            // execute config default
            List <NetworkProfile> list = NetworkProfileHelper.Load(fileName);

            UseCaseLogger.ShowInfo("Load file '" + Path.GetFullPath(fileName) + "'");

            if (!File.Exists(Path.GetFullPath(fileName)))
            {
                UseCaseLogger.ShowError("Ehi! No file '" + Path.GetFullPath(fileName) + "' found!");
            }
            else if (list.Count == 0)
            {
                UseCaseLogger.ShowError("Ehi! 0 profiles found!");
            }
            else
            {
                DataModel.NetworkProfileList = list;
                UseCaseProfile.Refresh();
            }
        }
예제 #9
0
 /// <summary>
 /// Selects the network card.
 /// </summary>
 /// <param name="card">The card.</param>
 public static void SelectNetworkCard(WindowsNetworkCard card)
 {
     DataModel.SelectedNetworkCard = card;
     UseCaseLogger.ShowInfo("Selected network card " + card.Name);
 }