/// <summary> /// Initializes a new instance of the <see cref="TaskForm"/> class and populates form controls with the <see cref="Task"/> properties. /// </summary> /// <param name="task"><see cref="Task"/> to be edited.</param> public TaskForm(Task task) : this() { _guid = task.Guid; titleTextBox.Text = task.Title; sourceFolderBrowserDialog.SelectedPath = sourceTextBox.Text = task.Source; PopulateSourceTreeView(); foreach (string path in task.ExcludedDirs) { TreeNode node = DirectoryTree.FindNode(sourceTreeView.Nodes, path); if (node != null) { node.Checked = false; } } foreach (string path in task.ExcludedFiles) { TreeNode node = DirectoryTree.FindNode(sourceTreeView.Nodes, path); if (node != null) { node.Checked = false; } } destinationFolderBrowserDialog.SelectedPath = destinationTextBox.Text = task.Destination; if (!string.IsNullOrEmpty(task.Credential)) { usernameTextBox.Text = Lang.Get("ReenterCredentials"); } if (task.Method == Method.Differential) { differentialRadioButton.Checked = true; retentionNumericUpDown.Value = task.Retention; } else if (task.Method == Method.Full) { fullRadioButton.Checked = true; retentionNumericUpDown.Value = task.Retention; } if (task.Period == Period.Weekly) { weekdayComboBox.SelectedIndex = (int)task.DayOfWeek; } else if (task.Period == Period.Monthly) { monthdayNumericUpDown.Value = task.DayOfMonth; } timeDateTimePicker.Value = DateTime.Today.AddHours(task.Hour).AddMinutes(task.Minute);; }
/// <summary> /// Populates the <see cref="sourceTreeView"/> with nodes corresponding to filesystem objects located under the directory selected by <see cref="sourceFolderBrowserDialog"/>. /// </summary> private void PopulateSourceTreeView() { sourceTreeView.Nodes.Clear(); sourceTreeView.Nodes.AddRange(DirectoryTree.LoadNodes(sourceFolderBrowserDialog.SelectedPath)); }
/// <summary> /// <see cref="sourceTreeView.AfterCheck"/> event handler. Toggles <see cref="TreeNode.Checked"/> for the <see cref="TreeNode.Nodes"/> of the node which received the click. /// </summary> private void SourceTreeView_AfterCheck(object sender, TreeViewEventArgs e) { DirectoryTree.ToggleChildren(e.Node, e.Node.Checked); }
/// <summary> /// Collects form control values and creates a <see cref="ResultTask"/> form result. /// </summary> private void CreateTask() { _guid = _guid ?? Guid.NewGuid().ToString(); Task task = new Task() { Guid = _guid, Title = titleTextBox.Text, Source = sourceTextBox.Text, Destination = destinationTextBox.Text }; List <TreeNode> excludedNodes = DirectoryTree.GetExcludedNodes(sourceTreeView.Nodes); List <string> excludedDirs = new List <string>(); List <string> excludedFiles = new List <string>(); foreach (TreeNode node in excludedNodes) { if ((EntryType)node.Tag == EntryType.Directory) { excludedDirs.Add(node.FullPath); } else { excludedFiles.Add(node.FullPath); } } task.ExcludedDirs = excludedDirs.ToArray(); task.ExcludedFiles = excludedFiles.ToArray(); task.Credential = Credential.Encrypt(_guid, new Credential() { Username = usernameTextBox.Text, Password = passwordTextBox.Text }); if (incrementalRadioButton.Checked) { task.Method = Method.Incremental; task.Retention = 1; } else if (differentialRadioButton.Checked) { task.Method = Method.Differential; task.Retention = (ushort)retentionNumericUpDown.Value; } else { task.Method = Method.Full; task.Retention = (ushort)retentionNumericUpDown.Value; } if (dailyRadioButton.Checked) { task.Period = Period.Daily; } else if (weeklyRadioButton.Checked) { task.Period = Period.Weekly; task.DayOfWeek = (DayOfWeek)weekdayComboBox.SelectedIndex; } else { task.Period = Period.Monthly; task.DayOfMonth = (byte)monthdayNumericUpDown.Value; } task.Hour = (byte)timeDateTimePicker.Value.Hour; task.Minute = (byte)timeDateTimePicker.Value.Minute; ResultTask = task; }