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); }
public void Path() { using (var s = new NSInputStream("Info.plist")) { // initWithFileAtPath: does not respond (see dontlink.app) but it works Assert.That(s.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); } }
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()); }); }
private void SetEncryptionOnStreams(SocketEncryption encryption, NSInputStream inStream, NSOutputStream outStream) { if (encryption == SocketEncryption.Ssl) { inStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.SslV3; outStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.SslV3; } else if (encryption == SocketEncryption.Tls10) { inStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.TlsV1; outStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.TlsV1; } else if (encryption == SocketEncryption.Tls11) { inStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.TlsV1; outStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.TlsV1; } else if (encryption == SocketEncryption.Tls12) { inStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.TlsV1; outStream.SocketSecurityLevel = NSStreamSocketSecurityLevel.TlsV1; //var key = ObjCRuntime.Dlfcn.GetStringConstant("kCFStreamPropertySSLSettings", Libraries.CoreFoundation.Handle); } }
public void Data() { using (var d = NSData.FromFile("Info.plist")) using (var s = new NSInputStream(d)) { // initWithData: does not respond (see dontlink.app) but it works Assert.That(s.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); } }
public void Url() { using (var u = NSUrl.FromFilename("Info.plist")) using (var s = new NSInputStream(u)) { // initWithURL: does not respond (see dontlink.app) but it works Assert.That(s.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); } }
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(); }
protected override void Dispose(bool disposing) { if (disposing) { _inputStream?.Close(); _inputStream?.Dispose(); _inputStream = null; _streamSubject?.Dispose(); _streamSubject = null; IsOpen = false; } }
public void Data() { #if MONOMAC || __MACCATALYST__ // Info.Plist isn't there to load from the same location on mac var plistPath = global::System.IO.Path.Combine(NSBundle.MainBundle.BundlePath, "Contents", "Info.plist"); #else var plistPath = global::System.IO.Path.Combine(NSBundle.MainBundle.BundlePath, "Info.plist"); #endif using (var d = NSData.FromFile(plistPath)) using (var s = new NSInputStream(d)) { // initWithData: does not respond (see dontlink.app) but it works Assert.That(s.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); } }
//Upload Image / Video void UploadImageVideo(bool isVideo, NSData data) { NSInputStream inputStream = new NSInputStream(data); //Upload Image using CloudRail var len = (int)data.Length; Random rand1 = new Random(); string extensionName = isVideo?".mov":".jpg"; string fileName = "/" + rand1.Next() + extensionName;//".jpg":".mov"; new System.Threading.Thread(new System.Threading.ThreadStart(() => { cloudStorageLogic.UploadFileToPath(cloudStorage, fileName, inputStream, len, true); GetRootFilesFolders(); })).Start(); }
protected override void Dispose(bool disposing) { if (_inputStream is object) { _inputStream.Close(); _inputStream.Dispose(); _inputStream = null; } if (_outputStream is object) { _outputStream.Close(); _outputStream.Unschedule(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode); _outputStream.Dispose(); _outputStream = null; } base.Dispose(disposing); }
private void ListeningInputStream(ConnectedClientInfo info) { NSInputStream stream = info.Stream.Input; stream.OnEvent += (_, e) => { if (e.StreamEvent == NSStreamEvent.HasBytesAvailable) { var buffer = ReadFromInputStream(stream, info.ClientUid); if (buffer != null && buffer.Length > 0) { ProcessBuffer(buffer, info); } } else if (e.StreamEvent == NSStreamEvent.ErrorOccurred) { _logger.LogMessage("Socket", LogLevel.Error, "Some error occured within the input stream"); } }; }
//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(); }
private byte[] ReadFromInputStream(NSInputStream stream, string clientUid) { var header = new MqttFixedHeader(); var headerByte = new byte[1]; nint receivedSize; // Read the fixed header do { receivedSize = stream.Read(headerByte, 0, (nuint)headerByte.Length); } while (receivedSize > 0 && header.AppendByte(headerByte[0])); if (!header.IsComplete) { _logger.LogMessage("Socket", LogLevel.Error, string.Format("Read header operation could not read header, aborting.")); return(null); } _logger.LogMessage("Socket", LogLevel.Verbose, string.Format("Received message header type '{0}' from client {1}.", header.MessageType, clientUid)); //_logger.LogMessage("Socket", LogLevel.Warning, // string.Format("Received message header=0x{0:X}, Remaining length={1}.", header.Buffer[0], header.RemainingLength)); // Create a buffer and read the remaining message var completeBuffer = header.CreateMessageBuffer(); receivedSize = 0; while (receivedSize < header.RemainingLength) { receivedSize += stream.Read(completeBuffer, header.HeaderSize + (int)receivedSize, (nuint)(header.RemainingLength - receivedSize)); } //_logger.LogMessage("Socket", LogLevel.Warning, // string.Format(" Bytes read= {0}.", receivedSize)); return(completeBuffer); }
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 DidReceiveStream(MCSession session, NSInputStream stream, string streamName, MCPeerID peerID) { throw new Exception("This service does not send/receive streams."); }
public override void DidReceiveStream(MCSession session, NSInputStream stream, string streamName, MCPeerID peerID) { Console.WriteLine("DidReceiveStream :{0}", streamName); }
public override void UserActivityReceivedData (NSUserActivity userActivity, NSInputStream inputStream, NSOutputStream outputStream) { // Log Console.WriteLine ("User Activity Received Data: {0}", userActivity.Title); }
//Upload File To Path - Uploads a file to the specified location. Can either overwrite the existing file or will fail if the file already exists. public void UploadFileToPath(ICRCloudStorageProtocol cloudStorage, string path, NSInputStream inputSteam, int size, bool overwrite) { try { cloudStorage.UploadFileToPath(path, inputSteam, size, overwrite); } catch (Exception e) { Console.WriteLine(e.Message); } }
public override void UserActivityReceivedData(NSUserActivity userActivity, NSInputStream inputStream, NSOutputStream outputStream) { // Log Console.WriteLine("User Activity Received Data: {0}", userActivity.Title); }
public void DidReceiveStream(MCSession session, NSInputStream stream, string streamName, MCPeerID peerID) { // this app doesn't use streams. }
public override void DidReceiveStream(MCSession session, NSInputStream stream, string streamName, MCPeerID peerID) { //Debug.WriteLine("### STREAM RECEIVE"); }
public BleInputStream(NSInputStream inputStream) { _inputStream = inputStream; _streamSubject = new Subject <IStreamData>(); _inputStream.WeakDelegate = this; }
public NSStreamPair(NSInputStream input, NSOutputStream output) { Input = input; Output = output; }
public static CFHTTPStream CreateForStreamedHTTPRequest(CFHTTPMessage request, NSInputStream body) { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (body is null) { throw new ArgumentNullException(nameof(body)); } var handle = CFReadStreamCreateForStreamedHTTPRequest(IntPtr.Zero, request.Handle, body.Handle); return(new CFHTTPStream(handle, true)); }
public override void DidReceiveStream(MCSession session, NSInputStream stream, string streamName, MCPeerID peerID) { }