Esempio n. 1
0
        //private bool OptionIsExecuting = false;

        ////--FORM RESIZING VARIABLES
        //private readonly int InitialFormHeight;
        //private readonly int InitialFormWidth;
        //private readonly int ListOptionHeight = 17;
        //private readonly int AditionalListViewItemCount = 6;
        //private readonly int InitialListViewItemCount = 10;
        //private readonly int MaximumListViewItemCount;

        public FormOptionsMenu(FormProfileMenu profileMenu, Profile profile)
        {
            //this.listViewOptions.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ContextMenuStripOptionsList_Click);
            ClickTimer.Elapsed  += ClickTimer_Elapsed;
            ClickTimer.AutoReset = false;
            InitializeComponent();
            listViewOptions.MouseDown += ListViewOptions_MouseDown;
            listViewOptions.DragEnter += ListViewOptions_DragEnter;
            listViewOptions.DragDrop  += ListViewOptions_DragDrop;
            listViewOptions.MouseUp   += ListViewOptions_MouseUp;

            Profile             = profile;
            ProfileMenu         = profileMenu;
            CancelExecutionForm = new FormCancelExecution();
            Text = "Profile:  " + Profile.Name;
            if (profileMenu.LastReport != null)
            {
                buttonShowResult.Enabled = true;
            }

            //InitialFormHeight = Bounds.Height;
            //InitialFormWidth = Bounds.Width;
            //AditionalListViewItemCount = 6;
            //InitialListViewItemCount = 10;
            //MaximumListViewItemCount = AditionalListViewItemCount + InitialListViewItemCount;

            ListOptions();
        }
Esempio n. 2
0
        public FormEditProfile(FormProfileMenu menu, Profile profile = null)
        {
            InitializeComponent();
            textBoxProfileName.AcceptsReturn = false;
            KeyPreview  = true;
            ProfileMenu = menu;

            if (profile == null)
            {
                Action = FormEditProfileAction.ADD;
                Text   = "Add profile";
                textBoxProfileName.Text = "New Profile";
            }
            else
            {
                Profile = profile;
                textBoxProfileName.Text = profile.Name;
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length > 0)
            {
                bool   showDialogs = true;
                string profileNamesStr;
                string dialogMessage;

                LogManager.BeginWritter();

                try
                {
                    if (args.Length == 1)
                    {
                        profileNamesStr = args[0];
                    }
                    else if (args.Length == 2)
                    {
                        if (!args[0].Equals("-nd", StringComparison.OrdinalIgnoreCase))
                        {
                            dialogMessage = $"Invalid parameter \"{args[0]}\". Canceled.";
                            if (showDialogs)
                            {
                                MessageBox.Show(dialogMessage);
                            }
                            LogManager.WriteLine(dialogMessage);
                            return;
                        }

                        showDialogs     = false;
                        profileNamesStr = args[1];
                    }
                    else
                    {
                        dialogMessage = "Invalid number of parameters. Canceled.";
                        LogManager.WriteLine(dialogMessage);
                        if (showDialogs)
                        {
                            MessageBox.Show(dialogMessage);
                        }
                        return;
                    }

                    //-- Set parent process as the console
                    AttachConsole(-1);
                    LogManager.WriteLine("Starting transfer from parameters...");

                    List <Profile> profiles = DBAccess.ListProfiles();

                    if (profiles.Count == 0)

                    {
                        dialogMessage = "No profiles saved in the database. Canceled.";
                        LogManager.WriteLine(dialogMessage);
                        if (showDialogs)
                        {
                            MessageBox.Show(dialogMessage);
                        }
                        return;
                    }

                    string[] profileNames = profileNamesStr.Split(';');
                    FileControlConsoleImpl fileControl = new FileControlConsoleImpl(showDialogs);

                    foreach (string profileName in profileNames)
                    {
                        Profile profile = profiles.Find(p => p.Name == profileName);

                        if (profile == null)
                        {
                            LogManager.WriteLine($"No profile named \"{profileName}\" available in the database.");
                            dialogMessage = $"No profile named \"{profileName}\" available in the database.{Environment.NewLine}" +
                                            $"Proceed to the next profile?";

                            if (showDialogs && MessageBox.Show(dialogMessage, "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                            {
                                LogManager.WriteLine("Transfer canceled by user.");
                                break;
                            }
                            else
                            {
                                LogManager.WriteLine("Continuing to the next profile.");
                                continue;
                            }
                        }

                        try
                        {
                            LogManager.WriteLine($"Working on profile \"{profileName}\"");
                            profile.Options = DBAccess.ListProfileOptions(profile).OrderBy(o => o.ListViewIndex).ToList();

                            foreach (Options o in profile.Options)
                            {
                                if (!o.AllowIgnoreFileExt)
                                {
                                    o.SpecifiedFileNamesAndExtensions.Clear();                        //-- Names must be ignored
                                }
                                o.SourcePath  = Environment.ExpandEnvironmentVariables(o.SourcePath);
                                o.DestinyPath = Environment.ExpandEnvironmentVariables(o.DestinyPath);
                            }

                            UpdateLastTimeExecuted(profile);
                            fileControl.ManageFiles(DBAccess.ListProfileOptions(profile).ToList <TransferSettings>());
                        }
                        catch (Exception e)
                        {
                            LogManager.WriteLine($"Error: {e.Message} while executing \"{profile.Name}\".");
                            dialogMessage = $"Error: {e.Message} while executing \"{profile.Name}\". Proceed to the next profile?";
                            if (showDialogs && MessageBox.Show(dialogMessage, "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                            {
                                LogManager.WriteLine("Transfer canceled by user.");
                                break;
                            }

                            LogManager.WriteLine("Continuing to the next profile.");
                        }
                        finally
                        {
                            if (profile != null)
                            {
                                UpdateLastTimeExecuted(profile);
                            }
                        }
                    }

                    return;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return;
                }
                finally
                {
                    LogManager.WriteLine("DONE");
                    LogManager.WriteLine("");
                    LogManager.CloseWritter();
                }
            }

            if (ApplicationIsRunning())
            {
                MessageBox.Show("Application is already running.");
                return;
            }

            //if (!File.Exists(DBPath))
            //{
            //File.Create(DBPath);
            //DBConnection dbc = new DBConnection();
            //dbc.CreateDatabase();
            //    File.Create()
            //}

            Console.WriteLine("Backup Helper - Log...");
            ProfileMenu = new FormProfileMenu();
            Application.Run(ProfileMenu);
        }