public void AddOrUpdateMethod(Method methodModel, ByteArray methodId)
    {
      Contract.Requires(methodModel != null);
      Contract.Requires(methodId != null);

      throw new NotImplementedException();
    }
Esempio n. 2
0
        public void CrashTestBeforeMerge()
        {
            string path = Path.GetFullPath ("TestData\\CrashTestBeforeMerge");
            using (var db = new KeyValueStore(path)) db.Truncate ();

            var doneSetting = new EventWaitHandle (false, EventResetMode.ManualReset, "CrashTestBeforeMerge");
            doneSetting.Reset ();

            string testPath = Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().GetName ().CodeBase), "RazorTest.exe");
            var process = Process.Start (testPath, "CrashTestBeforeMerge");

            doneSetting.WaitOne (30000);
            if (!process.HasExited) {
                process.Kill ();
                process.WaitForExit ();
            }

            // Open the database created by the other program
            using (var db = new KeyValueStore(path)) {
                db.Manifest.Logger = (msg) => Console.WriteLine (msg);

                Console.WriteLine ("Begin enumeration.");
                ByteArray lastKey = new ByteArray ();
                int ct = 0;
                foreach (var pair in db.Enumerate()) {
                    ByteArray k = new ByteArray (pair.Key);
                    Assert.True (lastKey.CompareTo (k) < 0);
                    lastKey = k;
                    ct++;
                }
                Assert.AreEqual (10000, ct);
                Console.WriteLine ("Found {0} items in the crashed database.", ct);
            }
        }
Esempio n. 3
0
        public static void CrashTestOnMerge()
        {
            string path = Path.GetFullPath("TestData\\CrashTestOnMerge");
            int num_items = 50000;

            using (var db = new KeyValueStore(path)) {
                db.Truncate();

                db.Manifest.Logger = (msg) => Console.WriteLine(msg);

                for (int i = 0; i < num_items; i++) {
                    byte[] keyBytes = new byte[40];
                    Array.Copy(BitConverter.GetBytes(i).Reverse().ToArray(), keyBytes, 4);
                    Array.Copy(ByteArray.Random(36).InternalBytes, 0, keyBytes, 4, 36);
                    var randomKey = new ByteArray(keyBytes);
                    var randomValue = ByteArray.Random(256);
                    db.Set(randomKey.InternalBytes, randomValue.InternalBytes);
                }

                // Signal our test to fall through
                try {
                    ManualResetEvent.OpenExisting("CrashTestOnMerge").Set();
                } catch (WaitHandleCannotBeOpenedException e) {
                    Console.WriteLine("{0}", e);
                }
            }
        }
Esempio n. 4
0
 public Value(byte[] bytes, ValueFlag type)
 {
     byte[] b = new byte[bytes.Length + 1];
     b [0] = (byte)type;
     Array.Copy (bytes, 0, b, 1, bytes.Length);
     _bytes = new ByteArray (b);
 }
    public bool TryGetMethodModelForHash(ByteArray hash, out Method result)
    {
      Contract.Requires(hash != null);
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out result) != null);

      throw new NotImplementedException();
    }
Esempio n. 6
0
 public override byte[] ToBytes()
 {
     ByteArray bytes = new ByteArray();
     bytes.Write(this.PassWord);
     bytes.Write(this.UserName.Length);
     bytes.Write(this.UserName);
     return bytes.ToBytes();
 }
Esempio n. 7
0
 public static Stream ToStream(byte[] inArg0)
 {
     Login stream = new Login();
     ByteArray data = new ByteArray(inArg0);
     stream.PassWord = data.ReadInt();
     stream.UserName = data.ReadString();
     return stream;
 }
Esempio n. 8
0
 public static byte[] GetByteArray(ByteArray byteArray)
 {
     byte[] data = new byte[byteArray.ArraySize];
     for (int i=0; i < byteArray.ArraySize; i++) {
         byte datum = Marshal.ReadByte (byteArray.Array, i * Marshal.SizeOf(typeof(byte)));
         data[i] = datum;
     }
     return data;
 }
Esempio n. 9
0
 public override byte[] ToBytes()
 {
     ByteArray bytes = new ByteArray();
     bytes.Write(this.age);
     bytes.Write(this.bookCount);
     for (int i = 0; (i < books.bookCount); i = (i + 1))
     {
         bytes.Write(this.books[i]);
     }
     return bytes.ToBytes();
 }
Esempio n. 10
0
 public static Stream ToStream(byte[] inArg0)
 {
     UserInfo stream = new UserInfo();
     ByteArray data = new ByteArray(inArg0);
     stream.age = data.ReadInt();
     stream.bookCount = data.ReadInt();
     stream.books = new System.Int32[bookCount];
     for (int i = 0; (i < stream.bookCount); i = (i + 1))
     {
         stream.books[i] = data.ReadInt();
     }
     return stream;
 }
Esempio n. 11
0
        //TODO: Would there be any point to having clearTextPassword be a SecureString since we both have to make it into bytes here and also likely store it anyways as the framework parsing the password field will be using a string
        public static ByteArray ComputeHash(string clearTextPassword, ByteArray salt, Encoding passwordToBytesEncoding, string hashAlgorithmName, Func<string, HashAlgorithm> createHashAlgorithm)
        {
            if (clearTextPassword == null)
                throw new ArgumentNullException("clearTextPassword");

            //Unclear if these are thead-safe so we trade performance for clarity
            using (var hash = createHashAlgorithm(hashAlgorithmName))
            {
                var passwordBytes = ByteArray.FromBytes(passwordToBytesEncoding.GetBytes(clearTextPassword));
                var combinedBytes = ByteArray.Concat(passwordBytes, salt);
                return ByteArray.FromBytes(hash.ComputeHash(combinedBytes.Bytes));
            }
        }
Esempio n. 12
0
public static int get_bytes(IntPtr L)
{
UnityEngine.TextAsset self = Funcs.GetObj(L,1) as UnityEngine.TextAsset;
if(self == null)
{
	LuaStatic.traceback(L,"nullobj call");
	LuaDLL.lua_error(L); return 1;
}
if(self.bytes != null)
{
ByteArray  bytes = new ByteArray(self.bytes);
LuaStatic.addGameObject2Lua(L,bytes,"ByteArray");
}
else { LuaStatic.addGameObject2Lua(L,null,""); }
return 1;
}
Esempio n. 13
0
 public void TestComparisonSpeed()
 {
     var a = new ByteArray (new byte[] { 0 });
     var b = new ByteArray (new byte[] { 1 });
     Stopwatch timer = new Stopwatch ();
     timer.Start ();
     for (int i = 0; i < 1000000; i++) Assert.True (a.CompareTo (b) < 0);
     timer.Stop ();
     Console.WriteLine ("Elapsed Time (1 byte): {0} ms", timer.ElapsedMilliseconds);
     a = new ByteArray (new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 });
     b = new ByteArray (new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20 });
     timer = new Stopwatch ();
     timer.Start ();
     for (int i = 0; i < 1000000; i++) Assert.True (a.CompareTo (b) < 0);
     timer.Stop ();
     Console.WriteLine ("Elapsed Time (20 byte): {0} ms", timer.ElapsedMilliseconds);
 }
Esempio n. 14
0
        public void Comparison()
        {
            var a0 = new ByteArray (new byte[] { 0 });
            var a2 = new ByteArray (new byte[] { 0, 1, 2, 4 });
            var a2B = new ByteArray (new byte[] { 0, 1, 2, 4 });
            var a3 = new ByteArray (new byte[] { 0, 1, 2, 5 });
            var a4 = new ByteArray (new byte[] { 0, 1, 2, 5, 6 });

            // Simple direct comparisons
            Assert.IsTrue (a2.CompareTo (a3) < 0);
            Assert.IsTrue (a3.CompareTo (a2) > 0);
            Assert.IsTrue (a2.CompareTo (a2B) == 0);

            // Length comparisons
            Assert.IsTrue (a4.CompareTo (a0) > 0);
            Assert.IsTrue (a3.CompareTo (a4) < 0);
        }
Esempio n. 15
0
        public override Task SendMessageAsync(ByteArray message, CancellationToken token)
        {
            if (token.IsCancellationRequested)
                return Task.FromResult<object>(null);

            if (tcp?.Connected == true)
                return WriteAsync(message, token);

            var delay = neverConnected ? ZeroSecondsTimeSpan : recoveryTime;
            neverConnected = false;

            return Task.Delay(delay, token)
                .Then(_ => InitTcpClient(), token)
                .Unwrap()
                .Then(_ => ConnectAsync(), token)
                .Unwrap()
                .Then(_ => WriteAsync(message, token), token)
                .Unwrap();
        }
Esempio n. 16
0
 public byte[] CombinePackets()
 {
     ByteArray[] packetBytes = new ByteArray[packets.Count];
     int totalSize = 0;
     for (int i = 0; i < packets.Count; i++) {
         packetBytes[i] = new ByteArray(ByteEncoder.StringToByteArray(packets[i].PacketString));
         totalSize += packetBytes[i].Length() + GetPacketSegmentHeaderSize();
     }
     byte[] packet = new byte[totalSize];
     int position = 0;
     for (int i = 0; i < packetBytes.Length; i++) {
         // Add the size of the packet segment
         Array.Copy(ByteArray.IntToByteArray(packetBytes[i].Length()), 0, packet, position, 4);
         position += 4;
         // Add the packet data
         Array.Copy(packetBytes[i].ToArray(), 0, packet, position, packetBytes[i].Length());
         position += packetBytes[i].Length();
     }
     return packet;
 }
        public static MethodHashAttribute FromDecoder(IIndexable<object> args)
        {
            if (args == null || args.Count != 2)
                return null;

            var hashObj = args[0]; // it can be null, when generated at the Slicer level
            var flagsObj = args[1];

            if ((hashObj == null || hashObj is string) && (flagsObj is int))
            {
                var flags = (MethodHashAttributeFlags)(int)flagsObj;
                var methodHash = new ByteArray(hashObj as string);

                return new MethodHashAttribute(methodHash, flags);
            }
            else
            {
                return null;
            }
        }
Esempio n. 18
0
public static int StopRecording(IntPtr L)
{
SpeechChat self = Funcs.GetObj(L,1) as SpeechChat;
if(self == null)
{
	LuaStatic.traceback(L,"nullobj call");
	LuaDLL.lua_error(L); return 1;
}
System.String param0 = default(System.String);
param0 = LuaDLL.lua_tostring(L,2);
System.Single param1 = default(System.Single);
param1 = (System.Single)LuaDLL.lua_tonumber(L,3);
System.Byte[] ret =  self.StopRecording(
(System.String)param0,
(System.Single)param1
);
if(ret != null)
{
ByteArray  bytes = new ByteArray(ret);
LuaStatic.addGameObject2Lua(L,bytes,"ByteArray");
}
else { LuaStatic.addGameObject2Lua(L,null,""); }
return 1;
}
Esempio n. 19
0
 public void ReadHeader(ByteArray payload)
 {
     header.pId = BitConverter.ToUInt16 (payload.data, 0);
     header.pSize = System.BitConverter.ToUInt16 (payload.data, 2);
     header.pGuidId = System.BitConverter.ToUInt16 (payload.data, 4);
 }
Esempio n. 20
0
 public static Sha256Object sha256(ByteArray data) {
     return new Sha256Object((IList<byte>)data);
 }
Esempio n. 21
0
        public byte[] ReadData(ByteArray payload)
        {
            int size = payload.Count - 6;
            byte[] b = new byte[size];
            Array.Copy (payload.data, 6, b, 0, size);

            return b;
        }
Esempio n. 22
0
        /// <summary> Interleave "bits" with corresponding error correction bytes. On success, store the result in
        /// "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
        /// </summary>
        internal static void interleaveWithECBytes(BitVector bits, int numTotalBytes, int numDataBytes, int numRSBlocks, BitVector result)
        {
            // "bits" must have "getNumDataBytes" bytes of data.
            if (bits.sizeInBytes() != numDataBytes)
            {
                throw new WriterException("Number of bits and data bytes does not match");
            }

            // Step 1.  Divide data bytes into blocks and generate error correction bytes for them. We'll
            // store the divided data bytes blocks and error correction bytes blocks into "blocks".
            int dataBytesOffset = 0;
            int maxNumDataBytes = 0;
            int maxNumEcBytes = 0;

            // Since, we know the number of reedsolmon blocks, we can initialize the vector with the number.
            System.Collections.Generic.List<Object> blocks = new System.Collections.Generic.List<Object>(numRSBlocks);

            for (int i = 0; i < numRSBlocks; ++i)
            {
                int[] numDataBytesInBlock = new int[1];
                int[] numEcBytesInBlock = new int[1];
                getNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, numRSBlocks, i, numDataBytesInBlock, numEcBytesInBlock);

                ByteArray dataBytes = new ByteArray();
                dataBytes.set_Renamed(bits.Array, dataBytesOffset, numDataBytesInBlock[0]);
                ByteArray ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]);
                blocks.Add(new BlockPair(dataBytes, ecBytes));

                maxNumDataBytes = System.Math.Max(maxNumDataBytes, dataBytes.size());
                maxNumEcBytes = System.Math.Max(maxNumEcBytes, ecBytes.size());
                dataBytesOffset += numDataBytesInBlock[0];
            }
            if (numDataBytes != dataBytesOffset)
            {
                throw new WriterException("Data bytes does not match offset");
            }

            // First, place data blocks.
            for (int i = 0; i < maxNumDataBytes; ++i)
            {
                for (int j = 0; j < blocks.Count; ++j)
                {
                    ByteArray dataBytes = ((BlockPair) blocks[j]).DataBytes;
                    if (i < dataBytes.size())
                    {
                        result.appendBits(dataBytes.at(i), 8);
                    }
                }
            }
            // Then, place error correction blocks.
            for (int i = 0; i < maxNumEcBytes; ++i)
            {
                for (int j = 0; j < blocks.Count; ++j)
                {
                    ByteArray ecBytes = ((BlockPair) blocks[j]).ErrorCorrectionBytes;
                    if (i < ecBytes.size())
                    {
                        result.appendBits(ecBytes.at(i), 8);
                    }
                }
            }
            if (numTotalBytes != result.sizeInBytes())
            {
                // Should be same.
                throw new WriterException("Interleaving error: " + numTotalBytes + " and " + result.sizeInBytes() + " differ.");
            }
        }
Esempio n. 23
0
 public void update(ByteArray newBytes) {
     update((IList<byte>)newBytes);
 }
Esempio n. 24
0
        internal static ByteArray generateECBytes(ByteArray dataBytes, int numEcBytesInBlock)
        {
            int numDataBytes = dataBytes.size();
            int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
            for (int i = 0; i < numDataBytes; i++)
            {
                toEncode[i] = dataBytes.at(i);
            }
            new ReedSolomonEncoder(GF256.QR_CODE_FIELD).encode(toEncode, numEcBytesInBlock);

            ByteArray ecBytes = new ByteArray(numEcBytesInBlock);
            for (int i = 0; i < numEcBytesInBlock; i++)
            {
                ecBytes.set_Renamed(i, toEncode[numDataBytes + i]);
            }
            return ecBytes;
        }
Esempio n. 25
0
 public void update(ByteArray newData) {
     update((IList<byte>)newData);
 }
Esempio n. 26
0
 public void ResetLava(ByteArray blocks, NibbleArray data)
 {
     for (int i = 0; i < blocks.Length; i++) {
         if ((blocks[i] == BlockType.STATIONARY_LAVA || blocks[i] == BlockType.LAVA) && data[i] != 0) {
             blocks[i] = BlockType.AIR;
             data[i] = 0;
         }
         else if (blocks[i] == BlockType.LAVA) {
             blocks[i] = BlockType.STATIONARY_LAVA;
         }
     }
 }
Esempio n. 27
0
    public ByteArray GetHashForDate(ByteArray methodId, DateTime datetime, bool afterDateTime)
    {
      Contract.Requires(methodId != null);
      // It may return null!!
      //Contract.Ensures(Contract.Result<ByteArray>() != null);

      throw new NotImplementedException();
    }
Esempio n. 28
0
 public void ResetWater(ByteArray blocks, NibbleArray data)
 {
     for (int i = 0; i < blocks.Length; i++) {
         if ((blocks[i] == BlockType.STATIONARY_WATER || blocks[i] == BlockType.WATER) && data[i] != 0) {
             blocks[i] = BlockType.AIR;
             data[i] = 0;
         }
         else if (blocks[i] == BlockType.WATER) {
             blocks[i] = BlockType.STATIONARY_WATER;
         }
     }
 }
Esempio n. 29
0
 public static MD5Type @new(ByteArray data) {
     return new MD5Type((IList<byte>)data);
 }
Esempio n. 30
0
            public int recv_into(ByteArray buffer, [DefaultParameterValue(0)]int nbytes, [DefaultParameterValue(0)]int flags) {
                int bytesRead;
                byte[] byteBuffer = new byte[byteBufferSize("recv_into", nbytes, buffer.Count, 1)];

                try {
                    bytesRead = _socket.Receive(byteBuffer, (SocketFlags)flags);
                } catch (Exception e) {
                    throw MakeException(_context, e);
                }

                for (int i = 0; i < bytesRead; i++) {
                    buffer[i] = byteBuffer[i];
                }
                return bytesRead;
            }