Ejemplo n.º 1
0
        public async void ClearActions()
        {
            var result = await Task.Run(() =>
            {
                using (var context = new VNMContext())
                {
                    foreach (var item in Core.Instance.allHosts)
                    {
                        var command = context.Database.ExecuteSqlRaw($"DELETE FROM Actions WHERE HostId = {item.HostId} AND ActionId NOT IN(SELECT ActionId FROM(SELECT ActionId FROM Actions WHERE HostId = {item.HostId} ORDER BY ActionId DESC  LIMIT 200))");
                        NotificationService.AddtoLog("Done", item.Name, $"Cleared {command} actions");
                    }

                    context.SaveChangesAsync();
                    return(context);
                }
            });

            waitingVisibility = Visibility.Hidden;
            Messenger.Default.Send <UIMessage>(new UIMessage {
                PropName = "WaitingVisibility"
            });
            GlobalSettings.Instance.Closing = true;

            Application.Current.Shutdown();
        }
Ejemplo n.º 2
0
        async public void UpdateCategory(Category category)
        {
            await using (var context = new VNMContext())
            {
                context.Entry(category).State = EntityState.Modified;
                await context.SaveChangesAsync();

                NotificationService.AddtoLog("Done", category.Name, "Updated");
            }
        }
Ejemplo n.º 3
0
        async public void RemoveHost(Host host)
        {
            await using (var context = new VNMContext())
            {
                context.Entry(host).State = EntityState.Deleted;
                var command = await context.Database.ExecuteSqlRawAsync($"DELETE from Actions WHERE HostId = {host.HostId}");

                await context.SaveChangesAsync();

                NotificationService.AddtoLog("Done", host.Name, $"Removed with {command} actions");
            }
        }
Ejemplo n.º 4
0
        async public void ReloadSettings()
        {
            await using (var context = new VNMContext())
            {
                if (await context.Globals.AnyAsync())
                {
                    await context.Entry(GlobalSettings.Instance).ReloadAsync();

                    NotificationService.AddtoLog("Done", "Core", "Settings updated");
                }
            }
        }
Ejemplo n.º 5
0
        async public void RemoveCategory(Category category)
        {
            await using (var context = new VNMContext())
            {
                for (int i = 0; i < category.Hosts.Count; i++)
                {
                    RemoveHost(category.Hosts[i]);
                }
                context.Entry(category).State = EntityState.Deleted;

                await context.SaveChangesAsync();

                NotificationService.AddtoLog("Done", category.Name, "Removed");
            }
        }
Ejemplo n.º 6
0
        async public void AddHost(Host host, int catId)
        {
            await using (var context = new VNMContext())
            {
                host.CategoryId = catId;
                await context.Hosts.AddAsync(host);

                await context.SaveChangesAsync();

                host = await context.Hosts.OrderBy(i => i.HostId).LastAsync();

                categories.Where(i => i.CategoryId == catId).First().Hosts.Add(host);
                allHosts.Add(host);
            }
            NotificationService.AddtoLog("Done", host.Name, "Added");
        }
Ejemplo n.º 7
0
        async public void AddRange(IEnumerable <Host> hosts)
        {
            await using (var context = new VNMContext())
            {
                await context.Hosts.AddRangeAsync(hosts);

                await context.SaveChangesAsync();

                hosts = await context.Hosts.OrderByDescending(i => i.HostId).Take(hosts.Count()).Reverse().ToListAsync();

                foreach (var item in hosts)
                {
                    categories.Where(i => i.CategoryId == targetCategory.CategoryId).First().Hosts.Add(item);
                    allHosts.Add(item);
                    NotificationService.AddtoLog("Done", item.Name, "Added");
                }
            }
        }
Ejemplo n.º 8
0
        async public void UpdateSettings()
        {
            await using (var context = new VNMContext())
            {
                if (await context.Globals.AnyAsync())
                {
                    context.Entry(GlobalSettings.Instance).State = EntityState.Modified;
                    await context.SaveChangesAsync();

                    NotificationService.AddtoLog("Done", "Core", "Settings saved");
                }
                else
                {
                    await context.Globals.AddAsync(GlobalSettings.Instance);

                    await context.SaveChangesAsync();

                    NotificationService.AddtoLog("Done", "Core", "Settings saved first time");
                }
            }
        }
Ejemplo n.º 9
0
        async public void AddCategory(string catName)
        {
            Category category = new Category {
                Name = catName
            };

            await using (var context = new VNMContext())
            {
                await context.Categories.AddAsync(category);

                await context.SaveChangesAsync();

                categories.Add(await context.Categories.OrderBy(i => i.CategoryId).LastAsync());
                categories.Last().Hosts = new ObservableCollection <Host>(allHosts.Where(c => c.CategoryId == categories.Last().CategoryId));
                categories.Last().HostsView = CollectionViewSource.GetDefaultView(categories.Last().Hosts);
                categories.Last().HostsView.SortDescriptions.Add(new SortDescription("Status", ListSortDirection.Ascending));
                categories.Last().HostsView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                var collectionViewLiveShaping = categories.Last().HostsView as ICollectionViewLiveShaping;
                collectionViewLiveShaping.IsLiveSorting   = true;
                collectionViewLiveShaping.IsLiveFiltering = true;
            }
            NotificationService.AddtoLog("Done", catName, "Added");
        }