Example #1
0
        public IActionResult Regist(UserModel u)
        {
            if (String.IsNullOrWhiteSpace(u.Description))
            {
                ViewData["Message"] = "You must complete the description";
                return(View("CreateRegex"));
            }
            if (u.Description.Length >= 200)
            {
                ViewData["Message"] = "Description must be less than 200";
                return(View("CreateRegex"));
            }
            if (u.MinLength > u.MaxLength || u.MaxLength < u.MinDigits || u.MaxLength < u.MinLowercase || u.MaxLength < u.MinSpecialSigns || u.MaxLength < u.MinUppercase)
            {
                ViewData["Message"] = "Error";
                return(View("CreateRegex"));
            }
            string reg = RegexModel.CreateReg(u.Description, u.MinLength,
                                              u.chMinLength, u.MaxLength, u.chMaxLength, u.MinUppercase,
                                              u.chUppercase, u.MinLowercase, u.chLowercase, u.MinSpecialSigns,
                                              u.chSpecialSigns, u.chDigits, u.MinDigits);

            u.Reg = reg;

            return(View(u));
        }
 public MainWindow()
 {
     InitializeComponent();
     _regexValidator = new RegexValidator();
     _matcher        = new RegexMatcher();
     Model           = new RegexModel();
 }
Example #3
0
        public IActionResult Middle(UserModel u)
        {
            //login czy jest taki sam w bazie danych
            string pass  = u.Password;
            string login = u.Login;

            if (login == null || pass == null)
            {
                ViewData["Register"] = "no";
                ViewData["Message"]  = "Login & Password cannot be empty";
                return(View("Regist", u));
            }
            if (login.Length > 200 || pass.Length > 200 || u.Description.Length > 200)
            {
                ViewData["Register"] = "no";
                ViewData["Message"]  = "Error";
                return(View("Regist", u));
            }

            if (u.Reg == null || u.Description == null)
            {
                ViewData["Register"] = "no";
                ViewData["Message"]  = "Regex & Description cannot be empty";
                return(View("Regist", u));
            }

            bool passValid = RegexModel.MatchPasswordWithRegex(u.Password, u.Reg);

            if (passValid)
            {
                ViewData["Register"] = "ok";
                Db db = new Db();
                db.OpenConnection();
                if (db.CheckLogin(u.Login) == 0)
                {
                    //do

                    var statusAddUser = db.AddUser(u);
                    //ViewData["Message"]=login+" "+pass+" "+" "+u.Reg+" "+passValid + Hash.Hashing(pass);
                    db.CloseConnection();
                    ViewData["Message"] = "You are registered! Good Job " + login + "!";
                    return(View("Index"));
                }
                else
                {
                    ViewData["Message"] = "The login is taken by someone else";
                    db.CloseConnection();
                    return(View("Regist", u));
                }
            }
            else
            {
                ViewData["Register"] = "no";
                ViewData["Message"]  = "Somethink wrong! Bad password, remember about your Regex.";
                return(View("CreateRegex"));
            }
        }
Example #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            RegexModel.OnStartup();
            FileType.OnStartup();
            var window = new MainWindow(new MainViewModel());

            window.Show();

            //Testing
            var folderWindow = new FolderDialogView(new FolderDialogViewModel());

            folderWindow.Show();
        }
Example #5
0
        private string PreCheckFilePathLegal(string prjSlnPath)
        {
            string str = string.Empty;

            if (!File.Exists(prjSlnPath))
            {
                str = string.Format("%s %s", (object)prjSlnPath, (object)LanguageInfo.MessageBox_Content100);
            }
            else if (RegexModel.IsHaveChinese(prjSlnPath))
            {
                str = LanguageInfo.MessageBox212_NotChinese;
            }
            return(str);
        }
Example #6
0
        public ActionResult CreateRegex(RegexModel model)
        {
            if (ModelState.IsValid)
            {
                if (ValidateRule(model.Name))
                {
                    string createdRegex = RegexModel.CreateRegexString(model.MinLength, model.ChMinLength, model.MaxLength, model.ChMaxLength, model.MinUpperCase, model.ChUpperCase, model.MinLowerCase, model.ChLowerCase, model.MinSpecialSigns, model.ChSpecialSigns, model.MinDigits, model.ChDigits);

                    AspDatabase db = new AspDatabase();

                    int insertResult = db.InsertRegexIntoDatabase(model, createdRegex);

                    if (insertResult == 1)
                    {
                        return(RedirectToAction("CollectRule", "Regex", new { regex = model.Name + ": " + createdRegex }));
                    }
                    else if (insertResult == 0)
                    {
                        ModelState.AddModelError("", "The rule name provided is already used.");
                    }
                    else if (insertResult == -1)
                    {
                        ModelState.AddModelError("", "The rule with given parameters already exsists.");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Something went wrong with database connection.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The rule name provided is incorrect.");
                }
            }
            return(View(model));
        }
Example #7
0
        public async Task AddAsync(RegexModel model)
        {
            await _regexRepository.AddAsync(_mapper.Map <Regex>(model));

            await _uow.CommitAsync();
        }
Example #8
0
        public List <CodeFile> RunCleanerSync(string dirPath, string[] filters, bool selectAll, RegexModel selectedRegex)
        {
            string[] allFiles = GetFiles(dirPath, filters, selectAll, true, selectedRegex);

            List <CodeFile> output = new List <CodeFile>();

            foreach (var file in allFiles)
            {
                CodeFile codeFile = new CodeFile();
                try
                {
                    codeFile.FullPath = file;
                    codeFile.FileName = Path.GetFileName(file);
                    using (StreamReader reader = new StreamReader(file))
                    {
                        string fileData = reader.ReadToEnd();
                        codeFile.UnchangedCode = fileData;
                        codeFile.CleanedCode   = RunCleanerRegex(fileData, Path.GetExtension(file));
                    }
                }
                catch (Exception e)
                {
                    codeFile.Error = e;
                }
                output.Add(codeFile);
            }

            return(output);
        }
Example #9
0
 public (List <CodeFile>, string[]) OpenFilesFromDir(string dirPath, string[] filters, bool selectAll, bool shallowSearch, RegexModel selectedRegex)
 {
     string[] allPaths = GetFiles(dirPath, filters, selectAll, shallowSearch, selectedRegex);
     return(OpenFiles(allPaths), allPaths);
 }
Example #10
0
        private string[] FilterFiles(string[] allFiles, string[] filters, bool selectAll, RegexModel selectedRegex)
        {
            List <string> selectedFiles = new List <string>();

            if (!selectAll)
            {
                foreach (var file in allFiles)
                {
                    if (Path.GetExtension(file) == selectedRegex.Extension)
                    {
                        selectedFiles.Add(file);
                    }
                }
            }
            else
            {
                selectedFiles = GetAllFilesWithExtensions(allFiles);
            }
            return(CustomFilter(selectedFiles, filters).ToArray());
        }
Example #11
0
        public string[] GetFiles(string dirPath, string[] filters, bool selectAll, bool shallowSearch, RegexModel selectedRegexModel)
        {
            if (!Directory.Exists(dirPath))
            {
                throw new DirectoryNotFoundException();
            }
            string[] everyFile = shallowSearch ? GetFilesShallow(dirPath) : GetFilesDeep(dirPath);

            return(FilterFiles(everyFile, filters, selectAll, selectedRegexModel));
        }
Example #12
0
        public async Task <List <CodeFile> > RunCleanerAsync(string dirPath, string[] filters, bool selectAll, RegexModel selectedRegex)
        {
            string[] allFiles = GetFiles(dirPath, filters, selectAll, true, selectedRegex);

            List <Task <CodeFile> > tasks = new List <Task <CodeFile> >();

            foreach (var file in allFiles)
            {
                tasks.Add(Task.Run(() =>
                {
                    CodeFile codeFile = new CodeFile();
                    try
                    {
                        codeFile.FullPath = file;
                        codeFile.FileName = Path.GetFileName(file);
                        using (StreamReader reader = new StreamReader(file))
                        {
                            string fileData        = reader.ReadToEnd();
                            codeFile.UnchangedCode = fileData;
                            codeFile.CleanedCode   = RunCleanerRegex(fileData, Path.GetExtension(file));
                        }
                    }
                    catch (Exception e)
                    {
                        codeFile.Error = e;
                    }
                    return(codeFile);
                }));
            }

            var results = await Task.WhenAll(tasks);

            return(results.ToList());
        }
Example #13
0
 public ActionResult <List <RegexFound> > RegexPaged([FromBody] RegexModel regexModel)
 {
     return(PdfHandler.RegexPaged(Convert.FromBase64String(regexModel.Source), regexModel.Pattern));
 }
Example #14
0
 public ActionResult <List <int> > RegexAbsolute([FromBody] RegexModel regexModel)
 {
     return(PdfHandler.RegexAbsolute(Convert.FromBase64String(regexModel.Source), regexModel.Pattern));
 }
Example #15
0
        private void btnNew_Clicked(object sender, EventArgs e)
        {
            this.result = new FileDialogResult();
            FileTypeInfo fileTypeInfo = this.selectedItem.FileTypeInfo;
            double       value        = this.entryHeight.Value;
            double       value2       = this.entryWidth.Value;

            Xwt.Size size = new Xwt.Size(value2, value);
            if (RegexModel.IsHasSystemReserveName(this.entry_FileName.Text))
            {
                MessageBox.Show(LanguageInfo.MessageBox215_WindowsNameLimit, this, null, MessageBoxImage.Info);
                this.entry_FileName.SelectRegion(0, this.entry_FileName.Text.Length);
                this.entry_FileName.HasFocus = true;
                this.result.IsSuccessful     = false;
            }
            else
            {
                string text = this.entry_FileName.Text + fileTypeInfo.Extension;
                if (!Regex.IsMatch(text, "^[A-Za-z0-9,._-]+$") || Regex.IsMatch(text, "[\\*\\\\/:?<>|\"]"))
                {
                    MessageBox.Show(LanguageInfo.MessageBox216_FileNameLimit, this, null, MessageBoxImage.Info);
                    this.entry_FileName.SelectRegion(0, this.entry_FileName.Text.Length);
                    this.entry_FileName.HasFocus = true;
                    this.result.IsSuccessful     = false;
                }
                else if (!FileService.IsValidFileName(text))
                {
                    string info = LanguageInfo.NewFile_WrongName.Replace("<", "&lt;").Replace(">", "&gt;");
                    MessageBox.Show(info, this, null, MessageBoxImage.Info);
                    this.entry_FileName.SelectRegion(0, this.entry_FileName.Text.Length);
                    this.entry_FileName.HasFocus = true;
                    this.result.IsSuccessful     = false;
                }
                else
                {
                    string value3 = text.Substring(0, text.Length - fileTypeInfo.Extension.Length);
                    if (string.IsNullOrWhiteSpace(value3))
                    {
                        MessageBox.Show(LanguageInfo.MessageBox_Content110, this, null, MessageBoxImage.Info);
                        this.entry_FileName.HasFocus = true;
                        this.result.IsSuccessful     = false;
                    }
                    else
                    {
                        this.result.FileName = text;
                        this.result.Size     = size;
                        this.result.FileType = this.selectedItem.FileTypeInfo.FileType;
                        string path = System.IO.Path.Combine(this.parentDir, this.result.FileName);
                        if (File.Exists(path))
                        {
                            MessageBox.Show(LanguageInfo.NewFile_SameName, this, null, MessageBoxImage.Info);
                            this.entry_FileName.SelectRegion(0, this.entry_FileName.Text.Length);
                            this.entry_FileName.HasFocus = true;
                            this.result.IsSuccessful     = false;
                        }
                        else
                        {
                            this.Destroy();
                            this.Dispose();
                        }
                    }
                }
            }
        }