public void StartReadingBerlinData() { DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Low).DispatchAsync(() => { var file = NSBundle.MainBundle.PathForResource(@"Berlin-Data", "json"); var inputStream = new NSInputStream(file); inputStream.Open(); NSError error; var dataAsJson = (NSArray)NSJsonSerialization.Deserialize(inputStream, 0, out error); var annotations = new List <(double lat, double lon, string title)>(BATCH_COUNT); for (uint i = 0; i < dataAsJson.Count; i++) { var annotationAsJson = dataAsJson.GetItem <NSDictionary>(i); var lat = (NSNumber)annotationAsJson.ValueForKeyPath(new NSString("location.coordinates.latitude")); var lon = (NSNumber)annotationAsJson.ValueForKeyPath(new NSString("location.coordinates.longitude")); var title = (NSString)annotationAsJson.ValueForKeyPath(new NSString("person.lastName")); annotations.Add((lat.DoubleValue, lon.DoubleValue, title.ToString())); if (annotations.Count == BATCH_COUNT) { DispatchAnnotations(annotations.ToArray()); annotations.Clear(); } } DispatchAnnotations(annotations.ToArray()); }); }
public bool LoadMesh() { NSInputStream inputStream = NSInputStream.FromFile(mMeshPath); if (inputStream != null) { inputStream.Open(); NSError error; try { var jsonMesh = NSJsonSerialization.Deserialize(inputStream, new NSJsonReadingOptions(), out error); if (error == null) { NSArray values = null; nuint i; NSDictionary dictVertices; NSDictionary dictTriangles; NSArray arrayVertices = (jsonMesh as NSDictionary)["vertices"] as NSArray; NSArray arrayTriangles = (jsonMesh as NSDictionary)["connectivity"] as NSArray; NSString nameVertices, nameTriangles; for (i = 0; i < arrayVertices.Count; i++) { dictVertices = arrayVertices.GetItem <NSDictionary>(i); values = dictVertices["values"] as NSArray; nameVertices = dictVertices["name"] as NSString; if (nameVertices == "position_buffer") { mVertices = VerticesToFloat(values); } else if (nameVertices == "normal_buffer") { mNormals = ToFloatArray(values); } else if (nameVertices == "texcoord_buffer") { mTexCoords = ToFloatArray(values); } } for (i = 0; i < arrayTriangles.Count; i++) { dictTriangles = arrayTriangles.GetItem <NSDictionary>(i); nameTriangles = dictTriangles["name"] as NSString; if (nameTriangles == "triangles") { values = dictTriangles["indices"] as NSArray; mIndices_Number = (int)values.Count; mIndex = ToShortIntArray(values); } } } } catch (Exception ee) { Console.WriteLine("Errore durante LoadMesh {0}", ee.Message); inputStream.Close(); return(false); } inputStream.Close(); } return(true); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ip), port); CFStream.CreatePairWithSocketToHost(ipEndPoint, out readStream, out writeStream); inputStream = ObjCRuntime.Runtime.GetNSObject <NSInputStream>(readStream.Handle); outputStream = ObjCRuntime.Runtime.GetNSObject <NSOutputStream>(writeStream.Handle); inputStream.ServiceType = NSStreamServiceType.VoIP; outputStream.ServiceType = NSStreamServiceType.VoIP; // // or ? inputStream[NSStream.NetworkServiceType] = NSStream.NetworkServiceTypeVoIP; outputStream[NSStream.NetworkServiceType] = NSStream.NetworkServiceTypeVoIP; inputStream.OnEvent += HandleInputEvent; outputStream.OnEvent += HandleOutputEvent; outputStream.Schedule(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); // TODO check inputStream.Schedule(NSRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); // TODO check // readStream.EnableEvents(CFRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); // writeStream.EnableEvents(CFRunLoop.Main, NSRunLoop.NSDefaultRunLoopMode); outputStream.Open(); inputStream.Open(); // UIApplication.SharedApplication.SetKeepAliveTimeout(1, null); // Not supported any more. return(true); }
internal ExternalAccessoryNetworkStream(EASession session) { _delegate = new EAStreamDelegate(this); _inputStream = session.InputStream; _outputStream = session.OutputStream; _inputStream.Open(); _outputStream.Delegate = _delegate; _outputStream.Schedule(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode); _outputStream.Open(); }
//Download File public void DownloadFile(CRCloudMetaData metaData) { new System.Threading.Thread(new System.Threading.ThreadStart(() => { InvokeOnMainThread(() => { CloudStorageLogic cloudStorageLogic = new CloudStorageLogic(); NSInputStream inputStream = cloudStorageLogic.DownloadFileWithPath(_cloudStorage, metaData.Path); NSMutableData data = new NSMutableData(); inputStream.Open(); var int32Value = metaData.Size.Int32Value; var intValue = metaData.Size.NIntValue; var buffer = new byte[1024]; while (inputStream.HasBytesAvailable()) { var len = inputStream.Read(buffer, 1024); data.AppendBytes(buffer); } if (inputStream.HasBytesAvailable() == false) { inputStream.Close(); var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var bytes = data.Bytes; string localFilename = metaData.Name; string localPath = Path.Combine(documents, localFilename); byte[] managedArray = new byte[intValue]; Marshal.Copy(bytes, managedArray, 0, int32Value); File.WriteAllBytes(localPath, managedArray); helper.Alert("Download Completed", "File downloaded and saved to file sharing", _controller); } }); })).Start(); }
public unsafe void Read() { using (var data = NSData.FromArray(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })) { using (var s = NSInputStream.FromData(data)) { byte[] arr = new byte[10]; s.Open(); Assert.IsTrue(s.HasBytesAvailable()); Assert.AreEqual((nint)2, s.Read(arr, 2), "#a 1"); Assert.AreEqual(0, arr [0], "#a[0]"); Assert.AreEqual(1, arr [1], "#a[1]"); } using (var s = new NSInputStream(data)) { byte[] arr = new byte[10]; s.Open(); Assert.IsTrue(s.HasBytesAvailable()); Assert.AreEqual((nint)2, s.Read(arr, 1, 2), "#b 1"); Assert.AreEqual(0, arr [0], "#b[0]"); Assert.AreEqual(0, arr [1], "#b[1]"); Assert.AreEqual(1, arr [2], "#b[2]"); } using (var s = new NSInputStream(data)) { byte[] arr = new byte[10]; s.Open(); Assert.IsTrue(s.HasBytesAvailable()); fixed(byte *ptr = &arr[2]) Assert.AreEqual((nint)2, s.Read((IntPtr)ptr, 2), "#c 1"); Assert.AreEqual(0, arr [0], "#c[0]"); Assert.AreEqual(0, arr [1], "#c[1]"); Assert.AreEqual(0, arr [2], "#c[2]"); Assert.AreEqual(1, arr [3], "#c[3]"); } } }
public void Open() { _inputStream?.Open(); }