Exemple #1
0
        public static void SerializationTest(System.Windows.Controls.Image image)
        {
            System.Diagnostics.Debug.WriteLine("*** SerializationTest ***");
            // "0,3,2,1"
            MRUItem item = new MRUItem();

            item.Path       = @"C:\Data";
            item.FileName   = "001";
            item.PageNumber = 101;
            //item.CoverImage = image;
            item.Thumb = (System.Windows.Media.Imaging.RenderTargetBitmap)image.Source;
            MRUItem.Serialize(@"D:\MRUItemXml.xml", item);

            MRUItem item2 = MRUItem.DeSerialize(@"D:\MRUItemXml.xml");

            if ((item.Path != item2.Path) || (item.FileName != item2.FileName))
            {
                throw new ArgumentOutOfRangeException();
            }
            MRUList list = FilledTestList();

            CheckPageNumber(list, "0,3,2,1");
            MRUList.Serialize(@"D:\MRUListXml.xml", list);
            MRUList list2 = MRUList.DeSerialize(@"D:\MRUListXml.xml");

            CheckPageNumber(list2, "0,3,2,1");
            System.Diagnostics.Debug.WriteLine("*** End SerializationTest ***");
        }
Exemple #2
0
        public static void InsertTest()
        {
            System.Diagnostics.Debug.WriteLine("*** InsertTest ***");
            MRUList list = FilledTestList();
            MRUItem item = new MRUItem();

            item.Path       = @"C:\Data";
            item.FileName   = "001";
            item.PageNumber = 101;
            list.Insert(3, item);
            CheckPageNumber(list, "0,3,2,101");
            list = FilledTestList();
            list.Insert(0, item);
            CheckPageNumber(list, "101,0,3,2");
            list = FilledTestList();
            list.Insert(1, item);
            CheckPageNumber(list, "0,101,3,2");
            list            = FilledTestList();
            item.Path       = @"C:\Data";
            item.FileName   = "004";
            item.PageNumber = 104;
            list.Insert(1, item);
            CheckPageNumber(list, "0,104,3,2,1");
            list            = FilledTestList();
            item.FileName   = "002";
            item.PageNumber = 102;
            list.AddMRUItem(item);
            CheckPageNumber(list, "102,0,3,1");

            System.Diagnostics.Debug.WriteLine("*** End InsertTest ***");
        }
Exemple #3
0
        public static MRUList FilledTestList()
        {
            MRUList list = new MRUList();
            MRUItem item = new MRUItem();

            item.Path       = @"C:\Data\";
            item.FileName   = @"000";
            item.PageNumber = 100;
            list.AddMRUItem(item);
            item            = new MRUItem();
            item.Path       = @"C:\Data";
            item.FileName   = @"001";
            item.PageNumber = 1;
            list.AddMRUItem(item);
            item            = new MRUItem();
            item.Path       = @"C:\Data\";
            item.FileName   = @"002";
            item.PageNumber = 2;
            list.AddMRUItem(item);
            item            = new MRUItem();
            item.Path       = @"C:\Data";
            item.FileName   = @"003";
            item.PageNumber = 3;
            list.AddMRUItem(item);
            item            = new MRUItem();
            item.Path       = @"C:\Data";
            item.FileName   = @"000";
            item.PageNumber = 0;
            list.AddMRUItem(item);
            return(list);
        }
Exemple #4
0
        public static void IndexOfTest()
        {
            System.Diagnostics.Debug.WriteLine("*** IndexOfTest ***");
            // "0,3,2,1"
            MRUList list = FilledTestList();
            MRUItem item = new MRUItem();

            item.Path       = @"C:\Data";
            item.FileName   = "001";
            item.PageNumber = 101;
            if (list.IndexOf(item) != 3)
            {
                throw new ArgumentOutOfRangeException();
            }
            item.FileName = "000";
            if (list.IndexOf(item) != 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            item.FileName = "OhGreat";
            if (list.Contains(item))
            {
                throw new ArgumentOutOfRangeException();
            }
            item.FileName = "003";
            if (!list.Contains(item))
            {
                throw new ArgumentOutOfRangeException();
            }


            System.Diagnostics.Debug.WriteLine("*** End IndexOfTest ***");
        }
Exemple #5
0
        //public List<MenuItem> GetMenuItems()
        //{
        //    List<MenuItem> result = new List<MenuItem>();
        //    foreach (MRUItem item in this)
        //    {
        //        //if (result.Count >= Math.Min(this.MaxEntries, this.ShowMaxEntries))
        //        if (result.Count >= this.ShowMaxEntries)
        //        {
        //            break;
        //        }

        //        MenuItem mu = new MenuItem();
        //        mu.FontFamily = new System.Windows.Media.FontFamily("Segoe UI"); ;
        //        mu.FontSize = 11;
        //        mu.Foreground=new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF,0xFF,0xFF,0xFF));
        //        mu.Background=new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF,0xF7,0x94,0x1E));
        //        Grid g = new Grid();
        //        ColumnDefinition cd = new ColumnDefinition();
        //        cd.Width = new GridLength(20);
        //        g.ColumnDefinitions.Add(cd);
        //        cd = new ColumnDefinition();
        //        cd.Width = new GridLength(300);
        //        g.ColumnDefinitions.Add(cd);
        //        cd = new ColumnDefinition();
        //        cd.Width = new GridLength(10);
        //        g.ColumnDefinitions.Add(cd);
        //        //cd = new ColumnDefinition();
        //        //cd.Width = new GridLength(25);
        //        //g.ColumnDefinitions.Add(cd);
        //        RowDefinition rd = new RowDefinition();
        //        rd.Height = new GridLength(35);
        //        g.RowDefinitions.Add(rd);
        //        rd = new RowDefinition();
        //        rd.Height = new GridLength(22);
        //        g.RowDefinitions.Add(rd);


        //        TextBlock tb = new TextBlock();
        //        //tb.FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
        //        tb.VerticalAlignment = VerticalAlignment.Center;
        //        tb.HorizontalAlignment = HorizontalAlignment.Center;
        //        //tb.FontSize = 11;
        //        tb.Text = IndexOf(item).ToString()+" - ";
        //        //tb.Hint = path;

        //        g.Children.Add(tb);
        //        Grid.SetRow(tb, 0);
        //        Grid.SetColumn(tb, 0);
        //        Grid.SetRowSpan(tb, 2);

        //        tb = new TextBlock();
        //        //tb.FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
        //        tb.FontSize = 24;
        //        tb.HorizontalAlignment = HorizontalAlignment.Center;
        //        tb.VerticalAlignment = VerticalAlignment.Center;
        //        tb.Text = System.IO.Path.GetFileNameWithoutExtension(item.FileName);

        //        g.Children.Add(tb);
        //        Grid.SetRow(tb, 0);
        //        Grid.SetColumn(tb, 1);
        //        Grid.SetColumnSpan(tb, 3);

        //        tb = new TextBlock();
        //        //tb.FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
        //        tb.VerticalAlignment = VerticalAlignment.Center;
        //        //tb.FontSize = 11;
        //        tb.Text = item.FullFileName;
        //        tb.ToolTip = item.FullFileName;

        //        g.Children.Add(tb);
        //        Grid.SetRow(tb, 1);
        //        Grid.SetColumn(tb, 1);

        //        tb = new TextBlock();
        //        //tb.FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
        //        //tb.FontSize = 11;
        //        tb.VerticalAlignment = VerticalAlignment.Center;
        //        tb.HorizontalAlignment = HorizontalAlignment.Right;
        //        tb.Text = '[' + item.PageNumber.ToString() + ']';

        //        g.Children.Add(tb);
        //        Grid.SetRow(tb, 1);
        //        Grid.SetColumn(tb, 4);

        //        mu.Icon = item.ThumbImage;

        //        mu.Header = g;
        //        if (this.MenuClick != null)
        //        {
        //            mu.CommandParameter = item.FullFileName + "," + item.PageNumber.ToString();

        //            mu.Click += new RoutedEventHandler(MenuClick);

        //        }

        //        // experimenting with keybinding for the menu.
        //        // experiment froozen (implement a more primitive keybinding first ;-) );

        //        //System.Windows.Input.InputGestureCollection igc = new System.Windows.Input.InputGestureCollection();
        //        //igc.Add(new System.Windows.Input.KeyGesture(System.Windows.Input.Key.D0, System.Windows.Input.ModifierKeys.Control, "[Ctrl+0]"));
        //        //System.Windows.Input.RoutedUICommand rc = new System.Windows.Input.RoutedUICommand("myText", "rucName",mu.GetType(), igc);

        //        //System.Windows.Input.CommandBinding cb = new System.Windows.Input.CommandBinding();
        //        //cb.Command = rc;
        //        //cb.Executed += new System.Windows.Input.ExecutedRoutedEventHandler(MenuClick);
        //        //cb.CanExecute += new System.Windows.Input.CanExecuteRoutedEventHandler(RequeryCanExecute);
        //        //if (result.Count == 0)
        //        //{
        //        //    mu.CommandBindings.Add(cb);
        //        //    mu.Command = cb.Command;
        //        //}

        //        result.Add(mu);
        //    }
        //    return result;
        //}

        //private void RequeryCanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        //{
        //    e.CanExecute = true;
        //}

        static public void Serialize(string path, MRUList list)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MRUList));

            using (System.IO.TextWriter writer = new System.IO.StreamWriter(path))
            {
                serializer.Serialize(writer, list);
            }
        }
Exemple #6
0
        public static void Test()
        {
            System.Diagnostics.Debug.WriteLine("*** Test ***");
            MRUList list = FilledTestList();

            CheckPageNumber(list, "0,3,2,1");
            InsertTest();
            IndexOfTest();
            MaxNumberTest();
            System.Diagnostics.Debug.WriteLine("*** End ***");
        }
Exemple #7
0
 public static void PrintList(MRUList list)
 {
     System.Diagnostics.Debug.WriteLine("*** Begin PrintList foreach ***");
     foreach (MRUItem item in list)
     {
         System.Diagnostics.Debug.WriteLine(item.FullFileName);
     }
     System.Diagnostics.Debug.WriteLine("*** End PrintList foreach ***");
     System.Diagnostics.Debug.WriteLine("*** Begin PrintList for ***");
     for (int i = 0; i < list.Count; i++)
     {
         System.Diagnostics.Debug.WriteLine(list[i].FullFileName);
     }
     System.Diagnostics.Debug.WriteLine("*** End PrintList for ***");
 }
Exemple #8
0
        public static void MaxNumberTest()
        {
            MRUList list = new MRUList();

            for (int i = 0; i < 11; i++)
            {
                MRUItem item = new MRUItem();
                item.Path       = @"D:\Data\";
                item.FileName   = i.ToString("D3");
                item.PageNumber = i;
                list.AddMRUItem(item);
            }

            CheckPageNumber(list, "10,9,8,7,6,5,4,3,2,1");
        }
Exemple #9
0
        public static void CheckPageNumber(MRUList list, string numbers)
        {
            System.Diagnostics.Debug.WriteLine("-c-");

            string[] nr = numbers.Split(',');
            if (list.Count != nr.Length)
            {
                throw new ArgumentOutOfRangeException();
            }
            for (int i = 0; i < list.Count; i++)
            {
                System.Diagnostics.Debug.WriteLine(list[i].FullFileName + " :: " + list[i].PageNumber.ToString());

                if (list[i].PageNumber.ToString() != nr[i])
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }