Beispiel #1
0
        private void CreateNewKeyedHandler(SessionProviderContext session)
        {
            var pack    = GetMessageEntity <GetCreateRegistryKeyResponsePack>(session);
            var handler = OnKeyCreatedEventHandler;

            handler?.Invoke(this, pack.ParentPath, pack.Match);
        }
Beispiel #2
0
        private void CreateValueHandler(SessionProviderContext session)
        {
            var pack    = GetMessageEntity <GetCreateRegistryValueResponsePack>(session);
            var handler = OnValueCreatedEventHandler;

            handler?.Invoke(this, pack.KeyPath, pack.Value);
        }
Beispiel #3
0
        private void RenameKeyedHandler(SessionProviderContext session)
        {
            var pack    = GetMessageEntity <GetRenameRegistryKeyResponsePack>(session);
            var handler = OnKeyRenamedEventHandler;

            handler?.Invoke(this, pack.ParentPath, pack.OldKeyName, pack.NewKeyName);
        }
Beispiel #4
0
        private void RenameValueHandler(SessionProviderContext session)
        {
            var pack    = GetMessageEntity <GetRenameRegistryValueResponsePack>(session);
            var handler = OnValueRenamedEventHandler;

            handler?.Invoke(this, pack.KeyPath, pack.OldValueName, pack.NewValueName);
        }
Beispiel #5
0
        private void ProcessLogin(SessionProviderContext session)
        {
            LoginPack login = PacketSerializeHelper.DeserializePacket <LoginPack>(session.CompletedBuffer.GetMessagePayload());


            session.AppTokens[2] = login.OpenScreenWall;

            if (this._manager_login_c == 0)
            {
                return;
            }

            LoginPackageModel login_model = new LoginPackageModel()
            {
                Msg             = AJaxMsgCommand.S_SESSION_LOGIN,
                Id              = (string)session.AppTokens[1],
                OS              = login.OSVersion,
                MachineName     = login.MachineName,
                Des             = login.Remark,
                DesktopViewOpen = login.OpenScreenWall.ToString().ToLower()
            };


            this.SendMessage(JsonConvert.SerializeObject(login_model));
        }
Beispiel #6
0
        private void SessionClosed(SessionProviderContext session)
        {
            string id = (string)session.AppTokens[1];

            this._sessionDictionary.Remove(id);

            if (this._manager_login_c == 0)
            {
                return;
            }

            object[]           arguments = session.AppTokens;
            ConnectionWorkType Worktype  = (ConnectionWorkType)arguments[0];

            if (Worktype == ConnectionWorkType.MAINCON)
            {
                SessionCloseModel model = new SessionCloseModel()
                {
                    Msg = AJaxMsgCommand.S_SESSION_CLOSE,
                    Id  = id
                };
                this.SendMessage(JsonConvert.SerializeObject(model));

                this.PutLogQueue("DEBUG Session Closed id:" + id);
            }
        }
        private void SetDataOneEvent(SessionProviderContext session)
        {
            //LogHelper.DebugWriteLog("SetDataOneEvent head:" + string.Join(",", session.CompletedBuffer.Take(2).Select(c => c.ToString()).ToArray()));
            var data = GetMessage(session);

            _workerStreamEvent.SetOneData();
        }
Beispiel #8
0
        private void ScreenSaveHandler(SessionProviderContext session)
        {
            var syncContext = session.AppTokens[SysConstants.INDEX_WORKER].ConvertTo <SessionSyncContext>();
            var status      = syncContext.KeyDictions[SysConstants.HasLaunchDesktopRecord].ConvertTo <bool>();
            var macName     = syncContext.KeyDictions[SysConstants.MachineName].ConvertTo <string>();

            if (!Directory.Exists(Path.Combine("DesktopRecord", macName)))
            {
                Directory.CreateDirectory(Path.Combine("DesktopRecord", macName));
            }

            using (var ms = new MemoryStream(GetMessage(session)))
            {
                string fileName = Path.Combine(Environment.CurrentDirectory, "DesktopRecord", macName, DateTime.Now.ToFileTime() + ".png");
                Image  img      = Image.FromStream(ms);
                img.Save(fileName);
                img.Dispose();
            }

            if (!status)
            {
                return;
            }

            SendTo(session, MessageHead.S_MAIN_DESKTOPRECORD_GETFRAME);
        }
Beispiel #9
0
        private void AddKeyedHandler(SessionProviderContext session)
        {
            var pack    = GetMessageEntity <GetRegistryKeysResponsePack>(session);
            var handler = OnKeysReceivedEventHandler;

            handler?.Invoke(this, pack.RootKey, pack.Matches);
        }
        private void SetOpenEvent(SessionProviderContext session)
        {
            //LogHelper.DebugWriteLog("C_FILE_FRIST_DATA SetOpenEvent head:" + string.Join(",", session.CompletedBuffer.Take(2).Select(c => c.ToString()).ToArray()) /*+ " fileName:" + session.CompletedBuffer.GetMessageEntity<FileFristDownloadDataPack>().fileName*/);
            var data = GetMessage(session);

            _workerStreamEvent.SetOneData(data);
        }
        private byte[] TakeHeadAndMessage(SessionProviderContext session)
        {
            var length = session.CompletedBuffer.Length - sizeof(long);
            var bytes  = new byte[length];

            Array.Copy(session.CompletedBuffer, sizeof(long), bytes, 0, length);
            return(GZipHelper.Decompress(bytes));
        }
 private void SetFilesTriggerEvent(SessionProviderContext session)
 {
     foreach (var file in GetMessageEntity <FileDirectoryFilesPack>(session).Files)
     {
         _filesQueue.Enqueue(file);
     }
     _filesTriggerEvent.Set();
 }
        public override void ContinueTask(SessionProviderContext session)
        {
            this._workerStreamEvent.Reset();
            this._isWorkSessionOfLines = true;
            this._sessionOfLinesEvent.Set();

            base.ContinueTask(session);
        }
        private void PlayerHandler(SessionProviderContext session)
        {
            var data = GetMessage(session);

            using (MemoryStream ms = new MemoryStream(data))
                OnImageFrameHandlerEvent?.Invoke(this, Image.FromStream(ms));

            SendTo(session, MessageHead.S_VIEDO_GET_DATA);
        }
Beispiel #15
0
        private void LoginHandler(SessionProviderContext session)
        {
            try
            {
                var login = GetMessageEntity <LoginPack>(session);
                if (!session.AppTokens[SysConstants.INDEX_WORKER].IsNull())//如果主连接同步对象存在,则对该对象更新
                {
                    this.UpdateSyncContextHandler(session.AppTokens[SysConstants.INDEX_WORKER].ConvertTo <SessionSyncContext>(), login);
                    return;
                }

                var dictions = new Dictionary <string, object>()
                {
                    { SysConstants.IPV4, login.IPV4 },
                    { SysConstants.MachineName, login.MachineName },
                    { SysConstants.Remark, login.Remark },
                    { SysConstants.ProcessorInfo, login.ProcessorInfo },
                    { SysConstants.ProcessorCount, login.ProcessorCount },
                    { SysConstants.MemorySize, login.MemorySize },
                    { SysConstants.StartRunTime, login.StartRunTime },
                    { SysConstants.ServiceVison, login.ServiceVison },
                    { SysConstants.UserName, login.UserName },
                    { SysConstants.OSVersion, login.OSVersion },
                    { SysConstants.GroupName, login.GroupName },
                    { SysConstants.ExistCameraDevice, login.ExistCameraDevice },
                    { SysConstants.ExitsRecordDevice, login.ExitsRecordDevice },
                    { SysConstants.ExitsPlayerDevice, login.ExitsPlayerDevice },
                    { SysConstants.OpenScreenWall, login.OpenScreenWall },
                    { SysConstants.IdentifyId, login.IdentifyId },
                    { SysConstants.OpenScreenRecord, login.OpenScreenRecord },
                    { SysConstants.HasLaunchDesktopRecord, false },
                    { SysConstants.RecordHeight, login.RecordHeight },
                    { SysConstants.RecordWidth, login.RecordWidth },
                    { SysConstants.RecordSpanTime, login.RecordSpanTime },
                    { SysConstants.HasLoadServiceCOM, login.HasLoadServiceCOM }
                };
                var syncContext = new SessionSyncContext(session, dictions);
                SessionSyncContexts.Add(syncContext);
                session.AppTokens[SysConstants.INDEX_WORKER] = syncContext;

                //是否开启桌面视图
                if (syncContext.KeyDictions[SysConstants.OpenScreenWall].ConvertTo <bool>())
                {
                    HasComWithSendTo(session, MessageHead.S_MAIN_CREATE_DESKTOPVIEW, new byte[] { 0 });//TODO : 强制创建视图,此处会触发载入插件
                }

                this.OnLoginHandlerEvent?.Invoke(syncContext);

                this.OnLogHandlerEvent?.Invoke($"计算机:{syncContext.KeyDictions[SysConstants.MachineName].ConvertTo<string>()}({syncContext.KeyDictions[SysConstants.Remark].ConvertTo<string>()}) -->已连接控制端!", LogSeverityLevel.Information);
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorByCurrentMethod(ex);
                //可能是旧版本上线包
            }
        }
Beispiel #16
0
        private void StartScreenRecordTaskHandler(SessionProviderContext session)
        {
            string macName     = GetMessage(session).ToUnicodeString();
            var    syncContext = session.AppTokens[SysConstants.INDEX_WORKER].ConvertTo <SessionSyncContext>();

            syncContext.KeyDictions[SysConstants.HasLaunchDesktopRecord] = true;    //开启
            syncContext.KeyDictions[SysConstants.MachineName]            = macName; //标识名(用计算机名作为唯一标识)

            SendTo(session, MessageHead.S_MAIN_DESKTOPRECORD_GETFRAME);
        }
 /// <summary>
 /// 加载插件
 /// </summary>
 /// <param name="session"></param>
 private void SendServicePlugins(SessionProviderContext session)
 {
     SendTo(session, MessageHead.S_MAIN_PLUGIN_FILES,
            new ServicePluginPack()
     {
         Files = _serviceCOMPlugins.Select(c => new PluginItem()
         {
             FileName = c.Key, PayLoad = c.Value
         }).ToArray()
     });
 }
Beispiel #18
0
 private void GetViewFrame(SessionProviderContext session, IDesktopView view)
 {
     SendTo(session, MessageHead.S_MAIN_DESKTOPVIEW_GETFRAME,
            new DesktopViewGetFramePack()
     {
         Height       = view.Height,
         Width        = view.Width,
         TimeSpan     = this.ViewRefreshInterval,
         InVisbleArea = view.InVisbleArea
     });
 }
Beispiel #19
0
        /// <summary>
        /// 通信完成消息处理方法
        /// </summary>
        /// <param name="session"></param>
        /// <param name="notify"></param>
        private void OnNotifyProc(SessionProviderContext session, TcpSessionNotify notify)
        {
            if (SynchronizationContext.IsNull())
            {
                NotifyProc(null);
            }
            else
            {
                SynchronizationContext.Send(NotifyProc, null);
            }

            void NotifyProc(object @object)
            {
                try
                {
                    switch (notify)
                    {
                    case TcpSessionNotify.OnConnected:
                        //先分配好工作类型,等待工作指令分配新的工作类型
                        session.AppTokens = new object[SysConstants.INDEX_COUNT]
                        {
                            ConnectionWorkType.NONE,    //未经验证的状态
                            null
                        };
                        break;

                    case TcpSessionNotify.OnSend:
                        //耗时操作会导致性能严重降低
                        this.OnTransmitHandlerEvent?.Invoke(session);
                        break;

                    case TcpSessionNotify.OnDataReceiveing:
                        //耗时操作会导致性能严重降低
                        this.OnReceiveHandlerEvent?.Invoke(session);
                        break;

                    case TcpSessionNotify.OnDataReceived:
                        this.OnReceiveComplete(session);
                        break;

                    case TcpSessionNotify.OnClosed:
                        this.OnClosed(session);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteErrorByCurrentMethod(ex);
                }
            }
        }
        public override void SessionClosed(SessionProviderContext session)
        {
            this._isWorkSessionOfLines = false;
            this._filesTriggerEvent.Set();        //释放
            this._sessionOfLinesEvent.Reset();    //阻塞等待重连
            this._workerStreamEvent.SetOneData(); //如果有正在等待数据响应的,则先释放信号,进入重置方法
            LogHelper.DebugWriteLog("close eventSet");
            if (this.WhetherClose)                //如果应用已关闭,则释放退出
            {
                this._sessionOfLinesEvent.Set();
            }

            base.SessionClosed(session);
        }
Beispiel #21
0
        private void OnCreateDesktopView(SessionProviderContext session)
        {
            var describePack = GetMessageEntity <DesktopViewDescribePack>(session);
            var syncContext  = session.AppTokens[SysConstants.INDEX_WORKER].ConvertTo <SessionSyncContext>();
            var view         = this.OnCreateDesktopViewHandlerEvent?.Invoke(syncContext);

            if (view.IsNull())
            {
                return;
            }
            view.Caption = describePack.MachineName + "-(" + describePack.RemarkInformation + ")";
            syncContext.KeyDictions[SysConstants.DesktopView] = view;
            this.GetViewFrame(session, view);
        }
Beispiel #22
0
        /// <summary>
        /// 移除在线信息
        /// </summary>
        /// <param name="session"></param>
        private void OnClosed(SessionProviderContext session)
        {
            try
            {
                object[] arguments = session.AppTokens;
                var      worktype  = arguments[SysConstants.INDEX_WORKTYPE].ConvertTo <ConnectionWorkType>();
                if (worktype == ConnectionWorkType.WORKCON)
                {
                    var adapterHandler = arguments[SysConstants.INDEX_WORKER].ConvertTo <ApplicationAdapterHandler>();

                    if (adapterHandler.WhetherClose)//如果是手动结束任务
                    {
                        return;
                    }

                    adapterHandler.StateContext = "工作连接已断开,正在重新连接中....";
                    adapterHandler.SessionClosed(session);
                    //非手动结束任务,将该任务扔到重连线程中
                    AddSuspendTaskContext(new SuspendTaskContext()
                    {
                        DisconnectTime = DateTime.Now,
                        AdapterHandler = adapterHandler
                    });
                }
                else if (worktype == ConnectionWorkType.MAINCON)
                {
                    var syncContext = arguments[SysConstants.INDEX_WORKER].ConvertTo <SessionSyncContext>();
                    SessionSyncContexts.Remove(syncContext);

                    if (syncContext.KeyDictions.ContainsKey(SysConstants.DesktopView) && syncContext.KeyDictions[SysConstants.DesktopView] != null)
                    {
                        var view = syncContext.KeyDictions[SysConstants.DesktopView].ConvertTo <IDesktopView>();
                        view.CloseDesktopView();
                    }

                    this.OnLogOutHandlerEvent?.Invoke(syncContext);

                    this.OnLogHandlerEvent?.Invoke($"计算机:{syncContext.KeyDictions[SysConstants.MachineName].ConvertTo<string>()}({syncContext.KeyDictions[SysConstants.Remark].ConvertTo<string>()}) --已与控制端断开连接!", LogSeverityLevel.Warning);
                }
                else if (worktype == ConnectionWorkType.NONE)
                {
                    LogHelper.WriteErrorByCurrentMethod("NONE Session Close");
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorByCurrentMethod(ex);
            }
        }
Beispiel #23
0
        private void InitSessionAppToken(SessionProviderContext session)
        {
            string id = "A" + Guid.NewGuid().ToString().Replace("-", "");

            //分配NONE,等待工作指令分配新的工作类型
            session.AppTokens = new object[3]
            {
                ConnectionWorkType.NONE,
                id,
                false//屏幕视图打开状态
            };

            this._sessionDictionary.Add(id, session);
            this.PutLogQueue("DEBUG Session Connect id:" + id);
        }
Beispiel #24
0
        private void CloseDesktopView(dynamic request)
        {
            string id = request.Id;

            if (this._sessionDictionary.ContainsKey(id))
            {
                SessionProviderContext session = this._sessionDictionary[id];
                if ((bool)session.AppTokens[2])
                {
                    session.AppTokens[2] = false;

                    byte[] data = Core.MessageHelper.CopyMessageHeadTo(MessageHead.S_MAIN_DESKTOPVIEW_CLOSE);
                    session.SendAsync(data);
                }
            }
        }
Beispiel #25
0
        /// <summary>
        /// 获取桌面视图
        /// </summary>
        /// <param name="id"></param>
        private void PullDesktopView(string id)
        {
            if (this._sessionDictionary.ContainsKey(id))
            {
                SessionProviderContext session = this._sessionDictionary[id];

                if (!(bool)session.AppTokens[2])
                {
                    return;
                }

                byte[] data = Core.MessageHelper.CopyMessageHeadTo(MessageHead.S_MAIN_DESKTOPVIEW_GETFRAME, _desktopView_width + "|" + _desktopView_height + "|" + _desktopView_spantime);
                session.SendAsync(data);

                this.PutLogQueue("DEBUG pull Image height:" + _desktopView_height + " width:" + _desktopView_width);
            }
        }
Beispiel #26
0
        private void OpenDesktopView(dynamic request)
        {
            string id = request.Id;

            if (this._sessionDictionary.ContainsKey(id))
            {
                SessionProviderContext session = this._sessionDictionary[id];
                if (!(bool)session.AppTokens[2])
                {
                    byte[] data = Core.MessageHelper.CopyMessageHeadTo(MessageHead.S_MAIN_CREATE_DESKTOPVIEW);
                    session.SendAsync(data);

                    session.AppTokens[2] = true;
                    this.PullDesktopView(id);
                }
            }
        }
Beispiel #27
0
        /// <summary>
        /// 确认连接包
        /// </summary>
        /// <param name="session"></param>
        private void ValiditySession(SessionProviderContext session)
        {
            var  ack       = GetMessageEntity <AckPack>(session);
            long accessKey = ack.AccessKey;

            if (accessKey != int.Parse(AppConfiguration.ConnectPassWord))
            {
                session.SessionClose();
                return;
            }
            else
            {
                //连接密码验证通过,设置成为主连接,正式接收处理数据包
                session.AppTokens[SysConstants.INDEX_WORKTYPE] = ConnectionWorkType.MAINCON;
                //告诉服务端一切就绪
                SendTo(session, MessageHead.S_GLOBAL_OK);
            }
        }
Beispiel #28
0
        private void OnMessage(SessionProviderContext session)
        {
            object[]           ars             = session.AppTokens;
            ConnectionWorkType sessionWorkType = (ConnectionWorkType)ars[0];

            if (sessionWorkType == ConnectionWorkType.WORKCON)
            {
                //消息扔给消息提供器,由提供器提供消息给所在窗口进行消息处理
                //((MessageAdapter)ars[1]).OnSessionNotify(session, SessionNotifyType.Message);
            }
            else if (sessionWorkType == ConnectionWorkType.MAINCON)
            {
                MessageHead cmd = session.CompletedBuffer.GetMessageHead <MessageHead>();
                switch (cmd)
                {
                case MessageHead.C_MAIN_LOGIN:    //上线包
                    this.ProcessLogin(session);
                    break;

                case MessageHead.C_MAIN_DESKTOPVIEW_FRAME:    //屏幕视图数据
                    this.ProcessDesktopViewData(session, session.CompletedBuffer.GetMessagePayload());
                    break;
                }
            }
            else if (sessionWorkType == ConnectionWorkType.NONE) //初始消息只能进入该方法块处理,连接密码验证正确才能正式处理消息
            {
                switch (session.CompletedBuffer.GetMessageHead <MessageHead>())
                {
                case MessageHead.C_GLOBAL_CONNECT:    //连接确认包
                                                      //CheckSessionValidity(session);

                    session.AppTokens[0] = ConnectionWorkType.MAINCON;

                    byte[] data = Core.MessageHelper.CopyMessageHeadTo(MessageHead.S_GLOBAL_OK);
                    session.SendAsync(data);

                    break;

                default:
                    session.SessionClose();    //伪造包断掉
                    break;
                }
            }
        }
Beispiel #29
0
        private void ProcessDesktopViewData(SessionProviderContext session, byte[] bytes)
        {
            if (this._manager_login_c == 0)
            {
                return;
            }

            string id = (string)session.AppTokens[1];

            DesktopViewModel model = new DesktopViewModel()
            {
                Msg         = AJaxMsgCommand.S_DESKTOPVIEW_IMG,
                Id          = id,
                ImageBase64 = Convert.ToBase64String(bytes)
            };

            this.SendMessage(JsonConvert.SerializeObject(model));
            this.PutLogQueue("DEBUG ImageProcess id:" + id + " " + bytes.Length / 1024 + "k");
        }
Beispiel #30
0
        private void PlayerDesktopImage(SessionProviderContext session)
        {
            var syncContext = session.AppTokens[SysConstants.INDEX_WORKER].ConvertTo <SessionSyncContext>();

            if (!syncContext.KeyDictions.ContainsKey(SysConstants.DesktopView) ||
                syncContext.KeyDictions[SysConstants.DesktopView].IsNull())
            {
                return;
            }

            var frameData = GetMessageEntity <DesktopViewFramePack>(session);
            var view      = syncContext.KeyDictions[SysConstants.DesktopView].ConvertTo <IDesktopView>();

            if (frameData.InVisbleArea)
            {
                using (var ms = new MemoryStream(frameData.ViewData))
                    view.PlayerDekstopView(Image.FromStream(ms));
            }
            this.GetViewFrame(session, view);
        }