Example #1
0
        /// <summary>
        /// informe de estadisiticas en protocolo http
        /// </summary>
        /// <param name="route"></param>
        protected void HttpMessageResponseState(Route route)
        {
            try
            {
                string content = string.Format("<html><p><h1>Nodo <b>{0}</b> de DodoNet</h1></p>",
                                               localNode.localBind);

                content += string.Format("<p>Dia/Hora del informe {0}</p>", DateTime.Now);
                content += string.Format("<p>Dia/Hora de inicio del nodo {0}</p>", localNode.InitiatedNode);

                int per = (localNode.localEvents.CurInUseThreads * 100) / localNode.localEvents.CurActiveThreads;
                if (localNode.localEvents.CurActiveThreads == localNode.localEvents.CurInUseThreads)
                {
                    content += string.Format(
                        "<div style=\"border-width:medium; font-size: 24px; font-weight: bold; background-color:#FF0000; color:#FFFFFF\">Estado: {0} {1}% de uso Num. hebras: {2} de {3}</div>",
                        "Ocupado", per, localNode.localEvents.CurInUseThreads, localNode.localEvents.CurActiveThreads);
                }
                else if (per > 60 && per < 100)
                {
                    content += string.Format(
                        "<div style=\"border-width:medium; font-size: 24px; font-weight: bold; background-color:#FF6600; color:#FFFFFF\">Estado: {0} {1}%  de uso Num. hebras: {2} de {3}</div>",
                        "", per, localNode.localEvents.CurInUseThreads, localNode.localEvents.CurActiveThreads);
                }
                else
                {
                    content += string.Format(
                        "<div style=\"border-width:medium; font-size: 24px; font-weight: bold; background-color:#009900; color:#FFFFFF\">Estado: {0} {1}%  de uso Num. hebras: {2} de {3}</div>",
                        "", per, localNode.localEvents.CurInUseThreads, localNode.localEvents.CurActiveThreads);
                }

                content += "<link rel='stylesheet' href='css/2col_leftNav.css' type='text/css' />";

                // content += "<br><h2>Lista de discos duros del servidor:</h2>";

                // foreach (ComputerInfo.InfoDrive infoDrive in ComputerInfo.GetInfoDrives())
                // {
                //     long perDisc = (infoDrive.freeSpace * 100) / infoDrive.size;
                //     content += string.Format("<p>Disco: {0}, {1}, {2} Espacio libre: {3:N} Mb <b>[{4}]</b>%</p>",
                //         infoDrive.unit,
                //         infoDrive.fileSystem, infoDrive.description,
                //         infoDrive.freeSpace / 1000000, perDisc);
                // }

                content += string.Format("<h2>Rutas conectados: {0}</h2>",
                                         localNode.RouteTable.Count);

                foreach (Route r in localNode.RouteTable.GetArray())
                {
                    content += string.Format(
                        "<p>** Extremo local: {0} Extremo remoto: {1} Ultima actividad: {2}</p>",
                        r.LocalEndPoint, r.RemoteEndPoint, r.LastActivity);
                }

                content += string.Format("<h2>Sesiones activas: {0}</h2>",
                                         localNode.Sessions.Count);

                foreach (ISessionRequest v in localNode.Sessions.GetArray())
                {
                    SessionRequest ss = (SessionRequest)v;
                    content += string.Format(
                        "<p>** Sesion: {0} Extremo remoto: {1} Ultima actividad: {2}</p>",
                        ss.NodeBindApplicant.NodeId, ss.NodeBindApplicant.NodeAddress, ss.NodeBindRemote.NodeAddress);
                }

                #region Processes

                content += "<br><h2>Procesos activos:</h2>\r\n";

                Thread[] at = localNode.localEvents.Threads;
                foreach (Thread tt in at)
                {
                    try
                    {
                        if (tt != null)
                        {
                            try
                            {
                                tt.Suspend();

                                content += string.Format("<p><u>Hebra: {0}-{1}</u></p>",
                                                         tt.ManagedThreadId,
                                                         tt.Name);

                                StackTrace st = new StackTrace(tt, true);

                                int x = 0;
                                int y = 0;
                                for (x = 0; x < st.FrameCount; x++)
                                {
                                    y++;
                                    StackFrame sf = st.GetFrame(x);
                                    content += string.Format("<p>({0:000})\t {1} Line: {2} File:{3}</p>",
                                                             y, sf.GetMethod().Name, sf.GetFileLineNumber(), sf.GetFileName());
                                }
                            }
                            catch { }
                        }
                    }
                    catch (Exception err)
                    {
                        content += string.Format("Error: {0}", err.Message);
                    }
                    finally
                    {
                        try
                        {
                            if (tt != null)
                            {
                                tt.Resume();
                            }
                        }
                        catch { }
                    }
                }

                #endregion

                content += "</html>";

                string msg =
                    string.Format(
                        "HTTP/1.1 200 OK\r\n" +
                        "Content-Type: text/html\r\n" +
                        "Content-Length: {0}\r\n" +
                        "Conection: Close\r\n" +
                        "\r\n{1}",
                        content.Length, content);

                byte[] tmp = Encoding.ASCII.GetBytes(msg);
                route.Send(tmp, 0, tmp.Length);
            }
            catch (Exception err)
            {
                try
                {
                    string content = string.Format(
                        "<html>Error: {0}</html>",
                        err.Message);
                    string msg =
                        string.Format(
                            "HTTP/1.1 200 OK\r\n" +
                            "Content-Type: text/html\r\n" +
                            "Content-Length: {0}\r\n" +
                            "Conection: Close\r\n" +
                            "\r\n{1}",
                            content.Length, content);

                    Node.LogAppendLine(err);

                    byte[] tmp = Encoding.ASCII.GetBytes(msg);
                    route.Send(tmp, 0, tmp.Length);
                }
                catch { }
            }
            finally
            {
                try
                {
                    localNode.RouteTable.RemoveRoute(route);
                }
                catch { }
            }
        }
Example #2
0
        /// <summary>
        /// envia un mensaje troceado en paquetes
        /// </summary>
        internal object BeginSend_tt(object state)
        {
            Route     route     = null;
            bool      success   = true;
            Exception exception = null;

            SendItemThread tmp = (SendItemThread)state;

            NodeBind          source = tmp.source;
            NodeBind          dest   = tmp.dest;
            Message           msg    = tmp.msg;
            RouteContCallback cb     = tmp.cb;

            try
            {
                // firewall
                if (localNode.blockedAddresses.IndexOf(dest.NodeId) > -1)
                {
                    throw new Exception("Dirección bloqueada");
                }

                // conseguir la ruta para mandar los datos al destino
                route = localNode.RouteTable.GetRoute(dest.NodeAddress);

                byte[] buf = new byte[8192];
                int    bytesRead;

                IHttpMessage httpMsg = msg.Serialize();

                using (var sourceStream = new HttpSenderStream(httpMsg))
                {
                    sourceStream.Position = 0;
                    // copy all data from in to out via the buffer layer
                    while ((bytesRead = sourceStream.Read(buf, 0, buf.Length)) > 0 &&
                           !msg.Cancelled)
                    {
                        route.Send(buf, 0, bytesRead);
                        totalBytesSent += (uint)bytesRead;
                    }

                    if (msg.Cancelled)
                    {
                        Node.LogAppendLine("Envio cancelado {0}");
                    }
                }
            }
            catch (Exception err)
            {
                exception = err;
                success   = false;
            }
            finally
            {
                try
                {
                    // llamamos al callback
                    if (cb != null)
                    {
                        cb(localNode, msg, route, success, exception);
                    }
                }
                catch { }
            }
            return(null);
        }