示例#1
0
        protected void ThreadExitHandler(ThreadProxy thread)
        {
            Disposed = true;
            OnExit();
            lock (mInputLock)
            {
                if (mInput != null)
                {
                    mInput.Clear();
                }
                mInput = null;
            }

            lock (mOutputLock)
            {
                if (mOutput != null)
                {
                    mOutput.Clear();
                }
                mOutput = null;
            }

            mThread     = null;
            mInputLock  = null;
            mOutputLock = null;
        }
示例#2
0
        protected override void onDispose()
        {
            base.onDispose();
            handler.PostDelayed(new Runnable(() =>
            {
                ThreadProxy.getInstance().execute(new Runnable(() =>
                {
                    if (session.receiveByteNum == 0 && session.bytesSent == 0)
                    {
                        return;
                    }

                    string configFileDir = $"{VPNConstants.CONFIG_DIR}{TimeFormatUtil.formatYYMMDDHHMMSS(session.vpnStartTime)}";
                    var parentFile       = new File(configFileDir);

                    if (!parentFile.Exists())
                    {
                        parentFile.Mkdirs();
                    }

                    var file = new File(parentFile, session.getUniqueName());

                    if (file.Exists())
                    {
                        return;
                    }

                    ACache configACache = ACache.get(parentFile);

                    configACache.put(session.getUniqueName(), session);
                }));
            }), 1000);
        }
示例#3
0
        protected ThreadResult Update(ThreadProxy thread)
        {
            ActorCmd[] cmdList = null;
            lock (mInputLock)
            {
                if (mInput.Count > 0)
                {
                    cmdList = mInput.ToArray();
                    mInput.Clear();
                }
            }

            if (cmdList != null)
            {
                foreach (ActorCmd cmd in cmdList)
                {
                    if (OnCmd(cmd) == ThreadResult.Stop)
                    {
                        mLogger.LogInfo("命令" + cmd.Cmd + "关闭了线程", "Update");
                        return(ThreadResult.Stop);
                    }
                }
            }

            ThreadResult result = OnUpdate(thread);

            return(result);
        }
示例#4
0
        public void CreateReview(string domainKey, string threadType, Guid itemId, string itemTitle, string message, decimal?rating, string status)
        {
            var cs          = SystemManager.GetCommentsService();
            var authorProxy = new AuthorProxy(ClaimsManager.GetCurrentUserId().ToString());

            var domainProxy = new GroupProxy("TestDomain", "TestDomainDescription", authorProxy)
            {
                Key = domainKey
            };

            cs.CreateGroup(domainProxy);

            var culture = this.GetCurrentCulture();

            var threadProxy = new ThreadProxy(itemTitle, threadType, domainKey, authorProxy)
            {
                Key = itemId.ToString() + "_" + culture + "_review", Language = culture
            };
            var thread = cs.CreateThread(threadProxy);

            DateTime dateCreated = DateTime.UtcNow.AddMinutes(5);

            var commentProxy = new CommentProxy(message, thread.Key, authorProxy, SystemManager.CurrentHttpContext.Request.UserHostAddress, rating)
            {
                Status = status, DateCreated = dateCreated
            };

            cs.CreateComment(commentProxy);
        }
示例#5
0
        private ManualResetEvent QueueOperation(OperationDuplex <T> function, T data, ManualResetEvent finishedEvent)
        {
            var threadContainer = new ThreadProxy(ref _engine, function, data, ref finishedEvent);

            ThreadPool.QueueUserWorkItem(a => threadContainer.Start());

            return(finishedEvent);
        }
示例#6
0
        private void refreshAppInfo()
        {
            if (session.appInfo != null)
            {
                return;
            }

            if (PortHostService.getInstance() != null)
            {
                ThreadProxy.getInstance().execute(new Runnable(() =>
                {
                    PortHostService.getInstance().refreshSessionInfo();
                }));
            }
        }
示例#7
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                //
                CheckingBeginEndTime();

                //
                this.ReportView.LocalReport.DataSources.Clear();

                ThreadProxy.QueueUserWorkItem(() =>
                {
                    ICollection dataSource = null;

                    try
                    {
                        UpdateControls(false);

                        _stopWatch.Restart();
                        dataSource = DoQuery();
                    }
                    catch (Exception ex)
                    {
                        dataSource = null;
                        MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        _stopWatch.Stop();
                        UpdateControls(true);
                    }

                    if (dataSource == null)
                    {
                        return;
                    }

                    LogUtility.Debug(string.Format("DoQuery--{0}--耗时{1}ms--记录数{2}", ReportName, _stopWatch.ElapsedMilliseconds, dataSource.Count));

                    this.SetDataSource(dataSource);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void CreateReview(string domainKey, string threadType, Guid itemId, string itemTitle, string message, decimal? rating, string status)
        {
            var cs = SystemManager.GetCommentsService();
            var authorProxy = new AuthorProxy(ClaimsManager.GetCurrentUserId().ToString());

            var domainProxy = new GroupProxy("TestDomain", "TestDomainDescription", authorProxy) { Key = domainKey };
            cs.CreateGroup(domainProxy);

            var threadProxy = new ThreadProxy(itemTitle, threadType, domainKey, authorProxy) { Key = itemId.ToString() + "_en_review", Language = "en" };
            var thread = cs.CreateThread(threadProxy);

            DateTime dateCreated = DateTime.UtcNow.AddMinutes(5);

            var commentProxy = new CommentProxy(message, thread.Key, authorProxy, SystemManager.CurrentHttpContext.Request.UserHostAddress, rating)
                                { Status = status, DateCreated = dateCreated };
            cs.CreateComment(commentProxy);
        }
示例#9
0
 private void OpenSplashScreen()
 {
     _splashSrceen = new SplashScreenManager();
     ThreadProxy.QueueUserWorkItem(() =>
     {
         try
         {
             if (_splashSrceen == null)
             {
                 return;
             }
             _splashSrceen.OpenSplashScreen();
         }
         catch (Exception ex)
         {
             _log.Error(ex.Message, ex);
         }
     });
 }
示例#10
0
 private void CloseSplashScreen()
 {
     ThreadProxy.QueueUserWorkItem(() =>
     {
         try
         {
             if (_splashSrceen == null)
             {
                 return;
             }
             _splashSrceen.CloseSplashScreen();
             _splashSrceen = null;
         }
         catch (Exception ex)
         {
             _log.Error("关闭闪屏时出现问题," + ex.Message, ex);
         }
     });
 }
示例#11
0
        private static void EnsureBlogPostThreadExists(string threadKey, IAuthor author, string threadTitle, BlogsManager manager, string language, ICommentService cs)
        {
            ThreadFilter threadFilter = new ThreadFilter();

            threadFilter.ThreadKey.Add(threadKey);
            var thread = cs.GetThreads(threadFilter).SingleOrDefault();

            if (thread == null)
            {
                var groupKey = ControlUtilities.GetUniqueProviderKey(typeof(BlogsManager).FullName, manager.Provider.Name);

                EnsureBlogPostGroupExists(groupKey, author, cs);

                var threadProxy = new ThreadProxy(threadTitle, typeof(BlogPost).FullName, groupKey, author)
                {
                    Language = language, Key = threadKey
                };
                thread = cs.CreateThread(threadProxy);
            }
        }
示例#12
0
        public ThreadActor(int sleeptime = 100, ILogger logger = null, string name = null)
        {
            if (name == null)
            {
                name = "ThreadActor_" + ActorCount;
            }
            Name = name;
            ActorCount++;

            if (logger == null)
            {
                logger = new DefaultLogger(Name);
            }

            mLogger = logger;
            mInput  = new Queue <ActorCmd>();
            mOutput = new Queue <ActorCmd>();
            mThread = new ThreadProxy(Update, ThreadExitHandler, sleeptime, logger);

            mInputLock  = new object();
            mOutputLock = new object();
        }
示例#13
0
        /// <summary>
        /// 运行
        /// </summary>
        private void Run()
        {
            try
            {
                SubscribeSystemEvents();

                // 系统预检查
                PreCheck();

                // 注册COM控件。
                RegisterCOM();

                InitializeLogSystem();

                GlobalMessageBus.SubscribeApplicationExiting(OnProcessKillingForcedly);

                _framework.Init();
                _framework.Start();
                _framework.WaitForStop();
            }
            catch (TargetInvocationException ex)
            {
                LogManager.GetLogger(LoggerNames.Platform).Error(ex.InnerException);
                MessageBox.Show(ex.InnerException.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(LoggerNames.Platform).Error(ex);
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                LocalMessageBus.Current.RemoveAll();
                ShutdownLogSystem();
                ThreadProxy.Shutdown();
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
        }
示例#14
0
        private static void EnsureBlogPostThreadExists(string threadKey, IAuthor author, string threadTitle, BlogsManager manager, string language, ICommentService cs)
        {
            ThreadFilter threadFilter = new ThreadFilter();
            threadFilter.ThreadKey.Add(threadKey);
            var thread = cs.GetThreads(threadFilter).SingleOrDefault();

            if (thread == null)
            {
                var groupKey = ControlUtilities.GetUniqueProviderKey(typeof(BlogsManager).FullName, manager.Provider.Name);

                EnsureBlogPostGroupExists(groupKey, author, cs);

                var threadProxy = new ThreadProxy(threadTitle, typeof(BlogPost).FullName, groupKey, author) { Language = language, Key = threadKey };
                thread = cs.CreateThread(threadProxy);
            }
        }
示例#15
0
        private CommentResponse PostInternal(CommentCreateRequest request)
        {
            CommentsWebServiceReflector.Validate(request);

            CommentResponse result;

            try
            {
                var author = CommentsUtilitiesReflector.GetAuthor(request);
                var cs     = SystemManager.GetCommentsService();
                var thread = cs.GetThread(request.ThreadKey);

                if (thread == null)
                {
                    request.Thread.Key = request.ThreadKey;

                    CommentsWebServiceReflector.Validate(request.Thread);
                    CommentsWebServiceReflector.ValidatePostRequest(request.Thread.Type, request.Captcha, false);

                    var group = cs.GetGroup(request.Thread.GroupKey);
                    if (group == null)
                    {
                        CommentsWebServiceReflector.Validate(request.Thread.Group);

                        request.Thread.Group.Key = request.Thread.GroupKey;

                        var groupProxy = new GroupProxy(request.Thread.Group.Name, request.Thread.Group.Description, author)
                        {
                            Key = request.Thread.Group.Key
                        };
                        group = cs.CreateGroup(groupProxy);
                    }

                    var threadProxy = new ThreadProxy(request.Thread.Title, request.Thread.Type, group.Key, author)
                    {
                        Key        = request.Thread.Key,
                        Language   = request.Thread.Language,
                        DataSource = request.Thread.DataSource,
                        Behavior   = request.Thread.Behavior
                    };

                    thread = cs.CreateThread(threadProxy);
                }
                else
                {
                    if (thread.IsClosed)
                    {
                        throw new InvalidOperationException("Thread is closed.");
                    }

                    CommentsWebServiceReflector.ValidatePostRequest(thread.Type, request.Captcha, false);
                }

                result = this.SubmitCommentInternal(request, thread, author);
            }
            catch (InvalidOperationException ex)
            {
                throw new InvalidOperationException("Comment cannot be submitted at the moment. Please refresh the page and try again.", ex);
            }

            ServiceUtility.DisableCache();

            return(result);
        }
示例#16
0
        protected override ThreadResult OnUpdate(ThreadProxy thread)
        {
            if (mState == NetState.Close)
            {
                return(ThreadResult.Stop);
            }

            if (mState != NetState.Connected)
            {
                return(ThreadResult.Sleep);
            }

            Socket socket = mSocket;

            if (socket == null)
            {
                mLogger.LogError("socket == null", "OnUpdate");
                return(ThreadResult.Stop);
            }

            if (!socket.Connected)
            {
                mLogger.LogError("socket.Connected = false", "OnUpdate");
                return(ThreadResult.Stop);
            }

            try
            {
                //利用socket本身的buff包,先收头,再收尾,满一个包,再从头开始,如此循环
                //if (MsgTransferLog)
                //    mLogger.LogInfo("Start recv data, position =" + mPosition + ", NeedSize =" + mNeedSize, "OnUpdate");

                int allLen = mPosition + mNeedSize;
                if (allLen > mBuffSize)
                {
                    throw new Exception("allLen > mBuffSize,need = " + allLen + ", current = " + mBuffSize);
                }

                int recvLen = socket.Receive(mBuffer, mPosition, mNeedSize, SocketFlags.None);
                if (recvLen < 1)
                {
                    mLogger.LogInfo(
                        "recvLen =" + recvLen +
                        ", socket.Connected = " + socket.Connected +
                        ", May be the server is close", "OnUpdate");

                    CloseSocket(socket);
                    return(ThreadResult.ErrorStop);
                }

                mPosition += recvLen;
                if (recvLen < mNeedSize)
                {
                    mNeedSize -= recvLen;
                    mLogger.LogInfo("mPosition < mNeedSize, recv = " + recvLen + ",  need = " + mNeedSize, "OnUpdate");
                    //下一次循环再收
                    return(ThreadResult.Just);
                }
            }
            catch (SocketException e)
            {
                mLogger.LogError("recv data error: " + e.Message, "OnUpdate");

                if ((SocketError)e.ErrorCode == SocketError.ConnectionAborted)
                {
                    //서버에서 끊어진건데 클라이언트가 끊을때도 나옴

                    CloseSocket(socket);
                    return(ThreadResult.ErrorStop);
                }

                mLogger.LogError("Socket Disconnect - " + String.Format("{0}({1})", e.ErrorCode, ((SocketError)e.ErrorCode).ToString()));

                CloseSocket(socket);
                return(ThreadResult.Stop);
            }

            //消息定义
            if (mIsHead)
            {
                Int16 msglen = 0;
                mReader.ReadI16(ref msglen);
                if (msglen < HEAD_SIZE)
                {
                    mLogger.LogError("msglen < HEAD_SIZE", "OnUpdate");
                    return(ThreadResult.Stop);
                }

                mReader.SetLength(msglen);

                //剩下读消息主体
                mNeedSize = msglen - HEAD_SIZE;
                if (mNeedSize == 0)
                {
                    //只有消息头的资源
                    ProcessMsg(mReader, mPosition);
                    mIsHead = true;
                }
                else
                {
                    //因为还没有读完
                    mIsHead = false;
                }
            }
            else
            {
                ProcessMsg(mReader, mPosition);
                //消息主体读完
                mIsHead = true;
            }

            //说明已经读完了
            //有时一个消息就只有包头,内容长度为0
            if (mIsHead)
            {
                mPosition        = 0;
                mReader.Position = 0;
                mNeedSize        = HEAD_SIZE;
            }

            return(ThreadResult.Just);
        }
示例#17
0
        private CommentResponse PostInternal(CommentCreateRequest request)
        {
            CommentsWebServiceReflector.Validate(request);

            CommentResponse result;
            try
            {
                var author = CommentsUtilitiesReflector.GetAuthor(request);
                var cs = SystemManager.GetCommentsService();
                var thread = cs.GetThread(request.ThreadKey);

                if (thread == null)
                {
                    request.Thread.Key = request.ThreadKey;

                    CommentsWebServiceReflector.Validate(request.Thread);
                    CommentsWebServiceReflector.ValidatePostRequest(request.Thread.Type, request.Captcha, false);

                    var group = cs.GetGroup(request.Thread.GroupKey);
                    if (group == null)
                    {
                        CommentsWebServiceReflector.Validate(request.Thread.Group);

                        request.Thread.Group.Key = request.Thread.GroupKey;

                        var groupProxy = new GroupProxy(request.Thread.Group.Name, request.Thread.Group.Description, author)
                        {
                            Key = request.Thread.Group.Key
                        };
                        group = cs.CreateGroup(groupProxy);
                    }

                    var threadProxy = new ThreadProxy(request.Thread.Title, request.Thread.Type, group.Key, author)
                    {
                        Key = request.Thread.Key,
                        Language = request.Thread.Language,
                        DataSource = request.Thread.DataSource,
                        Behavior = request.Thread.Behavior
                    };

                    thread = cs.CreateThread(threadProxy);
                }
                else
                {
                    if (thread.IsClosed)
                        throw new InvalidOperationException("Thread is closed.");

                    CommentsWebServiceReflector.ValidatePostRequest(thread.Type, request.Captcha, false);
                }

                result = this.SubmitCommentInternal(request, thread, author);
            }
            catch (InvalidOperationException ex)
            {
                throw new InvalidOperationException("Comment cannot be submitted at the moment. Please refresh the page and try again.", ex);
            }

            ServiceUtility.DisableCache();

            return result;
        }
示例#18
0
 /// <summary>
 /// 当没有Cmd进来时,就会执行这个
 /// </summary>
 /// <param name="thread"></param>
 /// <returns></returns>
 protected abstract ThreadResult OnUpdate(ThreadProxy thread);