Пример #1
0
 public void LogDestroyClient(FabulousClientInstance client)
 {
     if (!client.IsLogged)
         Log(client);
     string str = string.Format("Client Destroyed - In:{1}, Out:{2} - {0}", client.error != null ? client.error.Message.Replace("\n","\\n\\r") : "null", FabulousClientInstance.GetSizeString(client.TotalIn), FabulousClientInstance.GetSizeString(client.TotalOut));
     AppendLogLine(str, client);
 }
Пример #2
0
        public void Log(FabulousClientInstance client)
        {
            string method = (client.httpRequest != null ? client.httpRequest.method.ToString() : "null");
            string errorCode = (client.httpResponse != null ? client.httpResponse.errorCode.ToString() : "null");
            string errorString = (client.httpResponse != null ? ((HttpStatusCode)client.httpResponse.errorCode).ToString() : "null");
            string returnLength = (client.httpResponse != null ? client.httpResponse.contentLength.ToString() : "null");
            string path = (client.httpRequest != null ? client.httpRequest.path.ToString() : "null");
            string args = (client.httpRequest != null ? client.httpRequest.args.ToString() : "null");
            string protocol = (client.httpRequest != null ? client.httpRequest.protocol.ToString() : "null");
            string host = (client.httpRequest != null ? client.httpRequest.Host.ToString() : "null");
            string userAgent = (client.httpRequest != null ? client.httpRequest.UserAgent.ToString() : "null");
            string range = (client.httpRequest != null ? client.httpRequest.Range.ToString() : "null");

            string str = string.Format("{0} {1} {2}{3} - {4} {5} - Host: {6}{7}",
                method,
                path + (args != "" ? "?" + args : ""),
                protocol,
                range != "" ? " - Range: " + range : "",
                errorCode,
                errorString,
                host,
                userAgent != "" ? " Agent: " + userAgent : "");
            AppendLogLine(str, client);

                string consoleString = CreateLogLine(string.Format("{0} {1} - {2} {3}",
                    method,
                    path + (args != "" ? "?" + args : "") + (range != "" ? " " + range : ""),
                    errorCode,
                    errorString), client);
                Console.Write("\r");
                Console.WriteLine(consoleString);
                Console.Write(StaticServerStuff.promt);
        }
Пример #3
0
 public void AppendLogLine(string line, FabulousClientInstance client)
 {
     lock (mutex)
     {
         DateTime date = DateTime.Now.Date;
         string folder = string.Format("Logs\\{0:MM-yyyy}", date);
         if (!Directory.Exists(folder))
             Directory.CreateDirectory(folder);
         string fileName = folder + "\\" + requestsLogName + " [" + date.ToShortDateString() + "].log";
         File.AppendAllText(fileName, CreateLogLine(line,client) + Environment.NewLine);
     }
 }
Пример #4
0
 void AcceptNewClient(FabulousClientInstance client)
 {
     for (int i = 0; i < clientList.Count; i++)
     {
         if (clientList[i] == null)
         {
             client.ClearWatchDog();
             client.Start();
             clientList[i] = client;
             client.Id = i;
             return;
         }
     }
     client.Start();
     clientList.Add(client);
 }
Пример #5
0
 public void ListenThread()
 {
     active = true;
     TotalIn = 0;
     TotalOut = 0;
     if (serverListener != null)
         serverListener.Stop();
     serverListener = new TcpListener(IPAddress.Any, port);
     serverListener.Start();
     serverStarted = DateTime.Now;
     while (active)
     {
         TcpClient client = serverListener.AcceptTcpClient();
         FabulousClientInstance ffsClient = new FabulousClientInstance(client, this);
         LogAcceptClient(ffsClient);
         AcceptNewClient(ffsClient);
         if (checkThread == null || checkThread.ThreadState != ThreadState.Running)
         {
             if (checkThread != null)
                 checkThread.Abort();
             checkThread = new Thread(new ThreadStart(CheckThread));
             checkThread.Start();
         }
     }
 }
Пример #6
0
 public void LogAcceptClient(FabulousClientInstance client)
 {
     string str = string.Format("Client Accepted");
     AppendLogLine(str,client);
 }
Пример #7
0
 public string CreateLogLine(string line, FabulousClientInstance client)
 {
     DateTime time = DateTime.Now;
     return string.Format("[{0}] - ({1}:{2}) - ", time.ToString(), client.IP, client.Port) + line;
 }