Example #1
0
        void init_gui(EncryptedBackup encrypted_backup)
        {
            // Name_tb, Enabled_cb
            Name_tb.Text         = encrypted_backup.future_params.name;
            Enabled_cb.IsChecked = encrypted_backup.future_params.enabled;

            // Info_text
            source_base = encrypted_backup.source_base;

            var sb = new StringBuilder();

            sb.AppendLine("Source: " + encrypted_backup.source_base);

            if (encrypted_backup.destination_name.ToLower().Equals("disk"))
            {
                sb.AppendLine("Destination: " + encrypted_backup.destination_base);
            }
            else
            {
                sb.AppendLine("Destination: " + encrypted_backup.destination_name
                              + "\\" + encrypted_backup.destination_base);
            }

            sb.AppendLine("Embedded Prefix: " + encrypted_backup.embedded_prefix);
            Info_text.Text = sb.ToString();

            // Rules_lb
            rule_lists = encrypted_backup.future_params.rule_lists;
            AddBackup_Page.redraw_backup_rules_listbox(Rules_lb, rule_lists);
        }
Example #2
0
        void init_gui(DiskBackup disk_backup)
        {
            // Name_tb, Enabled_cb
            Name_tb.Text         = disk_backup.future_params.name;
            Enabled_cb.IsChecked = disk_backup.future_params.enabled;

            // Info_text
            source_base    = disk_backup.source_base;
            Info_text.Text = "Source: " + source_base + "\n"
                             + "Destination: " + disk_backup.destination_base;

            // Rules_lb
            rule_lists = disk_backup.future_params.rule_lists;
            AddBackup_Page.redraw_backup_rules_listbox(Rules_lb, rule_lists);
        }
Example #3
0
        /// <summary>
        /// Renders a BackupRuleLists object onto a list box.
        /// This function is also used by EditBackup_Page.
        /// </summary>
        internal static void redraw_backup_rules_listbox(ListBox lisbox, BackupRuleLists rule_lists)
        {
            lisbox.Items.Clear();

            int num_categories = rule_lists.backup_rule_lists.Count;

            for (int category = 0; category < num_categories; category++)
            {
                for (int index = 0;
                     index < rule_lists.backup_rule_lists[category].Count; index++)
                {
                    string display = rule_lists.backup_rule_lists[category][index].ToString();
                    if (num_categories > 1)
                    {
                        display = category + " " + display;
                    }

                    var item = new Rule_ListBoxItem(display, category, index);
                    lisbox.Items.Add(item);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Tests the BackupRuleList class. Instantiate rules from XML and
        /// asks these rules to accept or reject some file paths.
        /// </summary>
        public void test_BackupRuleList()
        {
            // BackupRuleList
            XElement backup_rule_list_xml = XElement.Parse(
                @"<BackupRuleList>
              <category>
                  <BackupRule>
                      <directory>E:\temp\temp</directory>
                      <rule_type>ACCEPT_ALL</rule_type>
                  </BackupRule>
                  <BackupRule>
                      <directory>E:\temp\temp\packages</directory>
                      <rule_type>REJECT_ALL</rule_type>
                  </BackupRule>
                  <BackupRule>
                      <directory>E:\temp\temp\config</directory>
                      <rule_type>ACCEPT_SUFFIX</rule_type>
                      <suffixes>.xml .json</suffixes>
                  </BackupRule>
                  <BackupRule>
                      <directory>E:\temp\temp\src</directory>
                      <rule_type>REJECT_SUFFIX</rule_type>
                      <suffixes>.tmp</suffixes>
                  </BackupRule>
              </category>
              <category>
                  <BackupRule>
                      <directory>E:\temp\temp</directory>
                      <rule_type>REJECT_SUB_DIR</rule_type>
                      <subdirs>__pycache__ .git</subdirs>
                  </BackupRule>
                  <BackupRule>
                      <directory>E:\temp\temp\temp2</directory>
                      <rule_type>ACCEPT_ALL</rule_type>
                  </BackupRule>
              </category>
          </BackupRuleList>"
                );

            Console.WriteLine("Testing BackupRuleList");
            var backup_rule_lists = new BackupRuleLists(backup_rule_list_xml);

            Console.WriteLine("backup_rule_list in XML form:");
            Console.WriteLine(backup_rule_lists.to_xml());

            Console.WriteLine();
            Console.WriteLine("Trying some files on BackupRuleList:");
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\whatever.txt") == true);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\xyz.anything") == true);

            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\packages\whatever.txt") == false);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\packages\xyz.anything") == false);

            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\config\whatever.txt") == false);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\config\whatever.xml") == true);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\config\whatever.json") == true);

            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\src\xyz.tmp") == false);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\src\xyz.anything_else") == true);

            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\src\__pycache__\whatever") == false);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\src\.git\whatever") == false);
            Debug.Assert(backup_rule_lists.accepts(@"E:\temp\temp\temp2\temp3\__pycache__\whatever") == true);

            Console.WriteLine("BackupRuleList has been tested.");
        }