예제 #1
0
        public async Task Load_CorrectFileContent()
        {
            var networkInfo = new NetworkInfo();

            networkInfo.ChCenterFrequency = 1;
            networkInfo.Channel           = 2;
            networkInfo.LinkQuality       = 3;
            networkInfo.Mac  = "4";
            networkInfo.Rssi = 5;
            networkInfo.Ssid = "6";

            var scanPoint = new ScanPoint();

            scanPoint.Position = new Point(7, 8);
            scanPoint.BssInfo.Add(networkInfo);

            var expected = new Project();

            expected.Bitmap = new byte[] { 9, 10, 11 };
            expected.ScanPoints.Add(scanPoint);

            var jsonFileStorage = new JsonFileStorage <Project>("Data\\test.json");
            var actual          = await jsonFileStorage.Load();

            Assert.Equal(expected, actual);
        }
예제 #2
0
파일: MainVm.cs 프로젝트: ki0ki0/WiFiMap
        private async Task Load(string fileName)
        {
            IStorage <Project> str = new JsonFileStorage <Project>(fileName);
            var project            = await str.Load();

            ScanVm.Project = project;
        }
예제 #3
0
        public async Task SaveLoad_CorrectProjectContent()
        {
            var random = new Random();

            var networkInfo = new NetworkInfo();

            networkInfo.ChCenterFrequency = (uint)random.Next();
            networkInfo.Channel           = (uint)random.Next();
            networkInfo.LinkQuality       = (uint)random.Next();
            networkInfo.Mac  = Guid.NewGuid().ToString();
            networkInfo.Rssi = random.Next();
            networkInfo.Ssid = Guid.NewGuid().ToString();

            var scanPoint = new ScanPoint();

            scanPoint.Position = new Point(random.Next(), random.Next());
            scanPoint.BssInfo.Add(networkInfo);

            var expected = new Project();

            expected.Bitmap = new byte[100];
            random.NextBytes(expected.Bitmap);
            expected.ScanPoints.Add(scanPoint);

            var tempFileName = Path.GetTempFileName();

            var jsonFileStorage = new JsonFileStorage <Project>(tempFileName);
            await jsonFileStorage.Save(expected);

            var actual = await jsonFileStorage.Load();

            Assert.Equal(expected, actual);
        }
예제 #4
0
        public async Task Save_CorrectFileContent()
        {
            var networkInfo = new NetworkInfo();

            networkInfo.ChCenterFrequency = 1;
            networkInfo.Channel           = 2;
            networkInfo.LinkQuality       = 3;
            networkInfo.Mac  = "4";
            networkInfo.Rssi = 5;
            networkInfo.Ssid = "6";

            var scanPoint = new ScanPoint();

            scanPoint.Position = new Point(7, 8);
            scanPoint.BssInfo.Add(networkInfo);

            var project = new Project();

            project.Bitmap = new byte[] { 9, 10, 11 };
            project.ScanPoints.Add(scanPoint);

            var tempFileName = Path.GetTempFileName();

            var jsonFileStorage = new JsonFileStorage <Project>(tempFileName);
            await jsonFileStorage.Save(project);

            var actual = await File.ReadAllTextAsync(tempFileName);

            var expected = await File.ReadAllTextAsync("Data\\test.json");

            Assert.Equal(expected, actual);
        }
예제 #5
0
        public void Clear()
        {
            Project.Clear();
            var storage = new JsonFileStorage <Project>(TEST_DATA_PATH);

            Project.Save(storage);
        }
예제 #6
0
        private static void MainProcess(string[] args)
        {
            JsonFileStorage <Project> storage =
                new JsonFileStorage <Project>(
                    ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH)
                    );

            Project.Load(storage);

            List <Project> projects = null;

            if (args.Length == 0)
            {
                projects = Project.GetAll();
            }
            else if (args.Length == 1)
            {
                projects = Project.FindByName(args[0]);
            }
            else
            {
                Console.WriteLine("Please, use");
                Console.WriteLine("prs [part_of_name]");
                Console.WriteLine("format");
                return;
            }
            PrintProjects(projects);
        }
예제 #7
0
        private static void AddTomorrowWithProject(string taskName, string projectName)
        {
            var taskStorage = new JsonFileStorage <Task>(
                ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH)
                );
            var projectStorage = new JsonFileStorage <Project>(
                ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH)
                );

            Task.Load(taskStorage);
            Project.Load(projectStorage);

            var     projects = Project.FindByName(projectName);
            Project project  =
                ConsoleServices.SelectProjectFromFilteringResult(projectName, projects);

            if (project == null)
            {
                return;
            }

            var task = Task.AddOnDate(taskName, DateTime.Now.AddDays(1).Date);

            Task.AttachToProject(task, project);

            Task.Save(taskStorage);
        }
예제 #8
0
        public void Clear()
        {
            Task.Clear();
            var storage = new JsonFileStorage <Task>(TEST_DATA_PATH);

            Task.Save(storage);
        }
예제 #9
0
        public void Load_LoadUnexistingProjects_ReturnEmptyCollection()
        {
            var storage = new JsonFileStorage <Project>(TEST_DATA_PATH);

            Project.Load(storage);

            Assert.AreEqual(0, Project.Count);
        }
예제 #10
0
        private static void AddTomorrowWithoutProject(string taskName)
        {
            var storage = new JsonFileStorage <Task>(ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH));

            Task.Load(storage);
            Task.AddOnDate(taskName, DateTime.Now.AddDays(1).Date);
            Task.Save(storage);
        }
예제 #11
0
        public void Load_LoadUnexistingTasks_ReturnEmptyCollection()
        {
            var storage = new JsonFileStorage <Task>(TEST_DATA_PATH);

            Task.Load(storage);

            Assert.AreEqual(0, Task.TasksCount);
        }
예제 #12
0
        private static void MainProcess(string[] args)
        {
            JsonFileStorage <Project> storage =
                new JsonFileStorage <Project>(ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH));

            Project.Load(storage);
            foreach (var project in args)
            {
                Project.Add(project);
                Project.Save(storage);
                Console.WriteLine("{0} added!", project);
            }
        }
예제 #13
0
파일: MainVm.cs 프로젝트: ki0ki0/WiFiMap
        public async void OnSaveProject(object param)
        {
            var openFileDialog = new SaveFileDialog();

            openFileDialog.Title  = "Select project file";
            openFileDialog.Filter = "HeatMap Project|*.heatproject" +
                                    "|All Files|*.*";
            if (openFileDialog.ShowDialog() == true)
            {
                IStorage <Project> str = new JsonFileStorage <Project>(openFileDialog.FileName);
                await str.Save(ScanVm.Project);

                ScanVm.IsModified = false;
            }
        }
예제 #14
0
        public void SaveLoad_AddThreeSaveThenClearLoad_AllThreeExist()
        {
            Project p1 = Project.Add("Test Project 1");
            Project p2 = Project.Add("Test Project 2");
            Project p3 = Project.Add("Test Project 3");

            var storage = new JsonFileStorage <Project>(TEST_DATA_PATH);

            Project.Save(storage);
            Project.Clear();
            Project.Load(storage);

            Assert.AreEqual(3, Project.Count);
            Assert.IsTrue(Project.GetAll().Contains(p1));
            Assert.IsTrue(Project.GetAll().Contains(p2));
            Assert.IsTrue(Project.GetAll().Contains(p3));
        }
예제 #15
0
        public void SaveLoad_CompleteAndSaveLoad_CompleteStatusSaved()
        {
            Project p1 = Project.Add("Test project 1");
            Project p2 = Project.Add("Test project 2");
            Project p3 = Project.Add("Test project 3");

            Project.Complete(p1);
            var storage = new JsonFileStorage <Project>(TEST_DATA_PATH);

            Project.Save(storage);
            Project.Clear();
            Project.Load(storage);

            Assert.IsTrue(Project.FindByName("Test project 1")[0].Completed);

            Assert.IsFalse(Project.FindByName("Test project 2")[0].Completed);
            Assert.IsFalse(Project.FindByName("Test project 3")[0].Completed);
        }
예제 #16
0
        public void SaveLoad_CompleteAndSaveLoad_CompleteStatusSaved()
        {
            Task task1 = Task.AddOnDate("NEW 2020/12/30 test task 1", new DateTime(2020, 12, 30));
            Task task2 = Task.AddOnDate("NEW 2020/11/10 test task 2", new DateTime(2020, 11, 10));
            Task task3 = Task.AddOnDate("NEW 2020/10/20 test task 3", new DateTime(2020, 10, 20));

            Task.Complete(task2);
            var storage = new JsonFileStorage <Task>(TEST_DATA_PATH);

            Task.Save(storage);
            Task.Clear();
            Task.Load(storage);

            Assert.IsTrue(Task.GetByDate(new DateTime(2020, 11, 10))[0].Completed);

            Assert.IsFalse(Task.GetByDate(new DateTime(2020, 12, 30))[0].Completed);
            Assert.IsFalse(Task.GetByDate(new DateTime(2020, 10, 20))[0].Completed);
        }
예제 #17
0
        private static void MainProcess(string[] args)
        {
            if (args.Length > 0)
            {
                Console.WriteLine("Please, use\ngettdy\nformat");
                return;
            }

            JsonFileStorage <Task> storage =
                new JsonFileStorage <Task>(
                    ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH)
                    );

            Task.Load(storage);

            List <Task> tasks = Task.GetByDate(DateTime.Now.Date);

            PrintTasks(tasks);
        }
예제 #18
0
        public void SaveLoad_SaveLoadTreeTasks_TasksContainsAllAfterLoading()
        {
            Task task1 = Task.AddOnDate("2020/12/30 test task 1", new DateTime(2020, 12, 30));
            Task task2 = Task.AddOnDate("2020/12/30 test task 2", new DateTime(2020, 12, 30));
            Task task3 = Task.AddOnDate("2020/12/30 test task 3", new DateTime(2020, 12, 30));

            var storage = new JsonFileStorage <Task>(TEST_DATA_PATH);

            Task.Save(storage);
            Task.Clear();
            Task.Load(storage);

            var tasks = Task.GetByDate(new DateTime(2020, 12, 30));

            Assert.AreEqual(3, tasks.Count);
            Assert.IsTrue(tasks.Contains(task1));
            Assert.IsTrue(tasks.Contains(task2));
            Assert.IsTrue(tasks.Contains(task3));
        }
예제 #19
0
        private static void CompleteSelectedProject(string[] args)
        {
            JsonFileStorage <Project> storage =
                new JsonFileStorage <Project>(
                    ConsoleServices.Config.GetField(ConsoleServices.DATA_PATH)
                    );

            Project.Load(storage);
            var project =
                ConsoleServices.SelectProjectFromFilteringResult(
                    args[0], Project.FindByName(args[0])
                    );

            if (project != null)
            {
                Project.Complete(project);
            }
            Project.Save(storage);
        }
예제 #20
0
        public void SaveLoad_AttachToTaskAndSaveLoad_AttachSaved()
        {
            Task task1 = Task.AddOnDate("2020/12/30 test task 1", new DateTime(2020, 12, 30));
            Task task2 = Task.AddOnDate("2020/11/10 test task 2", new DateTime(2020, 11, 10));
            Task task3 = Task.AddOnDate("2020/10/20 test task 3", new DateTime(2020, 10, 20));

            Project p1 = Project.Add("Test project 1");
            Project p2 = Project.Add("Test project 2");

            Task.AttachToProject(task1, p1);
            Task.AttachToProject(task2, p2);
            var storage = new JsonFileStorage <Task>(TEST_DATA_PATH);

            Task.Save(storage);
            Task.Clear();
            Task.Load(storage);

            Assert.AreEqual(p1, Task.GetByDate(new DateTime(2020, 12, 30))[0].Project);
            Assert.AreEqual(p2, Task.GetByDate(new DateTime(2020, 11, 10))[0].Project);
            Assert.IsNull(Task.GetByDate(new DateTime(2020, 10, 20))[0].Project);
        }
예제 #21
0
        public static void Main(string[] args)
        {
            var storage = new JsonFileStorage("./data/");
            var twitter = new HttpTwitterClient(new KeyStored <Credentials>(storage, "Credentials", () => Credentials.Invalid));
            var log     = new WithDateTime(new ConsoleLog());

            var options = new KeyStored <AppOptions>(storage, nameof(AppOptions), () => new AppOptions()).Get();

            if (options.ShowBirdArt)
            {
                new DrawBirdLogo().Execute();
            }

            var interactiveCli = Init(log, storage, twitter);

            interactiveCli.AddCommand(new Exit());
            var cli = Init(log, storage, twitter);

            cli.AddCommand(new InteractiveMode(interactiveCli));

            RunApp(args, cli);
        }
예제 #22
0
    static void Main(string[] args)
    {
        var log        = new ConsoleLog();
        var storage    = JsonFileStorage.AppData("ProcessAssassin");
        var targetList = new KeyStored <ProcessTargetList>(storage, "targets", () => new ProcessTargetList());

        var defaultCommand = "run";
        var cmd            = args.Length > 0 ? args[0] : defaultCommand;
        var paramArgs      = args.Skip(1).ToArray();

        var currentTargets = targetList.Get();

        if (cmd.ToLowerInvariant() != "help")
        {
            log.Info($"Targeting {currentTargets.Count} Processes");
            currentTargets.ToList().ForEach(x => log.Info($"  {x}"));
        }

        new CommandsWithHelp("Process Assassin", "ProcessAssassin", log,
                             new Run(new WithDateTime(log), targetList),
                             new ViewCurrentProcessNames(log),
                             new AddTargetProcess(log, targetList))
        .Execute(cmd, paramArgs);
    }