Exemple #1
0
 public void Fire_OperationStarted(Protocol.Request request)
 {
     if (OperationStarted != null)
     {
         OperationStarted(this, request);
     }
 }
Exemple #2
0
 public void Fire_OperationCompleted(Protocol.Request request, Protocol.Response response)
 {
     if (OperationCompleted != null)
     {
         OperationCompleted(this, new Tuple <Protocol.Request, Protocol.Response>(request, response));
     }
 }
 public void RemoveRequest(Protocol.Request request)
 {
     lock (_requests)
     {
         _requests.Remove(request.Id);
     }
 }
Exemple #4
0
        private void ReceiveRestCallback(IAsyncResult ar)
        {
            try
            {
                /* retrieve the SocketStateObject */
                SocketStateObject state    = (SocketStateObject)ar.AsyncState;
                Socket            socketFd = state.m_SocketFd;

                /* read data */
                int readSize = socketFd.EndReceive(ar);
                state.m_Data    = Protocol.combine(state.m_Data, state.m_DataBuf, readSize);
                state.m_DataBuf = new byte[state.size - state.m_Data.Length + 21];
                // receive the rest of header
                if (state.m_Data.Length - 21 < state.size)
                {
                    socketFd.BeginReceive(state.m_DataBuf, 0, state.size - state.m_Data.Length + 21, 0, new AsyncCallback(ReceiveRestCallback), state);
                }
                else
                {
                    Protocol.Request req = new Protocol.Request();
                    Protocol.req_decode(ref req, state.m_Data);
                    /* manage response */
                    feedback(ref req);
                    setThreadedSendButton(true);
                    setThreadedReceiveButton(true);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Exception:\t\n" + exc.Message.ToString());
                setThreadedStatusLabel("Check \"Server Info\" and try again!");
                setThreadedButton(true);
            }
        }
 public void AddRequest(Protocol.Request request)
 {
     lock (_requests)
     {
         _requests.Add(request.Id, request);
     }
 }
        public static Protocol.Request CreateOutlineFileRequest(Protocol.FileIdentifier fileIdentifier)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType        = Protocol.Request.RequestType.OutlineFile;
            ret.outlineFileRequest = new Protocol.Request.OutlineFileRequest();
            ret.outlineFileRequest.fileIdentifier = fileIdentifier;

            return(ret);
        }
        internal static Protocol.Request CreateFileParseMessagesRequest(Protocol.FileIdentifier fileIdentifier)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.FileParseMessages;
            ret.fileParseMessagesRequest = new Protocol.Request.FileParseMessagesRequest();
            ret.fileParseMessagesRequest.fileIdentifier = fileIdentifier;

            return(ret);
        }
        public static Protocol.Request CreateOutlineFileRequest(Protocol.FileIdentifier fileIdentifier)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.OutlineFile;
            ret.outlineFileRequest = new Protocol.Request.OutlineFileRequest();
            ret.outlineFileRequest.fileIdentifier = fileIdentifier;

            return ret;
        }
Exemple #9
0
        public void Stop()
        {
            var bye = new Protocol.Request();

            bye.requestType = Protocol.Request.RequestType.Bye;
            Send(null, bye);

            Telemetry.Client.Get().TrackMetric("App.Metric.MaxServerQueueLength", Telemetry_MaxQueueLength);
            Telemetry_MaxQueueLength = 0;
        }
Exemple #10
0
        internal static Protocol.Request CreateDisposeTypeRootRequest(Protocol.TypeRootIdentifier id)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.DisposeTypeRoot;

            ret.disposeTypeRootRequest = new Protocol.Request.DisposeTypeRootRequest();
            ret.disposeTypeRootRequest.typeRootIdentifier = id;

            return(ret);
        }
Exemple #11
0
        internal static Protocol.Request CreataAddTypeRootRequest(Protocol.TypeRootIdentifier id)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.AddTypeRoot;

            ret.addTypeRootRequest = new Protocol.Request.AddTypeRootRequest();
            ret.addTypeRootRequest.typeRootIdentifier = id;

            return(ret);
        }
Exemple #12
0
        public static Protocol.Request CreateDoneWithFileRequest(Protocol.FileIdentifier fileIdentifier)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.DisposeFile;

            ret.disposeFileRequest = new Protocol.Request.DisposeFileRequest();
            ret.disposeFileRequest.fileIdentifier = fileIdentifier;

            return(ret);
        }
Exemple #13
0
        internal static Protocol.Request CreateOpenTypeRootRequest(string fileName)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.OpenTypeRoot;

            ret.openTypeRootRequest          = new Protocol.Request.OpenTypeRootRequest();
            ret.openTypeRootRequest.fileName = fileName;

            return(ret);
        }
Exemple #14
0
 void javaEditor_OperationStarted(object sender, Protocol.Request e)
 {
     if (Root != null)
     {
         Root.Dispatcher.Invoke((Action) delegate()
         {
             Root.BusyProgressBar     = true;
             Root.BusyProgressMessage = e.ToString();
         });
     }
 }
        public static Protocol.Request CreateDoneWithFileRequest(Protocol.FileIdentifier fileIdentifier)
        {
            Protocol.Request ret = new Protocol.Request();
            
            ret.requestType = Protocol.Request.RequestType.DisposeFile;
            
            ret.disposeFileRequest = new Protocol.Request.DisposeFileRequest();
            ret.disposeFileRequest.fileIdentifier = fileIdentifier;

            return ret;
        }
Exemple #16
0
        public Task <Protocol.Response> Send(JavaEditor javaEditor, Protocol.Request request)
        {
            var source = new TaskCompletionSource <Protocol.Response>();

            lock (WorkItems)
            {
                WorkItems.Enqueue(new Tuple <Protocol.Request, TaskCompletionSource <Protocol.Response>, JavaEditor>(request, source, javaEditor));
                Telemetry_MaxQueueLength = Math.Max(WorkItems.Count, Telemetry_MaxQueueLength);
            }
            return(source.Task);
        }
        public static Protocol.Request CreateParamHelpPositionUpdateRequest(string content, int cursorPosition)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.ParamHelpPositionUpdate;

            ret.paramHelpPositionUpdateRequest = new Protocol.Request.ParamHelpPositionUpdateRequest();
            ret.paramHelpPositionUpdateRequest.fileParseContents = content;
            ret.paramHelpPositionUpdateRequest.cursorPosition = cursorPosition;

            return ret;
        }
        public static Protocol.Request CreateFileParseRequest(TextReader textReader, string fileName)
        {
            Protocol.Request ret = new Protocol.Request();
            
            ret.requestType = Protocol.Request.RequestType.FileParse;

            ret.fileParseRequest = new Protocol.Request.FileParseRequest();
            ret.fileParseRequest.fileParseContents = textReader.ReadToEnd();
            ret.fileParseRequest.fileName = fileName;

            return ret;
        }
Exemple #19
0
        public static Protocol.Request CreateFileParseRequest(TextReader textReader, string fileName)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.FileParse;

            ret.fileParseRequest = new Protocol.Request.FileParseRequest();
            ret.fileParseRequest.fileParseContents = textReader.ReadToEnd();
            ret.fileParseRequest.fileName          = fileName;

            return(ret);
        }
Exemple #20
0
        private void sendRequest(ref Protocol.Request req)
        {
            /* send */
            SocketStateObject state = new SocketStateObject();

            state.m_SocketFd = this.client.s_socket;
            state.m_DataBuf  = Protocol.req_encode(ref req);

            setThreadedStatusLabel("Wait! Sending information...");
            state.size = state.m_DataBuf.Length;
            client.s_socket.BeginSend(state.m_DataBuf, 0, state.size, 0, new AsyncCallback(SendCallback), state);
        }
Exemple #21
0
        public static Protocol.Request CreateParamHelpPositionUpdateRequest(string content, int cursorPosition)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.ParamHelpPositionUpdate;

            ret.paramHelpPositionUpdateRequest = new Protocol.Request.ParamHelpPositionUpdateRequest();
            ret.paramHelpPositionUpdateRequest.fileParseContents = content;
            ret.paramHelpPositionUpdateRequest.cursorPosition    = cursorPosition;

            return(ret);
        }
Exemple #22
0
        public static Protocol.Request CreateParamHelpRequest(TextReader textReader, Protocol.TypeRootIdentifier id, int cursorPosition)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.ParamHelp;

            ret.paramHelpRequest = new Protocol.Request.ParamHelpRequest();
            ret.paramHelpRequest.fileParseContents  = textReader.ReadToEnd();
            ret.paramHelpRequest.typeRootIdentifier = id;
            ret.paramHelpRequest.cursorPosition     = cursorPosition;

            return(ret);
        }
        public static Protocol.Request CreateParamHelpRequest(TextReader textReader, Protocol.TypeRootIdentifier id, int cursorPosition)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.ParamHelp;

            ret.paramHelpRequest = new Protocol.Request.ParamHelpRequest();
            ret.paramHelpRequest.fileParseContents = textReader.ReadToEnd();
            ret.paramHelpRequest.typeRootIdentifier = id;
            ret.paramHelpRequest.cursorPosition = cursorPosition;

            return ret;
        }
Exemple #24
0
        internal static Protocol.Request CreateFindDefinitionRequest(TextReader textReader, Protocol.TypeRootIdentifier id, int cursorPosition)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.FindDefinition;

            ret.findDefinitionRequest = new Protocol.Request.FindDefinitionRequest();
            ret.findDefinitionRequest.fileParseContents  = textReader.ReadToEnd();
            ret.findDefinitionRequest.typeRootIdentifier = id;
            ret.findDefinitionRequest.cursorPosition     = cursorPosition;

            return(ret);
        }
Exemple #25
0
        /* --------CONNECTION FUNCTIONS---------------------*/
        private void feedback(ref Protocol.Request response)
        {
            setThreadedStatusLabel("Managing response");
            setThreadedButton(true);

            if (response.header.req_type == Protocol.reqType.req_res)
            { //some error responses
                Protocol.RData_Response ans_data = (Protocol.RData_Response)Marshal.PtrToStructure(response.data, typeof(Protocol.RData_Response));
                if (ans_data.res_type == Protocol.resType.res_ok)
                {
                    if (ans_data.id == -1)
                    {
                        setThreadedStatusLabel("Connected succesfully");
                        setThreadedSendButton(true);
                    }
                    else //file accepted
                    {
                        client.tasksProgress.Add(ans_data.id);
                        setThreadedTasksProgress();
                        setThreadedStatusLabel("File accepted");
                        setThreadedReceiveButton(true);
                    }
                }

                else if (ans_data.res_type == Protocol.resType.res_empty)
                {
                    setThreadedStatusLabel("No files to download");
                }
                else if (ans_data.res_type == Protocol.resType.res_fail)
                {
                    setThreadedStatusLabel("Operation failed on server");
                }
                else if (ans_data.res_type == Protocol.resType.res_full)
                {
                    setThreadedStatusLabel("Server is busy. Try again later");
                }
                else
                { //other srver response
                    setThreadedStatusLabel("Unsupported request type");
                }
            }
            else if (response.header.req_type == Protocol.reqType.req_snd)
            { //there is a file
                Protocol.RData_File ans_data = (Protocol.RData_File)Marshal.PtrToStructure(response.data, typeof(Protocol.RData_File));
                taskDone(ref ans_data);
            }
            else
            { //other srver response
                setThreadedStatusLabel("Unsupported request type");
            }
        }
Exemple #26
0
        private void GetHostEntryCallback(IAsyncResult ar)
        {
            try {
                IPHostEntry hostEntry = null;
                IPAddress[] addresses = null;
                Socket      socketFd  = null;
                IPEndPoint  endPoint  = null;

                /* complete the DNS query */
                hostEntry = Dns.EndGetHostEntry(ar);
                addresses = hostEntry.AddressList;

                /* create a socket */
                socketFd = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                /* remote endpoint for the socket */
                endPoint = new IPEndPoint(addresses[0], Int32.Parse(this.textBoxPort.Text.ToString()));
                setThreadedStatusLabel("Wait! Connecting...");

                /* connect to the server */
                socketFd.BeginConnect(endPoint, new AsyncCallback(ConnectCallback), socketFd);
                this.client.connectDone.WaitOne();

                /* send client information */
                Protocol.Request req;
                req = new Protocol.Request();

                //creating data
                Protocol.RData_Connect data = new Protocol.RData_Connect();
                data.conn_type = Protocol.connType.conn_client;
                data.name      = "name";
                data.password  = "******";
                req.data       = Marshal.AllocHGlobal(Marshal.SizeOf(data));
                Marshal.StructureToPtr(data, req.data, false);

                //creating header
                req.header          = new Protocol.Header();
                req.header.req_type = Protocol.reqType.req_cnt;
                req.header.key      = "12345678\0";

                sendRequest(ref req);
                this.client.sendDone.WaitOne();
            }
            catch (Exception exc) {
                MessageBox.Show("Exception:\t\n" + exc.Message.ToString());
                setThreadedStatusLabel("Check \"Server Info\" and try again!");
                setThreadedButton(true);
            }
        }
Exemple #27
0
        /* Receive button */
        private void buttonReceive_Click(object sender, EventArgs e)
        {
            try {
                setThreadedSendButton(false);
                setThreadedReceiveButton(false);
                Protocol.Request req = new Protocol.Request();
                //creating data
                req.data = new IntPtr();
                //creating header
                req.header          = new Protocol.Header();
                req.header.req_type = Protocol.reqType.req_rcv;
                req.header.size     = 0;
                req.header.key      = "12345678";

                sendRequest(ref req);
            }
            catch (Exception exc)  {
                setThreadedStatusLabel("Exception:\t\n" + exc.Message.ToString());
            }
        }
Exemple #28
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                /* retrieve the SocketStateObject */
                SocketStateObject state    = (SocketStateObject)ar.AsyncState;
                Socket            socketFd = state.m_SocketFd;

                /* read data */
                int readSize = socketFd.EndReceive(ar);
                state.m_Data    = Protocol.combine(state.m_Data, state.m_DataBuf, readSize);
                state.m_DataBuf = new byte[state.size - state.m_Data.Length];
                // receive the rest of header
                if (state.m_Data.Length < state.size)
                {
                    socketFd.BeginReceive(state.m_DataBuf, 0, state.size - state.m_Data.Length, 0, new AsyncCallback(ReceiveCallback), state);
                }
                else
                {
                    Protocol.Request req = new Protocol.Request();
                    if (state.m_Data.Length != state.size)
                    {
                        throw new Exception("Wrong size of data");
                    }
                    Protocol.req_decode(ref req, state.m_Data, true);
                    state.size      = (int)req.header.size;
                    state.m_DataBuf = new byte[state.size];
                    /*begin receiving the rest */
                    socketFd.BeginReceive(state.m_DataBuf, 0, state.size, 0, new AsyncCallback(ReceiveRestCallback), state);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Exception:\t\n" + exc.Message.ToString());
                setThreadedStatusLabel("Check \"Server Info\" and try again!");
                setThreadedButton(true);
            }
        }
Exemple #29
0
 /* Send button */
 private void buttonSend_Click(object sender, EventArgs e)
 {
     if ((radioButtonP2.Checked || radioButtonP3.Checked) && textBoxFile.Text.Length > 0)
     {
         string filename = textBoxFile.Text;
         try {
             setThreadedSendButton(false);
             setThreadedReceiveButton(false);
             using (StreamReader sr = new StreamReader(filename)) {
                 String           line = sr.ReadToEnd();
                 Protocol.Request req;
                 req = new Protocol.Request();
                 //creating data
                 Protocol.RData_File data_file = new Protocol.RData_File();
                 data_file.file_type = radioButtonP2.Checked ? Protocol.fileType.file_py2_script : Protocol.fileType.file_py3_script;
                 data_file.size      = (ulong)line.Length;
                 data_file.data      = line;
                 req.data            = Marshal.AllocHGlobal(Marshal.SizeOf(data_file));
                 Marshal.StructureToPtr(data_file, req.data, false);
                 //creating header
                 req.header          = new Protocol.Header();
                 req.header.req_type = Protocol.reqType.req_snd;
                 req.header.size     = (ulong)Marshal.SizeOf(data_file.GetType());
                 req.header.key      = "12345678";
                 sendRequest(ref req);
             }
         }
         catch (Exception exc) {
             setThreadedStatusLabel("Exception:\t\n" + exc.Message.ToString());
         }
     }
     else
     {
         setThreadedStatusLabel("No file or file type!");
     }
 }
        internal static Protocol.Request CreataAddTypeRootRequest(Protocol.TypeRootIdentifier id)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.AddTypeRoot;

            ret.addTypeRootRequest = new Protocol.Request.AddTypeRootRequest();
            ret.addTypeRootRequest.typeRootIdentifier = id;

            return ret;
        }
 protected override void RemoveRequest(Protocol.Request request)
 {
     _request.Remove(request.Id);
 }
 protected override void AddRequest(Protocol.Request request)
 {
     _request.Add(request.Id, (SimpleRequest)request);
 }
        internal static Protocol.Request CreateOpenTypeRootRequest(string fileName)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.OpenTypeRoot;

            ret.openTypeRootRequest = new Protocol.Request.OpenTypeRootRequest();
            ret.openTypeRootRequest.fileName = fileName;

            return ret;
        }
        internal static Protocol.Request CreateQuickInfoRequest(TextReader textReader, Protocol.TypeRootIdentifier id, int cursorPosition)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.QuickInfo;

            ret.quickInfoRequest = new Protocol.Request.QuickInfoRequest();
            ret.quickInfoRequest.fileParseContents = textReader.ReadToEnd();
            ret.quickInfoRequest.typeRootIdentifier = id;
            ret.quickInfoRequest.cursorPosition = cursorPosition;

            return ret;
        }
Exemple #35
0
 public void WriteMessage(Protocol.Request request)
 {
     Serializer.SerializeWithLengthPrefix(PipeServer, request, PrefixStyle.Base128);
 }
        internal static Protocol.Request CreateDisposeTypeRootRequest(Protocol.TypeRootIdentifier id)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.DisposeTypeRoot;

            ret.disposeTypeRootRequest = new Protocol.Request.DisposeTypeRootRequest();
            ret.disposeTypeRootRequest.typeRootIdentifier = id;

            return ret;
        }
        public void Stop()
        {
            var bye = new Protocol.Request();
            bye.requestType = Protocol.Request.RequestType.Bye;
            Send(null, bye);

            Telemetry.Client.Get().TrackMetric("App.Metric.MaxServerQueueLength", Telemetry_MaxQueueLength);
            Telemetry_MaxQueueLength = 0;
        }
        internal static Protocol.Request CreateFileParseMessagesRequest(Protocol.FileIdentifier fileIdentifier)
        {
            Protocol.Request ret = new Protocol.Request();

            ret.requestType = Protocol.Request.RequestType.FileParseMessages;
            ret.fileParseMessagesRequest = new Protocol.Request.FileParseMessagesRequest();
            ret.fileParseMessagesRequest.fileIdentifier = fileIdentifier;

            return ret;
        }