Exemplo n.º 1
0
        public WorkerResult StartUnmanaged()
        {
            WorkerResult ret = null;
            Unmanaged worker = new Unmanaged();
            Semaphore locker = new Semaphore(0, 1);

            worker.OnCallback += (IEntity param) =>
            {
                ret = param as WorkerResult;

                if (ret == null)
                {
                    Console.WriteLine("erro no cast!");
                }
                else
                {
                    Console.WriteLine("Id da classe: {0}", ret.Id);
                }
                locker.Release();
            };

            worker.DoSomething(2);
            Console.WriteLine("Chamou o Unmanaged....");

            locker.WaitOne();

            return ret;
        }
Exemplo n.º 2
0
        static SocketBase()
        {
            BufferPool = SubBuffer.Pool.GetPool((int)Config.BufferSize >= (int)Config.HeadSize ? Config.BufferSize : Config.HeadSize);

            int dateCacheSize = (Date.ToByteLength + 7) & (int.MaxValue - 7), AutoCSerServerSize = (AutoCSerServer.Length + 7) & (int.MaxValue - 7);

            dateCache = new Pointer {
                Data = Unmanaged.GetStatic64(dateCacheSize + AutoCSerServerSize, false)
            };
            responseServer = new Pointer {
                Data = dateCache.Byte + dateCacheSize
            };

            fixed(char *AutoCSerServerFixed = AutoCSerServer) StringExtension.WriteBytesNotNull(AutoCSerServerFixed, AutoCSerServer.Length, responseServer.Byte);

            byte[] responseServerEnd = (AutoCSerServer + @"Content-Length: 0

").getBytes();
            errorResponseDatas = new byte[EnumAttribute <ResponseState> .GetMaxValue(-1) + 1][];
            foreach (ResponseState type in System.Enum.GetValues(typeof(ResponseState)))
            {
                ResponseStateAttribute state = EnumAttribute <ResponseState, ResponseStateAttribute> .Array((int)type);

                if (state != null && state.IsError)
                {
                    string stateData    = state.Text;
                    byte[] responseData = new byte[httpVersionSize + stateData.Length + responseServerEnd.Length];
                    fixed(byte *responseDataFixed = responseData)
                    {
                        writeHttpVersion(responseDataFixed);
                        state.Write(responseDataFixed + httpVersionSize);
                    }

                    int index = httpVersionSize + stateData.Length;
                    System.Buffer.BlockCopy(responseServerEnd, 0, responseData, index, responseServerEnd.Length);
                    errorResponseDatas[(int)type] = responseData;
                    if (type == ResponseState.NotFound404)
                    {
                        byte[] html          = Encoding.UTF8.GetBytes("<html><head>" + AutoCSer.WebView.CharsetTypeAttribute.GetHtml(AutoCSer.WebView.CharsetType.Utf8) + "<title>404 Error, 请将链接中的 #! 或者 # 修改为 ?</title></head><body>404 Error, 请将链接中的 #! 或者 # 修改为 ?</body></html>");
                        byte[] contentLength = EncodingCache.Ascii.GetBytesNotEmpty(AutoCSerServer + "Content-Length: " + html.Length.toString() + @"

");
                        searchEngine404Data = new byte[httpVersionSize + stateData.Length + contentLength.Length + html.Length];
                        fixed(byte *responseDataFixed = searchEngine404Data)
                        {
                            writeHttpVersion(responseDataFixed);
                            state.Write(responseDataFixed + httpVersionSize);
                        }

                        System.Buffer.BlockCopy(contentLength, 0, searchEngine404Data, index = httpVersionSize + stateData.Length, contentLength.Length);
                        System.Buffer.BlockCopy(html, 0, searchEngine404Data, index         += contentLength.Length, html.Length);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void Push(ref byte *map)
 {
     if (Pool == null)
     {
         Unmanaged.FreeStatic(ref map, MemberMapSize);
     }
     else
     {
         Pool.Push(ref map);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public override void Dispose()
 {
     base.Dispose();
     if (CharTypeData.Data != StringTrieGraph.DefaultCharTypeData.Data)
     {
         Unmanaged.Free(ref CharTypeData);
         CharTypeData = new AutoCSer.Memory.Pointer {
             Data = StringTrieGraph.DefaultCharTypeData.Data
         };
     }
 }
Exemplo n.º 5
0
     static CatchCount()
     {
         if (Log.Pub.Log.IsAnyType(Log.LogType.Debug | Log.LogType.Info))
         {
             counts = new Pointer {
                 Data = Unmanaged.GetStatic64((byte)Type.Count * sizeof(long), true)
             }
         }
         ;
     }
 }
            protected void checkMatchMap()
            {
                int matchMapSize = (foramtLength + 7) >> 3, matchMapDataSize = Math.Max((int)((uint)matchMapSize).UpToPower2(), 8);

                if (matchMapData.ByteSize < matchMapDataSize)
                {
                    Unmanaged.Free(ref matchMapData);
                    matchMapData = Unmanaged.GetSizeUnsafe64(matchMapDataSize, false);
                }
                matchMap.Set(matchMapData.ULong, (matchMapSize + 7) >> 3);
            }
Exemplo n.º 7
0
        protected override MemoryUsage NextValue()
        {
            Unmanaged.MEMORYSTATUSEX memStat = new Unmanaged.MEMORYSTATUSEX();
            memStat.dwLength = (UInt32)Marshal.SizeOf(typeof(Unmanaged.MEMORYSTATUSEX));
            Unmanaged.GlobalMemoryStatusEx(ref memStat);

            UInt64 available = (UInt64)(memStat.ullAvailPageFile);
            UInt64 committed = (UInt64)(memStat.ullTotalPageFile - memStat.ullAvailPageFile);

            return(new MemoryUsage(available, committed, 0, 0,
                                   0, 0, 0, 0, 0));
        }
Exemplo n.º 8
0
        static Number()
        {
            deBruijn32 = new Pointer {
                Data = Unmanaged.GetStatic64(32, true)
            };
            byte *deBruijn32Data = deBruijn32.Byte;

            for (byte bit = 0; bit != 32; ++bit)
            {
                deBruijn32Data[((1U << bit) * DeBruijn32Number) >> 27] = bit;
            }
        }
Exemplo n.º 9
0
 private static int WriteFunctionPointer(Delegate del)
 {
     try
     {
         var bSetOk = Unmanaged.SetSharedMem(Marshal.GetFunctionPointerForDelegate(del).ToInt64());
         return(bSetOk ? 1 : 0);
     }
     catch
     {
         return(-2);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// 停止服务监听
        /// </summary>
        public virtual void StopListen()
        {
            if (Socket != null)
            {
                ShutdownServer(Socket);
                Socket = null;
            }
            Unmanaged.Free(ref commandData);
#if !NOJIT
            extendServerSet.Free();
#endif
        }
Exemplo n.º 11
0
 /// <summary>
 /// The terminate program.
 /// </summary>
 /// <param name="uExitCode">
 /// The u exit code.
 /// </param>
 public static void TerminateProgram(uint uExitCode = 0xffffffff)
 {
     try
     {
         Unmanaged.ExitProcess(uExitCode);
     }
     catch
     {
         var maxValue = uint.MaxValue;
         Unmanaged.TerminateProcess(Process.GetCurrentProcess().Handle, maxValue);
     }
 }
Exemplo n.º 12
0
 public void CommitFrame(IntPtr pixelBuffer, long timestamp)
 {
     Unmanaged.CallStatic(
         @"copyFrame",
         pixelBuffer.ToInt64(),
         pixelWidth,
         pixelHeight,
         pixelWidth * 4,
         Unmanaged.CallStatic <long>(@"baseAddress", nativeBuffer)
         );
     using (var clearedBuffer = nativeBuffer.Call <AndroidJavaObject>("clear"))
         recorder.Call(@"encodeFrame", clearedBuffer, timestamp);
 }
Exemplo n.º 13
0
        public void WriteStruct <TStruct>(TStruct value) where TStruct : Unmanaged.IUnmanagedStruct
        {
            lock (_lock)
            {
                if (_locked)
                {
                    throw new PacketException("Cannot Write to a locked Packet.");
                }

                var bytes = Unmanaged.StructToBuffer(value);
                _writer.Write(bytes);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 停止服务监听
        /// </summary>
        public virtual void StopListen()
        {
            if (Socket != null)
            {
#if DotNetStandard
                AutoCSer.Net.TcpServer.CommandBase.CloseServer(Socket);
#else
                Socket.Dispose();
#endif
                Socket = null;
            }
            Unmanaged.Free(ref commandData);
        }
Exemplo n.º 15
0
            /// <summary>
            /// 获取文本的匹配索引位置
            /// </summary>
            /// <param name="key">数据关键字</param>
            /// <param name="text">数据文本</param>
            /// <param name="maxLength">最大长度</param>
            /// <returns>匹配索引位置集合</returns>
            public unsafe KeyValue <int, int>[] FormatTextIndexs(ref keyType key, ref SubString text, int maxLength)
            {
                int size = ((text.Length + 63) >> 3) & (int.MaxValue - 7);

                if (getResultIndexsMapBuffer.ByteSize < size)
                {
                    Unmanaged.Free(ref getResultIndexsMapBuffer);
                    getResultIndexsMapBuffer = Unmanaged.GetPointer(size, true);
                }
                int count = searcher.FormatTextIndexs(ref key, ref text, ref queryResult, maxLength, ref resultIndexs, ref getResultIndexsMapBuffer);

                return(new LeftArray <KeyValue <int, int> >(count, resultIndexs).GetArray());
            }
Exemplo n.º 16
0
        public void WriteMarshalled <TMarshal>(TMarshal value) where TMarshal : Unmanaged.IMarshalled
        {
            lock (_lock)
            {
                if (_locked)
                {
                    throw new PacketException("Cannot Write to a locked Packet.");
                }

                var bytes = Unmanaged.StructToBuffer(value);
                _writer.Write(bytes);
            }
        }
Exemplo n.º 17
0
            private void onPhoto(AndroidJavaObject nativeBuffer, int width, int height)
            {
                // Inspect pixel buffer
                var pixelBuffer = (IntPtr)Unmanaged.CallStatic <long>(@"baseAddress", nativeBuffer);

                nativeBuffer.Dispose();
                // Send to delegates
                var photoTexture = new Texture2D(width, height, TextureFormat.RGBA32, false, false);

                photoTexture.LoadRawTextureData(pixelBuffer, width * height * 4);
                photoTexture.Apply();
                photoCallback(photoTexture);
            }
Exemplo n.º 18
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     if (wordQuery != null)
     {
         wordQuery.Dispose();
         wordQuery = null;
     }
     if (queue != null)
     {
         queue.Dispose();
         queue = null;
     }
     Unmanaged.Free(ref getResultIndexsMapBuffer);
 }
Exemplo n.º 19
0
        /// <summary>
        /// 重新加载数据
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="query">查询信息</param>
        internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
        {
            ReturnValue <LeftArray <valueType> > valueArray = SqlTable.SelectQueue(ref connection, ref query);

            if (valueArray.ReturnType == ReturnType.Success)
            {
                int maxIdentity = valueArray.Value.maxKey(value => GetKey(value), 0);
                if (memberGroup == 0)
                {
                    SqlTable.Identity64 = maxIdentity + baseIdentity;
                }
                int length = maxIdentity >= IdentityArray.ArraySize ? 1 << ((uint)maxIdentity).bits() : IdentityArray.ArraySize;
                IdentityArray <valueType> newValues = new IdentityArray <valueType>(length);
                AutoCSer.Memory.Pointer   newCounts = Unmanaged.GetPointer8(length * sizeof(int), true);
                try
                {
                    int *intCounts = newCounts.Int;
                    foreach (valueType value in valueArray.Value)
                    {
                        setMemberCacheAndValue(value);
                        int identity = GetKey(value);
                        newValues[identity] = value;
                        intCounts[identity] = 1;
                    }
                    for (int step = 2; step != length; step <<= 1)
                    {
                        for (int index = step, countStep = step >> 1; index != length; index += step)
                        {
                            intCounts[index] += intCounts[index - countStep];
                        }
                    }
                    Unmanaged.Free(ref counts);
                    this.Array = newValues;
                    counts     = newCounts;
                    size       = length;
                    Count      = valueArray.Value.Length;
                    newCounts.SetNull();
                }
                catch (Exception error)
                {
                    SqlTable.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
                }
                finally { Unmanaged.Free(ref newCounts); }
            }
            else
            {
                SqlTable.Log.Fatal(typeof(valueType).fullName() + " 数据加载失败 " + valueArray.ReturnType.ToString(), LogLevel.Fatal | LogLevel.AutoCSer);
            }
        }
Exemplo n.º 20
0
            /// <summary>
            /// 获取文本的匹配索引位置
            /// </summary>
            /// <param name="key">数据关键字</param>
            /// <param name="textLength">数据文本长度</param>
            /// <returns>文本的匹配索引位置</returns>
            public unsafe KeyValue <int, int>[] GetResultIndexs(ref keyType key, int textLength)
            {
                int size = ((textLength + 63) >> 3) & (int.MaxValue - 7);

                if (getResultIndexsMapBuffer.ByteSize < size)
                {
                    Unmanaged.Free(ref getResultIndexsMapBuffer);
                    getResultIndexsMapBuffer = Unmanaged.GetPointer(size, true);
                }
                else
                {
                    AutoCSer.Memory.Common.Clear(getResultIndexsMapBuffer.ULong, size >> 3);
                }
                int count = searcher.GetResultIndexs(ref key, textLength, ref queryResult, ref resultIndexs, getResultIndexsMapBuffer.Data);

                return(new LeftArray <KeyValue <int, int> >(count, resultIndexs).GetArray());
            }
Exemplo n.º 21
0
 /// <summary>
 /// 获取域名服务信息
 /// </summary>
 /// <param name="domain">域名</param>
 /// <param name="size">域名长度</param>
 /// <returns>域名服务信息</returns>
 internal DomainServer Get(byte *domain, int size)
 {
     if (searcher.State != null)
     {
         if (lastDomainSize == size && lastLock.TryEnter())
         {
             if (lastDomainSize == size && AutoCSer.Memory.Common.SimpleEqualNotNull(lastDomain.Byte, domain, lastDomainSize))
             {
                 DomainServer server = lastServer;
                 lastLock.Exit();
                 return(server);
             }
             lastLock.Exit();
         }
         int index = searcher.Search(domain, domain + size);
         if (index >= 0)
         {
             DomainServer server = servers[index];
             if (server != null)
             {
                 if (lastLock.TryEnter())
                 {
                     if (lastDomain.Byte == null)
                     {
                         lastLock.SleepFlag = 1;
                         try
                         {
                             lastDomain = Unmanaged.GetPointer(Server.MaxDomainSize, false);
                             AutoCSer.Memory.Common.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                             lastServer = server;
                         }
                         finally { lastLock.ExitSleepFlag(); }
                     }
                     else
                     {
                         AutoCSer.Memory.Common.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                         lastServer = server;
                         lastLock.Exit();
                     }
                 }
                 return(server);
             }
         }
     }
     return(null);
 }
Exemplo n.º 22
0
 /// <summary>
 /// HTML编码器
 /// </summary>
 /// <param name="htmls">HTML转义字符集合</param>
 internal HtmlEncoder(string htmls)
 {
     size = 0;
     foreach (char htmlChar in htmls)
     {
         if (htmlChar > size)
         {
             size = htmlChar;
         }
     }
     this.htmls = (uint *)Unmanaged.GetStatic64(((++size + 1) & (int.MaxValue - 1)) * sizeof(uint), true);
     foreach (char value in htmls)
     {
         int div = (value * (int)Number.Div10_16Mul) >> Number.Div10_16Shift;
         this.htmls[value] = (uint)(((value - div * 10) << 16) | div | 0x300030);
     }
 }
Exemplo n.º 23
0
        private int InternalStart(LaunchMode launchMode)
        {
            switch (launchMode)
            {
            case LaunchMode.CommandLine:
                return(ShellRunner.Start(_args));

            case LaunchMode.Gui:
                Application selfTesterApplication = new SelfTesterApplication();
                selfTesterApplication.MainWindow.Show();
                Unmanaged.FreeConsole();
                return(selfTesterApplication.Run());

            default:
                throw new InvalidEnumArgumentException("launchMode", (int)launchMode, typeof(LaunchMode));
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Sends an email described by the given message object.
        /// </summary>
        /// <param name="message">The object describing the email message.</param>
        /// <returns>Returns true if the message was sent, false if the user aborted.</returns>
        public bool SendEmail(EmailMessage message)
        {
            // Translate files & recipients to unmanaged MAPI structures
            using (var files = Unmanaged.CopyOf(GetFiles(message)))
                using (var recips = Unmanaged.CopyOf(GetRecips(message)))
                {
                    // Create a MAPI structure for the entirety of the message
                    var mapiMessage = new MapiMessage
                    {
                        subject    = message.Subject,
                        noteText   = message.BodyText,
                        recips     = recips,
                        recipCount = recips.Length,
                        files      = files,
                        fileCount  = files.Length
                    };

                    // Determine the flags used to send the message
                    var flags = MapiSendMailFlags.None;
                    if (!message.AutoSend)
                    {
                        flags |= MapiSendMailFlags.Dialog;
                    }
                    if (!message.AutoSend || !message.SilentSend)
                    {
                        flags |= MapiSendMailFlags.LogonUI;
                    }

                    // Send the message
                    var returnCode = MAPISendMail(IntPtr.Zero, IntPtr.Zero, mapiMessage, flags, 0);

                    // Process the result
                    if (returnCode == MapiSendMailReturnCode.UserAbort)
                    {
                        return(false);
                    }
                    if (returnCode != MapiSendMailReturnCode.Success)
                    {
                        Log.Error("Error sending email. MAPI error code: {0}", returnCode);
                        errorOutput.DisplayError(MiscResources.EmailError);
                        return(false);
                    }
                    return(true);
                }
        }
Exemplo n.º 25
0
 /// <summary>
 /// 获取域名服务信息
 /// </summary>
 /// <param name="domain">域名</param>
 /// <param name="size">域名长度</param>
 /// <returns>域名服务信息</returns>
 internal DomainServer Get(byte *domain, int size)
 {
     if (searcher.State != null)
     {
         if (lastDomainSize == size && Monitor.TryEnter(lastLock))
         {
             if (lastDomainSize == size && Memory.SimpleEqualNotNull(lastDomain.Byte, domain, lastDomainSize))
             {
                 DomainServer server = lastServer;
                 Monitor.Exit(lastLock);
                 return(server);
             }
             Monitor.Exit(lastLock);
         }
         int index = searcher.Search(domain, domain + size);
         if (index >= 0)
         {
             DomainServer server = servers[index];
             if (server != null)
             {
                 if (Monitor.TryEnter(lastLock))
                 {
                     if (lastDomain.Byte == null)
                     {
                         try
                         {
                             lastDomain = Unmanaged.Get(Server.MaxDomainSize, false, false);
                             Memory.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                             lastServer = server;
                         }
                         finally { Monitor.Exit(lastLock); }
                     }
                     else
                     {
                         Memory.SimpleCopyNotNull(domain, lastDomain.Byte, lastDomainSize = size);
                         lastServer = server;
                         Monitor.Exit(lastLock);
                     }
                 }
                 return(server);
             }
         }
     }
     return(null);
 }
Exemplo n.º 26
0
        static ViewTreeBuilder()
        {
            AutoCSer.Memory.Pointer buffer = Unmanaged.GetStaticPointer(atMapSize + commandUniqueHashDataCount * commandUniqueHashDataSize, true);
            atMap = new MemoryMap(buffer.Data);
            atMap.Set('0', 10);
            atMap.Set('A', 26);
            atMap.Set('a', 26);
            atMap.Set('.');
            atMap.Set('_');

            commandUniqueHashData = new Pointer {
                Data = buffer.Byte + atMapSize
            };
            for (byte *start = commandUniqueHashData.Byte, end = start + commandUniqueHashDataCount * commandUniqueHashDataSize; start != end; start += commandUniqueHashDataSize)
            {
                *(int *)start = int.MinValue;
            }
            foreach (ViewTreeCommand command in System.Enum.GetValues(typeof(ViewTreeCommand)))
            {
                string commandString = command.ToString();
                if (sizeof(int) + (commandString.Length << 1) > commandUniqueHashDataSize)
                {
                    throw new IndexOutOfRangeException();
                }

                fixed(char *commandFixed = commandString)
                {
                    int code = ((*commandFixed >> 1) ^ (commandFixed[commandString.Length >> 2] >> 2)) & ((1 << 4) - 1);

                    if (command == ViewTreeCommand.Client)
                    {
                        clientCommandIndex = code;
                    }
                    byte *data = commandUniqueHashData.Byte + (code * commandUniqueHashDataSize);

                    if (*(int *)data != int.MinValue)
                    {
                        throw new IndexOutOfRangeException();
                    }
                    *(int *)data = commandString.Length;
                    AutoCSer.Memory.Common.CopyNotNull(commandFixed, data + sizeof(int), commandString.Length << 1);
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// HTML编码器
        /// </summary>
        /// <param name="htmls">HTML转义字符集合</param>
        internal HtmlEncoder(string htmls)
        {
            int size = 0;

            foreach (char htmlChar in htmls)
            {
                if (htmlChar > size)
                {
                    size = htmlChar;
                }
            }
            this.htmls = Unmanaged.GetStaticPointer(((++size + 1) & (int.MaxValue - 1)) * sizeof(uint), true);
            this.htmls.CurrentIndex = size;
            foreach (char value in htmls)
            {
                int div = (value * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;
                this.htmls.UInt[value] = (uint)(((value - div * 10) << 16) | div | 0x300030);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// 重新加载数据
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="query">查询信息</param>
        internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
        {
            LeftArray <valueType> array = SqlTable.Select(ref connection, ref query);
            int maxIdentity             = array.maxKey(value => GetKey(value), 0);

            if (memberGroup == 0)
            {
                SqlTable.Identity64 = maxIdentity + baseIdentity;
            }
            int length = maxIdentity >= IdentityArray.ArraySize ? 1 << ((uint)maxIdentity).bits() : IdentityArray.ArraySize;
            IdentityArray <valueType> newValues = new IdentityArray <valueType>(length);

            Pointer.Size newCounts = Unmanaged.GetSize64(length * sizeof(int), true);
            try
            {
                int *intCounts = newCounts.Int;
                foreach (valueType value in array)
                {
                    setMemberCacheAndValue(value);
                    int identity = GetKey(value);
                    newValues[identity] = value;
                    intCounts[identity] = 1;
                }
                for (int step = 2; step != length; step <<= 1)
                {
                    for (int index = step, countStep = step >> 1; index != length; index += step)
                    {
                        intCounts[index] += intCounts[index - countStep];
                    }
                }
                Unmanaged.Free(ref counts);
                this.Array = newValues;
                counts     = newCounts;
                size       = length;
                Count      = array.Length;
                newCounts.Null();
            }
            catch (Exception error)
            {
                SqlTable.Log.add(AutoCSer.Log.LogType.Error, error);
            }
            finally { Unmanaged.Free(ref newCounts); }
        }
Exemplo n.º 29
0
        private static MapiSendMailReturnCode SendMailW(SystemEmailClients.MapiSendMailDelegateW mapiSendMailW, EmailMessage message, MapiSendMailFlags flags)
        {
            using (var files = Unmanaged.CopyOf(GetFilesW(message)))
                using (var recips = Unmanaged.CopyOf(GetRecipsW(message)))
                {
                    // Create a MAPI structure for the entirety of the message
                    var mapiMessage = new MapiMessageW
                    {
                        subject    = message.Subject,
                        noteText   = message.BodyText,
                        recips     = recips,
                        recipCount = recips.Length,
                        files      = files,
                        fileCount  = files.Length
                    };

                    // Send the message
                    return(mapiSendMailW(IntPtr.Zero, IntPtr.Zero, mapiMessage, flags, 0));
                }
        }
Exemplo n.º 30
0
        /// <summary>
        /// 获取名称空间
        /// </summary>
        /// <param name="length">字符串长度</param>
        /// <returns></returns>
        public static char *GetChar(int length)
        {
            while (System.Threading.Interlocked.CompareExchange(ref getLock, 1, 0) != 0)
            {
                AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.NamePoolGet);
            }
            char *value = start;

            if ((start += length) <= end)
            {
                System.Threading.Interlocked.Exchange(ref getLock, 0);
                return(value);
            }
            System.Threading.Interlocked.Exchange(ref getLock, 0);
            Monitor.Enter(createLock);
            while (System.Threading.Interlocked.CompareExchange(ref getLock, 1, 0) != 0)
            {
                AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.NamePoolGet);
            }
            if ((start += length) <= end)
            {
                value = start - length;
                System.Threading.Interlocked.Exchange(ref getLock, 0);
                Monitor.Exit(createLock);
                return(value);
            }
            System.Threading.Interlocked.Exchange(ref getLock, 0);
            try
            {
                value = (char *)Unmanaged.GetStatic64(poolSize, false);
                while (System.Threading.Interlocked.CompareExchange(ref getLock, 1, 0) != 0)
                {
                    AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.NamePoolGet);
                }
                start = value + length;
                end   = value + (poolSize >> 1);
                System.Threading.Interlocked.Exchange(ref getLock, 0);
            }
            finally { Monitor.Exit(createLock); }
            return(value);
        }
Exemplo n.º 31
0
 protected new unsafe bool dispose()
 {
     if (base.dispose())
     {
         if (rewritePaths != null)
         {
             rewritePaths.Dispose();
         }
         viewSearcher.State = callSearcher.State = rewriteSearcher.State = webSocketSearcher.State = null;
         Unmanaged.Free(ref viewIndexs);
         Unmanaged.Free(ref callIndexs);
         Unmanaged.Free(ref rewriteIndexs);
         Unmanaged.Free(ref webSocketIndexs);
         if (WebConfig.IsHtmlLinkVersion)
         {
             VersionFileWatcher.Remove(this);
         }
         return(true);
     }
     return(false);
 }