Esempio n. 1
0
 /// <summary>
 /// Writes out a string (or series of strings) in sedna format.
 /// </summary>
 public static void WriteString(BinaryWriter writer, params string[] textItems)
 {
     foreach (string text in textItems)
     {
         writer.Write((byte)0);
         NetworkOperations.WriteInt(text.Length, int_array, 0);
         writer.Write(int_array);
         writer.Write(Encoding.ASCII.GetBytes(text));
     }
 }
Esempio n. 2
0
 public static void WriteMessage(Message msg, NetworkStream outputStream)
 {
     if (msg.Body.Length > SocketMessageBufferSize)
     {
         throw new IndexOutOfRangeException("Size of packet exceeds maximum buffer size");
     }
     NetworkOperations.WriteInt((int)msg.Instruction, outputStream);
     NetworkOperations.WriteInt((int)msg.Body.Length, outputStream);
     outputStream.Write(msg.Body, 0, msg.Body.Length);
     outputStream.Flush();
 }
Esempio n. 3
0
        public static bool BulkLoad(Stream input, NetworkStream bufInputStream, NetworkStream outputStream)
        {
            Message msg        = new Message();
            int     bytes_read = -1;

            try
            {
                while (bytes_read != 0)
                {
                    byte[] buffer = new byte[BulkLoadPortionSize];
                    bytes_read = input.Read(buffer, 0, BulkLoadPortionSize);
                    if (bytes_read != 0)
                    {
                        // crop the array to the correct size
                        msg.Body = new byte[bytes_read + IntSize + StringTypeSize];
                        Array.Copy(buffer, 0, msg.Body, IntSize + StringTypeSize, bytes_read);

                        msg.Instruction = InstructionCode.BulkLoadPortion;
                        msg.Body[0]     = 0;

                        NetworkOperations.WriteInt(bytes_read, msg.Body, 0 + StringTypeSize);
                        NetworkOperations.WriteMessage(msg, outputStream);
                    }
                }

                NetworkOperations.WriteMessage(InstructionCode.BulkLoadEnd, outputStream, bufInputStream, InstructionCode.BulkLoadSucceeded, InstructionCode.UpdateSucceeded);

                return(true);
            }
            catch (IOException e)
            {
                msg.Instruction = InstructionCode.BulkLoadError;
                try
                {
                    NetworkOperations.WriteMessage(msg, outputStream);
                    NetworkOperations.ReadMessage(msg, bufInputStream);
                }
                catch (IOException ex)
                {
                    throw new SednaException(InstructionCode.BulkLoadFailed, "Unable to bulk load: IO error: " + ex.Message);
                }

                throw new SednaException(InstructionCode.BulkLoadFailed, NetworkOperations.GetErrorInfo(msg.Instruction, msg.Body) + " : " + e.Message);
            }
        }