public void TryMixedTypeSave()
        {
            // 1. write data to notes
            _setupforlayoutests();
            int count = 25;
            //	FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            NoteDataInterface note = null;

            for (int i = 0; i < count; i++)
            {
                note = (NoteDataInterface)Activator.CreateInstance(typeof(NoteDataXML));                //new NoteDataXML ();

                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }

            // store a SECOND TYPE into the mix
            note         = (NoteDataInterface)Activator.CreateInstance(typeof(NoteDataXML_RichText));
            note.Caption = "textnote";
            string guid = note.GuidForNote;

            _w.output("new guid" + guid);
            layoutPanel.AddNote(note);
            note.CreateParent(layoutPanel);
            layoutPanel.SaveLayout();
        }
        public void TestSavingRTFTextWorks()
        {
            Type TypeToTest = typeof(NoteDataXML_RichText);

            // 1. write data to notes
            _setupforlayoutests();
            int count = 15;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            FAKE_LayoutPanel layoutPanel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            NoteDataInterface note = null;

            for (int i = 0; i < count; i++)
            {
                note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);                //new NoteDataXML ();

                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }


            note         = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
            note.Caption = "snake";
            string guid       = note.GuidForNote;
            string teststring = "\nthe test is this ";


            note.Data1 = (@"{\rtf1\ansi\ansicpg1252\deff0\deflang4105{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}" +
                          @"\viewkind4\uc1\pard\f0\fs17\par the test is this }");


            //	note.Data1=String.Format (@"{\rtf1\ansi\ansicpg1252\deff0\deflang4105{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}\viewkind4\uc1\pard\f0\fs17\par {0} \par}", teststring);

            //"This is the story of the bird.";
            note.CreateParent(layoutPanel);
            _w.output("new guid" + guid);

            layoutPanel.AddNote(note);
            //layout.SaveTo ();
            layoutPanel.SaveLayout();
            //layout = new FakeLayoutDatabase ("testguid");
            layoutPanel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.LoadLayout("testguid", false, null);
            //layout.LoadFrom(layoutPanel);

            //_w.output(String.Format ("{0} Objects Loaded", layout.GetNotes().Count));

            NoteDataInterface result = layoutPanel.GetLayoutDatabase().GetNoteByGUID(guid);
            string            astest = ((NoteDataXML_RichText)result).GetAsText();

            _w.output(result.Data1);
            _w.output(astest);
            Assert.AreEqual(teststring, astest);
        }
        /*// I made the decision to suppress Errors (hence not required CreateParent, for the purpose of MOVING notes
         * // This violated an earlier decision I had made and I had to disable the TryToSaveWithoutCreating a Parent Exception
         * [Test]
         * [ExpectedException]
         * public void TryToSaveWithoutCreatingAParent()
         * {
         *      Type TypeToTest = typeof(NoteDataXML_RichText);
         *      // 1. write data to notes
         *      _setupforlayoutests ();
         *      int count = 25;
         *      FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
         *      LayoutPanel layoutPanel = new LayoutPanel ();
         *
         *      NoteDataInterface note = null;
         *      for (int i = 0; i < count; i++) {
         *              note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);//new NoteDataXML ();
         *      //	note.CreateParent(layoutPanel);
         *              note.Caption = "boo" + i.ToString ();
         *              layout.Add (note);
         *      }
         *
         *
         *      note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
         *      note.Caption = "snake";
         *      string guid = note.GuidForNote;
         *      //note.CreateParent(layoutPanel);
         *      _w.output("new guid" + guid);
         *      layout.Add (note);
         *      layout.SaveTo ();
         *      _w.output ("save worked");
         * }*/

        /// <summary>
        /// Creates the lots of notes to test different types and return proper caption.
        ///
        /// Testing NOTE: You must CreateParent when building items. Else the save cannot work.
        ///
        /// </summary>
        /// <returns>
        /// The lots of notes to test different types and return proper caption.
        /// </returns>
        /// <param name='TestCaption'>
        /// Test caption.
        /// </param>
        /// <param name='TypeToTest'>
        /// Type to test.
        /// </param>
        private string CreateLotsOfNotesToTestDifferentTypesAndReturnProperCaption(string TestCaption, Type TypeToTest)
        {
            // 1. write data to notes
            //System.Windows.Forms .Form form = new System.Windows.Forms.Form();
            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            int count = 25;
            //	FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);

            NoteDataInterface note = null;

            for (int i = 0; i < count; i++)
            {
                note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);                //new NoteDataXML ();

                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }


            note         = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
            note.Caption = TestCaption;
            string guid = note.GuidForNote;

            note.CreateParent(layoutPanel);
            _w.output("new guid" + guid);
            layoutPanel.AddNote(note);
            layoutPanel.SaveLayout();
            _w.output("save worked");

            // 2. Now we pretend that later one, elsewhere in code, we need to get access to this (i.e., a Random Table)
            layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            //layout = new FakeLayoutDatabase ("testguid");
            layoutPanel.LoadLayout("testguid", false, null);

            //layoutPanel.LoadLayout( (null);
            //	_w.output (layout.Backup ());
            //_w.output(layoutPanel.GetNotes().Count.ToString());
            foreach (NoteDataXML _note in layoutPanel.GetAllNotes())
            {
                if (_note.GuidForNote == guid)
                {
                    _w.output(_note.Caption);
                    return(note.Caption);
                }
            }
            return("<error>");
        }
예제 #4
0
        public void Quicker_UpdateAfterLoadTest()
        {
            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            System.Windows.Forms.Form form = new System.Windows.Forms.Form();



            FAKE_LayoutPanel panel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            form.Controls.Add(panel);

            // needed else DataGrid does not initialize

            form.Show();
            //form.Visible = false;
            _w.output("boom");
            // March 2013 -- notelist relies on having this
            YOM2013.DefaultLayouts.CreateASystemLayout(form, null);


            //NOTE: For now remember that htis ADDS 1 Extra notes
            string panelname = System.Guid.NewGuid().ToString();

            panel.NewLayout(panelname, true, null);
            LayoutDetails.Instance.AddToList(typeof(FAKE_NoteDataXML_Panel), "testingpanel");
            _w.output("herefirst");

            // ADD 1 of each type
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 5; i++)
                {
                    NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                    panel.AddNote(note);
                    note.CreateParent(panel);

                    note.UpdateAfterLoad();
                }
            }

            panel.SaveLayout();
            form.Dispose();
        }
예제 #5
0
        public void SpeedTest()
        {
            // this will be a benchmarking test that will create a complicated Layout
            // Then it will time and record the results of LOADING and SAVING that layout into a
            // table saved in my backup paths
            // will also output a DAAbackup file (text readable) format too
            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            System.Windows.Forms.Form form = _TestSingleTon.Instance.FORM;             //new System.Windows.Forms.Form();



            FAKE_LayoutPanel panel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            form.Controls.Add(panel);

            // needed else DataGrid does not initialize

            form.Show();
            //form.Visible = false;
            _w.output("boom");
            // March 2013 -- notelist relies on having this
            YOM2013.DefaultLayouts.CreateASystemLayout(form, null);


            //NOTE: For now remember that htis ADDS 1 Extra notes
            string panelname = System.Guid.NewGuid().ToString();

            panel.NewLayout(panelname, true, null);
            LayoutDetails.Instance.AddToList(typeof(FAKE_NoteDataXML_Panel), "testingpanel");
            _w.output("herefirst");

            // ADD 1 of each type
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 10; i++)
                {
                    NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                    panel.AddNote(note);
                    note.CreateParent(panel);
                }
            }
            _w.output("here");
            FAKE_NoteDataXML_Panel panelA = new FAKE_NoteDataXML_Panel();

            panelA.Caption = "PanelA";
            panel.AddNote(panelA);
            string stringoftypes = "";

            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                panelA.AddNote(note);
                stringoftypes = stringoftypes + " " + t.ToString();
            }
            panel.SaveLayout();
            string base_path = _TestSingleTon.PATH_TO_SpeedTestFiles;            //@"C:\Users\BrentK\Documents\Keeper\Files\yomspeedtests2013\";

            _w.output("here");
            NoteDataXML_RichText richy;

            for (int i = 0; i < 20; i++)
            {
                richy         = new NoteDataXML_RichText();
                richy.Caption = "richtext";
                panel.AddNote(richy);
                Assert.True(richy.GetIsRichTextBlank());
                richy.DoOverwriteWithRTFFile(System.IO.Path.Combine(base_path, "speedtest.rtf"));
                Assert.False(richy.GetIsRichTextBlank());
            }
            _w.output("First save");
            panel.SaveLayout();
            string table = "layoutpanelsaveload";
            // Now try and write this data out.
            SqlLiteDatabase timetracking = new SqlLiteDatabase(System.IO.Path.Combine(base_path, "speedtests.s3db"));

            timetracking.CreateTableIfDoesNotExist(table, new string [5] {
                "id", "datetime", "timetook", "types", "saveorload"
            },
                                                   new string[5] {
                "INTEGER", "TEXT", "FLOAT", "TEXT", "TEXT"
            }, "id");


            // * Now start the Load Test
            TimeSpan time;

            CoreUtilities.TimerCore.TimerOn = true;
            time = CoreUtilities.TimerCore.Time(() => {
                panel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);
                form.Controls.Add(panel);
                panel.LoadLayout(panelname, false, null);
            });
            _w.output("TIME " + time);



            timetracking.InsertData(table, new string[4] {
                "datetime", "timetook", "types", "saveorload"
            }, new object[4] {
                DateTime.Now.ToString(),
                time.TotalSeconds, stringoftypes, "load"
            });

            time = CoreUtilities.TimerCore.Time(() => {
                // We keep the PANEL from above! Don't recreate it.
                //panel = new FAKE_LayoutPanel (CoreUtilities.Constants.BLANK);
                panel.SaveLayout();
            });


            Console.WriteLine("TIME " + time);

            timetracking.InsertData(table, new string[4] {
                "datetime", "timetook", "types", "saveorload"
            }, new object[4] {
                DateTime.Now.ToString(),
                time.TotalSeconds, stringoftypes, "save"
            });

            string backup = timetracking.BackupDatabase();

            System.IO.TextWriter write = new System.IO.StreamWriter(System.IO.Path.Combine(base_path, "timeresults.txt"));
            write.WriteLine(backup);

            write.Close();

            FakeLayoutDatabase   layout = new FakeLayoutDatabase("testguid");
            FAKE_SqlLiteDatabase db     = new FAKE_SqlLiteDatabase(layout.GetDatabaseName());

            _w.output("Backup of stored database: " + db.BackupDatabase());

            timetracking.Dispose();
            db.Dispose();
        }
예제 #6
0
        public void AutosaveThrash()
        {
            // just spawna timer and see if I can make it fail

            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            System.Windows.Forms.Form form = new System.Windows.Forms.Form();



            panelAutosave = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            form.Controls.Add(panelAutosave);

            // needed else DataGrid does not initialize

            form.Show();
            //form.Visible = false;
            _w.output("boom");
            // March 2013 -- notelist relies on having this
            YOM2013.DefaultLayouts.CreateASystemLayout(form, null);


            //NOTE: For now remember that htis ADDS 1 Extra notes
            string panelname = System.Guid.NewGuid().ToString();

            panelAutosave.NewLayout(panelname, true, null);
            LayoutDetails.Instance.AddToList(typeof(FAKE_NoteDataXML_Panel), "testingpanel");
            _w.output("herefirst");


            Timer SaveTimer = new Timer();

            SaveTimer.Interval = 300;
            SaveTimer.Tick    += HandleSaveTimerTick;
            SaveTimer.Start();

            // ADD 1 of each type
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 2; i++)
                {
                    NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                    panelAutosave.AddNote(note);
                    note.CreateParent(panelAutosave);

                    note.UpdateAfterLoad();
                }
            }

            panelAutosave.SaveLayout();


            //
            // Second panel
            //

            string           panelname2    = System.Guid.NewGuid().ToString();
            FAKE_LayoutPanel PanelOtherGuy = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            PanelOtherGuy.NewLayout(panelname2, true, null);
            PanelOtherGuy.SaveLayout();

            Assert.AreEqual(2, PanelOtherGuy.CountNotes(), "count1");

            // ADD 1 of each type
            //foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 10; i++)
                {
                    NoteDataInterface note = new NoteDataXML_RichText();
                    PanelOtherGuy.AddNote(note);
                    note.CreateParent(PanelOtherGuy);

                    note.UpdateAfterLoad();
                }
            }
            Assert.AreEqual(12, PanelOtherGuy.CountNotes(), "count2");
            PanelOtherGuy.SaveLayout();
            PanelOtherGuy = null;
            PanelOtherGuy = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);
            PanelOtherGuy.LoadLayout(panelname2, false, null);
            Assert.AreEqual(12, PanelOtherGuy.CountNotes(), "count2");
            // add another Layout and do something with it while autosave continues running


            SaveTimer.Stop();
            form.Dispose();
        }
예제 #7
0
        public void CopyNoteTest()
        {
            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            System.Windows.Forms.Form form = new System.Windows.Forms.Form();



            FAKE_LayoutPanel panelToUse = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            form.Controls.Add(panelToUse);

            // needed else DataGrid does not initialize

            form.Show();
            //form.Visible = false;
            _w.output("boom");
            // March 2013 -- notelist relies on having this
            YOM2013.DefaultLayouts.CreateASystemLayout(form, null);


            //NOTE: For now remember that htis ADDS 1 Extra notes
            string panelname = System.Guid.NewGuid().ToString();

            panelToUse.NewLayout(panelname, true, null);
            LayoutDetails.Instance.AddToList(typeof(FAKE_NoteDataXML_Panel), "testingpanel");
            _w.output("herefirst");


            Timer SaveTimer = new Timer();

            SaveTimer.Interval = 300;
            SaveTimer.Tick    += HandleSaveTimerTick;
            SaveTimer.Start();

            // ADD 1 of each type
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 2; i++)
                {
                    NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                    panelToUse.AddNote(note);
                    note.CreateParent(panelToUse);

                    note.UpdateAfterLoad();
                    panelToUse.CopyNote(note);
                    panelToUse.PasteNote();
                }
            }
            panelToUse.SaveLayout();
            //int propercount= 4 * LayoutDetails.Instance.ListOfTypesToStoreInXML().Length;
            Assert.AreEqual(46, panelToUse.CountNotes());



            //
            // Now we test pasting one of our notes onto another Layout
            //

            string           panelname2    = System.Guid.NewGuid().ToString();
            FAKE_LayoutPanel PanelOtherGuy = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            PanelOtherGuy.NewLayout(panelname2, true, null);
            PanelOtherGuy.SaveLayout();

            form.Controls.Add(PanelOtherGuy);

            Assert.AreEqual(2, PanelOtherGuy.CountNotes(), "count1");

            // ADD 1 of each type
            //foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 10; i++)
                {
                    NoteDataInterface note = new NoteDataXML_RichText();
                    PanelOtherGuy.AddNote(note);
                    note.CreateParent(PanelOtherGuy);

                    note.UpdateAfterLoad();
                }
            }
            Assert.AreEqual(12, PanelOtherGuy.CountNotes(), "count2");
            PanelOtherGuy.PasteNote();
            Assert.AreEqual(13, PanelOtherGuy.CountNotes(), "count2");
            PanelOtherGuy.SaveLayout();


            FAKE_NoteDataXML_Text Noter = new FAKE_NoteDataXML_Text();

            Noter.Caption = "Hello there";

            PanelOtherGuy.AddNote(Noter);

            Noter.GetRichTextBox().Text = "bear";
            PanelOtherGuy.SaveLayout();

            PanelOtherGuy.CopyNote(Noter);
            NoteDataXML_RichText CopyOfTextNote = (NoteDataXML_RichText)PanelOtherGuy.PasteNote();

            Assert.AreEqual("Hello there", CopyOfTextNote.Caption);
            Assert.AreEqual("bear", CopyOfTextNote.GetRichTextBox().Text);

            //
            //
            // Table Copy Test
            //
            //

            NoteDataXML_Table randomTables = new NoteDataXML_Table(100, 100, new ColumnDetails[2] {
                new ColumnDetails("id", 100), new ColumnDetails("tables", 100)
            });

            randomTables.Caption = LayoutDetails.SYSTEM_RANDOM_TABLES;
            //	randomTables.Columns = new appframe.ColumnDetails[2]{new appframe.ColumnDetails("id",100), new appframe.ColumnDetails("tables",100)};



            PanelOtherGuy.AddNote(randomTables);
            //randomTables.CreateParent(PanelOtherGuy);


            randomTables.AddRow(new object[2] {
                "1", "example|colors"
            });
            randomTables.AddRow(new object[2] {
                "2", "example|colorPROMPTS"
            });
            PanelOtherGuy.SaveLayout();


            PanelOtherGuy.CopyNote(randomTables);
            NoteDataXML_Table CopyOfTable = (NoteDataXML_Table)PanelOtherGuy.PasteNote();

            Assert.AreEqual(2, CopyOfTable.RowCount());
        }