public bool WriteDongleData(DongleData data)
        {
            var          DataToWrite     = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(data));
            var          status          = false;
            const double onekb           = 1024;
            double       totalDataLength = DataToWrite.Length;

            if (DataToWrite.Length > onekb)
            {
                var dataLength = onekb;
                var count      = Math.Ceiling(DataToWrite.Length / onekb);

                var dataWritten = false;
                var counter     = 1;
                var offset      = 0;
                while (counter <= count)
                {
                    var dataBlockToWrite = new byte[Convert.ToInt64(dataLength)];
                    Array.Copy(DataToWrite, offset, dataBlockToWrite, 0, Convert.ToInt64(dataLength));

                    dataWritten = WriteData(dataBlockToWrite, offset);

                    status |= dataWritten;

                    if (totalDataLength - onekb * counter < onekb)
                    {
                        dataLength = totalDataLength - onekb * counter;
                    }

                    offset = (int)(onekb * counter);
                    counter++;
                }

                status |= dataWritten;
            }
            else
            {
                status |= WriteData(DataToWrite, 0);
            }
            return(status);
        }
Esempio n. 2
0
        private static void DinkeyDongleTest()
        {
            var service = new DinkeyDongleService();

            var keysA = RandomDataGenerator.CardKeys(40, 0, 'A');
            var keysB = RandomDataGenerator.CardKeys(40, 0, 'B');

            keysA.AddRange(keysB);

            var dongleData = new DongleData
            {
                CardKeys = keysA,
            };

            var data = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(dongleData));

            //WriteBoundData(data, service);

            var stringData = ReadBoundData(service);

            var dData = JsonConvert.DeserializeObject <DongleData>((string)stringData);
        }