コード例 #1
0
        public void Invoke(Action<string> yield)
        {
            // 203f4a3d71
            // 20713d4a3f
            {
                var m = new ByteArray();

                // !
                m.endian = Endian.LITTLE_ENDIAN;

                m.writeByte(' ');

                //m.endian
                m.writeFloat(0.79);

                var bytes = m.ToMemoryStream().ToBytes();

                var base64 = Convert.ToBase64String(bytes);

                yield(base64);
            }

            // 20713d4a3f
            {
                var m = new MemoryStream();

                m.WriteByte((byte)' ');

                //                Implementation not found for type import :
                //type: System.IO.BinaryWriter
                //method: Void Write(Single)

                var w = new BinaryWriter(m);

                w.Write((float)0.79);

                var bytes = m.ToBytes();

                var base64 = Convert.ToBase64String(bytes);

                yield(base64);
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            {
                var m = new MemoryStream();

                m.WriteByte((byte)' ');


                var w = new BinaryWriter(m);

                w.Write((float)0.79);

                var bytes = m.ToBytes();

                Console.WriteLine(bytes.ToHexString());

            }

            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
        }
コード例 #3
0
        public static void Convert(TransportMessage message, IBytesMessage toSend, IMessageSerializer serializer)
        {
            byte[] body;
            if (message.Body == null && message.BodyStream != null)
            {
                body = message.BodyStream.ToBytes();
            }
            else
            {
                var stream = new MemoryStream();
                serializer.Serialize(message.Body, stream);
                body = stream.ToBytes();
            }

            toSend.WriteBytes(body);

            // TODO: clarify usage of JMSCorrelationID
            toSend.JMSCorrelationID = message.CorrelationId;
            toSend.JMSDeliveryMode = message.Recoverable ? DeliveryMode.Persistent : DeliveryMode.NonPersistent;
            toSend.SetStringProperty(HEADER_RETURNADDRESS, message.ReturnAddress);
            toSend.SetStringProperty(HEADER_IDFORCORRELATION, message.IdForCorrelation);
            toSend.SetStringProperty(HEADER_WINDOWSIDENTITYNAME, message.WindowsIdentityName);
            toSend.SetIntProperty(HEADER_MESSAGEINTENT, (int) message.MessageIntent);

            //TODO: set message expiration
            //toSend.JMSReplyTo = new Destination message.ReplyToAddress;
            //if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout)
            //toSend.JMSExpiration = (long) UTCNow.message.TimeToBeReceived.TotalMilliseconds;

            if (message.Headers == null)
                message.Headers = new List<HeaderInfo>();

            var nsbHeaderKeys = new List<string>();
            foreach (var keyValue in message.Headers)
            {
                toSend.SetStringProperty(keyValue.Key.ToXmsFriendly(), keyValue.Value);
                nsbHeaderKeys.Add(keyValue.Key.ToXmsFriendly());
            }
            toSend.SetStringProperty(HEADER_NBSKEYS, WrapKeys(nsbHeaderKeys));
        }
コード例 #4
0
ファイル: SqlQueue.cs プロジェクト: nnyamhon/shuttle-esb
        public Stream Dequeue(Guid messageId)
        {
            ResetUnderlyingMessageData();

            lock (padlock)
            {
                try
                {
                    using (databaseConnectionFactory.Create(dataSource))
                    {
                        var row = databaseGateway.GetSingleRowUsing(
                            dataSource,
                            RawQuery.CreateFrom(dequeueIdQueryStatement).AddParameterValue(QueueColumns.MessageId,
                                                                                           messageId));

                        if (row == null)
                        {
                            return null;
                        }

                        underlyingMessageData = row;

                        using (var stream = new MemoryStream((byte[]) row["MessageBody"]))
                        {
                            underlyingMessageData = new MemoryStream(stream.ToBytes());

                            return (Stream) underlyingMessageData;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Debug(string.Format("Could not dequeue message from queue '{0}'.  Exception: {1}.  Query: {2}",
                                            Uri, ex.Message, createQuery));

                    throw;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Downloads the BLOB.
        /// </summary>
        /// <param name="blob">The BLOB.</param>
        /// <param name="fetchAttribute">if set to <c>true</c> [fetch attribute].</param>
        /// <param name="metaData">The meta data.</param>
        /// <returns>System.Byte[].</returns>
        public static byte[] DownloadBlob(CloudBlockBlob blob, bool fetchAttribute, out IDictionary<string, string> metaData)
        {
            try
            {
                blob.CheckNullObject("blob");

                if (fetchAttribute)
                {
                    blob.FetchAttributes();
                    metaData = blob.Metadata;
                }
                else
                {
                    metaData = null;
                }

                var msRead = new MemoryStream { Position = 0 };
                using (msRead)
                {
                    blob.DownloadToStream(msRead);
                    return msRead.ToBytes();
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle("DownloadBlob", blob.Uri.ToString());
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the bytes.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="imageFormat">The image format.</param>
        /// <param name="qualityLevel">The quality level.
        /// <remarks>
        /// A quality level of 0 corresponds to the greatest compression, and a quality level of 100 corresponds to the least compression.
        /// https://msdn.microsoft.com/library/bb882583(v=vs.110).aspx
        /// </remarks></param>
        /// <returns>System.Byte[].</returns>
        /// <exception cref="OperationFailureException">GetBytes</exception>
        public static byte[] GetBytes(this Bitmap image, ImageFormat imageFormat = null, long qualityLevel = 100)
        {
            try
            {
                image.CheckNullObject("image");

                if (imageFormat == null)
                {
                    imageFormat = ImageFormat.Jpeg;
                }

                if (qualityLevel > 100 || qualityLevel < 1)
                {
                    qualityLevel = 100;
                }

                using (var memoryStream = new MemoryStream())
                {
                    var jpegEncoder = GetImageEncoder(imageFormat);
                    var encoder = Encoder.Quality;
                    var encoderParameters = new EncoderParameters(1);

                    var myEncoderParameter = new EncoderParameter(encoder, qualityLevel);
                    encoderParameters.Param[0] = myEncoderParameter;
                    image.Save(memoryStream, jpegEncoder, encoderParameters);

                    return memoryStream.ToBytes();
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle();
            }
        }
コード例 #7
0
 private static void CacheImage(string url, Bitmap bitmap)
 {
     string imagePath = GetProfileImagePath(url);
     if (!File.Exists(imagePath))
     {
         ByteBuffer byteBuffer = ByteBuffer.Allocate(bitmap.ByteCount);
         bitmap.CopyPixelsToBuffer(byteBuffer);
         MemoryStream ms = new MemoryStream();
         bitmap.Compress(Bitmap.CompressFormat.Png, 100, ms);
         byte[] bytes = ms.ToBytes();
         using (var fs = File.Create(imagePath))
         {
             fs.Write(bytes,0,bytes.Length);
         }
     }
 }