예제 #1
0
        internal static NSData NSDataFromDescription(string hexString)
        {
            NSMutableData data = new NSMutableData();

            byte[] hexAsBytes = new byte[hexString.Length / 2];
            for (int index = 0; index < hexAsBytes.Length; index++)
            {
                hexAsBytes[index] = Convert.ToByte(hexString.Substring(index * 2, 2), 16);
            }

            data.AppendBytes(hexAsBytes);
            return(data);
        }
        internal static NSData NSDataFromDescription(string hexString)
        {
            hexString = hexString.Trim('<', '>').Replace(" ", string.Empty);
            NSMutableData data = new NSMutableData();

            byte[] hexAsBytes = new byte[hexString.Length / 2];
            for (int index = 0; index < hexAsBytes.Length; index++)
            {
                string byteValue = hexString.Substring(index * 2, 2);
                hexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
            }

            data.AppendBytes(hexAsBytes);
            return(data);
        }
예제 #3
0
        public unsafe static NSData ToNSData(this IStream stream)
        {
            var data = new NSMutableData();

            byte[] buffer = new byte[32768];
            while (true)
            {
                ulong read;
                stream.Read(buffer, buffer.Length, (IntPtr)(&read));
                if (read == 0)
                    return(data);

                fixed(byte *value = &buffer[0])
                data.AppendBytes((IntPtr)(void *)value, (nuint)read);
            }
        }
예제 #4
0
        void ReadData()
        {
            nuint bufferSize = 128;

            byte[] buffer = new byte[bufferSize];

            while (_session.InputStream.HasBytesAvailable())
            {
                nint bytesRead = _session.InputStream.Read(buffer, bufferSize);

                if (_readData == null)
                {
                    _readData = new NSMutableData();
                }
                _readData.AppendBytes(buffer, 0, bytesRead);
                Console.WriteLine(buffer);
            }

            NSNotificationCenter.DefaultCenter.PostNotificationName(SessionDataReceivedNotification, this);
        }
예제 #5
0
        //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();
        }
        NSData NSDataFromDescription(string hexString)
        {
            hexString = hexString.Trim('<', '>').Replace(" ", string.Empty);
            NSMutableData data = new NSMutableData();
            byte[] hexAsBytes = new byte[hexString.Length / 2];
            for (int index = 0; index < hexAsBytes.Length; index++)
            {
                string byteValue = hexString.Substring(index * 2, 2);
                hexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
            }

            data.AppendBytes(hexAsBytes);
            return data;
        }