Exemple #1
0
        protected override IPerformanceLogger GetLogger()
        {
            var size1 = BytesHelper.GetHumanStringFromBytes(_file1.Length);
            var size2 = BytesHelper.GetHumanStringFromBytes(_file2.Length);

            return(FileGeneratorFactory.GetLogger($"{OperationType} - {size1} + {size2}", false));
        }
Exemple #2
0
        public void MessageSizeTestSNS_Empty()
        {
            var  request  = new PublishRequest();
            bool tooLarge = BytesHelper.TooLarge(request, 10);

            Assert.False(tooLarge);
        }
Exemple #3
0
        private void decodeE0(byte[] buffer, int index) //视频流
        {
            int length = readUshort(buffer, 4);         //PES packet length:16 位字段,指出了PES 分组中跟在该字段后的字节数目。值为0 表示PES 分组长度要么没有规定要么没有限制。这种情况只允许出现在有效负载包含来源于传输流分组中某个视频基本流的字节的PES 分组中。

            if (length != buffer.Length - 6)
            {
                return;
            }

            int start = 8 + buffer[8];

            index = start + 1;
            int startcodeLen = getStreamStartCode(buffer, index);

            if (startcodeLen == 4 || startcodeLen == 3)
            {
                Nalu nal = Nalu.Parse(BytesHelper.SubBytes(buffer, index + startcodeLen));
                //标记上一个包是一帧的结束。
                if (_lastFg != null)
                {
                    _lastFg.IsFrameEnd = true;
                    toFireUnpacked();
                }
                //因为有header值,因此此包是一帧开始
                _lastFg = new PSFragment(nal.Header, nal.Payload);
            }
            else
            {
                toFireUnpacked();
                _lastFg = new PSFragment(null, BytesHelper.SubBytes(buffer, index));
            }
        }
        public ChatbotService(CommandHelper commandHelper, TwitchClient client, TwitchAPI api, TwitchPubSub pubsub, FollowerService followerService, VipHelper vipHelper, BytesHelper bytesHelper)
        {
            this.commandHelper   = commandHelper;
            this.client          = client;
            this.api             = api;
            this.pubsub          = pubsub;
            this.followerService = followerService;
            this.vipHelper       = vipHelper;
            this.bytesHelper     = bytesHelper;

            this.commandHelper.Init();

            client.OnJoinedChannel       += onJoinedChannel;
            client.OnChatCommandReceived += onCommandReceived;
            client.OnNewSubscriber       += onNewSub;
            client.OnReSubscriber        += onReSub;
            client.Connect();

            pubsub.OnPubSubServiceConnected += onPubSubConnected;
            pubsub.OnListenResponse         += onListenResponse;

            // followerService.OnNewFollowersDetected += onNewFollowers;

            pubsub.Connect();
        }
Exemple #5
0
 private void dgvUser_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         DataTable dt = this.dgvUser.DataSource as DataTable;
         if (dt.Rows[e.RowIndex]["face"] != null)
         {
             object face_value = dt.Rows[e.RowIndex]["face"];
             if (face_value != null)
             {
                 byte[] face = face_value as byte[];
                 if (face != null)
                 {
                     this.picHead.Image = BytesHelper.ByteToImage(face);
                 }
                 else
                 {
                     this.picHead.Image = null;
                 }
             }
             else
             {
                 this.picHead.Image = null;
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
     }
 }
        private static CmdParseResult SerialParseProc(IList <byte> buffer, out Int32 parsedHeaderIndex, out Int32 parsingIndex)
        {
            parsedHeaderIndex = 0;
            parsingIndex      = 0;

            CmdParseResult result = CmdParseResult.IncompleteCmd;

            var index = BytesHelper.IndexOf(buffer, Header);

            if (buffer.Count > 0)
            {
                Logger.Debug("inderx:" + index);
                for (int i = 0; i < buffer.Count; i++)
                {
                    Logger.Debug("buffer:" + buffer[i].ToString());
                }
            }

            if (index >= 0)
            {
                parsedHeaderIndex = index;

                Boolean completeCmd = (buffer.Count - index) >= (Header.Length + 4);
                //协议数据是完整的
                if (completeCmd)
                {
                    parsingIndex = index + Header.Length + 4;

                    var checkIndex = parsingIndex - 2;

                    var checkValid = buffer[checkIndex] == 0x81 && buffer[checkIndex + 1] == 0x82;
                    Logger.Debug(buffer[checkIndex].ToString() + "@@@" + buffer[checkIndex + 1]);
                    if (checkValid)
                    {
                        result = CmdParseResult.Ok;
                        var msg = "检测到有效的串口数据:{Environment.NewLine}{BitConverter.ToString(buffer.ToArray())}";

                        Logger.Debug(msg);

                        var state = GetDeviceState(buffer, checkIndex - 2);

                        OnDeviceStateChanged(state);
                    }
                    else
                    {
                        result = CmdParseResult.Fail;

                        var msg = "检测到无效的串口数据:{Environment.NewLine}{BitConverter.ToString(buffer.ToArray())}";

                        Logger.Debug(msg);
                    }
                }
                else
                {
                    Logger.Debug("协议是不完整的");
                }
            }
            return(result);
        }
Exemple #7
0
        public void BytesHelperShouldReturnEmptyArrayOnEmptyString()
        {
            var input         = string.Empty;
            var expectedBytes = new byte[0];

            var actualBytes = BytesHelper.GetBytes(input);

            Assert.Equal(expectedBytes, actualBytes);
        }
Exemple #8
0
        /**
         * Writes bytes to the underlying buffer, with the length of the bytes prepended.
         * @param	bytes
         */
        public void writeBytes(byte[] bytes)
        {
            ushort len = System.UInt16.Parse(bytes.Length.ToString());

            byte[] lenbytes = System.BitConverter.GetBytes(BytesHelper.ReverseBytes(len));

            buffer.AddRange(lenbytes);
            buffer.AddRange(bytes);
        }
Exemple #9
0
 public string CreatePasswordHash(string password)
 {
     if (this._salt == null)
     {
         throw new SaltIsNullException("Salt canot be null. Set value or generate new one.");
     }
     byte[] hashed = GenerateHash(password);
     return(BytesHelper.BytesToString(hashed));
 }
Exemple #10
0
        public void MessageSizeTestSNS_TooManyBytesInBody()
        {
            var request = new PublishRequest();

            request.Message = "1234567890a";
            bool tooLarge = BytesHelper.TooLarge(request, 10);

            Assert.True(tooLarge);
        }
        public bool Logar(string _email, string _senha)
        {
            var senha = BytesHelper.StringToByte(_senha);

            if (!ValidacaoEmail.Validar(_email))
            {
                return(false);
            }
            return(_repositorio.Buscar(x => x.email == _email && x.senha == senha).Count == 1);
        }
Exemple #12
0
        static void Main(string[] args)
        {
#if NETCOREAPP2_0
            Console.WriteLine(RuntimeInformation.OSArchitecture.ToString());
            Console.WriteLine(RuntimeInformation.OSDescription);
            Console.WriteLine(RuntimeInformation.FrameworkDescription);
#endif
            Console.Title = "Server";

            var       receiveEncoding = Encoding.UTF8;
            var       sendEncoding    = Encoding.UTF8;
            var       port            = 18180;
            IPAddress ipa;
            IPAddress.TryParse("127.0.0.1", out ipa);
            ipa = IPAddress.Any;

            var es = new EchoServer <string>
                     (
                new IPEndPoint(ipa, port)
                , (x, y) =>
            {
                var s = receiveEncoding.GetString(y);
                s     = string
                        .Format
                        (
                    "Echo: {0}{1}{0}{2}{0}{3}{0}"
                    , "\r\n"
                    , s
                    , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
#if NETCOREAPP2_0
                    , RuntimeInformation.OSDescription
#else
                    , ""
#endif
                        );
                Console.WriteLine(s);
                Console.WriteLine($"Server ReceivedAsyncCount: {x.ReceivedAsyncCount}");
                Console.WriteLine($"Server ReceivedSyncCount: {x.ReceivedSyncCount}");
                Console.WriteLine($"Server ReceivedCount: {x.ReceivedCount}");

                Console.WriteLine($"Server ReceivedHeadersCount: {x.ReceivedHeadersCount}");
                Console.WriteLine($"Server ReceivedBodysCount: {x.ReceivedBodysCount}");

                Console.WriteLine($"Server ReceivedTotalBytesCount: {x.ReceivedTotalBytesCount} bytes");

                var buffer      = sendEncoding.GetBytes(s);
                byte[] intBytes = BytesHelper.GetLengthHeaderBytes(buffer);
                x.SendDataSync(intBytes);
                x.SendDataSync(buffer);
            }
                     );
            Console.WriteLine("Hello World");
            Console.WriteLine(Environment.Version.ToString());
            Console.ReadLine();
        }
Exemple #13
0
        public static Nalu Parse(byte[] data)
        {
            int sIndex = getStartCodeLen(data);

            byte[] ndata = BytesHelper.SubBytes(data, sIndex);
            Nalu   a     = new Nalu();

            a.Header  = NaluHeader.Parse(ndata[0]);
            a.Payload = BytesHelper.SubBytes(ndata, 1);
            return(a);
        }
Exemple #14
0
            iceD_ZoneSync(IZonePush obj, IceInternal.Incoming inS, Ice.Current current)
            {
                Ice.ObjectImpl.iceCheckMode(Ice.OperationMode.Normal, current.mode);
                var istr = inS.startReadParams();

                byte[] iceP_data;
                iceP_data = BytesHelper.read(istr);
                inS.endReadParams();
                obj.ZoneSync(iceP_data, current);
                return(inS.setResult(inS.writeEmptyParams()));
            }
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         BytesHelper.CopyBytes(encoding.GetBytes((string)value), buffer, index, length, padding, filler);
     }
 }
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         NumberByteHelper.FormatDecimal(buffer, index, length, (decimal)value, scale, groupingSize, padding, zerofill, filler);
     }
 }
Exemple #17
0
        public void BytesHelperShouldReturnCorrectBytesForString()
        {
            var input         = "Test";
            var expectedBytes = new byte[4] {
                84, 101, 115, 116
            };

            var actualBytes = BytesHelper.GetBytes(input);

            Assert.Equal(expectedBytes, actualBytes);
        }
Exemple #18
0
        public object transform(object input)
        {
            byte[]      message = input as byte[];
            List <byte> buffer  = new List <byte>();
            ushort      len     = System.UInt16.Parse(message.Length.ToString());

            byte[] lenbytes = System.BitConverter.GetBytes(BytesHelper.ReverseBytes(len));
            buffer.AddRange(lenbytes);
            buffer.AddRange(message);
            return(buffer.ToArray());
        }
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         NumberByteHelper.FormatInt64(buffer, index, length, (long)value, padding, zerofill, filler);
     }
 }
Exemple #20
0
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         DateTimeByteHelper.FormatDateTime(buffer, index, hasDatePart, entries, ((DateTimeOffset)value).UtcDateTime);
     }
 }
Exemple #21
0
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         BytesHelper.CopyBytes(encoding.GetBytes(((int)value).ToString(format, provider)), buffer, index, length, padding, filler);
     }
 }
        public object Read(byte[] buffer, int index)
        {
            var start = index;
            var count = length;

            if (trim)
            {
                BytesHelper.TrimRange(buffer, ref start, ref count, padding, filler);
            }

            return(encoding.GetString(buffer, start, count));
        }
Exemple #23
0
        private static async Task GenerateFileAsync(string path, long size)
        {
            var textSize = BytesHelper.GetHumanStringFromBytes(size);

            using var logger = FileGeneratorFactory.GetLogger($"Generate file {textSize}");
            var fileCreator = FileGeneratorFactory.GetFileCreator();

            using var progressReporter = new ProgressReporter(size);
            var file = await fileCreator.GenerateFileAsync(path, size, progressReporter);

            Console.WriteLine($"\nFile generated {file.FullName}");
        }
Exemple #24
0
        public static IEnumerable <ushort> Encode(int totalLength, byte ssidCrc)
        {
            ushort[] frames     = new ushort[4];
            var      blen       = (byte)totalLength;
            var      firstFrame = BytesHelper.CombineUshort(0x00, blen.Bisect().high);

            frames[0] = firstFrame != 0 ? firstFrame : (ushort)0x08;
            frames[1] = BytesHelper.CombineUshort(0x01, blen.Bisect().low);
            frames[2] = BytesHelper.CombineUshort(0x02, ssidCrc.Bisect().high);
            frames[3] = BytesHelper.CombineUshort(0x03, ssidCrc.Bisect().low);
            return(frames);
        }
Exemple #25
0
        public static IEnumerable <ushort> Encode(int passwordLength)
        {
            var frames  = new ushort[4];
            var blen    = (byte)passwordLength;
            var lenCrc8 = Crc8.ComputeOnceOnly(blen);

            frames[0] = BytesHelper.CombineUshort(0x04, blen.Bisect().high);
            frames[1] = BytesHelper.CombineUshort(0x05, blen.Bisect().low);
            frames[2] = BytesHelper.CombineUshort(0x06, lenCrc8.Bisect().high);
            frames[3] = BytesHelper.CombineUshort(0x07, lenCrc8.Bisect().low);
            return(frames);
        }
Exemple #26
0
        public bool ValidatePassword(string password, string correctHash)
        {
            if (this._salt == null)
            {
                throw new SaltIsNullException("Salt canot be null. Set the value.");
            }

            var hashedPassword = GenerateHash(password);
            var savedPassword  = BytesHelper.StringToBytes(correctHash);

            return(SlowEquals(hashedPassword, savedPassword));
        }
Exemple #27
0
        public void MessageSizeTestSNS_TooLargeMessageAttributes()
        {
            var request = new PublishRequest();

            request.Message = null;
            request.MessageAttributes.Add("12345", new MessageAttributeValue {
                DataType = "String", StringValue = "67890a"
            });
            bool tooLarge = BytesHelper.TooLarge(request, 10);

            Assert.True(tooLarge);
        }
Exemple #28
0
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         var bytes = encoding.GetBytes(((DateTime)value).ToString(format, provider));
         BytesHelper.CopyBytes(bytes, buffer, index, length, Padding.Right, filler);
     }
 }
Exemple #29
0
 public void Write(byte[] buffer, int index, object value)
 {
     if (value is null)
     {
         BytesHelper.Fill(buffer, index, length, filler);
     }
     else
     {
         var bytes = (byte[])value;
         BytesHelper.CopyBytes(bytes, buffer, index, length, Padding.Right, filler);
     }
 }
Exemple #30
0
        public static FragUnitA Parse(byte[] data)
        {
            FragUnitA fu = new FragUnitA();

            fu.Indicator = NaluHeader.Parse(data[0]);
            if (fu.Indicator.Type != NALU_TYPE)
            {
                throw new ArgumentException($"FU-B封包的指示字节的类型必须是{NALU_TYPE},当前类型是:" + fu.Indicator.Type);
            }
            fu.Header  = FuHeader.Parse(data[1]);
            fu.Payload = BytesHelper.SubBytes(data, 2);
            return(fu);
        }