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); }
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(); }
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(); }
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(); }
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); } }
//This is the activity for the Update bills button. private void UpdateBill_Clicked(Object sender, EventArgs e) { //Check the main text fields are empty or not. If empty it shows an alert message if (BillType.SelectedIndex.ToString() == null || Address.SelectedIndex.ToString() == null || Month.SelectedIndex.ToString() == null || txtAmount.Text == null || txtDueDate.Text == null) { DisplayAlert("Unsuccessfull !", "Please enter details to all the fields!", "Ok"); } //If the required text fields are with some values, then it will be added to the data base else { ListViewItems listView = new ListViewItems() { BillType = BillType.SelectedItem.ToString(), Address = Address.SelectedItem.ToString(), Month = Month.SelectedItem.ToString(), Amount = int.Parse(txtAmount.Text), DueDate = txtDueDate.Text }; using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) { conn.CreateTable <ListViewItems>(); int x = 1; var bill = conn.Table <ListViewItems>(); //Check the bill is already exist. If the bill is already there, then diplays an alert foreach (var item in bill) { if (item.Address == Address.SelectedIndex.ToString() && item.BillType == BillType.SelectedItem.ToString() && item.Month == Month.SelectedItem.ToString()) { DisplayAlert("Unsuccessfull !", "This bill is already exist. Insert a new bill!", "Ok"); x = 2; break; } } //If the bill is a new button then it will be added to the database if (x == 1) { conn.Insert(listView); DisplayAlert("Successfull !", "Bill Added !", "Ok"); } } } }
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) }); }
async void PostClicked(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem != null) { string name = e.SelectedItem.ToString(); int index = ListViewItems.IndexOf(name); if (index >= -1) { //Debug.WriteLine("index is "+index+", name is "+name); HackerNewsItem item = HackerNewsItems[index]; await Navigation.PushAsync(new DetailPage(item)); } else { Debug.WriteLine("index is -1"); } } }
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) }); }
async void DeleteCss(object commandParameter) { CSS css = commandParameter as CSS; var result = await Services.Popups.TwoOptionPopup ( "Delete Style Sheet?", "Permanently delete style sheet?", AppResources.AlertOption_Yes, AppResources.AlertOption_No ); if (result == TwoOptionPopupResult.LeftButton) { await Services.NoteDatabase.DeleteAsync(css); //UpdateListView(); ListViewItems.Remove(css); RaisePropertyChanged(nameof(ListViewItems)); } }
public void refreshList() { ListViewItems.Clear(); addFilesToList(_FM.getFiles(_profile)); }
private void Clear() { ListViewItems.Clear(); }
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 }