Beispiel #1
0
        private static void CreateUrl()
        {
            IRepository repository = new Repository(SessionFactoryProvider);
            var q = (from code in repository.AsQueryable<ResponseCodes>() where code.ResponseCode == 501 select code).Single();

            using (var transaction = new TransactionScope()){
            var ses = new Sesions {
                ExecutionTime = 4525,
                CreationTime = DateTime.Now,
                userIP = "asad"
            };
            repository.Save(ses);
            var url = new URLs {
                url = new Uri("http://www.google.lt"),
                sesion = ses,
            };
            repository.Save(url);
            var response = new Responses {
                ResponseTime = 12345,
                URL = url,
                ResponseCode = q,
                RequestStartTime = DateTime.Now
            };
            repository.Save(response);
            repository.Commit();
            transaction.Complete();
            }
            Sesions q2 = (from ses in repository.AsQueryable<Sesions>() where ses.userIP == "asad" select ses).Single();
            //ISesionToXML s2x = new SesionToXML();
            //s2x.ConvertSesionToXML(q2, "C:/hugas.xml");
        }
        public void ConvertSesionToXML(Sesions sesion, StringWriter stream)
        {
            IRepository repository = new Repository(SessionFactoryProvider);
            XmlWriterSettings setings = new XmlWriterSettings();
            setings.Indent = true;
            setings.IndentChars = "    ";
            using (XmlWriter writer = XmlWriter.Create(stream, setings)) {
                writer.WriteStartDocument();
                writer.WriteStartElement("Sesion");
                writer.WriteElementString("StatupTime", sesion.CreationTime.ToString());
                writer.WriteStartElement("URLs");

                List<URLs> q1 = (from url in repository.AsQueryable<URLs>() where url.sesion == sesion select url).ToList<URLs>();
                foreach (URLs url in q1) {
                    writer.WriteStartElement("URL");
                    writer.WriteElementString("url", url.url.ToString());
                    writer.WriteStartElement("Responses");
                    List<Responses> q2 = (from response in repository.AsQueryable<Responses>() where response.URL == url select response).ToList<Responses>();
                    foreach (Responses response in q2) {
                        writer.WriteStartElement("Response");
                        var q3 = (from code in repository.AsQueryable<ResponseCodes>() where code == response.ResponseCode select code.ResponseCode).Single();
                        writer.WriteElementString("ResponseCode", q3.ToString());
                        writer.WriteElementString("RequestTime", response.RequestStartTime.ToLongTimeString() + ":" + response.RequestStartTime.Millisecond);
                        writer.WriteElementString("ResponseTime", response.ResponseTime.ToString());
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
            }
        }
 public IList<URLs> selectUrlsBySesionTime(DateTime date, string ip)
 {
     IRepository repository = new Repository(SessionFactoryProvider);
     var curentSesion = (from sesion in repository.AsQueryable<Sesions>()
                   where sesion.CreationTime == date
                   && sesion.userIP == ip
                   select sesion).Single();
     var list = (from url in repository.AsQueryable<URLs>()
                 where url.sesion == curentSesion
                 select url).ToList<URLs>();
     return list;
 }
        public string Generatereport(DateTime date)
        {
            IRepository repository = new Repository(SessionFactoryProvider);
            var q = (from sesion in repository.AsQueryable<Sesions>() where sesion.CreationTime == date select sesion).Single();
            stream.Write("Sesijos pradzia: " + q.CreationTime + ",\nUztruko: " + q.ExecutionTime + "sekundziu,\n");
            stream.Write("Vartotojo IP: " + q.userIP + ",\n");
            List<URLs> q1 = (from url in repository.AsQueryable<URLs>() where url.sesion == q select url).ToList<URLs>();
            stream.Write("Nuorodu kiekis: " + q1.Count + ",\n\n");
            int requestCount = 0;
            int overalResponseTime = 0;
            int avgResponseTime = 0;
            double avgTimesOfSucces = 0;
            double avgTimesOfFailure = 0;
            int timesOfSuccesAll = 0;
            int timesOfFailureAll = 0;
            int timesOfSucces = 0;
            int timesOfFailure = 0;

            List<Responses> q2;
            foreach (URLs url in q1) {
                timesOfSucces = 0;
                timesOfFailure = 0;
                overalResponseTime = 0;
                q2 = (from response in repository.AsQueryable<Responses>() where response.URL == url select response).ToList<Responses>();
                requestCount = q2.Count;
                stream.Write("URL adresas: " + url.url + ",\n");
                stream.Write("Uzklausu skaicius: " + q2.Count + ",\n\n");
                foreach (Responses response in q2) {
                    overalResponseTime += response.ResponseTime;
                    if (response.ResponseCode.ResponseCode == 200)
                        timesOfSucces++;
                    else
                        timesOfFailure++;
                }
                avgResponseTime = overalResponseTime / q2.Count;
                stream.Write("Vidutinis atsako laikas: " + avgResponseTime + ",\n");
                stream.Write("Sekmingu uzklausu skaicius: " + timesOfSucces + ",\n");
                stream.Write("Nesekmingu uzklausu skaicius: " + timesOfFailure + ",\n\n");
                timesOfSuccesAll += timesOfSucces;
                timesOfFailureAll += timesOfFailure;
            }
            avgTimesOfSucces = (double)timesOfSuccesAll / (requestCount * q1.Count) * 100;
            avgTimesOfFailure = (double)timesOfFailureAll / (requestCount * q1.Count) * 100;
            stream.Write("Visos sesijos duomenys: \n\n");
            stream.Write("Sekmingu atsakymu vidurkis: " + avgTimesOfSucces + "% ,\n");
            stream.Write("Nesekmingu atsakymu vidurkis: " + avgTimesOfFailure + "% ,\n");
            return stream.ToString();
        }
        public void NewProgramSesion()
        {
            newSesion.CreationTime = DateTime.Now;
            newSesion.userIP = ip;
            IRepository repository = new Repository(SessionFactoryProvider);
            repository.Save(newSesion);
            repository.Commit();
            foreach (string url in urls)
            {
                if(url != "")
                    if (IsValidUrl(url))
                    {
                        Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);
                        ProgramManager pm = new ProgramManager(uri, newSesion);
                        pm.Execute(amount, time, buffer);
                    }
                    else
                        return;
            }
            buffer.Write();

            var t = DateTime.Now - newSesion.CreationTime;

            var q = (from sesion in repository.AsQueryable<Sesions>() where sesion == newSesion select sesion).Single();
            q.ExecutionTime = t.Value.Seconds + t.Value.Minutes * 60 + t.Value.Hours * 3600;
            repository.Save(q);
            repository.Commit();
            if (onSesionEnd != null)
                onSesionEnd(q.ExecutionTime.ToString());
            //Thread.Sleep(3000);
            //ISesionToXML s2x = new SesionToXML();
            //s2x.ConvertSesionToXML(newSesion, "C:/hugas.xml");
        }
 public IList<Sesions> selectByIp(string ip)
 {
     IRepository repository = new Repository(SessionFactoryProvider);
     var list = (from sesion in repository.AsQueryable<Sesions>()
                 where sesion.userIP == ip
                 select sesion).ToList<Sesions>();
     return list;
 }
 public string StreamFromSesionTime(DateTime time)
 {
     IRepository repository = new Repository(SessionFactoryProvider);
     var q = (from sesion in repository.AsQueryable<Sesions>() where sesion.CreationTime == time select sesion).Single();
     ISesionToXML stx = new SesionToXML();
     stx.ConvertSesionToXML(q, stream);
     return stream.ToString();
 }