public override bool LoadFromContents(NSObject contents, string typeName, out NSError outError) { outError = null; if (contents != null) { this.data = NSString.FromData((NSData)contents, NSStringEncoding.UTF8); } return(true); }
public ExperienceSelectionViewController(IntPtr handle) : base(handle) { NSUrl exampleDefinitionsFileURL = NSBundle.MainBundle.GetUrlForResource("samples", "json", "ARchitectExamples"); if (exampleDefinitionsFileURL != null) { NSData exampleExperienceData = NSData.FromUrl(exampleDefinitionsFileURL); NSString exampleExperienceDefinitions = NSString.FromData(exampleExperienceData, NSStringEncoding.UTF8); experienceGroups = ArExperienceManager.ParseExampleDefintion(exampleExperienceDefinitions); } }
private void Parse(NSData data) { try { var earthquakes = new List <Earthquake> (); var dump = JsonValue.Parse(NSString.FromData(data, NSStringEncoding.UTF8)) as JsonObject; JsonValue featureCollection = dump ["features"]; for (int i = 0; i < MaximumNumberOfEarthquakesToParse; i++) { var currentEarthquake = new Earthquake(); var earthquake = featureCollection [i] as JsonObject; JsonValue earthquakeProperties = earthquake ["properties"]; currentEarthquake.Magnitude = NSNumber.FromFloat((float)earthquakeProperties ["mag"]); currentEarthquake.USGSWebLink = new NSString((string)earthquakeProperties ["url"]); currentEarthquake.Location = new NSString((string)earthquakeProperties ["place"]); //date and time in milliseconds since epoch var seconds = (Int64)earthquakeProperties ["time"]; var date = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(seconds); string str = date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"); currentEarthquake.Date = dateFormatter.Parse(str); JsonValue earthquakeGeometry = earthquake ["geometry"]; var coordinates = earthquakeGeometry ["coordinates"] as JsonArray; currentEarthquake.Longitude = NSNumber.FromFloat(coordinates [0]); currentEarthquake.Latitude = NSNumber.FromFloat(coordinates [1]); if (earthquakes.Count > SizeOfEarthquakesBatch) { AddEarthquakesToList(earthquakes); earthquakes.Clear(); } else { earthquakes.Add(currentEarthquake); } } if (earthquakes.Count > 0) { AddEarthquakesToList(earthquakes); } } catch (Exception e) { Console.WriteLine(e.StackTrace + e.Message); var userInfo = NSDictionary.FromObjectAndKey(new NSString("Error while parsing GeoJSON"), NSError.LocalizedDescriptionKey); var parsingError = new NSError(new NSString(), 0, userInfo); InvokeOnMainThread(new Selector("HandleEarthquakesError:"), parsingError); } }
void ShowPeerPicker() { GameKitSession = new GKSession("com.mikebluestein.gamekitchat", UIDevice.CurrentDevice.Name, GKSessionMode.Peer); GameKitSession.ReceiveData += (s, e) => { AddMessage(NSString.FromData(e.Data, NSStringEncoding.UTF8).ToString()); }; GameKitSession.ConnectionRequest += (s, e) => { e.Session.AcceptConnection(e.PeerID, IntPtr.Zero); }; GKPeerPickerController peerPickerController = new GKPeerPickerController(); peerPickerController.Delegate = new PeerPickerDelegate(this); peerPickerController.ConnectionTypesMask = GKPeerPickerConnectionType.Nearby; peerPickerController.Show(); }
public static string FindInternetPassword(Uri url) { // See if there is already a password there for this uri var record = SecKeychainFindInternetPassword(url, out _); if (record != null) { return(NSString.FromData(record.ValueData, NSStringEncoding.UTF8)); } return(null); }
/// <summary> /// Fetches the currently saved set of account credentials or null if no credentials have been saved. /// </summary> /// <returns>The user credentials.</returns> public AccountCredentials GetAccountCredentials() { IEnumerable <SecRecord> records = this.GetRecords(); if (records.Any()) { string serializedData = NSString.FromData(records.First().Generic, NSStringEncoding.UTF8); return(AccountCredentials.TryDeserialize(serializedData)); } return(null); }
public static string NSDictToString(NSDictionary nsDict) { if (nsDict == null) { return(null); } NSError error; NSData jsonData = NSJsonSerialization.Serialize(nsDict, 0, out error); NSString jsonNSString = NSString.FromData(jsonData, NSStringEncoding.UTF8); return(jsonNSString.ToString()); }
public override void FinishedLoading(NSUrlConnection connection) { if (_data != null) { string scriptNotifyAndContent = _controller.ScriptNotify; scriptNotifyAndContent += NSString.FromData(_data, NSStringEncoding.UTF8).ToString(); _data = null; _controller.WebView.LoadHtmlString(scriptNotifyAndContent, _controller.Url); } }
/// <summary> /// Gets the password from the OSX keychain /// </summary> /// <returns> /// Password is present in the keychain /// </returns> /// <param name='username'> /// The username /// </param> /// <param name='password'> /// The stored password /// </param> bool GetPassword(string username, out string password) { SecRecord searchRecord; var record = FetchRecord(username, out searchRecord); if (record == null) { password = string.Empty; return(false); } password = NSString.FromData(record.ValueData, NSStringEncoding.UTF8); return(true); }
public static string GetUserPassword (string username) { string password = null; var searchRecord = new SecRecord (SecKind.InternetPassword) { Server = "Test1", Account = username.ToLower() }; SecStatusCode code; var record = SecKeyChain.QueryAsRecord(searchRecord, out code); if (code == SecStatusCode.Success && record != null) password = NSString.FromData (record.ValueData, NSStringEncoding.UTF8); return password; }
public static Dictionary <string, object> NSDictToPureDict(NSDictionary nsDict) { if (nsDict == null) { return(null); } NSError error; NSData jsonData = NSJsonSerialization.Serialize(nsDict, 0, out error); NSString jsonNSString = NSString.FromData(jsonData, NSStringEncoding.UTF8); string jsonString = jsonNSString.ToString(); return(Json.Deserialize(jsonString) as Dictionary <string, object>); }
public static string GetPat() { SecRecord searchRecord; var record = FetchKeychainRecord(out searchRecord); if (record == null) { return(string.Empty); } return(NSString.FromData(record.ValueData, NSStringEncoding.UTF8).ToString()); }
public override void DraggingEnded(NSDraggingInfo sender) { // Update the dropped item counter and display dragCount++; UpdateDragCount(); // Pull the individual items from the drag package and write them to the console var i = new NSImage(sender.DraggingPasteboard.GetDataForType(NSPasteboard.NSTiffType)); string s = NSString.FromData(sender.DraggingPasteboard.GetDataForType(NSPasteboard.NSStringType), NSStringEncoding.UTF8); Console.WriteLine("String Data: {0}", s); Console.WriteLine("Image Data: {0}", i.Size); }
private static string EncodedStringFromByte(byte charVal) { switch (charVal) { case 0x00: return(".com/"); case 0x01: return(".org/"); case 0x02: return(".edu/"); case 0x03: return(".net/"); case 0x04: return(".info/"); case 0x05: return(".biz/"); case 0x06: return(".gov/"); case 0x07: return(".com"); case 0x08: return(".org"); case 0x09: return(".edu"); case 0x0a: return(".net"); case 0x0b: return(".info"); case 0x0c: return(".biz"); case 0x0d: return(".gov"); default: return(NSString.FromData(NSData.FromArray(new byte[] { charVal }), NSStringEncoding.UTF8)); } }
/// <summary> /// Update the UI based on the userInfo dictionary of the notification. /// </summary> private void DataDidFlow(NSNotification notification) { if (notification.Object is CommandStatus commandStatus) { // If an error occurs, show the error message and returns. if (!string.IsNullOrEmpty(commandStatus.ErrorMessage)) { this.Log($"! {commandStatus.Command}...{commandStatus.ErrorMessage}"); } else { if (commandStatus.TimedColor != null) { this.Log($"#{commandStatus.Command}...\n{commandStatus.Phrase} at {commandStatus.TimedColor.TimeStamp}"); var fileURL = commandStatus.File?.FileUrl; if (fileURL != null) { if (fileURL.PathExtension == "log") { var content = NSString.FromData(NSData.FromUrl(fileURL), NSStringEncoding.UTF8); if (content.Length > 0) { this.Log($"{fileURL.LastPathComponent}\n{content}"); } else { this.Log($"{fileURL.LastPathComponent}\n"); } } } var fileTransfer = commandStatus.FileTransfer; if (fileTransfer != null && commandStatus.Command == Command.TransferFile) { if (commandStatus.Phrase == Phrase.Finished) { this.fileTransferObservers.Unobserve(fileTransfer); } else if (commandStatus.Phrase == Phrase.Transferring) { this.fileTransferObservers.Observe(fileTransfer, (_) => this.LogProgress(fileTransfer)); } } } this.NoteLabel.Hidden = !string.IsNullOrEmpty(this.LogView.Text); } } }
/// <summary> /// Find an existing key, create a new key, delete a previous key. /// </summary> /// <returns>The for key.</returns> /// <param name="key">Key.</param> public string ValueForKey(string key) { var record = ExistingRecordForKey(key); var match = SecKeyChain.QueryAsRecord(record, out SecStatusCode resultCode); if (resultCode == SecStatusCode.Success) { return(NSString.FromData(match.ValueData, NSStringEncoding.UTF8)); } else { return(String.Empty); } }
public static Tuple <string, string> FindInternetUserNameAndPassword(Uri url, SecProtocol protocol) { var record = SecKeychainFindInternetPassword(url, protocol, out _); if (record != null) { string username = record.Account != null?NSString.FromData(record.Account, NSStringEncoding.UTF8) : null; string password = record.ValueData != null?NSString.FromData(record.ValueData, NSStringEncoding.UTF8) : null; return(Tuple.Create(username, password)); } return(null); }
public override bool LoadFromContents(NSObject contents, string typeName, out NSError outError) { Console.WriteLine("LoadFromContents(" + typeName + ")"); outError = null; if (contents != null) { this.DocumentContent = NSString.FromData((NSData)contents, NSStringEncoding.UTF8); } NSNotificationCenter.DefaultCenter.PostNotificationName("taskModified", this); return(true); }
private void ResponseHandler(NSData data, NSUrlResponse response, NSError error) { if (data == null) { Debug.WriteLine("no data"); return; } NSString dataString = NSString.FromData(data, NSStringEncoding.UTF8); InvokeOnMainThread(() => { ResultTextView.Text = dataString; }); }
public static string GetKeyChainRecord(SecRecord record) { SecStatusCode resultCode; var match = SecKeyChain.QueryAsRecord(record, out resultCode); if (resultCode == SecStatusCode.Success) { return(NSString.FromData(match.ValueData, NSStringEncoding.UTF8)); } else { return(String.Empty); } }
private bool ProcessGreetingsService(string application, string service, string version, string method, Foundation.NSObject parameters, NSObject[] attachments, string requestID, out NSError goodError) { goodError = null; bool requestProcessed = false; if (String.Equals(version, "1.0.0")) { if (String.Equals(method, "greetMe")) { requestProcessed = GDService.ReplyTo(application, new NSString("G'day mate!"), GDTForegroundOption.EPreferPeerInForeground, null, requestID, out goodError); } else if (String.Equals(method, "sendFiles")) { StringBuilder fileString = new StringBuilder(20); GDFileStat fileStat = new GDFileStat(); for (int i = 0; i < attachments.Length; i++) { NSString file = (NSString)attachments [i]; NSError error = null; bool ok = GDFileSystem.GetFileStat(file, ref fileStat, out error); fileString.AppendFormat("{0}: ", file); if (ok && error == null) { goodError = null; fileString.AppendFormat("{0} bytes; ", fileStat.fileLen); NSData fileData = GDFileSystem.ReadFromFile(file, out error); if (fileData != null && error != null) { Console.WriteLine(String.Format("Filepath: {0}", file)); string fileDataString = NSString.FromData(fileData, NSStringEncoding.UTF8); Console.WriteLine(String.Format("File Contents: {0}", fileDataString)); } } else { goodError = error; fileString.AppendFormat("Error: {0}", error.LocalizedDescription); } } UIAlertView alertView = new UIAlertView("Recieved Files", fileString.ToString(), null, "OK", null); alertView.Show(); requestProcessed = true; } } return(requestProcessed); }
public string Load(string path = null) { try { SecRecord searchRecord; var parsedPath = ParsePath(path); var record = FetchRecord(parsedPath, out searchRecord); return(NSString.FromData(record.ValueData, NSStringEncoding.UTF8)); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public /*async Task <string>*/ string getFormString(string fileName) { //await Task.Delay(10); var path = NSBundle.MainBundle.PathForResource(fileName, "json"); var json = ""; using (var data = NSData.FromFile(path)) { json = NSString.FromData(data, NSStringEncoding.ASCIIStringEncoding).ToString(); } return(json); }
internal string ValueForKey(string key) { using (var record = ExistingRecordForKey(key)) using (var match = SecKeyChain.QueryAsRecord(record, out var resultCode)) { if (resultCode == SecStatusCode.Success) { return(NSString.FromData(match.ValueData, NSStringEncoding.UTF8)); } else { return(null); } } }
// contents supplied by iCloud to display, update local model and display (via notification) public override bool LoadFromContents(NSObject contents, string typeName, out NSError outError) { outError = null; Console.WriteLine("LoadFromContents({0})", typeName); if (contents != null) { dataModel = NSString.FromData((NSData)contents, NSStringEncoding.UTF8); } // LoadFromContents called when an update occurs NSNotificationCenter.DefaultCenter.PostNotificationName("monkeyDocumentModified", this); return(true); }
/// <summary> /// Basic post request. /// </summary> /// <returns>The post response.</returns> /// <param name="url">URL.</param> /// <param name="args">Arguments.</param> /// <param name="headers">Headers.</param> public static string BasicPostRequest(string url, Dictionary <string, string> args, Dictionary <string, string> headers = null) { NSString urlString = (NSString)url; NSMutableUrlRequest request = new NSMutableUrlRequest(); request.Url = new NSUrl(urlString); request.HttpMethod = "POST"; string boundary = "---------------------------14737809831466499882746641449"; NSString contentType = new NSString(string.Format("multipart/form-data; boundary={0}", boundary)); var keys = new List <object> { "Content-Type" }; var objects = new List <object> { contentType }; if (headers != null) { foreach (KeyValuePair <string, string> kvp in headers) { keys.Add(kvp.Key); objects.Add(kvp.Value); } } var dictionary = NSDictionary.FromObjectsAndKeys(objects.ToArray(), keys.ToArray()); request.Headers = dictionary; NSMutableData body = new NSMutableData(); foreach (KeyValuePair <string, string> kvp in args) { body.AppendData(NSData.FromString(new NSString(string.Format("\r\n--{0}\r\n", boundary)))); body.AppendData(NSData.FromString(new NSString(string.Format("Content-Disposition: form-data; name=\"{0}\"\r\n\r\n", kvp.Key)))); body.AppendData(NSData.FromString(new NSString(kvp.Value))); body.AppendData(NSData.FromString(new NSString(string.Format("\r\n--{0}--\r\n", boundary)))); } request.Body = body; NSUrlResponse resp; NSError err; NSData returnData = NSUrlConnection.SendSynchronousRequest(request, out resp, out err); return(NSString.FromData(returnData, NSStringEncoding.UTF8).ToString()); }