コード例 #1
0
        private void HandleGet()
        {
            // handle a "get" request from the client

            // if the client has a session open
            if (sessionId != 0)
            {
                try
                {
                    // get the document name from the client
                    var documentName = reader.ReadLine();

                    // get the document content from the session table
                    var documentContent = sessionTable.GetSessionValue(sessionId, documentName);

                    // send success and document to the client
                    SendSuccess(documentName, documentContent);
                }
                catch (SessionException se)
                {
                    SendError(se.Message);
                }
                catch (Exception ex)
                {
                    SendError(ex.Message);
                }
            }
            else
            {
                // error, cannot get without a session
                SendError($"Error, open session not found!");
            }
        }
コード例 #2
0
        private void HandleGet()
        {
            // handle a "get" request from the client

            // if the client has a session open
            if (sessionId != 0)
            {
                try
                {
                    string documentContent = string.Empty;

                    // get the document name from the client
                    var documentName = reader.ReadLine();

                    if (string.IsNullOrEmpty(documentName) || documentName.Equals("/"))
                    {
                        throw new Exception("Document name cannot be empty");
                    }

                    // test if the client is requesting a file or a session variable
                    if (documentName.StartsWith("/"))
                    {
                        // find the file on disk
                        var filePath = MakeFilename(documentName);

                        if (!File.Exists(filePath))
                        {
                            throw new Exception($"File {documentName} does not exist");
                        }

                        // read the contents
                        documentContent = File.ReadAllText(filePath);
                    }
                    else
                    {
                        // get the document content from the session table
                        documentContent = sessionTable.GetSessionValue(sessionId, documentName);
                    }

                    // send success and document to the client
                    SendSuccess(documentName, documentContent);
                }
                catch (SessionException se)
                {
                    SendError(se.Message);
                }
                catch (Exception ex)
                {
                    SendError(ex.Message);
                }
            }
            else
            {
                // error, cannot get without a session
                SendError($"Error, open session not found!");
            }
        }
コード例 #3
0
        private void HandleGet()
        {
            // handle a "get" request from the client

            // get the document name from the client
            string documentName = reader.ReadLine();

            // if the client has a session open
            if (sessionId != 0)
            {
                try
                {
                    string documentContent;
                    // check if request is for a file or a session variable
                    if (documentName.Length > 1 && documentName[0] == '/')
                    {
                        // get the file requested
                        string fileName = documentName.TrimStart('/').Replace('/', '\\');
                        string filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
                        Console.WriteLine("SDConnectedClient.HandleGet() - get requested for file: " + filePath);
                        documentContent = File.ReadAllText(filePath);      // get from file
                    }
                    else if (documentName.Length > 0)
                    {
                        // get the document content from the session table
                        documentContent = sessionTable.GetSessionValue(sessionId, documentName);
                    }
                    else
                    {
                        // invalid document name!
                        throw new Exception("Invalid document name!");
                    }


                    // send success and document to the client
                    SendSuccess(documentName, documentContent);
                }
                catch (SessionException se)
                {
                    SendError(se.Message);
                }
                catch (Exception ex)
                {
                    SendError(ex.Message);
                }
            }
            else
            {
                // error, cannot get without a session
                SendError("Cannot get document without an open session!");
            }
        }