Ejemplo n.º 1
0
        /// <summary>
        /// Processes the incoming request.
        /// </summary>
        protected override void ProcessCustomRequest(ConnectedClient client, DataPacket request,
                                                     out ResponsePacket response, out bool handled)
        {
            response = null;
            handled  = true;

            if (!GetClientInstance(client, out ScadaInstance instance))
            {
                response = new ResponsePacket(request, client.OutBuf);
                response.SetError(ErrorCode.InvalidOperation);
            }
            else if (instance.ProxyMode)
            {
                if (client.RoleID == AgentRoleID.Administrator)
                {
                    // redirect request to remote Agent
                    if (!RedirectRequest(client, instance, request))
                    {
                        response = new ResponsePacket(request, client.OutBuf);
                        response.SetError(ErrorCode.ProxyError);
                    }
                }
                else
                {
                    // redirect response to Administrator
                    RedirectResponse(client, instance, request);
                }
            }
            else
            {
                switch (request.FunctionID)
                {
                case FunctionID.AgentHeartbeat:
                    // no response
                    break;

                case FunctionID.GetServiceStatus:
                    GetServiceStatus(client, instance, request, out response);
                    break;

                case FunctionID.ControlService:
                    ControlService(client, instance, request, out response);
                    break;

                case FunctionID.DownloadFile:
                    DownloadFile(client, request);
                    break;

                case FunctionID.UploadFile:
                    UploadFile(client, request, out response);
                    break;

                default:
                    handled = false;
                    break;
                }
            }
        }