/// <summary> /// 指定されたType,WorkIDのValueを返す(int版) /// </summary> /// <param name="Type"></param> /// <param name="WorkID"></param> /// <param name="Value"></param> public int Get(int Type, int WorkID) { KeyStruct key = new KeyStruct(Type, WorkID); string Value = map[key].Value; return Int32.Parse(Value); }
public static unsafe int CursorFind(IntPtr handle, ref byte[] keydata, ref byte[] recdata, int flags) { KeyStruct key = new KeyStruct(); RecordStruct record = new RecordStruct(); fixed (byte* bk = keydata) { key.data = bk; key.size = (short)keydata.Length; int st = CursorFindLow(handle, ref key, ref record, flags); if (st != 0) return st; // I didn't found a way to avoid the copying... IntPtr recData = new IntPtr(record.data); byte[] newRecData = new byte[record.size]; Marshal.Copy(recData, newRecData, 0, record.size); recdata = newRecData; // also copy the key data if approx. matching was requested if ((flags & (UpsConst.UPS_FIND_LT_MATCH | UpsConst.UPS_FIND_GT_MATCH)) != 0) { IntPtr keyData = new IntPtr(key.data); byte[] newKeyData = new byte[key.size]; Marshal.Copy(keyData, newKeyData, 0, key.size); keydata = newKeyData; } return 0; } }
public void LoadObject(ref object obj, bool ignoreObjectNotFound) { Type type = AssemblyManager.GetBaseType(obj.GetType()); string identity = this.Context.ObjectManager.GetObjectIdentity(obj); KeyStruct key = GetKey(type, identity); LoadObject(identity, ref obj, ignoreObjectNotFound, type, key); }
public virtual object GetObject(object identity, Type type, bool lazy, bool ignoreObjectNotFound) { type = AssemblyManager.GetBaseType(type); KeyStruct key = GetKey(type, identity); object obj; ObjectCancelEventArgs e; IObjectCache cache = GetObjectCache(); obj = cache.LoadedObjects[key]; if (obj != null) { e = new ObjectCancelEventArgs(obj); this.Context.EventManager.OnGettingObject(this, e); if (e.Cancel) { return(null); } } else { obj = cache.UnloadedObjects[key]; if (obj != null) { e = new ObjectCancelEventArgs(obj); this.Context.EventManager.OnGettingObject(this, e); if (e.Cancel) { return(null); } } else { obj = this.Context.AssemblyManager.CreateInstance(type); this.Context.ObjectManager.SetObjectIdentity(obj, key); e = new ObjectCancelEventArgs(obj); this.Context.EventManager.OnGettingObject(this, e); if (e.Cancel) { return(null); } if (lazy) { RegisterLazyLoadedObject(obj); cache.UnloadedObjects[key] = obj; } else { string strIdentity = ToStringIdentity(identity); LoadObject(strIdentity, ref obj, ignoreObjectNotFound, type, key); } } } ObjectEventArgs e2 = new ObjectEventArgs(obj); this.Context.EventManager.OnGotObject(this, e2); return(obj); }
static unsafe public int CursorFind(IntPtr handle, byte[] data, int flags) { KeyStruct key = new KeyStruct(); fixed(byte *b = data) { key.data = b; key.size = (short)data.GetLength(0); return(CursorFindLow(handle, ref key, flags)); } }
static unsafe public byte[] ResultGetKey(IntPtr handle, int row) { KeyStruct key = new KeyStruct(); ResultGetKeyLow(handle, row, ref key); IntPtr pdata = new IntPtr(key.data); byte[] data = new byte[key.size]; Marshal.Copy(pdata, data, 0, key.size); return(data); }
static public unsafe int Erase(IntPtr handle, IntPtr txnhandle, byte[] data, int flags) { KeyStruct key = new KeyStruct(); fixed(byte *b = data) { key.data = b; key.size = (short)data.GetLength(0); return(EraseLow(handle, txnhandle, ref key, flags)); } }
public void SessionTest2() { using (var session1 = fht.NewSession()) using (var session2 = fht.NewSession()) { InputStruct input = default(InputStruct); OutputStruct output = default(OutputStruct); var key1 = new KeyStruct { kfield1 = 14, kfield2 = 15 }; var value1 = new ValueStruct { vfield1 = 24, vfield2 = 25 }; var key2 = new KeyStruct { kfield1 = 15, kfield2 = 16 }; var value2 = new ValueStruct { vfield1 = 25, vfield2 = 26 }; session1.Upsert(ref key1, ref value1, Empty.Default, 0); session2.Upsert(ref key2, ref value2, Empty.Default, 0); var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session1.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == value1.vfield1); Assert.IsTrue(output.value.vfield2 == value1.vfield2); status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session2.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == value2.vfield1); Assert.IsTrue(output.value.vfield2 == value2.vfield2); } }
public void SessionTest2() { using var session1 = fht.NewSession(new Functions()); using var session2 = fht.NewSession(new Functions()); InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 14, kfield2 = 15 }; var value1 = new ValueStruct { vfield1 = 24, vfield2 = 25 }; var key2 = new KeyStruct { kfield1 = 15, kfield2 = 16 }; var value2 = new ValueStruct { vfield1 = 25, vfield2 = 26 }; session1.Upsert(ref key1, ref value1, Empty.Default, 0); session2.Upsert(ref key2, ref value2, Empty.Default, 0); var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session1.CompletePending(true); } else { Assert.AreEqual(Status.OK, status); } Assert.AreEqual(value1.vfield1, output.value.vfield1); Assert.AreEqual(value1.vfield2, output.value.vfield2); status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session2.CompletePending(true); } else { Assert.AreEqual(Status.OK, status); } Assert.AreEqual(value2.vfield1, output.value.vfield1); Assert.AreEqual(value2.vfield2, output.value.vfield2); }
public virtual bool HasObject(object obj) { string identity = this.Context.ObjectManager.GetObjectIdentity(obj); if (this.Context.ObjectManager.HasIdentity(obj)) { return(HasObject(identity, obj.GetType())); } Type type = AssemblyManager.GetBaseType(obj.GetType()); KeyStruct key = GetOldKey(obj, identity); return(HasObject(identity, type, key)); }
private int CallOutside(int nCode, int wParam, KeyStruct lParam) { if (!(nCode >= 0)) { return(CallNextHookEx(hookId, nCode, wParam, lParam)); } bool shouldBlock = kc.Invoke((Keys)lParam.vkCode, wParam); if (!shouldBlock) { return(CallNextHookEx(hookId, nCode, wParam, lParam)); } return(1); }
static unsafe public byte[] CursorGetKey(IntPtr handle, int flags) { KeyStruct key = new KeyStruct(); int st = CursorMoveLow(handle, ref key, IntPtr.Zero, flags); if (st == 0) { // I didn't found a way to avoid the copying... IntPtr keyData = new IntPtr(key.data); byte[] newArray = new byte[key.size]; Marshal.Copy(keyData, newArray, 0, key.size); return(newArray); } throw new DatabaseException(st); }
static public unsafe int CursorInsert(IntPtr handle, byte[] keyData, byte[] recordData, int flags) { RecordStruct record = new RecordStruct(); KeyStruct key = new KeyStruct(); fixed(byte *br = recordData, bk = keyData) { record.data = br; record.size = recordData.GetLength(0); key.data = bk; key.size = (short)keyData.GetLength(0); return(CursorInsertLow(handle, ref key, ref record, flags)); } }
/// <summary> /// 指定されたType,WorkIDのValueを返す /// </summary> /// <param name="Type"></param> /// <param name="WorkID"></param> /// <param name="Value"></param> public void Get(int Type, int WorkID, ref string Value) { KeyStruct key = new KeyStruct(Type, WorkID); // キーがある場合は格納されている値を返す。 if (map.ContainsKey(key)) { Value = map[key].Value; } // キーがない場合は、0を返す else { Value = "0"; } }
public void SessionTest2() { using var session1 = fht.NewSession(new Functions()); using var session2 = fht.NewSession(new Functions()); InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 14, kfield2 = 15 }; var value1 = new ValueStruct { vfield1 = 24, vfield2 = 25 }; var key2 = new KeyStruct { kfield1 = 15, kfield2 = 16 }; var value2 = new ValueStruct { vfield1 = 25, vfield2 = 26 }; session1.Upsert(ref key1, ref value1, Empty.Default, 0); session2.Upsert(ref key2, ref value2, Empty.Default, 0); var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0); if (status.IsPending) { session1.CompletePendingWithOutputs(out var outputs, wait: true); (status, output) = GetSinglePendingResult(outputs); } Assert.IsTrue(status.Found); Assert.AreEqual(value1.vfield1, output.value.vfield1); Assert.AreEqual(value1.vfield2, output.value.vfield2); status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0); if (status.IsPending) { session2.CompletePendingWithOutputs(out var outputs, wait: true); (status, output) = GetSinglePendingResult(outputs); } Assert.IsTrue(status.Found); Assert.AreEqual(value2.vfield1, output.value.vfield1); Assert.AreEqual(value2.vfield2, output.value.vfield2); }
public void NativeInMemWriteReadDelete([Values] TestUtils.DeviceType deviceType) { Setup(128, new LogSettings { PageSizeBits = 10, MemorySizeBits = 12, SegmentSizeBits = 22 }, deviceType); uContext.ResumeThread(); try { InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 13, kfield2 = 14 }; var value = new ValueStruct { vfield1 = 23, vfield2 = 24 }; uContext.Upsert(ref key1, ref value, Empty.Default, 0); var status = uContext.Read(ref key1, ref input, ref output, Empty.Default, 0); AssertCompleted(new(StatusCode.Found), status); uContext.Delete(ref key1, Empty.Default, 0); status = uContext.Read(ref key1, ref input, ref output, Empty.Default, 0); AssertCompleted(new(StatusCode.NotFound), status); var key2 = new KeyStruct { kfield1 = 14, kfield2 = 15 }; var value2 = new ValueStruct { vfield1 = 24, vfield2 = 25 }; uContext.Upsert(ref key2, ref value2, Empty.Default, 0); status = uContext.Read(ref key2, ref input, ref output, Empty.Default, 0); AssertCompleted(new(StatusCode.Found), status); Assert.AreEqual(value2.vfield1, output.value.vfield1); Assert.AreEqual(value2.vfield2, output.value.vfield2); } finally { uContext.SuspendThread(); } }
/// <summary> /// Get collection of entries where the second key is equal 'name' /// </summary> /// <param name="name"></param> /// <returns></returns> public IEnumerable <KeyValuePair <KeyStruct, TValue> > this[TName name] { get { if (name == null) { throw new ArgumentNullException(nameof(name)); } try { var isSuccess = _dNameId.TryGetValue(name, out var idList); if (!isSuccess || idList.Count == 0) { throw new KeyNotExistsException($"Requested Key {name} - does not exist"); } IEnumerable <KeyValuePair <KeyStruct, TValue> > resultEnumerable; if (idList.Count == 1) { var strKey = new KeyStruct(idList[0], name); resultEnumerable = _dictionary.Where(x => x.Key.Equals(strKey)); } else // IdList contains more than 1 entries for uniq name. "A" - 1; "A" - 2; "A" - 3 { var keyStructs = new KeyStruct[idList.Count]; for (int i = 0; i < idList.Count; i++) { keyStructs[i] = new KeyStruct(idList[i], name); } resultEnumerable = keyStructs.Select(x => new KeyValuePair <KeyStruct, TValue>(x, _dictionary[x])); } return(resultEnumerable); } catch (Exception e) { throw new KeyNotExistsException($"Requested Key {name} - does not exist", e); } } }
public virtual void RemoveObject(object obj) { if (obj == null) { throw new NullReferenceException("Can't remove null object!"); // do not localize } KeyStruct key = GetKey(obj); IObjectCache cache = GetObjectCache(); cache.LoadedObjects[key] = null; cache.UnloadedObjects[key] = null; if (cache.AllObjects != null) { cache.AllObjects.Remove(obj); } }
static unsafe public int CursorGet(IntPtr handle, int flags, ref byte[] keyArray, ref byte[] recordArray) { KeyStruct key = new KeyStruct(); RecordStruct record = new RecordStruct(); int st = CursorMoveLow(handle, ref key, ref record, flags); if (st == 0) { IntPtr keyData = new IntPtr(key.data); keyArray = new byte[key.size]; Marshal.Copy(keyData, keyArray, 0, key.size); IntPtr recData = new IntPtr(record.data); recordArray = new byte[record.size]; Marshal.Copy(recData, recordArray, 0, record.size); } return(st); }
/// <summary> /// Get collection of entries where the first key is equal 'id' /// </summary> /// <param name="id"></param> /// <returns></returns> public IEnumerable <KeyValuePair <KeyStruct, TValue> > this[TId id] { get { if (id == null) { throw new ArgumentNullException(nameof(id)); } try { var isSuccess = _dIdName.TryGetValue(id, out var namesList); if (!isSuccess || namesList.Count == 0) { throw new KeyNotExistsException($"Requested Key {id} - does not exist"); } IEnumerable <KeyValuePair <KeyStruct, TValue> > resultEnumerable; if (namesList.Count == 1) { var strKey = new KeyStruct(id, namesList[0]); resultEnumerable = _dictionary.Where(x => x.Key.Equals(strKey)); } else // NamesList contains more than 1 entries for uniq id. 1-"A" 1-"B" 1-"C" { var keyStructs = new KeyStruct[namesList.Count]; for (int i = 0; i < namesList.Count; i++) { keyStructs[i] = new KeyStruct(id, namesList[i]); } resultEnumerable = keyStructs.Select(x => new KeyValuePair <KeyStruct, TValue>(x, _dictionary[x])); } return(resultEnumerable); } catch (Exception e) { throw new KeyNotExistsException($"Requested Key {id} - does not exist", e); } } }
public virtual void RegisterLoadedObject(object obj) { if (obj == null) { throw new NullReferenceException("Can't register null object as loaded!"); // do not localize } //This may throw if ReadConsistency is Pessimistic and a tx guid has already been set... SetTransactionGuid(obj); IContext ctx = this.Context; KeyStruct key = GetKey(obj); IObjectCache cache = GetObjectCache(); object result = cache.UnloadedObjects[key]; if (result != null) { cache.UnloadedObjects[key] = null; } else { result = cache.LoadedObjects[key]; if (result == null) { if (cache.AllObjects != null) { cache.AllObjects.Add(obj); } } } cache.LoadedObjects[key] = obj; this.Context.ReadOnlyObjectCacheManager.SaveObject(obj); if (this.Context.GetObjectStatus(obj) != ObjectStatus.Dirty) { ctx.ObjectManager.SetObjectStatus(obj, ObjectStatus.Clean); } LogMessage message = new LogMessage("Registered loaded object"); LogMessage verbose = new LogMessage("Type: {0}, Key: {1}", obj.GetType(), key); ctx.LogManager.Info(this, message, verbose); // do not localize }
/// <summary> /// Called when a key is pressed /// </summary> /// <param name="code">-</param> /// <param name="wParam">KeyStruct</param> /// <param name="lParam">-</param> /// <returns></returns> public IntPtr OnHook(int code, int wParam, int lParam) { IntPtr res = CallNextHookEx(hook, code, wParam, lParam); if (code >= 0 && m_DownEvent != null && wParam == WM_KEYDOWN) { KeyStruct s = (KeyStruct)Marshal.PtrToStructure(new IntPtr(lParam), typeof(KeyStruct)); Keys key = (Keys)s.vkCode; m_DownEvent(key); } else if (code >= 0 && m_UpEvent != null && wParam == WM_KEYUP) { KeyStruct s = (KeyStruct)Marshal.PtrToStructure(new IntPtr(lParam), typeof(KeyStruct)); Keys key = (Keys)s.vkCode; m_UpEvent(key); } return(res); }
protected virtual bool HasObject(string identity, Type type, KeyStruct key) { object obj; IObjectCache cache = GetObjectCache(); obj = cache.LoadedObjects[key]; if (obj != null) { return(true); } else { obj = cache.UnloadedObjects[key]; if (obj != null) { return(true); } } return(false); }
public virtual void RegisterCreatedObject(object obj) { if (obj == null) { throw new NullReferenceException("Can't register null object as created!"); // do not localize } //This may throw if ReadConsistency is Pessimistic and a tx guid has already been set... SetTransactionGuid(obj); IContext ctx = this.Context; KeyStruct key = GetKey(obj); IObjectCache cache = GetObjectCache(); object result = cache.LoadedObjects[key]; if (result != null) { throw new IdentityMapException("An object with the key " + key + " is already registered in the identity map!"); } result = cache.UnloadedObjects[key]; if (result != null) { throw new IdentityMapException("An object with the key " + key + " is already registered in the identity map!"); } if (cache.AllObjects != null) { cache.AllObjects.Add(obj); } cache.LoadedObjects[key] = obj; LogMessage message = new LogMessage("Registered created object"); LogMessage verbose = new LogMessage("Type: {0}, Key: {1}", obj.GetType(), key); ctx.LogManager.Info(this, message, verbose); // do not localize }
static public unsafe byte[] Find(IntPtr handle, IntPtr txnhandle, byte[] data, int flags) { KeyStruct key = new KeyStruct(); RecordStruct record = new RecordStruct(); key.size = (short)data.GetLength(0); fixed(byte *bk = data) { key.data = bk; int st = FindLow(handle, txnhandle, ref key, ref record, flags); if (st == 0) { // I didn't found a way to avoid the copying... IntPtr recData = new IntPtr(record.data); byte[] newArray = new byte[record.size]; Marshal.Copy(recData, newArray, 0, record.size); return(newArray); } throw new DatabaseException(st); } }
/// <summary> /// Remove Value by Id and Name keys /// </summary> /// <param name="id"></param> /// <param name="name"></param> public bool Remove(TId id, TName name) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } var result = false; if (!Contains(id) || !Contains(name)) { return(false); } try { var key = new KeyStruct(id, name); lock (_locker) { if (Keys.Contains(key)) { result = _dictionary.Remove(key); RemoveKeyPairHelper(id, name); } } } catch (Exception e) { throw new CollectionException("Remove operation Error. " + e.Message); } return(result); }
public void ReadAtAddressReadFlagsNone() { // Just functional test of ReadFlag so one device is enough deviceType = TestUtils.DeviceType.MLSD; Setup(128, new LogSettings { MemorySizeBits = 29 }, deviceType); uContext.ResumeThread(); try { InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 13, kfield2 = 14 }; var value = new ValueStruct { vfield1 = 23, vfield2 = 24 }; ReadOptions readOptions = new() { StartAddress = fht.Log.BeginAddress }; uContext.Upsert(ref key1, ref value, Empty.Default, 0); var status = uContext.ReadAtAddress(ref input, ref output, ref readOptions, Empty.Default, 0); AssertCompleted(new(StatusCode.Found), status); Assert.AreEqual(value.vfield1, output.value.vfield1); Assert.AreEqual(value.vfield2, output.value.vfield2); Assert.AreEqual(key1.kfield1, 13); Assert.AreEqual(key1.kfield2, 14); } finally { uContext.SuspendThread(); } }
public void ReadWithoutSerialID() { // Just checking without Serial ID so one device type is enough deviceType = TestUtils.DeviceType.MLSD; Setup(128, new LogSettings { MemorySizeBits = 29 }, deviceType); uContext.ResumeThread(); try { InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 13, kfield2 = 14 }; var value = new ValueStruct { vfield1 = 23, vfield2 = 24 }; uContext.Upsert(ref key1, ref value, Empty.Default, 0); var status = uContext.Read(ref key1, ref input, ref output, Empty.Default); AssertCompleted(new(StatusCode.Found), status); Assert.AreEqual(value.vfield1, output.value.vfield1); Assert.AreEqual(value.vfield2, output.value.vfield2); Assert.AreEqual(key1.kfield1, 13); Assert.AreEqual(key1.kfield2, 14); } finally { uContext.SuspendThread(); } }
public static unsafe byte[] ResultGetKey(IntPtr handle, int row) { KeyStruct key = new KeyStruct(); ResultGetKeyLow(handle, row, ref key); IntPtr pdata = new IntPtr(key.data); byte[] data = new byte[key.size]; Marshal.Copy(pdata, data, 0, key.size); return data; }
private static extern void ResultGetKeyLow(IntPtr handle, int row, ref KeyStruct key);
/// <summary> /// 指定されたType,WorkIDにValueを設定する /// </summary> /// <param name="Type"></param> /// <param name="WorkID"></param> public void Set(int Type, int WorkID, string Value, int SearchType = SystemConstants.DB_GROUP_SEARCH_TYPE_NONE) { KeyStruct key = new KeyStruct(Type, WorkID); WorkDataStruct w = new WorkDataStruct(Type, WorkID, Value); map[key] = w; }
public static unsafe int CursorGet(IntPtr handle, int flags, ref byte[] keyArray, ref byte[] recordArray) { KeyStruct key = new KeyStruct(); RecordStruct record = new RecordStruct(); int st = CursorMoveLow(handle, ref key, ref record, flags); if (st == 0) { IntPtr keyData = new IntPtr(key.data); keyArray = new byte[key.size]; Marshal.Copy(keyData, keyArray, 0, key.size); IntPtr recData = new IntPtr(record.data); recordArray = new byte[record.size]; Marshal.Copy(recData, recordArray, 0, record.size); } return st; }
public static unsafe byte[] CursorGetKey(IntPtr handle, int flags) { KeyStruct key = new KeyStruct(); int st = CursorMoveLow(handle, ref key, IntPtr.Zero, flags); if (st == 0) { // I didn't found a way to avoid the copying... IntPtr keyData = new IntPtr(key.data); byte[] newArray = new byte[key.size]; Marshal.Copy(keyData, newArray, 0, key.size); return newArray; } throw new DatabaseException(st); }
public void SessionTest4() { using var session1 = fht.NewSession(new Functions()); using var session2 = fht.NewSession(new Functions()); var t1 = Task.CompletedTask.ContinueWith((t) => { InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 14, kfield2 = 15 }; var value1 = new ValueStruct { vfield1 = 24, vfield2 = 25 }; session1.Upsert(ref key1, ref value1, Empty.Default, 0); var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session1.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == value1.vfield1); Assert.IsTrue(output.value.vfield2 == value1.vfield2); }); var t2 = Task.CompletedTask.ContinueWith((t) => { InputStruct input = default; OutputStruct output = default; var key2 = new KeyStruct { kfield1 = 15, kfield2 = 16 }; var value2 = new ValueStruct { vfield1 = 25, vfield2 = 26 }; session2.Upsert(ref key2, ref value2, Empty.Default, 0); var status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session2.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == value2.vfield1); Assert.IsTrue(output.value.vfield2 == value2.vfield2); }); t1.Wait(); t2.Wait(); }
public void SetKeyStruct(KeyStruct keyStruct) { identityHelperMixin.SetKeyStruct(keyStruct); }
/// <summary> /// バンクデータをまるごと加工値メモリに設定する /// </summary> /// <param name="BankData"></param> public int SetArray(BankDataStruct[] BankData) { int[] groupID = null; int[] temp_workID = null; List<int> workID = new List<int>(); MemAllocStruct memAllocStruct = null; int[] btnWorkID = new int[0]; int result = SystemConstants.DCPF_SUCCESS; // 加工メモリをクリアする map.Clear(); // バンクデータ配列がnullの場合、長さ0の配列を作る if (BankData == null) { BankData = new BankDataStruct[0]; } // 受け取ったBankDataを全て加工値メモリに書く for (int i = 0; i < BankData.Length; i++) { Set(BankData[i].Type, BankData[i].ID, BankData[i].value); } // *メモリ割当データに存在するが、BankDataにないものは初期値で補填する // 加工値のgroup codeの一覧を取得 try { memAllocData.GetMemoryDataGroupList(SystemConstants.WORKID_TYPE_WORKDATA, SystemConstants.WORKGROUP_ROOT, ref groupID); } catch (MemoryAllocationDataException) { return SystemConstants.ERR_WORKID_RANGE; } // 一覧取得したgroup codeのwork idの一覧を取得 for (int i = 0; i < groupID.Length; i++) { try { memAllocData.GetMemoryDataGroupList(SystemConstants.WORKID_TYPE_WORKDATA, groupID[i], ref temp_workID); } catch (MemoryAllocationDataException) { return SystemConstants.ERR_WORKID_RANGE; } for (int j = 0; j < temp_workID.Length; j++) { // ArrayListにtemp_workID追加 workID.Add(temp_workID[j]); } } // メモリ割当にあって加工値メモリにない値を補う for (int i = 0; i < workID.Count; i++) { // work idのメモリ割当データを取得する try { // メモリ割当データを使用し、WorkIDに対応する共有メモリのアドレスを取得 memAllocStruct = memAllocData.GetEntry(SystemConstants.WORKID_TYPE_WORKDATA, workID[i]); } // WorkIDがメモリ割当データに存在していない場合 catch (MemoryAllocationDataException) { continue; } // 加工値メモリに存在しない場合は、デフォルト値で補う KeyStruct key = new KeyStruct(SystemConstants.WORKMEM_TYPE_WORKDATA, workID[i]); if (!map.ContainsKey(key)) { // 加工値メモリへ当該不足IDを、メモリ割当データの初期値で追加 Set(SystemConstants.WORKMEM_TYPE_WORKDATA, workID[i], memAllocStruct.DefaultValue.ToString()); // バンク保存ありの値が欠損していた場合は、ERR_BANK_PARTS_BREKEを返す。 if (memAllocStruct.BankStore) { result = SystemConstants.ERR_BANK_PARTS_BREAK; } } } // 全てのボタンIDを取得 buttonControl.GetAllBtnWorkID(ref btnWorkID); // ボタンIDの数だけループする for (int i = 0; i < btnWorkID.Length; i++) { // ボタンIDのバンク保存対象を取得 ButtonActionStruct btnBankStore = buttonControl.Get(btnWorkID[i]); KeyStruct key = new KeyStruct(SystemConstants.WORKMEM_TYPE_WORKBTN, btnWorkID[i]); // 加工値メモリに存在しない場合は、デフォルト値で補う if (!map.ContainsKey(key)) { Set(SystemConstants.WORKMEM_TYPE_WORKBTN, btnWorkID[i], btnBankStore.DefaultMode.ToString()); // バンク保存ありの値が欠損していた場合は、ERR_BANK_PARTS_BREKEを返す。 if (btnBankStore.BankStore == SystemConstants.BTN_BANK_SAVED) { result = SystemConstants.ERR_BANK_PARTS_BREAK; } } } return result; }
private static extern int CursorMoveLow(IntPtr handle, ref KeyStruct key, ref RecordStruct record, int flags);
private static extern int EraseLow(IntPtr handle, IntPtr txnhandle, ref KeyStruct key, int flags);
/// <summary> /// 学習データをまるごと加工値メモリに設定する /// </summary> /// <param name="LearnData"></param> /// <returns></returns> public int SetArray(LearnDataStruct[] LearnData) { List<int> workID = new List<int>(); int[] groupID = null; int[] temp_workID = null; MemAllocStruct memAllocStruct = null; int result = SystemConstants.MCPF_SUCCESS; // 加工メモリをクリアする map.Clear(); // 学習データ配列がnullの場合、長さ0の配列を作る if (LearnData == null) LearnData = new LearnDataStruct[0]; // 受け取った学習データをすべて加工値メモリに書く for (int i = 0; i < LearnData.Length; i++) Set(LearnData[i].Type, LearnData[i].ID, LearnData[i].value); /* メモリ割当データの一覧を取得する */ // 加工値のgroup code の一覧を取得 try { memAllocData.GetMemoryDataGroupList(SystemConstants.WORKID_TYPE_WORKDATA, SystemConstants.WORKGROUP_ROOT, ref groupID); } catch (MemoryAllocationDataException) { return SystemConstants.ERR_WORKID_RANGE; } // 一覧取得したgroup codeからwork IDの一覧を取得 for (int i = 0; i < groupID.Length; i++) { try { memAllocData.GetMemoryDataGroupList(SystemConstants.WORKID_TYPE_WORKDATA, groupID[i], ref temp_workID); } catch (MemoryAllocationDataException) { return SystemConstants.ERR_WORKID_RANGE; } // WorkIDに取得したworkID一覧を追加する for (int j = 0; j < temp_workID.Length; j++) workID.Add(temp_workID[j]); } // メモリ割当データにあって、加工メモリに不足しているデータを補う for (int i = 0; i < workID.Count; i++) { // workID のメモリ割当データを取得する try { memAllocStruct = memAllocData.GetEntry(SystemConstants.WORKID_TYPE_WORKDATA, workID[i]); } catch (MemberAccessException) { continue; } // 加工値メモリに存在しない場合は、デフォルト値で補う KeyStruct key = new KeyStruct(SystemConstants.WORKMEM_TYPE_WORKDATA, workID[i]); if (!map.ContainsKey(key)) { // 加工値メモリに不足IDを、メモリ割当データの初期値で追加 Set(SystemConstants.WORKMEM_TYPE_WORKDATA, workID[i], memAllocStruct.DefaultValue.ToString()); // 学習データ割当の値が欠損していた場合は、ERROR_LEARN_PARTS_BREAKを返す。 if (LearnDataStorage.IsLearnSearchKeyCode(memAllocStruct.learn_key_code)) result = SystemConstants.ERR_LEARN_PARTS_BREAK; } } // 全てのボタンIDを取得 int[] btnWorkID = new int[0]; buttonControl.GetAllBtnWorkID(ref btnWorkID); // ボタンworkIDの数だけループする for (int i = 0; i < btnWorkID.Length; i++) { // ボタンIDを取得 ButtonActionStruct btnStore = buttonControl.Get(btnWorkID[i]); KeyStruct key = new KeyStruct(SystemConstants.WORKMEM_TYPE_WORKBTN, btnWorkID[i]); // 加工値メモリが存在しない場合は、デフォルト値で補う if (!map.ContainsKey(key)) { Set(SystemConstants.WORKMEM_TYPE_WORKBTN, btnWorkID[i], btnStore.DefaultMode.ToString()); } } return result; }
private static extern int InsertLow(IntPtr handle, IntPtr txnhandle, ref KeyStruct key, ref RecordStruct record, int flags);
public void NativeDiskWriteReadCache() { using var session = fht.NewSession(new Functions()); InputStruct input = default; for (int i = 0; i < 2000; i++) { var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i, vfield2 = i + 1 }; session.Upsert(ref key1, ref value, Empty.Default, 0); } session.CompletePending(true); // Evict all records from main memory of hybrid log fht.Log.FlushAndEvict(true); // Read 2000 keys - all should be served from disk, populating and evicting the read cache FIFO for (int i = 0; i < 2000; i++) { OutputStruct output = default; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i, vfield2 = i + 1 }; var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0); Assert.IsTrue(status.IsPending); session.CompletePending(true); } // Read last 100 keys - all should be served from cache for (int i = 1900; i < 2000; i++) { OutputStruct output = default; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i, vfield2 = i + 1 }; var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0); Assert.IsTrue(status.Found); Assert.AreEqual(value.vfield1, output.value.vfield1); Assert.AreEqual(value.vfield2, output.value.vfield2); } // Evict the read cache entirely fht.ReadCache.FlushAndEvict(true); // Read 100 keys - all should be served from disk, populating cache for (int i = 1900; i < 2000; i++) { OutputStruct output = default; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i, vfield2 = i + 1 }; var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0); Assert.IsTrue(status.IsPending); session.CompletePending(true); } // Read 100 keys - all should be served from cache for (int i = 1900; i < 2000; i++) { OutputStruct output = default; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i, vfield2 = i + 1 }; var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0); Assert.IsTrue(status.Found); Assert.AreEqual(value.vfield1, output.value.vfield1); Assert.AreEqual(value.vfield2, output.value.vfield2); } // Upsert to overwrite the read cache for (int i = 1900; i < 1950; i++) { var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i + 1, vfield2 = i + 2 }; session.Upsert(ref key1, ref value, Empty.Default, 0); } // RMW to overwrite the read cache for (int i = 1950; i < 2000; i++) { OutputStruct output = default; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; input = new InputStruct { ifield1 = 1, ifield2 = 1 }; var status = session.RMW(ref key1, ref input, ref output, Empty.Default, 0); if (status.IsPending) { session.CompletePending(true); } else { Assert.AreEqual(i + 1, output.value.vfield1); Assert.AreEqual(i + 2, output.value.vfield2); } } // Read 100 keys for (int i = 1900; i < 2000; i++) { OutputStruct output = default; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var value = new ValueStruct { vfield1 = i + 1, vfield2 = i + 2 }; var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0); Assert.IsTrue(status.Found); Assert.AreEqual(value.vfield1, output.value.vfield1); Assert.AreEqual(value.vfield2, output.value.vfield2); } }
public static unsafe int InsertRecNo(IntPtr handle, IntPtr txnhandle, ref byte[] keydata, byte[] recordData, int flags) { KeyStruct key = new KeyStruct(); RecordStruct record = new RecordStruct(); fixed (byte* br = recordData) { record.data = br; record.size = recordData.GetLength(0); key.data = null; key.size = 0; int st = InsertLow(handle, txnhandle, ref key, ref record, flags); if (st != 0) return st; IntPtr keyData = new IntPtr(key.data); byte[] newKeyData = new byte[key.size]; Marshal.Copy(keyData, newKeyData, 0, key.size); keydata = newKeyData; return 0; } }
public void SessionTest5() { var session = fht.NewSession(new Functions()); InputStruct input = default; OutputStruct output = default; var key1 = new KeyStruct { kfield1 = 16, kfield2 = 17 }; var value1 = new ValueStruct { vfield1 = 26, vfield2 = 27 }; session.Upsert(ref key1, ref value1, Empty.Default, 0); var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == value1.vfield1); Assert.IsTrue(output.value.vfield2 == value1.vfield2); session.Dispose(); session = fht.NewSession(new Functions()); var key2 = new KeyStruct { kfield1 = 17, kfield2 = 18 }; var value2 = new ValueStruct { vfield1 = 27, vfield2 = 28 }; session.Upsert(ref key2, ref value2, Empty.Default, 0); status = session.Read(ref key2, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } status = session.Read(ref key2, ref input, ref output, Empty.Default, 0); if (status == Status.PENDING) { session.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == value2.vfield1); Assert.IsTrue(output.value.vfield2 == value2.vfield2); session.Dispose(); }
public static unsafe int Insert(IntPtr handle, IntPtr txnhandle, byte[] keyData, byte[] recordData, int flags) { KeyStruct key = new KeyStruct(); RecordStruct record = new RecordStruct(); fixed (byte* br = recordData, bk = keyData) { record.data = br; record.size = recordData.GetLength(0); key.data = bk; key.size = (short)keyData.GetLength(0); return InsertLow(handle, txnhandle, ref key, ref record, flags); } }
internal static SecurityStatus SafeQueryContextAttribute( SafeContextHandle handle, ContextQueryAttrib attribute, ref byte[] buffer ) { bool gotRef = false; SecurityStatus status = SecurityStatus.InternalError; RuntimeHelpers.PrepareConstrainedRegions(); int pointerSize = System.Environment.Is64BitOperatingSystem ? 8 : 4; //NOTE: update this when 128 bit processors exist IntPtr alloc_buffer = Marshal.AllocHGlobal(sizeof(uint) + pointerSize); //NOTE: this is at most 4 + sizeof(void*) bytes //see struct SecPkgContext_SessionKey // https://msdn.microsoft.com/en-us/library/windows/desktop/aa380096(v=vs.85).aspx try { handle.DangerousAddRef(ref gotRef); } catch (Exception) { if (gotRef) { handle.DangerousRelease(); gotRef = false; buffer = null; } throw; } finally { if (gotRef) { status = ContextNativeMethods.QueryContextAttributes( ref handle.rawHandle, attribute, alloc_buffer ); if (status == SecurityStatus.OK) { KeyStruct key = new KeyStruct(); Marshal.PtrToStructure(alloc_buffer, key); // fit to the proper size, read a byte[] byte[] sizedBuffer = new byte[key.size]; for (int i = 0; i < key.size; i++) { sizedBuffer[i] = Marshal.ReadByte(key.data, i); } buffer = sizedBuffer; } handle.DangerousRelease(); } } Marshal.FreeHGlobal(alloc_buffer); return(status); }
public static unsafe int Erase(IntPtr handle, IntPtr txnhandle, byte[] data, int flags) { KeyStruct key = new KeyStruct(); fixed (byte* b = data) { key.data = b; key.size = (short)data.GetLength(0); return EraseLow(handle, txnhandle, ref key, flags); } }