public static CUQueue Lock(tagOperationSystem os) { #if TASKS_ENABLED CUQueue UQueue; if (!m_sQueue.TryPop(out UQueue)) { UQueue = new CUQueue(); } #else CUQueue UQueue = null; lock (m_cs) { if (m_sQueue.Count > 0) { UQueue = m_sQueue.Pop(); } } if (UQueue == null) { UQueue = new CUQueue(); } #endif UQueue.OS = os; return(UQueue); }
private void OnChatComing(ulong hSocket, tagChatRequestID chatRequestID, uint len) { uint res; CSocketPeer sp = Seek(hSocket); if (sp == null) { return; } sp.m_CurrReqID = (ushort)chatRequestID; CUQueue q = sp.m_qBuffer; q.SetSize(0); if (len > q.MaxBufferSize) { q.Realloc(len); } unsafe { fixed(byte *buffer = q.m_bytes) { res = ServerCoreLoader.RetrieveBuffer(hSocket, len, buffer, true); } } System.Diagnostics.Debug.Assert(res == len); q.SetSize(res); sp.OnChatComing(chatRequestID); }
static void EnqueueToServerBatch(CAsyncQueue sq, string message, int cycles, uint batchSize = 8 * 1024) { Console.WriteLine("Going to enqueue " + cycles + " messages ......"); using (CScopeUQueue sb = new CScopeUQueue()) { CUQueue q = sb.UQueue; byte[] utf8 = Encoding.UTF8.GetBytes(message); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); for (int n = 0; n < cycles; ++n) { CAsyncQueue.BatchMessage(idMessage, utf8, q); if (q.GetSize() >= batchSize) { sq.EnqueueBatch(TEST_QUEUE_KEY, q); } } if (q.GetSize() > 0) { sq.EnqueueBatch(TEST_QUEUE_KEY, q); } sq.WaitAll(); sw.Stop(); Console.WriteLine(cycles + " messages sent to server and enqueued within " + sw.ElapsedMilliseconds + " ms"); } }
public static bool Publish(object Message, params uint[] Groups) { uint len; if (Groups == null) { len = 0; } else { len = (uint)Groups.Length; } using (CScopeUQueue su = new CScopeUQueue()) { CUQueue q = su.UQueue; q.Save(Message); unsafe { fixed(byte *buffer = q.m_bytes) { fixed(uint *p = Groups) { return(ServerCoreLoader.SpeakPush(buffer, q.GetSize(), p, len)); } } } } }
protected override void OnResultReturned(ushort sRequestId, CUQueue UQueue) { if (RouteeRequest) { switch (sRequestId) { case piConst.idComputePi: { double dStart; double dStep; int nNum; UQueue.Load(out dStart).Load(out dStep).Load(out nNum); double dX = dStart + dStep / 2; double dd = dStep * 4.0; double ComputeRtn = 0.0; for (int n = 0; n < nNum; n++) { dX += dStep; ComputeRtn += dd / (1 + dX * dX); } SendRouteeResult(ComputeRtn, dStart); } break; default: break; } } }
protected override void OnResultReturned(ushort sRequestId, CUQueue UQueue) { if (RouteeRequest) { switch (sRequestId) { case piConst.idComputePi: { double dStart; double dStep; int nNum; UQueue.Load(out dStart).Load(out dStep).Load(out nNum); double dX = dStart + dStep / 2; double dd = dStep * 4.0; double ComputeRtn = 0.0; for (int n = 0; n < nNum; n++) { dX += dStep; ComputeRtn += dd / (1 + dX * dX); } SendRouteeResult(ComputeRtn); } break; default: break; } } }
internal CAsyncResult(CAsyncServiceHandler ash, ushort sReqId, CUQueue q, CAsyncServiceHandler.DAsyncResultHandler arh) { m_AsyncServiceHandler = ash; m_RequestId = sReqId; m_UQueue = q; m_CurrentAsyncResultHandler = arh; }
/// <summary> /// Read data from a source stream at server side and send its content onto a client /// </summary> /// <param name="PeerHandle">A peer socket handle to represent a client</param> /// <param name="source">A stream to a source file or other object</param> /// <returns>The number of data sent in bytes</returns> public static ulong ReadDataFromServerToClient(ulong PeerHandle, Stream source) { uint res; ulong sent = 0; using (CScopeUQueue su = new CScopeUQueue()) { CUQueue q = su.UQueue; uint read = CStreamSerializationHelper.Read(source, q); while (read != 0) { unsafe { fixed(byte *p = q.m_bytes) { res = ServerCoreLoader.SendReturnData(PeerHandle, CStreamSerializationHelper.idReadDataFromServerToClient, read, p); } } if (res == CSocketPeer.REQUEST_CANCELED || res == CSocketPeer.SOCKET_NOT_FOUND) { break; } sent += res; q.SetSize(0); read = CStreamSerializationHelper.Read(source, q); } } return(sent); }
private void Clean() { if (m_UQueue != null) { m_UQueue = null; } }
public CUQueue Detach() { CUQueue q = m_UQueue; m_UQueue = null; return(q); }
static CMyStruct Load(CUQueue q) { CMyStruct ms = new CMyStruct(); ms.LoadFrom(q); return(ms); }
static void Main(string[] args) { Console.WriteLine("Remote host: "); string host = Console.ReadLine(); CConnectionContext cc = new CConnectionContext(host, 20901, "async_queue_client", "pwd_for_async_queue"); using (CSocketPool <CAsyncQueue> spAq = new CSocketPool <CAsyncQueue>()) { if (!spAq.StartSocketPool(cc, 1, 1)) { Console.WriteLine("Failed in connecting to remote async queue server"); Console.WriteLine("Press any key to close the application ......"); Console.Read(); return; } CAsyncQueue aq = spAq.Seek(); //Optionally, you can enqueue messages with transaction style by calling the methods StartQueueTrans and EndQueueTrans in pair aq.StartQueueTrans(TEST_QUEUE_KEY, (errCode) => { //error code could be one of CAsyncQueue.QUEUE_OK, CAsyncQueue.QUEUE_TRANS_ALREADY_STARTED, ...... }); TestEnqueue(aq); //test message batching using (CScopeUQueue sb = new CScopeUQueue()) { CUQueue q = sb.UQueue; CAsyncQueue.BatchMessage(idMessage3, "Hello", "World", q); CAsyncQueue.BatchMessage(idMessage4, true, 234.456, "MyTestWhatever", q); aq.EnqueueBatch(TEST_QUEUE_KEY, q, (res) => { System.Diagnostics.Debug.Assert(res == 2); }); } aq.EndQueueTrans(false); TestDequeue(aq); aq.WaitAll(); //get a queue key two parameters, message count and queue file size by default option oMemoryCached aq.FlushQueue(TEST_QUEUE_KEY, (messageCount, fileSize) => { Console.WriteLine("Total message count={0}, queue file size={1}", messageCount, fileSize); }); aq.GetKeys((keys) => { keys = null; }); aq.CloseQueue(TEST_QUEUE_KEY, (errCode) => { //error code could be one of CAsyncQueue.QUEUE_OK, CAsyncQueue.QUEUE_TRANS_ALREADY_STARTED, ...... }); Console.WriteLine("Press any key to close the application ......"); Console.Read(); } }
public static void BatchMessage <T0, T1>(ushort idMessage, T0 t0, T1 t1, CUQueue q) { CUQueue b = CScopeUQueue.Lock(); b.Save(t0).Save(t1); BatchMessage(idMessage, b.IntenalBuffer, b.Size, q); CScopeUQueue.Unlock(b); }
internal static void Write(Stream s, CUQueue q) { if (q == null || q.GetSize() == 0) { return; } s.Write(q.m_bytes, (int)q.HeadPosition, (int)q.GetSize()); }
public static void Unlock(CUQueue UQueue) { if (UQueue != null) { UQueue.SetSize(0); m_sQueue.Enqueue(UQueue); } }
public void SaveTo(CUQueue UQueue) { UQueue.Save(Count); foreach (long n in this) { UQueue.Save(n); } }
protected override void OnResultReturned(ushort sRequestId, CUQueue UQueue) { m_AdoSerializer.Load(sRequestId, UQueue); if (OnAdonetLoaded != null) { OnAdonetLoaded.Invoke(this, sRequestId); } }
public static void BatchMessage <T0, T1, T2, T3, T4, T5>(ushort idMessage, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, CUQueue q) { CUQueue b = CScopeUQueue.Lock(); b.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5); BatchMessage(idMessage, b.IntenalBuffer, b.Size, q); CScopeUQueue.Unlock(b); }
public static void BatchMessage <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(ushort idMessage, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, CUQueue q) { CUQueue b = CScopeUQueue.Lock(); b.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5).Save(t6).Save(t7).Save(t8).Save(t9); BatchMessage(idMessage, b.IntenalBuffer, b.Size, q); CScopeUQueue.Unlock(b); }
public Task <CScopeUQueue> sendRequest <T0, T1, T2, T3, T4, T5, T6, T7>(ushort reqId, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { using (CScopeUQueue sb = new CScopeUQueue()) { CUQueue b = sb.UQueue; b.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5).Save(t6).Save(t7); return(sendRequest(reqId, b.IntenalBuffer, b.GetSize())); } }
private bool PushText(string text) { using (CScopeUQueue sb = new CScopeUQueue()) { CUQueue q = sb.UQueue; q.Push(text); return(PushBlob(q.IntenalBuffer, q.GetSize(), (ushort)tagVariantDataType.sdVT_BSTR)); } }
public Task <CScopeUQueue> sendRequest <T0>(ushort reqId, T0 t0) { using (CScopeUQueue sb = new CScopeUQueue()) { CUQueue b = sb.UQueue; b.Save(t0); return(sendRequest(reqId, b.IntenalBuffer, b.GetSize())); } }
uint EndDataSet(DataSet ds, bool bNeedRelations, CUQueue UQueue) { UQueue.SetSize(0); if (bNeedRelations && ds.Relations != null) { m_AdoSerializer.Push(UQueue, ds.Relations); } return(SendResult(CAdoSerializationHelper.idEndDataSet, UQueue)); }
public Task <CScopeUQueue> sendRequest <T0, T1, T2, T3>(ushort reqId, T0 t0, T1 t1, T2 t2, T3 t3) { using (CScopeUQueue sb = new CScopeUQueue()) { CUQueue b = sb.UQueue; b.Save(t0).Save(t1).Save(t2).Save(t3); return(sendRequest(reqId, b.IntenalBuffer, b.GetSize())); } }
internal static uint Read(Stream s, CUQueue q) { uint res; if (q.MaxBufferSize < STREAM_CHUNK_SIZE + 16) q.Realloc(STREAM_CHUNK_SIZE + 16); res = (uint)s.Read(q.m_bytes, 0, (int)STREAM_CHUNK_SIZE); q.SetSize(res); return res; }
public bool Send <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(ushort reqId, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { CUQueue su = CScopeUQueue.Lock(); su.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5).Save(t6).Save(t7).Save(t8).Save(t9); bool ok = Send(reqId, su); CScopeUQueue.Unlock(su); return(ok); }
public bool Enqueue<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(byte[] key, ushort idMessage, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, DEnqueue e) { if (key == null) key = new byte[0]; CUQueue sb = CScopeUQueue.Lock(); sb.Save(key).Save(idMessage).Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5).Save(t6).Save(t7).Save(t8).Save(t9); bool ok = SendRequest(idEnqueue, sb, GetRH(e)); CScopeUQueue.Unlock(sb); return ok; }
public bool Send <T0, T1, T2>(ushort reqId, T0 t0, T1 t1, T2 t2) { CUQueue su = CScopeUQueue.Lock(); su.Save(t0).Save(t1).Save(t2); bool ok = Send(reqId, su); CScopeUQueue.Unlock(su); return(ok); }
public bool Send <T0>(ushort reqId, T0 t0) { CUQueue su = CScopeUQueue.Lock(); su.Save(t0); bool ok = Send(reqId, su); CScopeUQueue.Unlock(su); return(ok); }
public bool Enqueue<T0>(byte[] key, ushort idMessage, T0 t0, DEnqueue e) { if (key == null) key = new byte[0]; CUQueue sb = CScopeUQueue.Lock(); sb.Save(key).Save(idMessage).Save(t0); bool ok = SendRequest(idEnqueue, sb, GetRH(e)); CScopeUQueue.Unlock(sb); return ok; }
public bool Enqueue<T0, T1, T2, T3, T4>(byte[] key, ushort idMessage, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, DEnqueue e) { if (key == null) key = new byte[0]; CUQueue sb = CScopeUQueue.Lock(); sb.Save(key).Save(idMessage).Save(t0).Save(t1).Save(t2).Save(t3).Save(t4); bool ok = SendRequest(idEnqueue, sb, GetRH(e)); CScopeUQueue.Unlock(sb); return ok; }
public bool Send <T0, T1, T2, T3, T4, T5>(ushort reqId, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { CUQueue su = CScopeUQueue.Lock(); su.Save(t0).Save(t1).Save(t2).Save(t3).Save(t4).Save(t5); bool ok = Send(reqId, su); CScopeUQueue.Unlock(su); return(ok); }
//make sure both serialization and de-serialization match against each other. public void LoadFrom(CUQueue UQueue) { UQueue.Load(out NullString) .Load(out ObjectNull) .Load(out ADateTime) .Load(out ADouble) .Load(out ABool) .Load(out UnicodeString) //UTF16-lowendian .Load(out AsciiString) .Load(out ObjBool) .Load(out ObjString) //UTF16-lowendian .Load(out objArrString) //UTF16-lowendian .Load(out objArrInt) ; }
//make sure both serialization and de-serialization match against each other. public void SaveTo(CUQueue UQueue) { UQueue.Save(NullString) //4 bytes for length .Save(ObjectNull) //2 bytes for data type .Save(ADateTime) //8 bytes for double, and all micro/nano seconds are lost .Save(ADouble) //8 bytes .Save(ABool) //1 byte .Save(UnicodeString) //4 bytes for string length + (length * 2) bytes for string data -- UTF16-lowendian .Save(AsciiString) //4 bytes for ASCII string length + length bytes for string data .Save(ObjBool) //2 bytes for data type + 2 bytes for variant bool .Save(ObjString) //2 bytes for data type + 4 bytes for string length + (length * 2) bytes for string data -- UTF16-lowendian .Save(objArrString) //2 bytes for data type + 4 bytes for array size + (string length + (length * 2) bytes for string data) * arraysize -- UTF16-lowendian .Save(objArrInt) //2 bytes for data type + 4 bytes for array size + arraysize * 4 bytes for int data ; }
private uint PopTableColNamesOnly(CUQueue UQueue, ref DataColumn[] dcs) { int n; int count; int ordinal; string tableName; uint start = UQueue.GetSize(); UQueue.Load(out count); dcs = new DataColumn[count]; for (n = 0; n < count; ++n) { UQueue.Load(out tableName); UQueue.Load(out ordinal); dcs[n] = CurrentDataSet.Tables[tableName].Columns[ordinal]; } return (start - UQueue.GetSize()); }
private void Push(CUQueue UQueue, DataColumn dc) { bool bNull = (dc == null); UQueue.Save(bNull); if (bNull) return; byte bData = 0; if (dc.AllowDBNull) bData += (byte)tagColumnBit.cbAllowDBNull; if (dc.AutoIncrement) bData += (byte)tagColumnBit.cbIsAutoIncrement; if (dc.ReadOnly) bData += (byte)tagColumnBit.cbIsReadOnly; if (dc.Unique) bData += (byte)tagColumnBit.cbIsUnique; UQueue.Save(bData); UQueue.Save(dc.AutoIncrementSeed); UQueue.Save(dc.AutoIncrementStep); UQueue.Save(dc.Caption); UQueue.Save((byte)dc.ColumnMapping); UQueue.Save(dc.ColumnName); UQueue.Save((short)GetDT(dc.DataType.FullName)); // UQueue.Push((byte)dc.DateTimeMode); UQueue.Save(dc.DefaultValue, false, false); UQueue.Save(dc.Expression); //dc.ExtendedProperties ignored. If needed, write your own code UQueue.Save(dc.MaxLength); UQueue.Save(dc.Namespace); UQueue.Save(dc.Prefix); }
private void Push(CUQueue UQueue, DataColumnCollection Cols) { bool bNull = (Cols == null); UQueue.Save(bNull); if (!bNull) { int n; int nLen = 0; if (Cols != null && Cols.Count > 0) nLen = Cols.Count; UQueue.Save(nLen); for (n = 0; n < nLen; n++) { Push(UQueue, Cols[n]); } } }
DataSet LoadDataSetHeader(CUQueue UQueue) { if (UQueue.GetSize() == 0) return null; string str = null; byte bData = 0; DataSet ds = new DataSet(); m_ds = ds; UQueue.Load(out m_nAffected); UQueue.Load(out bData); ds.CaseSensitive = ((bData & 2) == 2); ds.EnforceConstraints = ((bData & 4) == 4); UQueue.Load(out str); ds.DataSetName = str; UQueue.Load(out str); ds.Namespace = str; UQueue.Load(out str); ds.Prefix = str; return ds; }
internal void PushHeader(CUQueue UQueue, DataTable dt, bool bNeedParentRelations, bool bNeedChildRelations) { int n; int nSize; if (dt == null) return; UQueue.SetSize(0); m_dts = new tagDataTypeSupported[dt.Columns.Count]; UQueue.Save(dt.Rows.Count); byte bData = 0; /* if (dt.RemotingFormat == SerializationFormat.Xml) bData += 1;*/ if (bNeedParentRelations) bData += 2; if (bNeedChildRelations) bData += 4; UQueue.Save(bData); UQueue.Save(dt.TableName); Push(UQueue, dt.Columns); for (n = 0; n < dt.Columns.Count; n++) { m_dts[n] = GetDT(dt.Columns[n].DataType.FullName); } UQueue.Save(dt.DisplayExpression); UQueue.Save(dt.MinimumCapacity); UQueue.Save(dt.Namespace); UQueue.Save(dt.Prefix); nSize = dt.PrimaryKey.Length; UQueue.Save(nSize); for (n = 0; n < nSize; n++) { UQueue.Save(dt.PrimaryKey[n].Ordinal); } if (bNeedParentRelations) { Push(UQueue, dt.ParentRelations); } if (bNeedChildRelations) { Push(UQueue, dt.ChildRelations); } }
private uint Pop(CUQueue UQueue, ref DataRelationCollection drc) { int n; string str; bool b; int nData; uint nSize = UQueue.GetSize(); UQueue.Load(out nData); drc.Clear(); for (n = 0; n < nData; n++) { DataColumn[] dcsChild = null; PopTableColNamesOnly(UQueue, ref dcsChild); UQueue.Load(out b); UQueue.Load(out str); DataColumn[] dcsParent = null; PopTableColNamesOnly(UQueue, ref dcsParent); DataRelation dr = new DataRelation(str, dcsParent, dcsChild); dr.Nested = b; drc.Add(dr); } return (nSize - UQueue.GetSize()); }
private void Push(CUQueue UQueue, UniqueConstraint uc) { bool bNull = (uc == null); UQueue.Save(bNull); if (!bNull) { Push(UQueue, uc.Columns); UQueue.Save(uc.ConstraintName); UQueue.Save(uc.IsPrimaryKey); } }
private void PushTableColNamesOnly(CUQueue UQueue, DataColumn[] dcs) { UQueue.Save(dcs.Length); foreach (DataColumn dc in dcs) { UQueue.Save(dc.Table.TableName); UQueue.Save(dc.Ordinal); } }
internal void Load(ushort sRequestID, CUQueue UQueue) { if (UQueue == null) throw new ArgumentException("Invalid input parameter UQueue"); switch (sRequestID) { case idDataSetHeaderArrive: if (UQueue.GetSize() > 0) { m_bDataSet = true; if (m_dt != null && m_dt.Columns.Count > 0) m_dt = new DataTable(); LoadDataSetHeader(UQueue); } break; case idDataReaderHeaderArrive: if (UQueue.GetSize() > 0) { if (m_ds != null && m_ds.Tables.Count > 0) m_ds = new DataSet(); m_bDataReader = true; LoadDataReaderHeader(UQueue); m_dtBackup = m_dt.Clone(); //for better performance RemoveAAU(); } break; case idDataTableHeaderArrive: if (UQueue.GetSize() > 0) { if (!m_bDataSet && m_ds != null && m_ds.Tables.Count > 0) m_ds = new DataSet(); m_bLoadingDataTable = true; LoadDataTableHeader(UQueue); m_dtBackup = m_dt.Clone(); //for better performance RemoveAAU(); if (m_bDataSet) m_ds.Tables.Add(m_dt); } break; case idDataTableRowsArrive: case idDataReaderRecordsArrive: if (UQueue.GetSize() > 0) LoadRows(UQueue); break; case idEndDataReader: if (m_bDataReader) { if (m_dt != null) m_dt.AcceptChanges(); AddAAU(); //reset datatable m_bDataReader = false; } break; case idEndDataTable: if (m_bLoadingDataTable) { AddAAU(); //reset datatable m_bLoadingDataTable = false; } break; case idEndDataSet: if (m_bDataSet) { DataRelationCollection drc = LoadDataSetRelations(UQueue); if (drc != null) { int n; int nSize = drc.Count; for (n = 0; n < nSize; n++) { DataRelation dr = drc[n]; m_ds.Relations.Add(dr); } } m_bDataSet = false; } break; default: break; } }
internal void Push(CUQueue UQueue, IDataReader dr) { int n; bool bNull; if (dr == null) throw new ArgumentNullException("Datarow object can't be null"); if (m_dts == null) throw new ArgumentNullException("DataTable header is not serialized yet"); if (m_dts.Length != dr.FieldCount) throw new InvalidOperationException("The size of the input data type array does not match the size of data row"); byte b = 0; byte bOne = 1; m_qBit.SetSize(0); m_qTemp.SetSize(0); int nLen = m_dts.Length; for (n = 0; n < nLen; n++) { bNull = dr.IsDBNull(n); if (bNull) { b += (byte)(bOne << (byte)(n % 8)); } if ((n % 8) == 7) { m_qBit.Save(b); b = 0; } if (bNull) continue; switch (m_dts[n]) { case tagDataTypeSupported.dtBoolean: m_qTemp.Save(dr.GetBoolean(n)); break; case tagDataTypeSupported.dtByte: m_qTemp.Save(dr.GetByte(n)); break; case tagDataTypeSupported.dtChar: m_qTemp.Save(dr.GetChar(n)); break; case tagDataTypeSupported.dtDateTime: m_qTemp.Save(dr.GetDateTime(n)); break; case tagDataTypeSupported.dtDecimal: m_qTemp.Save(dr.GetDecimal(n)); break; case tagDataTypeSupported.dtDouble: m_qTemp.Save(dr.GetDouble(n)); break; case tagDataTypeSupported.dtFloat: m_qTemp.Save(dr.GetFloat(n)); break; case tagDataTypeSupported.dtGuid: m_qTemp.Save(dr.GetGuid(n)); break; case tagDataTypeSupported.dtInt16: m_qTemp.Save(dr.GetInt16(n)); break; case tagDataTypeSupported.dtInt32: m_qTemp.Save(dr.GetInt32(n)); break; case tagDataTypeSupported.dtInt64: m_qTemp.Save(dr.GetInt64(n)); break; case tagDataTypeSupported.dtString: { string str = dr.GetString(n); m_qTemp.Save(str); } break; case tagDataTypeSupported.dtBytes: { uint nBytes = (uint)dr.GetBytes(n, (long)0, null, 0, 0); if (m_Buffer == null || nBytes > m_Buffer.Length) m_Buffer = new byte[nBytes + 1024]; dr.GetBytes(n, (long)0, m_Buffer, 0, (int)nBytes); m_qTemp.Save(nBytes); m_qTemp.Push(m_Buffer, nBytes); } break; case tagDataTypeSupported.dtUInt64: case tagDataTypeSupported.dtUInt32: case tagDataTypeSupported.dtUInt16: case tagDataTypeSupported.dtValue: case tagDataTypeSupported.dtValues: case tagDataTypeSupported.dtTimeSpan: { object obj = dr.GetValue(n); m_qTemp.Save(obj, false, false); } break; case tagDataTypeSupported.dtUDT: { object obj = dr.GetValue(n); m_qTemp.Save(obj.ToString()); } break; default: throw new InvalidOperationException("Unsupported data type for serialization"); } } if ((n % 8) != 0) m_qBit.Save(b); UQueue.Push(m_qBit.m_bytes, m_qBit.GetSize()); UQueue.Push(m_qTemp.m_bytes, m_qTemp.GetSize()); }
internal void Push(CUQueue UQueue, DataRow dr) { int n; bool bNull; if (dr == null) throw new ArgumentNullException("Datarow object can't be null"); if (m_dts == null) throw new ArgumentNullException("DataTable header is not serialized yet"); if (m_dts.Length != dr.ItemArray.Length) throw new InvalidOperationException("The size of the input data type array does not match the size of data row"); byte b = 0; byte bOne = 1; m_qBit.SetSize(0); m_qTemp.SetSize(0); bool bDelete = (dr.RowState == DataRowState.Deleted); if (bDelete) dr.RejectChanges(); object[] data = dr.ItemArray; int nLen = m_dts.Length; for (n = 0; n < nLen; n++) { object myData = data[n]; bNull = (myData == null || myData.Equals(DBNull.Value)); if (bNull) { b += (byte)(bOne << (byte)(n % 8)); } if ((n % 8) == 7) { m_qBit.Save(b); b = 0; } if (bNull) continue; switch (m_dts[n]) { case tagDataTypeSupported.dtBoolean: m_qTemp.Save((bool)myData); break; case tagDataTypeSupported.dtByte: m_qTemp.Save((byte)myData); break; case tagDataTypeSupported.dtChar: m_qTemp.Save((char)myData); break; case tagDataTypeSupported.dtDateTime: m_qTemp.Save((DateTime)myData); break; case tagDataTypeSupported.dtDecimal: m_qTemp.Save((decimal)myData); break; case tagDataTypeSupported.dtDouble: m_qTemp.Save((double)myData); break; case tagDataTypeSupported.dtFloat: m_qTemp.Save((float)myData); break; case tagDataTypeSupported.dtGuid: m_qTemp.Save((Guid)myData); break; case tagDataTypeSupported.dtUInt16: m_qTemp.Save((ushort)myData); break; case tagDataTypeSupported.dtUInt32: m_qTemp.Save((uint)myData); break; case tagDataTypeSupported.dtUInt64: m_qTemp.Save((ulong)myData); break; case tagDataTypeSupported.dtInt16: m_qTemp.Save((short)myData); break; case tagDataTypeSupported.dtInt32: m_qTemp.Save((int)myData); break; case tagDataTypeSupported.dtInt64: m_qTemp.Save((long)myData); break; case tagDataTypeSupported.dtString: m_qTemp.Save((string)myData); break; case tagDataTypeSupported.dtValue: case tagDataTypeSupported.dtValues: case tagDataTypeSupported.dtChars: case tagDataTypeSupported.dtBytes: case tagDataTypeSupported.dtTimeSpan: m_qTemp.Save(myData, false, false); break; case tagDataTypeSupported.dtUDT: m_qTemp.Save(myData.ToString()); break; default: throw new InvalidOperationException("Unsupported data type for serialization"); } } if ((n % 8) != 0) m_qBit.Save(b); UQueue.Push(m_qBit.m_bytes, m_qBit.GetSize()); UQueue.Push(m_qTemp.m_bytes, m_qTemp.GetSize()); if (bDelete) dr.Delete(); UQueue.Save((byte)dr.RowState); UQueue.Save(dr.HasErrors); if (dr.HasErrors) UQueue.Save(dr.RowError); }
uint EndDataSet(DataSet ds, bool bNeedRelations, CUQueue UQueue) { UQueue.SetSize(0); if (bNeedRelations && ds.Relations != null) m_AdoSerializer.Push(UQueue, ds.Relations); return SendResult(CAdoSerializationHelper.idEndDataSet, UQueue); }
internal void Push(CUQueue UQueue, DataRelationCollection drc) { UQueue.Save(drc.Count); foreach (DataRelation dr in drc) { PushTableColNamesOnly(UQueue, dr.ChildColumns); UQueue.Save(dr.Nested); UQueue.Save(dr.RelationName); PushTableColNamesOnly(UQueue, dr.ParentColumns); } }
private uint Pop(CUQueue UQueue, out ForeignKeyConstraint fkc) { bool b; uint nSize = UQueue.GetSize(); UQueue.Load(out b); if (b) //null { fkc = null; } else { byte bData = 0; string str = null; DataColumn[] dcsChild = null; Pop(UQueue, ref dcsChild); DataColumn[] dcsParent = null; Pop(UQueue, ref dcsParent); fkc = new ForeignKeyConstraint(dcsParent, dcsChild); UQueue.Load(out str); fkc.ConstraintName = str; UQueue.Load(out bData); fkc.AcceptRejectRule = (AcceptRejectRule)bData; UQueue.Load(out bData); fkc.UpdateRule = (Rule)bData; UQueue.Load(out bData); fkc.DeleteRule = (Rule)bData; } return (nSize - UQueue.GetSize()); }
private uint PopDataRecord(CUQueue UQueue, ref object[] aData) { int n; byte bData = 0; byte bOne = 1; if (m_dts == null) throw new InvalidOperationException("DataTable header is not de-serialized yet"); uint nSize = UQueue.GetSize(); int nLen = m_dts.Length; if (aData == null || aData.Length != nLen) aData = new object[nLen]; uint nBits = (uint)(m_dts.Length / 8 + (((m_dts.Length % 8) != 0) ? 1 : 0)); byte[] aBit = new byte[nBits]; UQueue.Pop(out aBit, nBits); for (n = 0; n < nLen; n++) { if ((n % 8) == 0) bData = aBit[n / 8]; if ((bData & (bOne << (byte)(n % 8))) != 0) { aData[n] = DBNull.Value; } else { switch (m_dts[n]) { case tagDataTypeSupported.dtBoolean: { bool myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtByte: { byte myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtChar: { char myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtDateTime: { DateTime myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtDecimal: { decimal myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtDouble: { double myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtFloat: { float myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtGuid: { Guid myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtInt16: { short myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtInt32: { int myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtInt64: { long myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtUDT: case tagDataTypeSupported.dtString: { string myData; UQueue.Load(out myData); aData[n] = myData; } break; case tagDataTypeSupported.dtBytes: { byte[] buffer; uint nBytes; UQueue.Load(out nBytes); UQueue.Pop(out buffer, nBytes); aData[n] = buffer; } break; case tagDataTypeSupported.dtUInt64: case tagDataTypeSupported.dtUInt32: case tagDataTypeSupported.dtUInt16: case tagDataTypeSupported.dtValue: case tagDataTypeSupported.dtValues: case tagDataTypeSupported.dtTimeSpan: UQueue.Load(out aData[n]); break; default: throw new InvalidOperationException("Unsupported data type for serialization"); } } } return (nSize - UQueue.GetSize()); }
internal void PushHeader(CUQueue UQueue, DataSet ds) { byte bData = 0; UQueue.SetSize(0); /* if (ds.RemotingFormat == SerializationFormat.Xml) bData += 1;*/ if (ds.CaseSensitive) bData += 2; if (ds.EnforceConstraints) bData += 4; UQueue.Save(ds.Tables.Count); UQueue.Save(bData); UQueue.Save(ds.DataSetName); UQueue.Save(ds.Namespace); UQueue.Save(ds.Prefix); }
private uint Pop(CUQueue UQueue, ref UniqueConstraint uc) { bool bNull = false; uint nSize = UQueue.GetSize(); UQueue.Load(out bNull); if (!bNull) { string str; DataColumn[] dcs = null; bool b; Pop(UQueue, ref dcs); UQueue.Load(out str); UQueue.Load(out b); uc = new UniqueConstraint(str, dcs, b); } return nSize - UQueue.GetSize(); }
internal void PushHeader(CUQueue UQueue, IDataReader dr) { int n; int nCount; if (dr == null) throw new ArgumentNullException("Must pass in a valid data reader object"); ArrayList al = new ArrayList(); UQueue.SetSize(0); UQueue.Save(dr.FieldCount); UQueue.Save(dr.RecordsAffected); DataTable dtSchema = dr.GetSchemaTable(); int nColumnName = dtSchema.Columns.IndexOf("ColumnName"); int nColumnSize = dtSchema.Columns.IndexOf("ColumnSize"); int nDataType = dtSchema.Columns.IndexOf("DataType"); int nIsLong = dtSchema.Columns.IndexOf("IsLong"); int nAllowDBNull = dtSchema.Columns.IndexOf("AllowDBNull"); int nIsReadOnly = dtSchema.Columns.IndexOf("IsReadOnly"); int nIsRowVersion = dtSchema.Columns.IndexOf("IsRowVersion"); int nIsUnique = dtSchema.Columns.IndexOf("IsUnique"); int nIsKey = dtSchema.Columns.IndexOf("IsKey"); int nIsAutoIncrement = dtSchema.Columns.IndexOf("IsAutoIncrement"); m_dts = new tagDataTypeSupported[dr.FieldCount]; for (n = 0; n < dr.FieldCount; n++) { tagDataTypeSupported dts = GetDT(dr.GetFieldType(n)); m_dts[n] = dts; UQueue.Save((short)dts); } foreach (DataRow row in dtSchema.Rows) { int nData = 0; string str = null; if (nIsAutoIncrement != -1) { if (row[nIsAutoIncrement].Equals(true)) nData |= (int)tagColumnBit.cbIsAutoIncrement; } if (nIsKey != -1) { if (row[nIsKey].Equals(true)) nData |= (int)tagColumnBit.cbIsKey; } if (nAllowDBNull != -1) { if (row[nAllowDBNull].Equals(true)) nData |= (int)tagColumnBit.cbAllowDBNull; } if (nIsReadOnly != -1) { if (row[nIsReadOnly].Equals(true)) nData |= (int)tagColumnBit.cbIsReadOnly; } if (nIsRowVersion != -1) { if (row[nIsRowVersion].Equals(true)) nData |= (int)tagColumnBit.cbIsRowVersion; } if (nIsUnique != -1) { if (row[nIsUnique].Equals(true)) nData |= (int)tagColumnBit.cbIsUnique; } if (nIsLong != -1) { if (row[nIsLong].Equals(true)) nData |= (int)tagColumnBit.cbIsLong; } UQueue.Save(nData); nData = 0; if (nColumnSize != -1) { nData = (int)row[nColumnSize]; } UQueue.Save(nData); if (nColumnName != -1) { str = (string)row[nColumnName]; nCount = CountNames(al, str); if (nCount > 0) str += nCount.ToString(); al.Add(str); } UQueue.Save(str); } }
private DataTable LoadDataTableHeader(CUQueue UQueue) { int n; bool bNeedChildRelations; bool bNeedbParentRelations; if (UQueue.GetSize() == 0) return null; int nData = 0; byte bData = 0; string str = null; DataTable dt = new DataTable(); m_dt = dt; m_bLoadingDataTable = true; UQueue.Load(out m_nAffected); UQueue.Load(out bData); bNeedChildRelations = ((bData & 2) == 2); bNeedbParentRelations = ((bData & 4) == 4); DataColumnCollection dcc = dt.Columns; UQueue.Load(out str); dt.TableName = str; Pop(UQueue, ref dcc); m_dts = new tagDataTypeSupported[dcc.Count]; for (n = 0; n < dcc.Count; n++) { m_dts[n] = GetDT(dcc[n].DataType.FullName); } UQueue.Load(out str); dt.DisplayExpression = str; UQueue.Load(out nData); dt.MinimumCapacity = nData; UQueue.Load(out str); dt.Namespace = str; UQueue.Load(out str); dt.Prefix = str; UQueue.Load(out nData); DataColumn[] pk = new DataColumn[nData]; for (n = 0; n < nData; n++) { UQueue.Load(out nData); pk[n] = dt.Columns[nData]; } dt.PrimaryKey = pk; if (bNeedbParentRelations) { DataRelationCollection drc = dt.ParentRelations; Pop(UQueue, ref drc); } if (bNeedChildRelations) { DataRelationCollection drc = dt.ChildRelations; Pop(UQueue, ref drc); } if (UQueue.GetSize() >= 4) { UQueue.Load(out m_nBatchSize); } else { m_nBatchSize = 0; } return dt; }
private DataTable LoadDataReaderHeader(CUQueue UQueue) { int n; int nData; short sData; string str; int nFieldCount; if (UQueue.GetSize() == 0) return null; m_dt = new DataTable(); DataTable dt = m_dt; m_bLoadingDataTable = false; UQueue.Load(out nFieldCount); UQueue.Load(out m_nAffected); m_dts = new tagDataTypeSupported[nFieldCount]; for (n = 0; n < nFieldCount; n++) { UQueue.Load(out sData); m_dts[n] = (tagDataTypeSupported)sData; } m_qTemp.SetSize(0); for (n = 0; n < nFieldCount; n++) { UQueue.Load(out nData); DataColumn dc = new DataColumn(); dc.DataType = GetType(m_dts[n]); dc.AllowDBNull = ((nData & (int)tagColumnBit.cbAllowDBNull) == (int)tagColumnBit.cbAllowDBNull); dc.AutoIncrement = ((nData & (int)tagColumnBit.cbIsAutoIncrement) == (int)tagColumnBit.cbIsAutoIncrement); dc.ReadOnly = ((nData & (int)tagColumnBit.cbIsReadOnly) == (int)tagColumnBit.cbIsReadOnly); dc.Unique = ((nData & (int)tagColumnBit.cbIsUnique) == (int)tagColumnBit.cbIsUnique); bool cbIsLong = ((nData & (int)tagColumnBit.cbIsLong) == (int)tagColumnBit.cbIsLong); if ((nData & (int)tagColumnBit.cbIsKey) == (int)tagColumnBit.cbIsKey) { m_qTemp.Save(n); } UQueue.Load(out nData); if (nData > 0 && !cbIsLong && (m_dts[n] == tagDataTypeSupported.dtString || m_dts[n] == tagDataTypeSupported.dtChars)) { dc.MaxLength = nData; //ColumnSize } UQueue.Load(out str); dc.ColumnName = str; dt.Columns.Add(dc); } if (m_qTemp.GetSize() > 0) { int nIndex = 0; DataColumn[] dcs = new DataColumn[m_qTemp.GetSize() / 4]; while (m_qTemp.GetSize() > 0) { m_qTemp.Load(out nData); DataColumn dc = dt.Columns[nData]; dcs[nIndex] = dc; ++nIndex; } dt.PrimaryKey = dcs; } if (UQueue.GetSize() >= 4) { UQueue.Load(out m_nBatchSize); } else { m_nBatchSize = 0; } return dt; }
internal static void Write(Stream s, CUQueue q) { if (q == null || q.GetSize() == 0) return; s.Write(q.m_bytes, (int)q.HeadPosition, (int)q.GetSize()); }
private DataRelationCollection LoadDataSetRelations(CUQueue UQueue) { DataRelationCollection drc = null; if (UQueue != null && UQueue.GetSize() > 0) { drc = CurrentDataSet.Relations; drc.Clear(); Pop(UQueue, ref drc); } return drc; }
private void Push(CUQueue UQueue, ForeignKeyConstraint fkc) { bool bNull = (fkc == null); UQueue.Save(bNull); if (!bNull) { Push(UQueue, fkc.Columns); Push(UQueue, fkc.RelatedColumns); UQueue.Save(fkc.ConstraintName); UQueue.Save((byte)fkc.DeleteRule); UQueue.Save((byte)fkc.AcceptRejectRule); UQueue.Save((byte)fkc.UpdateRule); } }
private void Push(CUQueue UQueue, DataColumn[] dcs) { if (dcs == null) { UQueue.Save((int)-1); } else { UQueue.Save(dcs.Length); foreach (DataColumn dc in dcs) { Push(UQueue, dc); } } }
private int LoadDataTableRows(CUQueue UQueue) { if (UQueue.GetSize() == 0) return 0; int nSize = 0; DataTable dt = m_dt; DataRowState drs = DataRowState.Detached; //dt.BeginLoadData(); while (UQueue != null && UQueue.GetSize() > 0) { DataRow dr = dt.NewRow(); Pop(UQueue, ref dr, ref drs); dt.Rows.Add(dr); switch (drs) { case DataRowState.Added: break; case DataRowState.Unchanged: dr.AcceptChanges(); break; case DataRowState.Modified: dr.AcceptChanges(); { int n; object obj; int nCount = dt.Columns.Count; for (n = 0; n < nCount; ++n) { if (!dt.Columns[n].ReadOnly) { obj = dr[0]; dr[0] = obj; break; } } } break; case DataRowState.Deleted: dr.AcceptChanges(); dr.Delete(); break; default: //DataRowState.Detached throw new InvalidOperationException("Wrong DataRow state"); } ++nSize; } //dt.EndLoadData(); return nSize; }
private int LoadDataReaderRecords(CUQueue UQueue) { if (UQueue.GetSize() == 0) return 0; DataTable dt = m_dt; int nSize = 0; object[] aData = null; //dt.BeginLoadData(); while (UQueue != null && UQueue.GetSize() > 0) { PopDataRecord(UQueue, ref aData); dt.Rows.Add(aData); ++nSize; } //dt.EndLoadData(); return nSize; }