static IEnumerable <XElement> ReadXml(System.IO.FileInfo file) { var start = LocalTime.Now; var result = file.ReadAllText().To <XDocument>().Root.Elements(); Console.WriteLine($"########################### Finished running ReadXml for {file.Name} in " + LocalTime.Now.Subtract(start).ToNaturalTime()); return(result); }
private void ApplicationControl_DragDrop(object sender, DragEventArgs e) { label1.Text = "DragDrop"; //e.Data.GetFormats().WithEach( // f => // { // label1.Text += "\n" + f; // } //); // just a path // jsc: fixme //(e.Data.GetData("FileDrop") as string[]).WithEach( var FileDrop = (string[])e.Data.GetData("FileDrop"); FileDrop.WithEach( path => { label1.Text += "\n" + path; if (File.Exists(path)) { var f = new FileInfo(path); label1.Text += "\n is a file " + f.Length + " bytes"; if (path.EndsWith(".txt")) { //new ScriptCoreLib.JavaScript.DOM.FileReader); // await? f.ReadAllText( text => { label1.Text += "\n " + text; } ); } } } ); }
public void ReadAllText() { // Type var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ReadAllText.txt")); // Intialization using (FileStream stream = @this.Create()) { byte[] byteToWrites = Encoding.Default.GetBytes("Fizz" + Environment.NewLine + "Buzz"); stream.Write(byteToWrites, 0, byteToWrites.Length); } // Examples string result = @this.ReadAllText(); // return "Fizz" + Environment.NewLine + "Buzz"; // Unit Test Assert.AreEqual("Fizz" + Environment.NewLine + "Buzz", result); }
private string ReadFileContents(FileInfo file) { return file.ReadAllText(Encoding.UTF8); }
protected virtual void OnTransactionImport(FileInfo file) { JsonException e; var o = Json.Decode(file.ReadAllText(), out e); if (e != null) { User.SendMessage(e.ToString()); Refresh(true); return; } var list = new List<DonationTransaction>(); DonationTransaction trans; string id, email, notes, extra; double total, time; long credit; int version; TransactionState state; IAccount account; var stateType = typeof(TransactionState); if (o is IEnumerable<object>) { var col = ((IEnumerable<object>)o).OfType<IDictionary<string, object>>(); foreach (var obj in col) { /*try {*/ id = (string)obj.GetValue("id"); state = (TransactionState)Enum.Parse(stateType, (string)obj.GetValue("state"), true); account = Accounts.GetAccount((string)obj.GetValue("account")); email = (string)obj.GetValue("email"); total = (double)obj.GetValue("total"); credit = (long)(double)obj.GetValue("credit"); time = (double)obj.GetValue("time"); version = (int)(double)obj.GetValue("version"); notes = (string)obj.GetValue("notes"); extra = (string)obj.GetValue("extra"); trans = CreateTransaction(id, state, account, email, total, credit, time, version, notes, extra); /*} catch { trans = null; }*/ if (trans != null) { list.Add(trans); } } } else if (o is IDictionary<string, object>) { var obj = (IDictionary<string, object>)o; /*try {*/ id = (string)obj.GetValue("id"); state = (TransactionState)Enum.Parse(stateType, (string)obj.GetValue("state"), true); account = Accounts.GetAccount((string)obj.GetValue("account")); email = (string)obj.GetValue("email"); total = (double)obj.GetValue("total"); credit = (long)(double)obj.GetValue("credit"); time = (double)obj.GetValue("time"); version = (int)(double)obj.GetValue("version"); notes = (string)obj.GetValue("notes"); extra = (string)obj.GetValue("extra"); trans = CreateTransaction(id, state, account, email, total, credit, time, version, notes, extra); /*} catch { trans = null; }*/ if (trans != null) { list.Add(trans); } } var count = 0; if (list.Count > 0) { DonationProfile p; DonationTransaction ot; foreach (var g in list.Where(t => t.Account != null).ToLookup(t => t.Account, t => t)) { p = AutoDonate.EnsureProfile(g.Key); if (p == null) { continue; } foreach (var t in g) { ot = p[t.ID]; if (ot == null || ot.Version <= t.Version) { p.Add(t); ++count; } } } } if (count > 0) { User.SendMessage("Imported {0:#,0} transactions!", count); } else { User.SendMessage("No transactions to import."); } Refresh(true); }