Пример #1
0
        public void Fill_Passes_InputIsCorrect()
        {
            // Arrange
            var ff = new FileFiller("Test1");

            // Act
            ff.Fill(1, 100);

            // Assert
            Assert.True(File.Exists("Test1"));
        }
Пример #2
0
        public void Find_Passes_InputIsCorrect()
        {
            // Arrange
            var ff = new FileFiller("Test4");

            ff.Fill(0, 50);
            // Act
            var found = ff.Find(10);

            // Assert
            Assert.True(found);
        }
Пример #3
0
        public void Append_Passes_InputIsCorrect()
        {
            // Arrange
            var ff       = new FileFiller("Test1");
            var startLen = ff.ReadAllFile().Length;

            // Act
            ff.Append();

            // Assert
            Assert.True(startLen < ff.ReadAllFile().Length);
        }
Пример #4
0
        public void RandomChanges()
        {
            const string Tag        = "TestWatcherRandomChanges_";
            string       folderName = Directory.GetCurrentDirectory();
            string       pattern    = Tag + "*";

            foreach (string file in Directory.EnumerateFiles(folderName, pattern))
            {
                File.Delete(file);
            }

            var ff = new FileFiller();

            var initialPopulation = new List <FileEntry>();

            for (int i = 1; i <= 99; i++)
            {
                string fName = Tag + i + ".txt";
                ff.FillFile(fName, numberOfLines: i, lineLength: FileFiller.RandomLength);
                initialPopulation.Add(new FileEntry(fName, DateTime.UtcNow, i, 0));
            }
            for (int i = 100; i <= 102400; i *= 2)
            {
                string fName = Tag + i + ".txt";
                ff.FillFile(fName, numberOfLines: i, lineLength: FileFiller.RandomLength);
                initialPopulation.Add(new FileEntry(fName, DateTime.UtcNow, i, 0));
            }

            _RandomCounted = 0;

            var model   = new FolderModel();
            var view    = new Log(toConsole: false, fileName: "out.txt");
            var counter = new LineCounter();
            var loader  = new BulkLoader();

            var controller = new Watcher(view, model, counter, loader, folderName, Tag + "*");

            controller.FolderChanged += Controller_FolderChanged_Random;
            controller.Status        += Controller_Status;
            System.Threading.Tasks.Task w = controller.StartAsync();

            int loops = 0;

            while (_lastStatus != Watcher.Monitoring)
            {
                loops++;
                Thread.Sleep(1000);
                if (loops > 100)
                {
                    Assert.Fail("Some Ting Wong"); break;
                }
            }
        }
Пример #5
0
        public void CreateMatrix_ThrowsArgumentNullException_InputStreamIsNull()
        {
            // Arrange
            var ff = new FileFiller("Test2");

            // Act
            void Result()
            {
                ff.Fill(100, 1);
            }

            // Assert
            Assert.Throws <ArgumentOutOfRangeException>(Result);
        }
Пример #6
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            HelloBtn.Content = $"Hello, {UserPrefs.Login}!";
            FontFamily       = UserPrefs.FontFamily;
            Background       = UserPrefs.Theme.BackColor;

            var drives = DriveInfo.GetDrives();

            Places.ItemsSource = DriveFiller.FillTheListBoxWithDrives(drives);
            fileFiller1        = new FileFiller(_graphics1, new WatchersFactory(_graphics1, Dispatcher));
            fileFiller2        = new FileFiller(_graphics2, new WatchersFactory(_graphics2, Dispatcher));
            fileFiller1.OpenEntry(new Folder(drives[0].Name));
            fileFiller2.OpenEntry(new Folder(drives[1].Name));
        }
Пример #7
0
        public void Initialize()
        {
            const string Tag = "TestWatcherInitialize_";

            var x = new FileFiller();

            x.FillFile(Tag + "1" + ".txt", numberOfLines: 1, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "2" + ".txt", numberOfLines: 2, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "3" + ".txt", numberOfLines: 3, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "4" + ".txt", numberOfLines: 4, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "5" + ".txt", numberOfLines: 5, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "6" + ".txt", numberOfLines: 6, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "7" + ".txt", numberOfLines: 7, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "8" + ".txt", numberOfLines: 8, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "9" + ".txt", numberOfLines: 9, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "10" + ".txt", numberOfLines: 10, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "100" + ".txt", numberOfLines: 100, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "1000" + ".txt", numberOfLines: 1000, lineLength: FileFiller.RandomLength);
            x.FillFile(Tag + "10000" + ".txt", numberOfLines: 10000, lineLength: FileFiller.RandomLength);

            var    model   = new FolderModel();
            var    view    = new Log(toConsole: false, fileName: "out.txt");
            var    counter = new LineCounter();
            var    loader  = new BulkLoader();
            string dir     = Directory.GetCurrentDirectory();

            var controller = new Watcher(view, model, counter, loader, dir, Tag + "*");

            System.Threading.Tasks.Task w = controller.StartAsync();
            w.Wait(10000);
            var q = model[Tag + "1" + ".txt"];

            Assert.AreEqual(model.Count(), 13);
            Assert.AreEqual(model[Tag + "1" + ".txt"].LineCount, 1);
            Assert.AreEqual(model[Tag + "2" + ".txt"].LineCount, 2);
            Assert.AreEqual(model[Tag + "3" + ".txt"].LineCount, 3);
            Assert.AreEqual(model[Tag + "4" + ".txt"].LineCount, 4);
            Assert.AreEqual(model[Tag + "5" + ".txt"].LineCount, 5);
            Assert.AreEqual(model[Tag + "6" + ".txt"].LineCount, 6);
            Assert.AreEqual(model[Tag + "7" + ".txt"].LineCount, 7);
            Assert.AreEqual(model[Tag + "8" + ".txt"].LineCount, 8);
            Assert.AreEqual(model[Tag + "9" + ".txt"].LineCount, 9);
            Assert.AreEqual(model[Tag + "10" + ".txt"].LineCount, 10);
            Assert.AreEqual(model[Tag + "100" + ".txt"].LineCount, 100);
            Assert.AreEqual(model[Tag + "1000" + ".txt"].LineCount, 1000);
            Assert.AreEqual(model[Tag + "10000" + ".txt"].LineCount, 10000);

            Console.WriteLine("DONE");
        }
Пример #8
0
        public void CountZeroLengthFile()
        {
            const string Test_0 = "Test_0.txt";

            if (!File.Exists(Test_0))
            {
                var ff = new FileFiller();
                ff.FillFile(Test_0, 0, -2);
            }
            var fc    = new LineCounter();
            var model = new FileEvent(FileEventType.Create, new FileEntry(Test_0));
            LineCountProgress result = fc.Count(model);

            Assert.AreEqual(result.Status, LineCountStatus.Success);
            Assert.AreEqual(0, result.Count);
        }
Пример #9
0
        // POST: api/Devis
        public HttpResponseMessage Post(object genObjec_d) // DEVRA CREER UN DEVIS
        {                                                  // recup informations envoyer PUIIIS fabrique WORD et met son emplacement dans la bd
          //try
          //{
            //JObject job = JObject.Parse(genObjec_d);

            var           escouilles   = genObjec_d.ToString();
            GeneralObject newGenObject = JsonConvert.DeserializeObject <GeneralObject>(escouilles);

            foreach (Projet p in newGenObject.projets)
            {
                p.découpageStories.Add("B", new List <MasterStories>());
                p.découpageStories.Add("PR", new List <MasterStories>());
                p.découpageStories.Add("PNR", new List <MasterStories>());
                foreach (MasterStories s in p.Stories)
                {
                    if ((bool)s.Bonus)
                    {
                        p.découpageStories["B"].Add(s);
                    }
                    else if (s.nonEffetue)
                    {
                        p.découpageStories["PNR"].Add(s);
                    }
                    else
                    {
                        p.découpageStories["PR"].Add(s);
                    }
                }
            }
            //GeneralObject genTest = CreateATestingContext();
            Calculator devisCalculator          = new Calculator(newGenObject);
            SumManager resultFromcallCalculator = devisCalculator.CalculateFactu();
            Devis      devis  = new Devis();
            FileFiller filler = new FileFiller(devis, false, resultFromcallCalculator, newGenObject);

            newGenObject.SaveToDb(false, devis);
            return(new HttpResponseMessage(HttpStatusCode.Accepted));
            //}
            //catch (Exception e)
            //{
            //    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)); //lance exception si y'a eu un problème
            //}
        }
Пример #10
0
        public void CountLockedFile()
        {
            const string Test_Locked = "Test_Locked.txt";

            if (!File.Exists(Test_Locked))
            {
                var ff = new FileFiller();
                ff.FillFile(Test_Locked, 10, -2);
            }

            var x = Task.Run(() => LockFile(Test_Locked, seconds: 30));

            Thread.Sleep(1000); // give it time to open and lock the file
            var fc    = new LineCounter();
            var model = new FileEvent(FileEventType.Create, new FileEntry(Test_Locked));
            LineCountProgress result = fc.Count(model);

            Assert.AreEqual(result.Status, LineCountStatus.TimedOut);

            x.Wait();
        }
Пример #11
0
        // POST: api/Facturation
        public void Post(object genObjec_f)
        {
            var           stringed     = genObjec_f.ToString();
            GeneralObject newGenObject = JsonConvert.DeserializeObject <GeneralObject>(stringed);

            foreach (Projet p in newGenObject.projets)
            {
                p.découpageStories.Add("B", new List <MasterStories>());
                p.découpageStories.Add("PR", new List <MasterStories>());
                p.découpageStories.Add("PNR", new List <MasterStories>());
                foreach (MasterStories s in p.Stories)
                {
                    if ((bool)s.Bonus)
                    {
                        p.découpageStories["B"].Add(s);
                    }
                    else if (s.nonEffetue)
                    {
                        p.découpageStories["PNR"].Add(s);
                    }
                    else
                    {
                        p.découpageStories["PR"].Add(s);
                    }
                }
            }
            Calculator devisCalculator = new Calculator(newGenObject);
            //DevisCalculator devisCalculator = new DevisCalculator(genObjec_d);
            SumManager  resultFromcallCalculator = devisCalculator.CalculateFactu();
            Facturation facturation = new Facturation();
            FileFiller  filler      = new FileFiller(facturation, true, resultFromcallCalculator, newGenObject);

            //StreamWriter logFile = new StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\test.txt");
            //logFile.WriteLine("je suis juste un petit fichier de test qui va me permettre de savoir si j'arriva a renvoyer des fichiers au clients");
            //logFile.Close();
            //  DateTime longDate = DateTime.Now;
            //var path = System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\" + "Etat_des_lieux_VS_Devis_initial_All_NS_Reneco_" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + ".docx";
            //HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            //var stream = new FileStream(path, FileMode.Open);
            //result.Content = new StreamContent(stream);
            //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            //result.Content.Headers.ContentDisposition.FileName = Path.GetFileName(path);
            //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
            //result.Content.Headers.ContentLength = stream.Length;

            // string strdocPath;
            //strdocPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\Calcul" + ".txt";
            // strdocPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\" + "Etat_des_lieux_VS_Devis_initial_All_NS_Reneco_" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + ".docx";

            //FileStream objfilestream = new FileStream(strdocPath, FileMode.Open, FileAccess.Read);
            //int len = (int)objfilestream.Length;
            // Byte[] documentcontents = File.ReadAllBytes(strdocPath);
            // objfilestream.Read(documentcontents, 0, len);
            // objfilestream.Close();

            //string stringFile = Convert.ToBase64String(documentcontents);

            //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
            //response.Content = new StringContent(stringFile, Encoding.UTF8);
            //response.Content = new StringContent(stringFile);
            //response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");

            //return response;
            newGenObject.SaveToDb(true, facturation);
            //return new HttpResponseMessage(HttpStatusCode.Accepted);
            //}
            //catch (Exception e)
            //{
            //    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)); //lance exception si un attribut dans l'objet est nulle
            //}
        }
Пример #12
0
        private static void Main()
        {
            Console.Write("Enter file name: ");
            var ff = new FileFiller($"{Console.ReadLine()}.txt");

            Console.Write("Enter lower limit for RNG: ");
            var ll = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter higher limit for RNG: ");
            var hl = Convert.ToInt32(Console.ReadLine());

            ff.Fill(ll, hl);
            Console.WriteLine("File was successfully filled with random numbers");

            Console.WriteLine("Want to find number? (Y/N)");
            var exitState = Console.ReadKey();

            switch (exitState.Key)
            {
            case ConsoleKey.Y:
                Console.Write("\rEnter your number: ");
                var numberForFind = Convert.ToInt32(Console.ReadLine());

                Console.Write(ff.Find(numberForFind) ? "Number was found" : "Number wasn't found");
                break;
            }

            Console.WriteLine("\nWant to add number? (Y/N)");
            exitState = Console.ReadKey();

            if (exitState.Key == ConsoleKey.Y)
            {
                Console.Write("\rEnter your number or left empty for random: ");
                var consoleRead = Console.ReadLine();
                if (!string.IsNullOrEmpty(consoleRead))
                {
                    var numberForAppend = Convert.ToInt32(consoleRead);
                    Console.WriteLine(ff.Append(numberForAppend)
                        ? "Number was append"
                        : "Number wasn't append due to duplicate");
                }
                else
                {
                    ff.Append();
                    Console.WriteLine("Number was append");
                }
            }

            var fileText   = ff.ReadAllFile();
            var lineNumber = 0;

            Console.WriteLine("Press 'w' to read up or 's' to read bottom line");
            Console.WriteLine("Press 'ESC' to exit");
            while (true)
            {
                Console.Write("\r");
                Console.WriteLine($"{fileText[lineNumber]} - line number {lineNumber}");

                exitState = Console.ReadKey();

                switch (exitState.Key)
                {
                case ConsoleKey.W when lineNumber > 0:
                    lineNumber--;
                    break;

                case ConsoleKey.S when lineNumber < fileText.Length - 1:
                    lineNumber++;
                    break;

                case ConsoleKey.Escape:
                    return;
                }
            }
        }