Advertisement
Guest User

PerformanceEngine

a guest
Feb 19th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices.WindowsRuntime;
  8. using System.Threading.Tasks;
  9. using Windows.Foundation;
  10. using Windows.Foundation.Collections;
  11. using Windows.Storage;
  12. using Windows.Storage.Pickers;
  13. using Windows.UI.Xaml;
  14. using Windows.UI.Xaml.Controls;
  15. using Windows.UI.Xaml.Controls.Primitives;
  16. using Windows.UI.Xaml.Data;
  17. using Windows.UI.Xaml.Input;
  18. using Windows.UI.Xaml.Media;
  19. using Windows.UI.Xaml.Navigation;
  20.  
  21. // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
  22.  
  23. namespace App2
  24. {
  25.     public sealed partial class MainPage : Page
  26.     {
  27.         public MainPage()
  28.         {
  29.             this.InitializeComponent();
  30.         }
  31.  
  32.         public async void WriteFile()
  33.         {
  34.             StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("ProgSchedule.txt");
  35.         }
  36.  
  37.  
  38.         private ObservableCollection<string> _items = new ObservableCollection<string>();
  39.  
  40.         public ObservableCollection<string> Items
  41.         {
  42.             get { return this._items; }
  43.         }
  44.  
  45.         public static async Task<string> WriteToSettings(string filename, string[] text)
  46.         {
  47.             //Create dataFile.txt in LocalFolder and write “My text” to it
  48.             StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  49.             //await localFolder.CreateFileAsync(@"ProgSchedule.txt");
  50.             var file = await ApplicationData.Current.LocalFolder.GetFileAsync(@"ProgSchedule.txt");
  51.             StorageFile sampleFile = await localFolder.GetFileAsync(@"ProgSchedule.txt");
  52.             foreach (string i in text)
  53.             {
  54.                 await FileIO.AppendTextAsync(sampleFile, i);
  55.             }
  56.             return "kek";
  57.         }
  58.  
  59. #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
  60.         public static async Task<string> ReadStringFromLocalFile(string filename, int actualLine)
  61. #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
  62.         {
  63.             // reads the contents of file 'filename' in the app's local storage folder and returns it as a string
  64.             StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  65.             StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
  66.             IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
  67.             return fileContent[actualLine];
  68.         }
  69.  
  70. #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
  71.         public static async Task<string> DeleteLineFromFile(string filename, int actualLine)
  72. #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
  73.         {
  74.             StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  75.             StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
  76.             IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
  77.             fileContent.RemoveAt(actualLine);
  78.             await FileIO.WriteLinesAsync(sampleFile, fileContent);
  79.             //string really = await refreshItemList();
  80.             return "okey dokey";
  81.         }
  82.  
  83.         public async Task<string> refreshItemList()
  84.         {
  85.             StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  86.             StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
  87.             IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
  88.             Items.Clear();
  89.             foreach (string readline in fileContent)
  90.             {
  91.                 int idx = readline.LastIndexOf('|');
  92.                 string appName = readline.Substring(idx + 1);
  93.                 Items.Add(appName);
  94.             }
  95.             return "ok";
  96.         }
  97.  
  98. #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
  99.         public async Task<string> ReplaceLineFromFile(string filename, int actualLine, string textToReplace)
  100. #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
  101.         {
  102.             StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  103.             StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
  104.             IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
  105.             fileContent[actualLine] = textToReplace;
  106.             await FileIO.WriteLinesAsync(sampleFile, fileContent);
  107.             //string really = await refreshItemList();
  108.             return "okey dokey";
  109.         }
  110.  
  111.         protected override async void OnNavigatedTo(NavigationEventArgs e)
  112.         {
  113.             base.OnNavigatedTo(e);
  114.  
  115.             StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  116.             StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
  117.             IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
  118.             Items.Clear();
  119.             foreach (string readline in fileContent)
  120.             {
  121.                 int idx = readline.LastIndexOf('|');
  122.                 string appName = readline.Substring(idx + 1);
  123.                 Items.Add(appName);
  124.             }
  125.         }
  126.  
  127.  
  128.         private void Button_Click_1(object sender, RoutedEventArgs e)
  129.         {
  130.  
  131.         }
  132.  
  133.         private async void Button_Click_1Async(object sender, RoutedEventArgs e)
  134.         {
  135.             string hello = await DeleteLineFromFile(@"ProgSchedule.txt", itemListView.SelectedIndex);
  136.         }
  137.  
  138.         private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  139.         {
  140.  
  141.         }
  142.  
  143.         private async void Button_Click_3Async(object sender, RoutedEventArgs e)
  144.         {
  145.             string path = Path.Text;
  146.             string name = Name.Text;
  147.             string time = timePick.Time.ToString(@"hh\:mm");
  148.             bool ignore = isIgnore.IsOn;
  149.             bool restart = isRestart.IsOn;
  150.             string strIgnore = Convert.ToString(Convert.ToInt32(ignore));
  151.             string strRestart = Convert.ToString(Convert.ToInt32(restart));
  152.             string parameters = '"' + time + '"' + strIgnore + '|' + strRestart + '|' + path + '|' + name;
  153.             string noneed = await ReplaceLineFromFile(@"ProgSchedule.txt", itemListView.SelectedIndex, parameters);
  154.         }
  155.  
  156.         private async void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  157.         {
  158.             string readline = await ReadStringFromLocalFile(@"ProgSchedule.txt", itemListView.SelectedIndex);
  159.             string[] appTime = readline.Split('"');
  160.             TimeSpan systemTime = TimeSpan.Parse(appTime[1]);
  161.             readline = readline.Substring(7);
  162.             string[] splitString = readline.Split('|');
  163.             bool ignore = false;
  164.             bool restart = false;
  165.             if (readline[0].Equals('1'))
  166.             {
  167.                 ignore = true;
  168.             }
  169.             if (readline[0].Equals('0'))
  170.             {
  171.                 ignore = false;
  172.             }
  173.             if (readline[2].Equals('1'))
  174.             {
  175.                 restart = true;
  176.             }
  177.             if (readline[2].Equals('0'))
  178.             {
  179.                 restart = false;
  180.             }
  181.             timePick.Time = systemTime;
  182.             Path.Text = splitString[2];
  183.             Name.Text = splitString[3];
  184.             isIgnore.IsOn = ignore;
  185.             isRestart.IsOn = restart;
  186.         }
  187.  
  188.         private void isRestart_Toggled(object sender, RoutedEventArgs e)
  189.         {
  190.  
  191.         }
  192.  
  193.         private void isIgnore_Toggled(object sender, RoutedEventArgs e)
  194.         {
  195.  
  196.         }
  197.  
  198.         private async void Button_Click_2Async(object sender, RoutedEventArgs e)
  199.         {
  200.             string[] toWrite = new string[] { '"' + "00:00" + '"' + "|0|0|C:\\|newapp"};
  201.             string cmon = await WriteToSettings(@"ProgSchedule.txt", toWrite);
  202.         }
  203.     }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement