//Chapter 29 skipped as I was already asynchronous public async Task <List <ScheduledClass> > FetchClassesAsync() { XmlDocument xmlDoc; try { ScheduledClasses = new List <ScheduledClass>(); HttpWebRequest request = WebRequest.Create("http://bookapi.bignerdranch.com/courses.xml") as HttpWebRequest; HttpWebResponse response = await request.GetResponseAsync().ConfigureAwait(false) as HttpWebResponse; xmlDoc = new XmlDocument(); xmlDoc.Load(response.GetResponseStream()); if (xmlDoc == null) { throw new Exception("XmlDoc is null"); } Console.WriteLine("Received {0} bytes", xmlDoc.InnerXml); } catch (Exception ex) { Console.WriteLine("Error getting XML: {0}\n{1}", ex.Message, ex.StackTrace); return(null); } //Create namespace manager - MSDN said this needed to be done. Seems to work without it. // Perhaps needed when you don't know what you are getting. // XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); // nsmgr.AddNamespace("rest","http://schemas.microsoft.com/search/local/ws/rest/v1"); XmlNode regionNode = xmlDoc.SelectSingleNode("/summary/region"); XmlNodeList classNodes = regionNode.SelectNodes("class"); // Console.WriteLine("Show all formatted class names"); foreach (XmlNode scheduledClass in classNodes) { ScheduledClass sc = new ScheduledClass(); sc.Name = scheduledClass.SelectSingleNode("offering").InnerText; sc.Location = scheduledClass.SelectSingleNode("location").InnerText; sc.Href = scheduledClass.SelectSingleNode("offering").Attributes.GetNamedItem("href").Value; sc.Begin = scheduledClass.SelectSingleNode("begin").InnerText; // sc.Begin = DateTime.Parse(scheduledClass.SelectSingleNode("begin").InnerText).ToUniversalTime(); // Console.WriteLine(sc); ScheduledClasses.Add(sc); } return(ScheduledClasses); }
public Foundation.NSObject GetObjectValue(AppKit.NSTableView tableView, AppKit.NSTableColumn tableColumn, System.nint row) { ScheduledClass cl = scheduleFetcher.ScheduledClasses[(int)row]; if (tableColumn.Identifier != "Begin") { return(cl.ValueForKey(new NSString(tableColumn.Identifier))); } else { DateTime date = DateTime.Parse(cl.ValueForKey(new NSString(tableColumn.Identifier)).ToString()).ToUniversalTime(); // Manually make NSString with desired date format to pass to cell // return new NSString(date.ToLongDateString()); // Convert DateTime to NSDate to pass to cell and use Date Formatter for cell. date = DateTime.SpecifyKind(date, DateTimeKind.Local); return((NSDate)date); } }
public void TableViewDoubleClick(NSObject sender) { // NSTableView tv = (NSTableView)sender; // Console.WriteLine("TableView: {0}", tv); ScheduledClass c = scheduleFetcher.ScheduledClasses[(int)tableView.ClickedRow]; // webPanel = new NSPanel(); webPanel = new NSWindow(); webPanel.StyleMask = NSWindowStyle.Resizable | webPanel.StyleMask; webPanel.SetContentSize(new CGSize(Window.ContentView.Frame.Size.Width, 500.0f)); webView = new WebView(new CGRect(0.0f, 50.0f, Window.ContentView.Frame.Size.Width, 450.0f), "", ""); webView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable; webPanel.ContentView.AddSubview(webView); webView.WeakResourceLoadDelegate = this; webView.WeakFrameLoadDelegate = this; progressBar = new NSProgressIndicator(new CGRect(25.0f, 12.0f, Window.ContentView.Frame.Size.Width - 175.0f, 25.0f)); progressBar.Style = NSProgressIndicatorStyle.Bar; progressBar.Indeterminate = false; progressBar.AutoresizingMask = NSViewResizingMask.WidthSizable; webPanel.ContentView.AddSubview(progressBar); progressBar.MinValue = 0; progressBar.MaxValue = 100; progressBar.DoubleValue = progress; NSButton closebutton = new NSButton(new CGRect(webPanel.Frame.Width - 125.0f, 12.0f, 100.0f, 25.0f)); closebutton.Title = "Close"; closebutton.BezelStyle = NSBezelStyle.Rounded; closebutton.Target = this; closebutton.Action = new Selector("closePanel:"); closebutton.AutoresizingMask = NSViewResizingMask.MinXMargin; webPanel.DefaultButtonCell = closebutton.Cell; webPanel.ContentView.AddSubview(closebutton); webView.MainFrameUrl = c.Href; // Window.BeginSheet(webPanel, (nint) => { // // }); NSApplication.SharedApplication.BeginSheet(webPanel, Window); //NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(c.Href)); }
//Chapter 29 skipped as I was already asynchronous public async Task<List<ScheduledClass>> FetchClassesAsync() { XmlDocument xmlDoc; try { ScheduledClasses = new List<ScheduledClass>(); HttpWebRequest request = WebRequest.Create("http://bookapi.bignerdranch.com/courses.xml") as HttpWebRequest; HttpWebResponse response = await request.GetResponseAsync().ConfigureAwait(false) as HttpWebResponse; xmlDoc = new XmlDocument(); xmlDoc.Load(response.GetResponseStream()); if (xmlDoc == null) { throw new Exception("XmlDoc is null"); } Console.WriteLine("Received {0} bytes", xmlDoc.InnerXml); } catch (Exception ex) { Console.WriteLine("Error getting XML: {0}\n{1}", ex.Message, ex.StackTrace); return null; } //Create namespace manager - MSDN said this needed to be done. Seems to work without it. // Perhaps needed when you don't know what you are getting. // XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); // nsmgr.AddNamespace("rest","http://schemas.microsoft.com/search/local/ws/rest/v1"); XmlNode regionNode = xmlDoc.SelectSingleNode("/summary/region"); XmlNodeList classNodes = regionNode.SelectNodes("class"); // Console.WriteLine("Show all formatted class names"); foreach (XmlNode scheduledClass in classNodes) { ScheduledClass sc = new ScheduledClass(); sc.Name = scheduledClass.SelectSingleNode("offering").InnerText; sc.Location = scheduledClass.SelectSingleNode("location").InnerText; sc.Href = scheduledClass.SelectSingleNode("offering").Attributes.GetNamedItem("href").Value; sc.Begin = scheduledClass.SelectSingleNode("begin").InnerText; // sc.Begin = DateTime.Parse(scheduledClass.SelectSingleNode("begin").InnerText).ToUniversalTime(); // Console.WriteLine(sc); ScheduledClasses.Add(sc); } return ScheduledClasses; }