Beispiel #1
0
        public static void Edit(Cleaning cleaning)
        {
            using (var conn = new SqliteContext())
            {
                Cleaning cleaningToChange = conn.Cleanings.Where(p => p.Id == cleaning.Id).FirstOrDefault();
                if (cleaningToChange != null)
                {
                    cleaningToChange.IdRoom   = cleaning.IdRoom;
                    cleaningToChange.IdWorker = cleaning.IdWorker;

                    TimeSpan startHour = new TimeSpan(10, 0, 0);
                    DateTime startTime = cleaning.CleanTime.Date + startHour; //dany dzień godz. 10:00

                    DateTime?dateToSet = CheckIfWorkerHaveTimeAndReturnFirstFreeDate(conn, cleaning.IdWorker, startTime);

                    if (dateToSet.HasValue)
                    {
                        cleaningToChange.CleanTime = dateToSet.Value;
                    }
                    else
                    {
                        throw new Exception("Pracownik o tym Id nie jest dostępny w wybranym dniu. Wybierze inny dzień lub innego pracownika.");
                    }

                    conn.SaveChanges();
                }
                else
                {
                    throw new Exception("Nie znaleziono wpisu sprzątania do zmodyfikowania");
                }
            }
        }
Beispiel #2
0
 public string Check(string text)
 {
     var cleaner = Cleaning.MakeCleaner("none");
     List<string> wrds = new List<string>();
     (text ?? "").Split('.', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(t => wrds.AddRange(t.Split(' ', StringSplitOptions.RemoveEmptyEntries)));
     return string.Join(',', wrds.Select(t => _li.Identify(cleaner(t))).Distinct());
 }
        public ActionResult AddCleaning(AddCleaningModel model)
        {
            var listusers = new List <User>();

            foreach (var user in model.AssignedWorkers)
            {
                if (user.Value)
                {
                    var usertoinsert = _repo.GetUserFromName(user.Key);
                    listusers.Add(usertoinsert);
                }
            }
            var cleaningtopost = new Cleaning(model.StartDate, null, model.Size, model.Comment, listusers,
                                              model.TramID);

            try
            {
                _repo.AddCleaning(cleaningtopost);
            }
            catch
            {
                model.Error =
                    "Something went wrong with posting the ervice. Check if the date field is filled and if the tram number is valid!";
                return(View(model));
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult EditCleaning(EditCleaningViewModel viewmodel)
        {
            var logic     = new SRLogic();
            var listusers = new List <User>();

            foreach (var user in viewmodel.AssignedWorkers)
            {
                if (user.Value)
                {
                    var usertoinsert = _repo.GetUserFromName(user.Key);
                    listusers.Add(usertoinsert);
                }
            }
            if (viewmodel.EndDate < viewmodel.StartDate)
            {
                viewmodel.EndDate = null;
            }
            var changedCleaning = new Cleaning(viewmodel.Id, viewmodel.StartDate, viewmodel.EndDate, viewmodel.Size,
                                               viewmodel.Comment, listusers, viewmodel.TramID);

            try
            {
                _repo.EditService(changedCleaning);
            }
            catch
            {
                viewmodel.Error =
                    "Something went wrong with posting the ervice. Check if the date field is filled and if the tram number is valid!";
                return(View(viewmodel));
            }
            logic.Error = "Cleaning posted succesfully!";
            //TempData["SRLogic"] = logic;
            return(RedirectToAction("Index", "SR"));
        }
        /// <summary>
        /// Public static function to pre-process (data cleaning, normalization) the tokenized list of words. (version on list of strings)
        /// </summary>
        /// <param name="words"></param>
        /// <param name="toLowerOption"></param>
        /// <param name="keepOnlyCapitalizedWords"></param>
        /// <returns></returns>
        public static List <string> PreProcessingPipeline(List <string> words, bool toLowerOption = false, bool keepOnlyCapitalizedWords = false)
        {
            List <string> newWords = new List <string>();

            foreach (var sw in words)
            {
                if (Cleaning.IsStopWord(sw))
                {
                    continue;
                }
                string tsw = Cleaning.EliminateDigitsFromWord(sw);
                if (string.IsNullOrEmpty(tsw))
                {
                    continue;
                }
                if (toLowerOption)
                {
                    tsw = Normalization.ToLowerCaseNormalization(tsw);
                }

                if (keepOnlyCapitalizedWords)
                {
                    if (!char.IsUpper(tsw[0]))
                    {
                        continue;
                    }
                }

                newWords.Add(tsw);
            }
            return(newWords);
        }
Beispiel #6
0
        public void TestNhsNumberCleaning()
        {
            // All invalid so should be null
            Assert.Null(Cleaning.CleanAndValidateNhsNumber(null));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber(""));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("sdfghjkl"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("12345"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("12345rtyuio"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("1234567890"));

            Assert.Equal("1103396005", Cleaning.CleanAndValidateNhsNumber("1103396005"));
            Assert.Equal("1126883867", Cleaning.CleanAndValidateNhsNumber("1126883867"));
            Assert.Equal("1653224894", Cleaning.CleanAndValidateNhsNumber("1653224894"));
            Assert.Equal("1704571790", Cleaning.CleanAndValidateNhsNumber("1704571790"));
            Assert.Equal("1167742664", Cleaning.CleanAndValidateNhsNumber("1167742664"));
            Assert.Equal("1420642626", Cleaning.CleanAndValidateNhsNumber("1420642626"));
            Assert.Equal("1201545757", Cleaning.CleanAndValidateNhsNumber("1201545757"));
            Assert.Equal("1619090120", Cleaning.CleanAndValidateNhsNumber("1619090120"));
            Assert.Equal("1713647656", Cleaning.CleanAndValidateNhsNumber("1713647656"));
            Assert.Equal("1896417531", Cleaning.CleanAndValidateNhsNumber("1896417531"));

            Assert.Null(Cleaning.CleanAndValidateNhsNumber("0000000000"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("1111111111"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("2222222222"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("3333333333"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("4444444444"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("5555555555"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("6666666666"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("7777777777"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("8888888888"));
            Assert.Null(Cleaning.CleanAndValidateNhsNumber("9999999999"));
        }
Beispiel #7
0
        public Cleaning AddCleaning(Cleaning cleaning)
        {
            var serviceQuery = new SqlCommand(@"INSERT INTO Service (StartDate, EndDate, TramFk) VALUES (@startdate, @enddate, @tramfk); SELECT SCOPE_IDENTITY();");

            serviceQuery.Parameters.AddWithValue("@startdate", cleaning.StartDate);
            if (cleaning.EndDate == null)
            {
                serviceQuery.Parameters.AddWithValue("@enddate", DBNull.Value);
            }
            else
            {
                serviceQuery.Parameters.AddWithValue("@enddate", cleaning.EndDate);
            }
            serviceQuery.Parameters.AddWithValue("@tramfk", cleaning.TramId);

            var data = Database.GetData(serviceQuery);

            var cleaningQuery = new SqlCommand(@"INSERT INTO Clean (ServiceFk, Size, Remarks) VALUES (@id, @size, @remarks)");

            cleaningQuery.Parameters.AddWithValue("@id", data.Rows[0].ItemArray[0]);
            cleaningQuery.Parameters.AddWithValue("@size", (int)cleaning.Size);
            cleaningQuery.Parameters.AddWithValue("@remarks", cleaning.Comments ?? "");
            Database.GetData(cleaningQuery);

            cleaning.SetId(Convert.ToInt32((decimal)data.Rows[0].ItemArray[0]));
            SetUsersToServices(cleaning);

            return(cleaning);
        }
        public ActionResult DeleteConfirmed(long id)
        {
            Cleaning cleaning = db.Cleanings.Find(id);

            db.Cleanings.Remove(cleaning);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #9
0
 public List<Models.LangModel> CheckPost()
 {
     string text = HttpContext.Request.Form["text"];
     var cleaner = Cleaning.MakeCleaner("none");
     List<string> wrds = new List<string>();
     (text ?? "").Split('.', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(t => wrds.AddRange(t.Split(' ', StringSplitOptions.RemoveEmptyEntries)));
     return wrds.Select(t => _li.Identify(cleaner(t))).GroupBy(t => t).Select(t1 => new Models.LangModel() { lang = t1.Key, count = t1.Count() }).ToList();
 }
Beispiel #10
0
 public string ProfileCheck(string owner, string lang_prof, string text)
 {
     var path = System.IO.Path.Combine(_env.WebRootPath, "Content", "UserData", owner, lang_prof, (lang_prof ?? "").Substring(0, lang_prof.LastIndexOf('_')) + ".bin.gz");
     var lip = LanguageIdentifier.New(path, "Vector", -1);
     var cleaner = Cleaning.MakeCleaner("none");
     List<string> wrds = new List<string>();
     (text ?? "").Split('.', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(t => wrds.AddRange(t.Split(' ', StringSplitOptions.RemoveEmptyEntries)));
     return string.Join(',', wrds.Select(t => lip.Identify(cleaner(t))).Distinct());
 }
 public ActionResult Edit([Bind(Include = "Task_ID,Room_ID,Task_Time,Task_Date,Staff_ID")] Cleaning cleaning)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cleaning).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cleaning));
 }
Beispiel #12
0
 public ActionResult Edit([Bind(Include = "CleaningId,Date,Cleanings,Notes,ReptileId")] Cleaning cleaning)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cleaning).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReptileId = new SelectList(db.Reptiles, "ReptileId", "SpeciesName", cleaning.ReptileId);
     return(View(cleaning));
 }
Beispiel #13
0
        public void UpdateCleaninginDatabase(User activeUser, Form targetform, DateTime startdate, DateTime?enddate,
                                             ComboBox sortsrvc_cb, RichTextBox commenttb, List <User> users, TextBox tramnrtb, Cleaning toupdatecleaning)
        {
            var cleaning = new Cleaning(startdate, enddate, (CleaningSize)sortsrvc_cb.SelectedIndex,
                                        commenttb.Text, users, Convert.ToInt32(tramnrtb.Text));

            cleaning.SetId(toupdatecleaning.Id);
            _repo.EditService(cleaning);

            targetform.Close();
        }
        public ActionResult Create([Bind(Include = "Task_ID,Room_ID,Task_Time,Task_Date,Staff_ID")] Cleaning cleaning)
        {
            if (ModelState.IsValid)
            {
                db.Cleanings.Add(cleaning);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cleaning));
        }
Beispiel #15
0
 public List<Models.LangModel> ProfilePost()
 {
     string owner = HttpContext.Request.Form["owner"];
     string lang_prof = HttpContext.Request.Form["lang_prof"];
     var path = System.IO.Path.Combine(_env.WebRootPath, "Content", "UserData", owner, lang_prof, (lang_prof ?? "").Substring(0, lang_prof.LastIndexOf('_')) + ".bin.gz");
     var lip = LanguageIdentifier.New(path, "Vector", -1);
     string text = HttpContext.Request.Form["text"];
     var cleaner = Cleaning.MakeCleaner("none");
     List<string> wrds = new List<string>();
     (text ?? "").Split('.', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(t => wrds.AddRange(t.Split(' ', StringSplitOptions.RemoveEmptyEntries)));
     return wrds.Select(t => lip.Identify(cleaner(t))).GroupBy(t => t).Select(t1 => new Models.LangModel() { lang = t1.Key, count = t1.Count() }).ToList();
 }
        public SprzatanieAddView(Cleaning cleaning)
        {
            InitializeComponent();

            SprzAddId.Text             = cleaning.Id.ToString();
            SprzAddIdPokoju.Text       = cleaning.IdRoom.ToString();
            SprzAddIdPracownika.Text   = cleaning.IdWorker.ToString();
            SprzStartDate.SelectedDate = cleaning.CleanTime;

            SprzatanieAddModBtn.Content = "Modyfikuj";
            IdStack.Visibility          = Visibility.Visible;
        }
Beispiel #17
0
        public bool EditCleaning(Cleaning cleaning)
        {
            using (var db = new ZooMasterDBEntities())
            {
                var originalCleaning = db.Cleanings.First(c => c.CleainingID == cleaning.CleainingID);

                originalCleaning.CageID = cleaning.CageID;
                originalCleaning.Time = cleaning.Time;
                originalCleaning.EmployeeID = cleaning.EmployeeID;

                return db.SaveChanges() == 1;
            }
        }
        public async Task <ActionResult> Cleaning([Bind(Include = "CleaningId,Date,Cleanings,Notes,ReptileId")] Cleaning cleaning)
        {
            if (ModelState.IsValid)
            {
                db.Cleanings.Add(cleaning);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }


            return(View(cleaning));
        }
        // GET: Cleanings/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cleaning cleaning = db.Cleanings.Find(id);

            if (cleaning == null)
            {
                return(HttpNotFound());
            }
            return(View(cleaning));
        }
        // GET: Cleanings/Create
        public async Task <ActionResult> Cleaning(string id, Cleaning clean)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            clean.ReptileId = reptile.ReptileId;
            return(View(clean));
        }
Beispiel #21
0
        // in reptile controller
        // GET: Cleanings/Create

        /*   public ActionResult Create()
         * {
         *     ViewBag.ReptileId = new SelectList(db.Reptiles, "ReptileId", "SpeciesName");
         *     return View();
         * }
         *
         * // POST: Cleanings/Create
         * // To protect from overposting attacks, please enable the specific properties you want to bind to, for
         * // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
         * [HttpPost]
         * [ValidateAntiForgeryToken]
         * public ActionResult Create([Bind(Include = "CleaningId,Date,Cleanings,Notes,ReptileId")] Cleaning cleaning)
         * {
         *     if (ModelState.IsValid)
         *     {
         *         db.Cleanings.Add(cleaning);
         *         db.SaveChanges();
         *         return RedirectToAction("Index");
         *     }
         *
         *     ViewBag.ReptileId = new SelectList(db.Reptiles, "ReptileId", "SpeciesName", cleaning.ReptileId);
         *     return View(cleaning);
         * }
         */
        // GET: Cleanings/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cleaning cleaning = db.Cleanings.Find(id);

            if (cleaning == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ReptileId = new SelectList(db.Reptiles, "ReptileId", "SpeciesName", cleaning.ReptileId);
            return(View(cleaning));
        }
Beispiel #22
0
        public bool AddCleaning(Cage cage, DateTime time, int regularEmployeeID)
        {
            var newCleaning = new Cleaning()
            {
                CageID = cage.CageID,
                Time = time,
                EmployeeID = regularEmployeeID
            };

            using (var db = new ZooMasterDBEntities())
            {
                db.Cleanings.Add(newCleaning);
                return db.SaveChanges() == 1;
            }
        }
Beispiel #23
0
 public static void Delete(Cleaning cleaning)
 {
     using (var conn = new SqliteContext())
     {
         Cleaning toDelete = conn.Cleanings.FirstOrDefault(p => p.Id == cleaning.Id);
         if (toDelete != null)
         {
             conn.Cleanings.Remove(toDelete);
             conn.SaveChanges();
         }
         else
         {
             throw new Exception("Nie znaleziono wpisu sprzątania do usunięcia");
         }
     }
 }
Beispiel #24
0
        public void TestTrim()
        {
            Assert.Null(Cleaning.Trim(""));
            Assert.Null(Cleaning.Trim(" "));
            Assert.Null(Cleaning.Trim("   "));

            Assert.Equal("hello", Cleaning.Trim("hello"));
            Assert.Equal("hello", Cleaning.Trim("hello "));
            Assert.Equal("hello", Cleaning.Trim(" hello"));
            Assert.Equal("hello", Cleaning.Trim(" hello "));
            Assert.Equal("hello", Cleaning.Trim("hello\n"));
            Assert.Equal("hello", Cleaning.Trim("\nhello"));
            Assert.Equal("hello", Cleaning.Trim("\thello"));
            Assert.Equal("hello", Cleaning.Trim("\t \thello"));
            Assert.Equal("hello", Cleaning.Trim("\n \thello"));
            Assert.Equal("hello", Cleaning.Trim("\n    hello"));
        }
        private async Task CreateReservationAsync(ApplicationUser guest)
        {
            var room = (await this.roomRepo.GetAllAsync())
                       .FirstOrDefault(room => room.RoomNumber == this.addReservationViewModel.RoomNumber);

            room.IsBusy = true;

            await this.roomRepo.SaveChangesAsync();

            var receptionistName = this.httpContextAccessor.HttpContext.User.Identity.Name;

            var receptionistId = (await this.userRepo.GetAllAsync()).FirstOrDefault(user => user.UserName == receptionistName).Id;

            var reservation = new Reservation()
            {
                GuestId        = guest.Id,
                StartDate      = DateTime.Parse(this.addReservationViewModel.StartDate),
                EndDate        = DateTime.Parse(this.addReservationViewModel.EndDate),
                Adults         = this.addReservationViewModel.Adults,
                Children       = this.addReservationViewModel.Children,
                RoomId         = room.Id,
                HotelId        = this.hotelId,
                ReceptionistId = receptionistId,
            };

            var hotel = await this.hotelRepo.GetAsync(this.hotelId);

            for (DateTime i = reservation.StartDate.AddDays(hotel.CleaningPeriod); i < reservation.EndDate; i = i.AddDays(hotel.CleaningPeriod))
            {
                var cleaning = new Cleaning()
                {
                    RoomId = reservation.RoomId,
                    Date   = i,
                    Status = CleaningStatus.Upcoming,
                };

                await this.cleaningRepo.AddAsync(cleaning);
            }

            await this.cleaningRepo.SaveChangesAsync();

            await this.reservationRepo.AddAsync(reservation);

            await this.reservationRepo.SaveChangesAsync();
        }
        public async Task CreateAsync(CreateCleaningViewModel model, string id)
        {
            var hotelId  = id.Split()[0];
            var assignTo = await this.userRepo.GetAsync(model.AssignedTo);

            var room = (await this.hotelRepo.GetAsync(hotelId)).Rooms.FirstOrDefault(r => r.RoomNumber == model.RoomNumber);

            var cleaning = new Cleaning()
            {
                Cleaner = assignTo,
                Date    = model.Date,
                Room    = room,
            };

            await this.cleaningRepo.AddAsync(cleaning);

            await this.cleaningRepo.SaveChangesAsync();
        }
Beispiel #27
0
 public bool AddServicetoDatabase(User activeUser, DateTime startdate, DateTime?enddate,
                                  ComboBox sortsrvc_cb, string comment, List <User> users, int tramNr)
 {
     if (activeUser.Role == Role.HeadCleaner && _repo.DoesTramExist(tramNr))
     {
         var cleaning = new Cleaning(startdate, enddate, (CleaningSize)sortsrvc_cb.SelectedIndex,
                                     comment, users, tramNr);
         _repo.AddCleaning(cleaning);
         return(true);
     }
     else if (activeUser.Role == Role.HeadEngineer && _repo.DoesTramExist(tramNr))
     {
         var repair = new Repair(startdate, enddate, (RepairType)sortsrvc_cb.SelectedIndex,
                                 comment, "", users, tramNr);
         _repo.AddRepair(repair);
         return(true);
     }
     return(false);
 }
Beispiel #28
0
 private void btnEditService_Click(object sender, EventArgs e)
 {
     if (dataGridView.CurrentRow.DataBoundItem != null && dataGridView.SelectedRows.Count != 0)
     {
         if (_activeUser.Role == Role.HeadEngineer)
         {
             Repair rep         = (Repair)dataGridView.CurrentRow.DataBoundItem;
             var    editService = new EditService(_activeUser, rep);
             editService.ShowDialog();
         }
         else if (_activeUser.Role == Role.HeadCleaner)
         {
             Cleaning clean       = (Cleaning)dataGridView.CurrentRow.DataBoundItem;
             var      editService = new EditService(_activeUser, clean);
             editService.ShowDialog();
         }
         _logic.RefreshDatagridView(_activeUser, cboxFilter, dataGridView);
     }
 }
        private void AddCleaning(Reservation rez, SqliteContext conn)
        {
            DateTime dateStart = rez.StartTime.Date;

            var clinings = conn.Cleanings.Where(p => p.IdRoom == rez.IdRoom).ToList();

            if (clinings.Any(p => p.CleanTime.Date == dateStart))
            {
                dateStart = dateStart.AddDays(1);
            }

            for (DateTime date = dateStart; date < rez.StopTime.Date; date = date.AddDays(1))
            {
                Cleaning clining = new Cleaning
                {
                    IdRoom    = rez.IdRoom,
                    CleanTime = date.Date,
                    IdWorker  = -1
                };
                CleaningController.Add(clining);
            }

            if (clinings.Any(p => p.CleanTime.Date == rez.StopTime.Date))
            {
                Cleaning cliningToDelete = clinings.First(p => p.CleanTime.Date == rez.StopTime.Date);
                CleaningController.Delete(cliningToDelete);
            }

            Cleaning lastClining = new Cleaning
            {
                IdRoom    = rez.IdRoom,
                CleanTime = rez.StopTime.Date,
                IdWorker  = -1
            };

            CleaningController.Add(lastClining, true);
        }
Beispiel #30
0
 /// <summary>
 ///     Voegt een Schoonmaak toe en geeft de schoonmaak met ID terug.
 /// </summary>
 /// <param name="cleaning"></param>
 /// <returns></returns>
 public Cleaning AddCleaning(Cleaning cleaning)
 {
     return(_serviceContext.AddCleaning(cleaning));
 }
Beispiel #31
0
 public void SetUp()
 {
     room     = NewMock <RoomStub>();
     cleaning = new Cleaning(HardwareRobot, room);
 }
Beispiel #32
0
        public static void Train(Models.LangProfile profile)
        {
            var  tokenizer = Tokenization.Tokenizer(profile.PType);
            int  lo        = int.Parse(profile.MinGram);
            int  hi        = int.Parse(profile.MaxGram);
            bool tlc       = profile.CaseSensitive == "tlc";
            int  n         = -1; // int.Parse(args[4]);
            var  cleaner   = Cleaning.MakeCleaner("none");
            //var inFileNames = File.ReadAllLines(args[6]);
            //var inFileNames = profile.Files.Select(t => t. Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "Data"), "*", SearchOption.AllDirectories);
            var nfolds = -1;
            var fold   = -1;
            //string out_profile = Path.Combine(Directory.GetCurrentDirectory(), profile.ProfileName + ".bin.gz");
            //string out_profile = Path.Combine(profile.Path, profile.ProfileName + ".bin.gz");
            string out_profile = profile.ProfileFilePath;

            using (var bw = new BinaryWriter(new GZipStream(new FileStream(out_profile, FileMode.Create, FileAccess.Write), CompressionMode.Compress)))
            {
                bw.Write(profile.PType);
                bw.Write(lo);
                bw.Write(hi);
                bw.Write(tlc);
                bw.Write(profile.Files.Count());
                foreach (var eafile in profile.Files)
                {
                    //var langCode = inFileName.Substring(0, inFileName.IndexOf("_"));
                    var          langCode = eafile.Label;
                    long         absCnt   = 0;
                    MemoryStream tmpFile  = new MemoryStream();
                    using (var rd = new StreamReader(eafile.FilePath))
                    {
                        using (var wr = new StreamWriter(tmpFile))
                        {
                            for (; ;)
                            {
                                var text = rd.ReadLine();
                                if (text == null)
                                {
                                    break;
                                }
                                if (fold == -1 || (absCnt % nfolds) != fold)
                                {
                                    wr.WriteLine(cleaner(text));
                                }
                                absCnt++;
                            }
                        }
                    }
                    using (var rd = new StreamReader(new MemoryStream(tmpFile.ToArray())))
                    {
                        var distro = new Dictionary <string, long>();
                        foreach (var tok in tokenizer(EnumFromRd(rd), tlc, lo, hi))
                        {
                            if (!distro.ContainsKey(tok))
                            {
                                distro[tok] = 1;
                            }
                            else
                            {
                                distro[tok]++;
                            }
                        }
                        var orderedDistro = n > 0
                          ? distro.OrderByDescending(x => x.Value).Take(n)
                          : distro.OrderByDescending(x => x.Value);
                        bw.Write(langCode);
                        bw.Write(orderedDistro.LongCount());
                        long grams = 0;
                        long occs  = 0;
                        foreach (var kv in orderedDistro)
                        {
                            bw.Write(kv.Key);
                            bw.Write(kv.Value);
                            grams++;
                            occs += kv.Value;
                        }
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}", langCode, absCnt, grams, occs);
                    }
                }
            }
        }