Beispiel #1
0
        public ControlService()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            logger.Trace("Initialize ControlService.");
            Settings.Update();

            //enure existence of all databases
            using (var c = new LogConnection()) { }
            using (var c = new StatisticsConnection()) { }

            CanStop             = true;
            CanShutdown         = true;
            CanPauseAndContinue = true;
            ServiceName         = "CrossoutLogView.ControlService";

            fsWatcher = new FileSystemWatcher();
            fsWatcher.EnableRaisingEvents   = false;
            fsWatcher.IncludeSubdirectories = true;
            fsWatcher.NotifyFilter          = NotifyFilters.CreationTime | NotifyFilters.FileName;
            fsWatcher.Path     = Settings.Current.LogRootPath;
            fsWatcher.Created += FileCreated;
            fsWatcher.Filter   = "combat.log";

            logChangeTrackTimer          = new Timer();
            logChangeTrackTimer.Enabled  = false;
            logChangeTrackTimer.Interval = 2000.0;
            logChangeTrackTimer.Elapsed += FileChangedElapsed;

            uploader = new StatisticsUploader(Settings.Current.StatisticsParseDateTime);

            logger.Trace("Initialized ControlService.");
        }
Beispiel #2
0
        public void loadDataLocal()
        {
            LogConnection logConnection = new LogConnection();

            this.listLog = logConnection.getAllLog();
            listenChange();
        }
Beispiel #3
0
 public void delLogConnection(LogConnection logConn)
 {
     if (dc.LogConnections.Contains(logConn))
     {
         dc.LogConnections.DeleteOnSubmit(logConn);
         dc.SubmitChanges();
     }
 }
Beispiel #4
0
 public void addLogConnection(LogConnection logConn)
 {
     if (!dc.LogConnections.Contains(logConn))
     {
         logConn.Id = getMaxIdLogConnection() + 1;
         dc.LogConnections.InsertOnSubmit(logConn);
         dc.SubmitChanges();
     }
 }
Beispiel #5
0
        public bool updateLog(LogInfo log)
        {
            LogConnection logConnection = new LogConnection();
            bool          result        = logConnection.updateInfoLog(log);

            if (result)
            {
                loadDataLocal();
                return(true);
            }
            return(false);
        }
        public void InsertLogConnection(int id)
        {
            LogConnection cnx = new LogConnection()
            {
                IdAdministrator = id,
                ConnetionDate   = DateTime.UtcNow
            };

            using (ContextDataContext context = new ContextDataContext())
            {
                context.LogConnection.InsertOnSubmit(cnx);
                context.SubmitChanges();
            }
        }
        public void Commit()
        {
            if (OperatingMode != UploaderOperatingMode.Incremental)
            {
                throw new InvalidOperationException();
            }
            List <ILogEntry> delta;

            using (var logCon = new LogConnection())
            {
                delta = logCon.RequestAll(LogEntryTimeStampLowerLimit);
            }
            if (delta.Count == 0)
            {
                return;
            }
            delta.Sort(new LogEntryTimeStampAscendingComparer());
            InternalCommit(delta);
        }
Beispiel #8
0
        public void incConnectionCount(DateTime time)
        {
            IEnumerable <LogConnection> logCol = dbAccess.getLogConnection().Where <LogConnection>(l => l.Date == time.Date);
            LogConnection inLog;

            if (logCol.ToList().Count == 0)
            {
                inLog                 = new LogConnection();
                inLog.Date            = time;
                inLog.ConnectionCount = 1;
                dbAccess.addLogConnection(inLog);
            }
            else
            {
                inLog = logCol.First <LogConnection>();
                inLog.ConnectionCount++;
                dbAccess.updLogConnection(inLog);
            }
        }
Beispiel #9
0
 public void updLogConnection(LogConnection logConn)
 {
     dc.SubmitChanges();
 }
Beispiel #10
0
    static void Main(string[] args)
    {
        string putanja = @"\\WS-VENTEX\files\";
        string path2   = "C:\\Users\\jerko.viskov\\Documents\\Logovi\\";

        //string connectionstring = "Server=ws-ventex;Database=Parsiranje;Uid=sa;Pwd=Test123!";
        //string connectionstring1 = "Server=VISKOV1\\SQLEXPRESS;Database=Parsiranje;Uid=sa;Pwd=Test123!";
        RuckusLogEntities    db     = new RuckusLogEntities();
        List <LogConnection> logovi = new List <LogConnection>();
        string     filename         = NewestFileofDirectory(putanja);
        int        counter          = 0;
        Ruckus_Log rc  = new Ruckus_Log();
        User       us  = new User();
        Ssid       s   = new Ssid();
        Device     d   = new Device();
        EventType  eve = new EventType();



        if (filename == null)
        {
            Environment.Exit(0);
        }



        StreamReader sr = new StreamReader(putanja + filename);

        System.IO.StreamReader file = new System.IO.StreamReader(putanja + filename);
        try
        {
            {
                string pattern3 = @"@@209";
                string pattern4 = @"@@202";
                string pattern5 = @"@@204";



                /// <summary>
                ///  Streamreader učita liniju texta
                /// </summary>
                String line1;
                while ((line1 = file.ReadLine()) != null)
                {
                    /// <summary>
                    ///  Nova instanca log za svaki event odnosno liniju texta.
                    /// </summary>
                    LogConnection log = new LogConnection();


                    string line2 = sr.ReadLine();
                    if (line2.Length > 50)
                    {
                        string[] niz = line2.Split(new[] { "Jadranka-Ruckus-WLC Core: " }, StringSplitOptions.None);


                        string drugidio = niz[1];
                        string prvidio  = niz[0];

                        log.Datetime = DateTime.Parse(prvidio.Substring(0, 20).Replace("-", " "));
                        Console.WriteLine(log.Datetime);


                        /// <summary>
                        ///  Ispitujem koji o kojem je "tipu" loga riječ.3 tipa Nakon ispitavanja tretiram ga regex metodom.
                        /// </summary>

                        if (Regex.Match(drugidio, pattern3).Success)

                        {
                            string[] listapodataka = drugidio.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);


                            string[] podatak = listapodataka[2].ToString().Split(new[] { "=" }, StringSplitOptions.None);
                            log.AP_MAC = podatak[1].Replace(@"""", "");



                            string[] podatak1 = listapodataka[3].Split(new[] { "=" }, StringSplitOptions.None);
                            log.User_MAC = podatak1[1].Replace(@"""", "");

                            string[] podatak2 = listapodataka[4].Split(new[] { "=" }, StringSplitOptions.None);
                            log.WLAN_NAME = podatak2[1].Replace(@"""", "");

                            string[] podatak3 = listapodataka[10].Split(new[] { "=" }, StringSplitOptions.None);
                            log.AP_NAME = podatak3[1].Replace(@"""", "");


                            log.EventType = "Roaming";

                            if (listapodataka.Length == 36)
                            {
                                string[] podatak4 = listapodataka[17].Split(new[] { "=" }, StringSplitOptions.None);

                                log.RSSI = Int32.Parse(podatak4[1].Replace(@"""", ""));
                            }

                            if (listapodataka.Length == 39)
                            {
                                string[] podatak4 = listapodataka[19].Split(new[] { "=" }, StringSplitOptions.None);

                                log.RSSI = Int32.Parse(podatak4[1].Replace(@"""", ""));
                            }
                        }


                        if (Regex.Match(drugidio, pattern4).Success)
                        {
                            string[] listapodataka = drugidio.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                            string[] podatak = listapodataka[2].ToString().Split(new[] { "=" }, StringSplitOptions.None);
                            log.AP_MAC = podatak[1].Replace(@"""", "");

                            string[] podatak1 = listapodataka[3].Split(new[] { "=" }, StringSplitOptions.None);
                            log.User_MAC = podatak1[1].Replace(@"""", "");

                            string[] podatak2 = listapodataka[4].Split(new[] { "=" }, StringSplitOptions.None);
                            log.WLAN_NAME = podatak2[1].Replace(@"""", "");

                            log.EventType = "clientJoin";

                            string[] podatak3 = listapodataka[10].Split(new[] { "=" }, StringSplitOptions.None);
                            log.AP_NAME = podatak3[1].Replace(@"""", "");
                        }
                        if (Regex.Match(drugidio, pattern5).Success)
                        {
                            string[] listapodataka = drugidio.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            Console.WriteLine(listapodataka.Length);
                            string[] podatak = listapodataka[2].ToString().Split(new[] { "=" }, StringSplitOptions.None);
                            log.AP_MAC = podatak[1].Replace(@"""", "");

                            string[] podatak1 = listapodataka[3].Split(new[] { "=" }, StringSplitOptions.None);
                            log.User_MAC = podatak1[1].Replace(@"""", "");

                            string[] podatak2 = listapodataka[4].Split(new[] { "=" }, StringSplitOptions.None);
                            log.WLAN_NAME = podatak2[1].Replace(@"""", "");

                            string[] podatak3 = listapodataka[10].Split(new[] { "=" }, StringSplitOptions.None);
                            log.AP_NAME = podatak3[1].Replace(@"""", "");

                            log.EventType = "clientDisconnect";

                            if (listapodataka.Length == 48)
                            {
                                string[] podatak4 = listapodataka[29].Split(new[] { "=" }, StringSplitOptions.None);

                                log.RSSI = Int32.Parse(podatak4[1].Replace(@"""", ""));
                            }

                            if (listapodataka.Length == 51)
                            {
                                string[] podatak4 = listapodataka[31].Split(new[] { "=" }, StringSplitOptions.None);

                                log.RSSI = Int32.Parse(podatak4[1].Replace(@"""", ""));
                            }
                        }
                        logovi.Add(log);
                        counter++;
                    }
                }
                sr.Close();
                sr.Dispose();
                file.Close();
                file.Dispose();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);


            LogHistory  history2   = new LogHistory(filename + ".......Zapis neuspješan!" + e);
            string      sourceFile = System.IO.Path.Combine(putanja, filename);
            string      destFile   = System.IO.Path.Combine(@"\\WS-VENTEX\files\izbrisano", filename);
            MailMessage mail       = new MailMessage("*****@*****.**", "[email protected],[email protected]");
            {
                mail.Subject = "RUCKUS ALARMS";
                mail.Body    = e.ToString();
            }

            SmtpClient client = new SmtpClient();
            {
                client.Port                  = 25;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Host                  = "webmail2.jadranka.hr";
                client.Send(mail);
            }


            sr.Close();
            sr.Dispose();
            file.Close();
            file.Dispose();
            System.IO.File.Move((putanja + filename), destFile);
            Environment.Exit(0);
            return;
        }



        int u = 0;

        /// <summary>
        ///  Spremanje u bazu.Entity framework klase.
        /// </summary>
        foreach (LogConnection m in logovi)
        {
            EventType tmpEvent = db.EventType.Where(x => x.EventName == m.EventType).FirstOrDefault <EventType>();


            if (tmpEvent == null)
            {
                eve.EventName = m.EventType;
                db.EventType.Add(eve);
                rc.EventTypeId = eve.EventId;
            }
            else
            {
                rc.EventTypeId = tmpEvent.EventId;
            }

            User tmpMac = db.User.Where(x => x.UserMac == m.User_MAC).FirstOrDefault <User>();


            if (tmpMac == null)
            {
                us.UserMac = m.User_MAC;
                db.User.Add(us);
                rc.UserId = us.UserId;
            }
            else
            {
                rc.UserId = tmpMac.UserId;
            }

            Device tmpDev = db.Device.Where(x => x.DeviceMac == m.AP_MAC && x.DeviceName == m.AP_NAME).FirstOrDefault <Device>();

            if (tmpDev == null)
            {
                d.DeviceName = m.AP_NAME;
                d.DeviceMac  = m.AP_MAC;
                db.Device.Add(d);
                rc.DeviceId = d.DeviceId;
            }
            else
            {
                rc.DeviceId = tmpDev.DeviceId;
            }

            Ssid tmpSsid = db.Ssid.Where(x => x.SsidName == m.WLAN_NAME).FirstOrDefault <Ssid>();

            if (tmpSsid == null)
            {
                s.SsidName = m.WLAN_NAME;
                rc.SsidId  = s.SsidId;
                db.Ssid.Add(s);
            }
            else
            {
                rc.SsidId = tmpSsid.SsidId;
            }



            rc.TimeStamp = m.Datetime;
            rc.Snr       = m.SNR;
            rc.Rssi      = m.RSSI;


            db.Ruckus_Log.Add(rc);
            //db.SaveChanges();

            Console.WriteLine(u);

            u++;


            try

            {
                db.SaveChanges();
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine(e.Message);
                MailMessage mail = new MailMessage("*****@*****.**", "[email protected],[email protected]");
                {
                    mail.Subject = "RUCKUS ALARMS";
                    mail.Body    = e.ToString();
                }

                SmtpClient client = new SmtpClient();
                {
                    client.Port                  = 25;
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Host                  = "webmail2.jadranka.hr";
                    client.Send(mail);
                }


                LogHistory history1   = new LogHistory(filename + ".......Zapis neuspješan!" + e);
                string     sourceFile = System.IO.Path.Combine(putanja, filename);
                string     destFile   = System.IO.Path.Combine(@"\\WS-VENTEX\files\izbrisano", filename);
                System.IO.File.Move((putanja + filename), destFile);

                db.Database.CurrentTransaction.Rollback();
                Environment.Exit(0);
                return;
            }
        }

        //Nakon što se log parsira premješta se u folder "izbrisano".

        string path1  = @"\\WS-VENTEX\files\";
        string path10 = @"C:\Users\jerko.viskov\Documents\logovi\";

        if (System.IO.File.Exists(path1 + filename))
        {
            Console.WriteLine("Brisanje filea");
            Console.WriteLine(path1 + filename);
            string sourceFile = System.IO.Path.Combine(path1, filename);
            string destFile   = System.IO.Path.Combine(@"\\WS-VENTEX\files\izbrisano", filename);
            System.IO.File.Move((path1 + filename), destFile);
        }

        LogHistory history = new LogHistory(filename + "........Zapis uspješan!");
    }
Beispiel #11
0
        public int getNumber_Xe(int type)
        {
            LogConnection logConnection = new LogConnection();

            return(logConnection.GetNumber_Xe(type));
        }
Beispiel #12
0
        public int getNumberLog()
        {
            LogConnection logConnection = new LogConnection();

            return(logConnection.GetNumberLog());;
        }