Esempio n. 1
0
        internal static async ValueTask DeleteViewRoute(string viewName, Transaction txn)
        {
            IntPtr keyPtr;
            int    keySize = EntityStoreWriter.CalcStringUtf8Size(viewName) + 1;

            unsafe
            {
                byte *pk = stackalloc byte[keySize];
                KeyUtil.WriteViewRouteKey(pk, viewName);
                keyPtr = new IntPtr(pk);
            }

            var req = new ClrDeleteRequire
            {
                RaftGroupId   = KeyUtil.META_RAFTGROUP_ID,
                KeyPtr        = keyPtr,
                KeySize       = new IntPtr(keySize),
                SchemaVersion = 0,
                ReturnExists  = false,
                DataCF        = -1
            };
            IntPtr reqPtr;

            unsafe { reqPtr = new IntPtr(&req); }
            await HostApi.ExecKVDeleteAsync(txn.Handle, reqPtr);
        }
Esempio n. 2
0
        /// <summary>
        /// 保存编译好的服务组件或视图运行时代码
        /// </summary>
        /// <param name="asmName">eg: sys.HelloService or sys.CustomerView</param>
        internal static ValueTask UpsertAssemblyAsync(bool isService, string asmName, byte[] asmData, Transaction txn)
        {
            IntPtr keyPtr;
            int    keySize = EntityStoreWriter.CalcStringUtf8Size(asmName) + 1;
            IntPtr dataPtr = IntPtr.Zero;

            unsafe
            {
                byte *pk = stackalloc byte[keySize];
                KeyUtil.WriteAssemblyKey(isService, pk, asmName);
                keyPtr = new IntPtr(pk);

                dataPtr = NativeApi.NewNativeString(asmData.Length, out byte *destDataPtr);
                fixed(byte *srcDataPtr = asmData)
                {
                    Buffer.MemoryCopy(srcDataPtr, destDataPtr, asmData.Length, asmData.Length);
                }
            }

            var req = new ClrInsertRequire
            {
                RaftGroupId      = KeyUtil.META_RAFTGROUP_ID,
                KeyPtr           = keyPtr,
                KeySize          = new IntPtr(keySize),
                DataPtr          = dataPtr,
                SchemaVersion    = 0,
                OverrideIfExists = true,
                DataCF           = -1
            };
            IntPtr reqPtr;

            unsafe { reqPtr = new IntPtr(&req); }
            return(HostApi.ExecKVInsertAsync(txn.Handle, reqPtr));
        }
Esempio n. 3
0
        private static ValueTask <INativeData> LoadAssemblyAsync(bool isService, string asmName)
        {
            IntPtr keyPtr;
            int    keySize = EntityStoreWriter.CalcStringUtf8Size(asmName) + 1;

            unsafe
            {
                byte *pk = stackalloc byte[keySize];
                KeyUtil.WriteAssemblyKey(isService, pk, asmName);
                keyPtr = new IntPtr(pk);
            }

            return(StoreApi.Api.ReadIndexByGetAsync(KeyUtil.META_RAFTGROUP_ID, keyPtr, (uint)keySize));
        }
Esempio n. 4
0
        /// <summary>
        /// 保存视图模型路由表
        /// </summary>
        /// <param name="viewName">eg: sys.CustomerList</param>
        /// <param name="path">无自定义路由为空,有上级路由;分隔</param>
        internal static ValueTask UpsertViewRoute(string viewName, string path, Transaction txn)
        {
            //TODO:简化Key与Value编码,直接utf8,各减去3字节字符数标记
            IntPtr keyPtr;
            int    keySize   = EntityStoreWriter.CalcStringUtf8Size(viewName) + 1;
            IntPtr dataPtr   = IntPtr.Zero;
            int    valueSize = EntityStoreWriter.CalcStringUtf8Size(path);

            unsafe
            {
                byte *pk = stackalloc byte[keySize];
                KeyUtil.WriteViewRouteKey(pk, viewName);
                keyPtr = new IntPtr(pk);

                if (!string.IsNullOrEmpty(path))
                {
                    dataPtr = NativeApi.NewNativeString(valueSize, out byte *destDataPtr);
                    var sr = new EntityStoreWriter(destDataPtr, 0);
                    sr.WriteString(path, null);
                }
            }

            var req = new ClrInsertRequire
            {
                RaftGroupId      = KeyUtil.META_RAFTGROUP_ID,
                KeyPtr           = keyPtr,
                KeySize          = new IntPtr(keySize),
                DataPtr          = dataPtr,
                SchemaVersion    = 0,
                OverrideIfExists = true,
                DataCF           = -1
            };
            IntPtr reqPtr;

            unsafe { reqPtr = new IntPtr(&req); }
            return(HostApi.ExecKVInsertAsync(txn.Handle, reqPtr));
        }