Exemple #1
0
        public Window1ViewModel()
        {
            var drives = Directory.GetLogicalDrives();

            foreach (var drive in drives)
            {
                var treeItem = new TreeViewItemViewModel
                               (
                    type: ItemModel.Types.Drive,
                    fullpath: drive,
                    isRoot: true
                               );
                treeItem.Expanded += TreeViewItem_Expanded;
                treeItem.Selected += TreeViewItem_Selected;
                TreeViewItems.Add(treeItem);

                var listItem = new ListViewItemViewModel
                               (
                    type: ItemModel.Types.Drive,
                    fullpath: drive,
                    isRoot: true
                               );
                listItem.Selected += ListViewItem_Selected;
                ListViewItems.Add(listItem);
            }
        }
        async Task processPost(MainPage mainPage, int i)
        {
            HackerNewsItem item = await getDetail(mainPage, i);

            ListViewItems.Add(item.title);
            HackerNewsItems.Add(item);
        }
Exemple #3
0
        private void XMLSaveLoad()
        {
            //XML serialization----------------------------------------------------------------------------
            //By far the simplest and easiest method. But is it really the most feasible??
            //string xmlPath = "C:\\Users\\rforzisi\\Documents\\Test Projects\\StorageTesting\\XmlStorage.ICPWorksheet";
            string rootProgramDirectory    = AppDomain.CurrentDomain.BaseDirectory;
            string allExercisesXmlFilename = "XMLStorage.ICPWorksheet";
            string xmlPath = rootProgramDirectory + allExercisesXmlFilename;

            watch.Start();
            XmlHelper.ToXmlFile(worksheetIn, xmlPath);
            worksheetOut = XmlHelper.FromXmlFile <ExampleWorksheet2>(xmlPath);

            ListViewItems.Add("XML Create/load time = " + watch.Elapsed);

            watch.Restart();

            //for (int i = 0; i < worksheetIn.Solutions.Count; i++)
            //{
            //    //worksheetIn.Solutions.ElementAtOrDefault(i).SolutionName = "We are all the same";
            //    XmlHelper.ToXmlFile(worksheetIn, xmlPath);
            //    worksheetOut = XmlHelper.FromXmlFile<ExampleWorksheet2>(xmlPath); //i know this is only going to keep the last one but mehhh
            //}

            ListViewItems.Add("XML update time = " + watch.Elapsed);

            string written = XmlHelper.ToXml(worksheetIn);
            //ListViewItems.Add("Total Chars written: " + written.Length);
            int lineCount = written.Length - written.Replace("\r\n", "").Length;

            //ListViewItems.Add("Total Lines written: " + lineCount);

            watch.Reset();
        }
Exemple #4
0
        private void XMLSaveLoadEncrypt()
        {
            //XML serialization with Encryption ----------------------------------------------------------------------------
            //Still pretty simple and easy. plus adds a detail of encryption so you cant sneakily change results
            string xmlPath = "C:\\Users\\rforzisi\\Documents\\Test Projects\\StorageTesting\\XmlStorageEncrypted.ICPWorksheet";

            watch.Start();
            string toEncrypt = XmlHelper.ToXml(worksheetIn);
            //string toEncrypt = "Test";
            string Testout = "";
            string toWrite = EncryptionHelper.EncryptString(toEncrypt, "Password");

            File.WriteAllText(xmlPath, toWrite);

            string read      = File.ReadAllText(xmlPath);
            string decrypted = EncryptionHelper.DecryptString(read, "Password");

            worksheetOut = XmlHelper.FromXml <ExampleWorksheet2>(decrypted);
            watch.Stop();


            ListViewItems.Add("Write/Read time:" + watch.Elapsed);
            ListViewItems.Add("Total Chars written: " + toEncrypt.Length);
            int lineCount = toEncrypt.Length - toEncrypt.Replace("\r\n", "").Length;

            ListViewItems.Add("Total Lines written: " + lineCount);

            watch.Reset();
        }
Exemple #5
0
        private void AddTask_Click(object sender, RoutedEventArgs e)
        {
            if (Url.Text == string.Empty)
            {
                return;
            }
            if (TimeStampComboBox.SelectedItem == null)
            {
                return;
            }

            var ts  = (TimeStampComboBox.SelectedItem as ComboBoxItem).TimeStamp;
            var lvi = new ListViewItem()
            {
                Url = Url.Text, ScheduledAt = $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}", Status = "Waiting Schedule"
            };
            // If CTS is implemented within your custom class like in this instance, make sure its the same passed in the tuple.
            // The reason for this token here is that if we want to cancel one specific message (not the whole block) and the timestamp is
            // Quite delayed, this would prevent it to be lock waiting until its time.
            var t = new Tuple <TimeSpan, CancellationTokenSource, ListViewItem>(ts, lvi.CTS, lvi);

            ListViewItems.Add(lvi);
            lvi.Id = lvi.CurrentTask.Id.ToString();
            BlockScheduler.SendAsync(t);

            // Can do tasks continuation.
            lvi.CurrentTask.ContinueWith(T =>
            {
                switch (T.Status)
                {
                case TaskStatus.Canceled:
                    ListViewItems.Where(l => l.Id == T.Id.ToString()).First().Status = "Canceled";
                    break;

                case TaskStatus.Faulted:
                    ListViewItems.Where(l => l.Id == T.Id.ToString()).First().Status = T.Exception.InnerException.Message;
                    break;

                case TaskStatus.RanToCompletion:
                    T.Result.Status = "Completed";
                    break;
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());

            Ids++;

            //Consumer.Completion.Wait();
        }
Exemple #6
0
 public void TreeViewItem_Selected(object sender, EventArgs e)
 {
     // sender must be the original sender of this event
     if (!(sender is TreeViewItemViewModel treeViewModel))
     {
         Console.WriteLine("Invalid sender");
         return;
     }
     // update list view according to the selected folder in treeview
     ListViewItems.Clear();
     foreach (var treeViewItem in treeViewModel.Items)
     {
         var listViewItem = new ListViewItemViewModel(treeViewItem.Model);
         listViewItem.Selected += ListViewItem_Selected;
         ListViewItems.Add(listViewItem);
     }
 }
 public void AddListViewItem(string Content)
 {
     ListViewItems.Add(
         new GameListViewItem()
     {
         Background = new GameImage()
         {
             Image = DefaultBackground
         },
         Label = new GameLabel()
         {
             Font    = DefaultFont,
             Content = Content
         },
         Position = getAbsPosition(ListViewItems.Count)
     });
 }
 public void AddListViewItem(Texture2D Background, System.Drawing.Font Font, string Content, string Tag)
 {
     ListViewItems.Add(
         new GameListViewItem()
     {
         Background = new GameImage()
         {
             Image = Background
         },
         Label = new GameLabel()
         {
             Font    = Font,
             Content = Content
         },
         Tag      = Tag,
         Position = getAbsPosition(ListViewItems.Count)
     });
 }
Exemple #9
0
        private void SQLiteSaveLoad()
        {
            //Creating the Database------------------------------------------------------------------------
            //In this method, store the entire DB in memory/ram
            //string dbPath = "C:\\Users\\rforzisi\\Documents\\Test Projects\\StorageTesting\\DBStorage.ICPWorksheet";
            string rootProgramDirectory    = AppDomain.CurrentDomain.BaseDirectory;
            string allExercisesXmlFilename = "DBStorage.ICPWorksheet";
            string dbPath = rootProgramDirectory + allExercisesXmlFilename;

            try
            {
                if (File.Exists(dbPath))
                {
                    File.Delete(dbPath);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return;
            }

            SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath + ";" + "Pooling=true;" + "Synchronous=Off;"); //journal mode off didnt do too much, Synchronous off made creating it ~10x faster

            //connection.SetPassword("a"); //comment out deleting the db so that this will actually mean something. If you then comment out this line itself it wont work because the database will be locked
            connection.Open();

            watch.Restart();
            SQLiteHelper.CreateDatabase(dbPath);
            SQLiteHelper.CreateNewSolutionTable(connection);
            SQLiteHelper.CreateNewElementsTable(connection);
            SQLiteHelper.CreateNewMeasurementTable(connection);
            ListViewItems.Add("Creating/Setup of database = " + watch.Elapsed);
            watch.Restart();

            foreach (var solution in worksheetIn.Solutions)
            {
                solution.SolutionType = SolutionType.Default;
            }
            List <Measurement2> allMeasurements = new List <Measurement2>();

            foreach (var sol in worksheetIn.Solutions)
            {
                allMeasurements.AddRange(sol.Measurements);
            }

            watch.Restart();
            SQLiteHelper.AddMultipleSolutions(connection, worksheetIn.Solutions);
            SQLiteHelper.AddMultipleElements(connection, worksheetIn.Elements);
            SQLiteHelper.AddMultipleMeasurements(connection, allMeasurements);

            ListViewItems.Add("Adding Everything as transaction = " + watch.Elapsed);
            watch.Restart();

            foreach (var solution in worksheetIn.Solutions)
            {
                solution.SolutionType = SolutionType.Blank;
            }

            watch.Restart();
            SQLiteHelper.UpdateMultipleSolutions(connection, worksheetIn.Solutions);
            //foreach (var sol in worksheetIn.Solutions) //uhh this is rather nasty and could take a while to do. Try to avoid doing lots of writes in a loop like this and try do it in the helper where you can put it all in a transaction to significantly increase speed
            //{
            //    SQLiteHelper.UpdateMultipleMeasurements(connection, sol.Measurements);
            //}

            ListViewItems.Add("Update data as transaction = " + watch.Elapsed);
            watch.Restart();

            SQLiteHelper.AddSingleSolution(connection, new Solution2()
            {
                SolutionName = "Odd One out", SolutionID = 1234, SolutionType = SolutionType.Standard
            });
            SQLiteHelper.AddSingleElement(connection, new ElementWavelength2()
            {
                ElementName = "Unobtainium", ElementId = 42, Wavelength = 999.999f
            });
            SQLiteHelper.AddSingleMeasurement(connection, new Measurement2()
            {
                SolutionId = 999, ElementId = 42, Conc = 555, Intensity = 123456789
            });

            worksheetIn.Solutions[7].SolutionName = "Foo";
            SQLiteHelper.UpdateSingleSolution(connection, worksheetIn.Solutions[7]);

            watch.Restart();
            var loadedSolutions    = SQLiteHelper.LoadMultipleSolutions(connection);
            var loadedMeasurements = SQLiteHelper.LoadMultipleMeasurementsFromSolution(connection, 999);

            WorksheetOutSolutions.Clear();
            foreach (var solution in loadedSolutions)
            {
                WorksheetOutSolutions.Add(solution);
            }
            ListViewItems.Add("Load Solutions and measurements into memory= " + watch.Elapsed);



            connection.Close();
            connection.Dispose();
            System.GC.Collect(); //the is required to quickly get rid of the excess ram that is generated after the large SQL statements
        }