Exemplo n.º 1
0
        public static void ShowNotification(int PID, string applicationName, string applicationPath, CustomNotification.ActionType actionType)
        {
            DateTime time = DateTime.Now;

            Application.Current.Dispatcher.BeginInvoke(
                new Action(() => _notifier.ShowNotification(PID, applicationName, applicationPath, actionType, time)));

            AddToNotificationList(applicationName, applicationPath, actionType, time);

            Task.Run(() =>
            {
                using (var db = new ArgonDB())
                    db.InsertAsync(new Notification
                    {
                        Time            = time.Ticks,
                        ApplicationName = applicationName,
                        ApplicationPath = applicationPath,
                        Type            = (int)actionType,
                        NotActivated    = 1
                    });
            });

            try {
                Application.Current.Dispatcher.BeginInvoke(
                    new Action(() =>
                {
                    ((MainWindow)Application.Current.MainWindow).Notifications.UpdateViewSource();
                }));
            }
            catch { }
        }
Exemplo n.º 2
0
        static void WriteToDb()
        {
            using (var db = new ArgonDB())
                try {
                    db.BeginTransaction();
                    lock (ProcessDataList)
                        foreach (ProcessData p in ProcessDataList)
                        {
                            if (p.ProcessorLoadPercent != 0)
                            {
                                db.InsertAsync(new ProcessCounter
                                {
                                    Time = p.Time,
                                    Name = p.Name,
                                    Path = p.Path,
                                    ProcessorLoadPercent = p.ProcessorLoadPercent
                                });
                            }
                        }

                    lock (NetworkTrafficList) {
                        foreach (NetworkTraffic n in NetworkTrafficList)
                        {
                            db.InsertAsync(n);
                        }
                        NetworkTrafficList.Clear();
                    }
                    db.CommitTransaction();
                }
                catch { db.RollbackTransaction(); }
        }
Exemplo n.º 3
0
        protected void GetAppDetails(AppUsage a)
        {
            KillRunningThreads();
            AppDetailsViewSource.Source = null;
            ProgressRing2.Visibility    = Visibility.Visible;

            Task.Run(() =>
            {
                threads.Add(Thread.CurrentThread);
                List <AppDetail> details;
                using (var db = new ArgonDB()) {
                    details = db.NetworkTraffic
                              .Where(x => x.Time.Between(DateFrom.Ticks, DateTo.Ticks) && x.FilePath == a.Path && x.ApplicationName == a.Name)
                              .Select(x => new AppDetail
                    {
                        SourceIP        = x.SourceAddr,
                        SourcePort      = x.SourcePort,
                        DestinationIP   = x.DestAddr,
                        DestinationPort = x.DestPort
                    }).Distinct().ToList();
                }

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    ProgressRing2.Visibility    = Visibility.Collapsed;
                    AppDetailsViewSource.Source = details;
                }));

                threads.Clear();
            });
        }
Exemplo n.º 4
0
        private void ActionButton_Click(object sender, RoutedEventArgs e)
        {
            var notif = (NotificationItem)((FrameworkElement)sender).DataContext;

            if (notif.Type == (int)CustomNotification.ActionType.BlockAllow)
            {
                Firewall.SetRule(notif.ApplicationName, notif.ApplicationPath, false);
            }
            else if (notif.Type == (int)CustomNotification.ActionType.UnblockAllow)
            {
                Firewall.RemoveRule(notif.ApplicationName, notif.ApplicationPath);
            }
            else if (notif.Type == (int)CustomNotification.ActionType.SuspendWhitelist ||
                     notif.Type == (int)CustomNotification.ActionType.TerminateWhitelist)
            {
                Controller.AddToWhitelist(notif.ApplicationName, notif.ApplicationPath);
            }

            Task.Run(() =>
            {
                Controller.NotificationList.Find(x => x == notif).NotActivated = false;

                using (var db = new ArgonDB())
                    db.NotificationsList
                    .Where(x => x.Type == notif.Type &&
                           x.ApplicationPath == notif.ApplicationPath &&
                           x.Time == notif.Time.Ticks)
                    .Set(x => x.NotActivated, 0)
                    .Update();

                UpdateViewSource();
            });
        }
Exemplo n.º 5
0
        public void GetProcValues(int duration)
        {
            using (var db = new ArgonDB()) {
                var time = new DateTime(DateTime.Now.AddSeconds(-duration).Ticks.NextSecond());
                var data = db.ProcessCounters
                           .OrderByDescending(x => x.Time)
                           .Take(200000)
                           .Where(x => x.Time > time.Ticks)
                           .GroupBy(x => x.Time)
                           .Select(y => new
                {
                    Time     = y.Select(z => z.Time).First(),
                    ProcLoad = y.Sum(z => z.ProcessorLoadPercent)
                }).ToList();

                for (int i = 0; i < duration; i++)
                {
                    var _time = time.AddSeconds(i);
                    var val   = data.Where(x => x.Time == _time.Ticks).FirstOrDefault();
                    if (val != null)
                    {
                        ProcLoadValues.Add(new DateTimePoint(_time, (double)val.ProcLoad));
                    }
                    else
                    {
                        ProcLoadValues.Add(new DateTimePoint(_time, 0));
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void GetNetValues(int duration)
        {
            using (var db = new ArgonDB()) {
                var time = new DateTime(DateTime.Now.AddSeconds(-duration).Ticks.NextSecond());
                var data = db.NetworkTraffic
                           .OrderByDescending(x => x.Time)
                           .Take(30000)
                           .Where(x => x.Time > time.Ticks)
                           .GroupBy(x => x.Time)
                           .Select(y => new
                {
                    Time = y.Select(z => z.Time).First(),
                    Sent = y.Sum(z => z.Sent),
                    Recv = y.Sum(z => z.Recv)
                }).ToList();

                for (int i = 0; i < duration; i++)
                {
                    var _time = time.AddSeconds(i);
                    var val   = data.Where(x => x.Time == _time.Ticks).FirstOrDefault();
                    if (val != null)
                    {
                        SentValues.Add(new DateTimePoint(_time, val.Sent));
                        RecvValues.Add(new DateTimePoint(_time, val.Recv));
                    }
                    else
                    {
                        SentValues.Add(new DateTimePoint(_time, 0));
                        RecvValues.Add(new DateTimePoint(_time, 0));
                    }
                }
            }
        }
Exemplo n.º 7
0
 static void ReadNotifications()
 {
     using (var db = new ArgonDB())
         db.NotificationsList
         .Where(x => x.Time > DateTime.Today.AddDays(-7).Ticks)
         .ForEachAsync(x => AddToNotificationList(
                           x.ApplicationName, x.ApplicationPath, (ActionType)x.Type, new DateTime(x.Time), x.NotActivated == 1));
 }
Exemplo n.º 8
0
 static List <string> GetNetworkProcessList()
 {
     using (var db = new ArgonDB())
         return(db.NetworkTraffic
                .Select(x => x.FilePath)
                .Distinct()
                .ToList());
 }
Exemplo n.º 9
0
        private void MarkAllAsReadButton_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
                Controller.NotificationList.ForEach(x => x.NotActivated = false);

                UpdateViewSource();

                using (var db = new ArgonDB())
                    db.NotificationsList
                    .Set(x => x.NotActivated, 0)
                    .UpdateAsync();
            });
        }
Exemplo n.º 10
0
 static void ReadConfig()
 {
     using (var db = new ArgonDB()) {
         NotifyNewApplication   = db.Config.First(x => x.Name == "NotifyNewApplication").Value == 1;
         BlockNewConnections    = db.Config.First(x => x.Name == "BlockNewConnections").Value == 1;
         SuspendHighCpu         = db.Config.First(x => x.Name == "SuspendHighCpu").Value == 1;
         NotifyHighCpu          = db.Config.First(x => x.Name == "NotifyHighCpu").Value == 1;
         ProcessorLoadThreshold = db.Config.First(x => x.Name == "HighCpuThreshold").Value;
         CpuSuspendWhitelist.Add(new WhitelistedApp {
             Name = "Argon", Path = Process.GetCurrentProcess().MainModule.FileName
         });
         db.CpuSuspendWhitelist.ForEachAsync(x => CpuSuspendWhitelist.Add(x));
     }
 }
Exemplo n.º 11
0
        private void ChkSuspendHighCPU_Click(object sender, RoutedEventArgs e)
        {
            bool val = ((CheckBox)sender).IsChecked ?? false;

            Controller.SuspendHighCpu = val;

            using (var db = new ArgonDB())
                db.Config
                .Where(x => x.Name == "SuspendHighCpu")
                .Set(x => x.Value, val ? 1 : 0)
                .Update();

            e.Handled = true;
        }
Exemplo n.º 12
0
        private void ChkBlockFirstConn_Click(object sender, RoutedEventArgs e)
        {
            bool val = ((CheckBox)sender).IsChecked ?? false;

            Controller.BlockNewConnections = val;

            using (var db = new ArgonDB())
                db.Config
                .Where(x => x.Name == "BlockNewConnections")
                .Set(x => x.Value, val ? 1 : 0)
                .Update();

            e.Handled = true;
        }
Exemplo n.º 13
0
        private void UpdateThresholdValue(int threshold)
        {
            if (!SliderInit)
            {
                SliderInit = true;
                return;
            }

            Controller.ProcessorLoadThreshold = threshold;

            using (var db = new ArgonDB())
                db.Config
                .Where(x => x.Name == "HighCpuThreshold")
                .Set(x => x.Value, threshold)
                .Update();
        }
Exemplo n.º 14
0
        public static List <FirewallRule> GetFirewallRules()
        {
            var rules = new List <FirewallRule>();

            foreach (INetFwRule rule in Firewall.FirewallPolicy.Rules.Cast <INetFwRule>().Where(x => x.Grouping == "Argon"))
            {
                if (!rules.Exists(x => x.Name == rule.Name) && rule.Name != "Argon")
                {
                    rules.Add(new FirewallRule
                    {
                        Action = rule.Action == NET_FW_ACTION_.NET_FW_ACTION_ALLOW ? true : false,
                        Name   = rule.Name,
                        Path   = rule.ApplicationName,
                    });
                }
            }

            foreach (FirewallRule r in rules)
            {
                r.Name = r.Name.Split(new string[] { "__" }, StringSplitOptions.None)[0];
            }

            foreach (FirewallRule app in GetAppsList())
            {
                if (!rules.Any(x => x.Name == app.Name && x.Path == app.Path))
                {
                    rules.Add(app);
                }
            }

            return(rules);


            List <FirewallRule> GetAppsList()
            {
                using (var db = new ArgonDB())
                    return(db.NetworkTraffic
                           .Select(x => new FirewallRule
                    {
                        Path = x.FilePath,
                        Name = x.ApplicationName,
                        Action = null
                    })
                           .Distinct()
                           .ToList());
            }
        }
Exemplo n.º 15
0
        public static void AddToWhitelist(int PID, string name, string path)
        {
            var app = new WhitelistedApp
            {
                Name = name,
                Path = path
            };

            using (var db = new ArgonDB())
                try {
                    db.InsertAsync(app);
                }
                catch { }

            CpuSuspendWhitelist.Add(app);
            SuspendedProcessList.RemoveAll(x => x.ID == PID);
        }
Exemplo n.º 16
0
 protected List <ProcApp> GetProcAppList()
 {
     using (var db = new ArgonDB()) {
         return(db.ProcessCounters
                .OrderByDescending(x => x.Time)
                .Take(10000)
                .Where(x => ((double)x.Time).Between(From, To))
                .GroupBy(x => x.Name)
                .Select(y => new ProcApp
         {
             Icon = y.First().Path.GetIcon(),
             Name = y.First().Name,
             Path = y.First().Path,
             Processor = Math.Round(y.Average(z => z.ProcessorLoadPercent), 2)
         }).ToList());
     }
 }
Exemplo n.º 17
0
        List <DateTimePoint> GetLast2ProcValues()
        {
            var time = new DateTime(DateTime.Now.AddSeconds(-3).Ticks.NextSecond());

            using (var db = new ArgonDB()) {
                return(db.ProcessCounters
                       .OrderByDescending(x => x.Time)
                       .Take(1000)
                       .Where(x => x.Time.Between(time.Ticks, time.AddSeconds(1).Ticks))
                       .GroupBy(x => x.Time)
                       .Select(y => new DateTimePoint
                {
                    DateTime = new DateTime(y.First().Time),
                    Value = y.Sum(z => z.ProcessorLoadPercent)
                })
                       .ToList());
            }
        }
Exemplo n.º 18
0
 protected ObservableCollection <NetApp> GetNetAppList()
 {
     using (var db = new ArgonDB()) {
         return(db.NetworkTraffic
                .OrderByDescending(x => x.Time)
                .Take(30000)
                .Where(x => ((double)x.Time).Between(From, To))
                .GroupBy(x => x.ApplicationName)
                .Select(y => new NetApp
         {
             Icon = y.First().FilePath.GetIcon(),
             Name = y.First().ApplicationName,
             Path = y.First().FilePath,
             Sent = y.Sum(z => z.Sent),
             Recv = y.Sum(z => z.Recv),
             Total = y.Sum(z => z.Sent) + y.Sum(z => z.Recv)
         }).ToObservableCollection());
     }
 }
Exemplo n.º 19
0
        List <DateTimePoint> GetLast2NetValues()
        {
            var time = new DateTime(DateTime.Now.AddSeconds(-3).Ticks.NextSecond());
            List <NetworkTraffic> data;
            List <DateTimePoint>  list = new List <DateTimePoint>();

            using (var db = new ArgonDB()) {
                data = db.NetworkTraffic
                       .OrderByDescending(x => x.Time)
                       .Take(100)
                       .Where(x => x.Time.Between(time.Ticks, time.AddSeconds(1).Ticks))
                       .GroupBy(x => x.Time)
                       .Select(y => new NetworkTraffic
                {
                    Time = y.First().Time,
                    Sent = y.Sum(z => z.Sent),
                    Recv = y.Sum(z => z.Recv)
                })
                       .ToList();
            }

            for (var i = 0; i < 2; i++)
            {
                if (data.Count > i)
                {
                    list.Add(new DateTimePoint(time.AddSeconds(i), data[i].Sent));
                    list.Add(new DateTimePoint(time.AddSeconds(i), data[i].Recv));
                }
                else
                {
                    list.Add(new DateTimePoint(time.AddSeconds(i), 0));
                    list.Add(new DateTimePoint(time.AddSeconds(i), 0));
                }
            }
            return(list);
        }
Exemplo n.º 20
0
        protected List <AppUsage> GetApplicationList()
        {
            var proc = new List <AppUsage>();
            var net  = new List <AppUsage>();

            Task readProc = Task.Factory.StartNew(() =>
            {
                threads.Add(Thread.CurrentThread);
                using (var db = new ArgonDB()) {
                    proc = db.ProcessCounters
                           .AsParallel()
                           .Where(x => ((double)x.Time).Between(DateFrom.Ticks, DateTo.Ticks))
                           .GroupBy(x => new { x.Name, x.Path })
                           .Select(y => new AppUsage
                    {
                        Icon = y.First().Path.GetIcon(),
                        Name = y.First().Name,
                        Path = y.First().Path,
                        CPU  = Math.Round(y.Average(z => z.ProcessorLoadPercent), 2)
                    }).ToList();
                }
            });

            Task readNet = Task.Factory.StartNew(() =>
            {
                threads.Add(Thread.CurrentThread);
                using (var db = new ArgonDB()) {
                    net = db.NetworkTraffic
                          .Where(x => ((double)x.Time).Between(DateFrom.Ticks, DateTo.Ticks))
                          .GroupBy(x => new { x.ApplicationName, x.FilePath })
                          .Select(y => new AppUsage
                    {
                        Name  = y.First().ApplicationName,
                        Path  = y.First().FilePath,
                        Sent  = y.Sum(z => z.Sent),
                        Recv  = y.Sum(z => z.Recv),
                        Total = y.Sum(z => z.Sent) + y.Sum(z => z.Recv)
                    }).ToList();
                }
            });

            var net2 = new List <AppUsage>();

            readNet.Wait();
            readProc.Wait();

            Parallel.ForEach(net, (n) =>
            {
                var p = proc.Where(x => x.Path == n.Path && x.Name == n.Name).FirstOrDefault();
                if (p == null)
                {
                    net2.Add(new AppUsage
                    {
                        Icon  = n.Path.GetIcon(),
                        Name  = n.Name,
                        Path  = n.Path,
                        Sent  = n.Sent,
                        Recv  = n.Recv,
                        Total = n.Total
                    });
                }
                else
                {
                    p.Sent  = n.Sent;
                    p.Recv  = n.Recv;
                    p.Total = n.Total;
                }
            });

            proc.AddRange(net2);
            return(proc);
        }
Exemplo n.º 21
0
        public CustomNotification(int PID, string applicationName, string applicationPath, ActionType actionType, DateTime time)
        {
            Time = time.ToLongTimeString();
            string title = actionType == ActionType.BlockAllow ? "First connection: " :
                           actionType == ActionType.UnblockAllow ? "Blocked connection: " :
                           actionType == ActionType.SuspendWhitelist ? "High CPU load: " :
                           actionType == ActionType.TerminateWhitelist ? "Suspended: " :
                           "";

            Title   = title + applicationName;
            Message = applicationPath;

            Button1 = actionType == ActionType.BlockAllow ? "BLOCK" :
                      actionType == ActionType.UnblockAllow ? "UNBLOCK" :
                      actionType == ActionType.SuspendWhitelist ? "SUSPEND" :
                      actionType == ActionType.TerminateWhitelist ? "TERMINATE" :
                      null;

            Button2 = actionType == ActionType.BlockAllow ? "ALLOW" :
                      actionType == ActionType.UnblockAllow ? "ALLOW" :
                      actionType == ActionType.SuspendWhitelist ? "WHITELIST" :
                      actionType == ActionType.TerminateWhitelist ? "WHITELIST" :
                      null;

            BackgroundColor = actionType == ActionType.BlockAllow ?
                              new SolidColorBrush(Color.FromArgb(255, 0, 182, 0)) :
                              actionType == ActionType.UnblockAllow ?
                              new SolidColorBrush(Color.FromArgb(255, 182, 0, 0)) :
                              actionType == ActionType.SuspendWhitelist ?
                              new SolidColorBrush(Color.FromArgb(255, 0, 112, 128)) :
                              actionType == ActionType.TerminateWhitelist ?
                              new SolidColorBrush(Color.FromArgb(255, 204, 80, 0)) :
                              new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));

            Action _button1Action = actionType == ActionType.BlockAllow ?
                                    new Action(() => Firewall.SetRule(applicationName, applicationPath, false)) :
                                    actionType == ActionType.UnblockAllow ?
                                    new Action(() => Firewall.RemoveRule(applicationName + "__" + applicationPath)) :
                                    actionType == ActionType.SuspendWhitelist ?
                                    new Action(() => Controller.SuspendProcess(PID)) :
                                    actionType == ActionType.TerminateWhitelist ?
                                    new Action(() => Controller.TerminateProcess(PID)) :
                                    new Action(() => { });

            Action _button2Action = actionType == ActionType.BlockAllow ?
                                    new Action(() => Firewall.SetRule(applicationName, applicationPath, true)) :
                                    actionType == ActionType.UnblockAllow ?
                                    new Action(() => Firewall.SetRule(applicationName, applicationPath, true)) :
                                    actionType == ActionType.SuspendWhitelist ?
                                    new Action(() =>
            {
                Controller.AddToWhitelist(PID, applicationName, applicationPath);
                ((MainWindow)Application.Current.MainWindow).SuspendedProcesses.UpdateViewSource();
            }) :
                                    actionType == ActionType.TerminateWhitelist ?
                                    new Action(() =>
            {
                Controller.ResumeProcess(PID);
                Controller.AddToWhitelist(PID, applicationName, applicationPath);
                ((MainWindow)Application.Current.MainWindow).SuspendedProcesses.UpdateViewSource();
            }) :
                                    new Action(() => { });

            var _closeAction = new Action <CustomNotification>(n => n.Close());

            Action setNotificationActivated = new Action(() =>
            {
                Controller.NotificationList.Find(x => x.Type == (int)actionType && x.ApplicationPath == applicationPath && x.Time == time).NotActivated = false;
                ((MainWindow)Application.Current.MainWindow).Notifications.UpdateViewSource();

                using (var db = new ArgonDB())
                    db.NotificationsList
                    .Where(x => x.Type == (int)actionType &&
                           x.ApplicationPath == applicationPath &&
                           x.Time == time.Ticks)
                    .Set(x => x.NotActivated, 0)
                    .Update();
            });

            Button1Command = new RelayCommand(x => { _button1Action(); setNotificationActivated(); _closeAction(this); });
            Button2Command = new RelayCommand(x => { _button2Action(); setNotificationActivated(); _closeAction(this); });
            CloseCommand   = new RelayCommand(x => _closeAction(this));
        }
Exemplo n.º 22
0
 public static void RemoveFromWhitelist(WhitelistedApp app)
 {
     CpuSuspendWhitelist.RemoveAll(x => x == app);
     using (var db = new ArgonDB())
         db.DeleteAsync(app);
 }
Exemplo n.º 23
0
        private void CreateDbIfNotExist()
        {
            using (var db = new ArgonDB()) {
                try {
                    db.Config.Any();
                }
                catch {
                    string sql = "BEGIN TRANSACTION;" +
                                 "DROP TABLE IF EXISTS `ProcessCounters`;" +
                                 "CREATE TABLE IF NOT EXISTS `ProcessCounters` (" +
                                 "	`Time`	INTEGER NOT NULL,"+
                                 "	`Name`	TEXT NOT NULL,"+
                                 "	`Path`	TEXT NOT NULL,"+
                                 "	`ProcessorLoadPercent`	REAL NOT NULL"+
                                 ");" +
                                 "DROP TABLE IF EXISTS `Notifications`;" +
                                 "CREATE TABLE IF NOT EXISTS `Notifications` (" +
                                 "	`Time`	INTEGER,"+
                                 "	`ApplicationName`	TEXT,"+
                                 "	`ApplicationPath`	TEXT,"+
                                 "	`Type`	INTEGER,"+
                                 "	`NotActivated`	INTEGER"+
                                 ");" +
                                 "DROP TABLE IF EXISTS `NetworkTraffic`;" +
                                 "CREATE TABLE IF NOT EXISTS `NetworkTraffic` (" +
                                 "	`Time`	INTEGER NOT NULL,"+
                                 "	`ApplicationName`	TEXT NOT NULL,"+
                                 "	`ProcessName`	TEXT NOT NULL,"+
                                 "	`FilePath`	TEXT NOT NULL,"+
                                 "	`Sent`	INTEGER NOT NULL,"+
                                 "	`Recv`	INTEGER NOT NULL,"+
                                 "	`SourceAddr`	TEXT NOT NULL,"+
                                 "	`SourcePort`	INTEGER NOT NULL,"+
                                 "	`DestAddr`	TEXT NOT NULL,"+
                                 "	`DestPort`	INTEGER NOT NULL,"+
                                 "	`Type`	INTEGER NOT NULL,"+
                                 "	`ProcessID`	INTEGER"+
                                 ");" +
                                 "DROP TABLE IF EXISTS `CpuSuspendWhitelist`;" +
                                 "CREATE TABLE IF NOT EXISTS `CpuSuspendWhitelist` (" +
                                 "	`Name`	TEXT NOT NULL,"+
                                 "	`Path`	TEXT NOT NULL UNIQUE"+
                                 ");" +
                                 "DROP TABLE IF EXISTS `Config`;" +
                                 "CREATE TABLE IF NOT EXISTS `Config` (" +
                                 "	`Name`	TEXT,"+
                                 "	`Value`	INTEGER"+
                                 ");" +
                                 "INSERT INTO `Config` VALUES ('NotifyNewApplication',1);" +
                                 "INSERT INTO `Config` VALUES ('BlockNewConnections',0);" +
                                 "INSERT INTO `Config` VALUES ('NotifyHighCpu',1);" +
                                 "INSERT INTO `Config` VALUES ('SuspendHighCpu',0);" +
                                 "INSERT INTO `Config` VALUES ('HighCpuThreshold',30);" +
                                 "DROP INDEX IF EXISTS `processor_time_index`;" +
                                 "CREATE INDEX IF NOT EXISTS `processor_time_index` ON `ProcessCounters` (" +
                                 "	`time`	DESC"+
                                 ");" +
                                 "DROP INDEX IF EXISTS `network_time_path_index`;" +
                                 "CREATE INDEX IF NOT EXISTS `network_time_path_index` ON `NetworkTraffic` (" +
                                 "	`time`	DESC,"+
                                 "	`filepath`,"+
                                 "	`ApplicationName`"+
                                 ");" +
                                 "DROP INDEX IF EXISTS `network_time_index`;" +
                                 "CREATE INDEX IF NOT EXISTS `network_time_index` ON `NetworkTraffic` (" +
                                 "	`time`	DESC"+
                                 ");" +
                                 "DROP INDEX IF EXISTS `network_applicationname_index`;" +
                                 "CREATE INDEX IF NOT EXISTS `network_applicationname_index` ON `NetworkTraffic` (" +
                                 "	`ApplicationName`"+
                                 ");" +
                                 "COMMIT;";

                    SQLiteCommand cmd = new SQLiteCommand(sql, new SQLiteConnection(db.ConnectionString).OpenAndReturn());
                    cmd.ExecuteNonQuery();
                }
            }
        }