Exemplo n.º 1
0
        private void OnDataSaving()
        {
            using (var context = new MetricsDataContext(_connectionString))
            {
                for (int i = 0; i < _report.Count; i++)
                {
                    var existingUser = context.Usernames.FirstOrDefault(u => u.Value == _report[i].Username1.Value);
                    if (existingUser != null)
                    {
                        _report[i].Username1 = existingUser;
                    }

                    var existingIp = context.IpAddresses.FirstOrDefault(ip => ip.Value == _report[i].IpAddress.Value);
                    if (existingIp != null)
                    {
                        _report[i].IpAddress = existingIp;
                    }

                    var existingMac = context.MacAddresses.FirstOrDefault(m => m.Value == _report[i].MacAddress.Value);
                    if (existingMac != null)
                    {
                        _report[i].MacAddress = existingMac;
                    }

                    context.Registries.InsertOnSubmit(_report[i]);
                }
                context.SubmitChanges(); // TODO transaction
                _report.Clear();
            }
        }
 public static void DeleteProcessedRegistries(string connectionString)
 {
     using (var context = new MetricsDataContext(connectionString))
     {
         var registriesToDelete = context.Registries.Where(r => r.Processed.HasValue && r.Processed.Value);
         context.Registries.DeleteAllOnSubmit(registriesToDelete);
         context.SubmitChanges();
     }
 }
Exemplo n.º 3
0
 public static void MarkAsTransmitted(string connectionString, ActivitiesRegistry transmittedRegistry)
 {
     using (var context = new MetricsDataContext(connectionString))
     {
         var dbRegistry = context.ActivitiesRegistries.Single(r => r.Id == transmittedRegistry.Id);
         dbRegistry.Transmitted = true;
         context.SubmitChanges();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Marks 'processed' field with NULL, so that the given registry won't be obtainable
 /// but also isn't marked as a processed.
 /// Usings: 1. If only one registry is obtained, there's no more registries in db - cannot be processed
 /// 2. Filter ban
 /// </summary>
 public static void SetProcessedToNull(string connectionString, Registry registry)
 {
     using (var context = new MetricsDataContext(connectionString))
     {
         var reg = context.Registries.First(r => r.Id == registry.Id);
         reg.Processed = null;
         context.SubmitChanges();
     }
 }
Exemplo n.º 5
0
 public static void MarkAsProcessed(string connectionString, List <Registry> registries)
 {
     using (var context = new MetricsDataContext(connectionString))
     {
         List <Registry> contextRegistries = new List <Registry>();
         registries.ForEach(r => contextRegistries.Add(context.Registries.Single(rg => rg.Id == r.Id)));
         contextRegistries.ForEach(r => r.Processed = true);
         context.SubmitChanges();
     }
 }
Exemplo n.º 6
0
 public static void MarkAllAsNonProcessed(string connectionString)
 {
     using (var context = new MetricsDataContext(connectionString))
     {
         var registries = context.Registries.ToArray();
         for (int i = 0; i < registries.Count(); i++)
         {
             registries[i].Processed = false;
         }
         context.SubmitChanges();
     }
 }
Exemplo n.º 7
0
 public static void StoreJsonInActivitiesRegistry(string connectionString, string json)
 {
     using (var context = new MetricsDataContext(connectionString))
     {
         context.ActivitiesRegistries.InsertOnSubmit(new ActivitiesRegistry()
         {
             Json        = json,
             Transmitted = false
         });
         context.SubmitChanges();
     }
 }
Exemplo n.º 8
0
 private static void DeleteDatabase()
 {
     using (
         MetricsDataContext context =
             new MetricsDataContext(ConfigHelper.GetConnectionString(ConfigFileName, ConnectionName)))
     {
         if (context.DatabaseExists())
         {
             context.DeleteDatabase();
             context.SubmitChanges();
         }
     }
 }
Exemplo n.º 9
0
        public void CreateDatabaseIfNotExists()
        {
            DatabaseMutex.WaitOne();

            using (var context = new MetricsDataContext(_connectionString))
            {
                if (!context.DatabaseExists())
                {
                    context.CreateDatabase();
                    context.SubmitChanges();
                }
            }

            DatabaseMutex.ReleaseMutex();
        }
Exemplo n.º 10
0
        public static void MarkRegistriesAsProcessed(string connectionString, IEnumerable <long> ids)
        {
            var enumerable = ids as long[] ?? ids.ToArray();

            if (!enumerable.Any())
            {
                return;
            }

            using (var context = new MetricsDataContext(connectionString))
            {
                var registriesToMark = context.Registries.Where(r => enumerable.Contains(r.Id)).ToArray();
                for (int i = 0; i < registriesToMark.Length; i++)
                {
                    registriesToMark[i].Processed = true;
                }
                context.SubmitChanges();
            }
        }