public void AddOrReplaceKey(PassRecord passRecord)
        {
            var model = PasswordModel;

            model.LastUpdate = DateTime.Now;
            if (passRecord != null)
            {
                var record = model.PassRecords.FirstOrDefault(x => x.Id == passRecord.Id);
                if (record == null)
                {
                    model.PassRecords.Add(passRecord);
                }
                else
                {
                    record.Details  = passRecord.Details;
                    record.Login    = passRecord.Login;
                    record.Password = passRecord.Password;
                    record.URL      = passRecord.URL;
                    record.Group    = passRecord.Group;
                    record.Name     = passRecord.Name;
                }
            }
            var serialize = JsonSerializer.Serialize(model);

            EncryptedData = EncryptionHelper.Encrypt(serialize, CurrentPassword);
        }
        public async Task <IActionResult> Edit(int id, [Bind("PassId,Reason,IsssuedDate,memberId")] PassRecord passRecord)
        {
            if (id != passRecord.PassId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(passRecord);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PassRecordExists(passRecord.PassId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["memberId"] = new SelectList(_context.Member, "MemberId", "Email", passRecord.memberId);
            return(View(passRecord));
        }
        public async Task <IActionResult> Create([Bind("PassId,Reason,IsssuedDate,memberId")] PassRecord passRecord)
        {
            if (ModelState.IsValid)
            {
                _context.Add(passRecord);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["memberId"] = new SelectList(_context.Member, "MemberId", "Email", passRecord.memberId);
            return(View(passRecord));
        }
Exemple #4
0
 public IActionResult Create(PassRecord model)
 {
     ModelState.Remove(nameof(model.Id));
     if (ModelState.IsValid)
     {
         model.Id = Guid.NewGuid();
         DataContext.GetInstance().AddOrReplaceKey(model);
         DataContext.GetInstance().SaveToFile();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Exemple #5
0
 public IActionResult Edit(PassRecord model)
 {
     if (ModelState.IsValid)
     {
         var item = DataContext.GetInstance().PasswordModel.PassRecords.FirstOrDefault(x => x.Id == model.Id);
         item.URL      = model.URL;
         item.Login    = model.Login;
         item.Password = model.Password;
         item.Details  = model.Details;
         DataContext.GetInstance().SaveToFile();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Exemple #6
0
        /// <summary>
        /// Call this to load each file
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="maxCount"></param>
        public void ParseFile(
            string filename, int maxPass,
            CancellationToken cancellationToken,
            IProgress <Progress> progress
            )
        {
            var  progressValue = new Progress();
            var  fi = new FileInfo(filename);
            var  fileLength = fi.Length;
            long totalPassCount = 0, totalErrorCount = 0;
            var  provider = CultureInfo.InvariantCulture;
            var  done     = false;

#if OLDMODE
            // var lineCount = 0;
            // long bytesRead = 0;
            //var lines = File.ReadLines(filename);
            //var fileLineAtLastErrorLine = -100L; // this will help fix lines that got split somehow
            //todo - better error line merging
            foreach (var line1 in lines)

            {
#else
            var regexes = new[] { passRegex, errorRegex }
            ;
            int matchIndex;
            var fileSplitter = new FileSplitter(filename);
            var line1        = fileSplitter.Next(regexes, out matchIndex);
            do
            {
                var lineCount = fileSplitter.LineCount;
                var bytesRead = fileSplitter.BytesRead;
#endif

                cancellationToken.ThrowIfCancellationRequested();
                if ((lineCount & 511) == 0)
                {
                    progressValue.Message = String.Format(
                        "File parsing phase: {0}/{1} kb read ({2:F2}%), {3} lines read, {4} passes read, {5} errors read, {6} error lines",
                        bytesRead / 1024, fileLength / 1024,
                        bytesRead * 100.0 / fileLength,
                        lineCount,
                        totalPassCount,
                        totalErrorCount,
                        ErrorLines.Count
                        );
                    progress.Report(progressValue);
                }

                ++lineCount;
                bytesRead += line1.Length;
                var line = line1;

                while (!done && !String.IsNullOrEmpty(line))
                {
                    var passMatch = passRegex.Match(line);
                    var errMatch  = (!passMatch.Success)
                        ? errorRegex.Match(line)
                        : null;
                    if (passMatch.Success)
                    {
                        var pass  = Int32.Parse(passMatch.Groups["pass"].Value);
                        var frame = Int32.Parse(passMatch.Groups["frame"].Value);

                        uint offset;
                        if (
                            !UInt32.TryParse(passMatch.Groups["offset"].Value, NumberStyles.HexNumber, provider,
                                             out offset))
                        {
                            throw new Exception("Illegal format");
                        }

                        uint tick;
                        if (!UInt32.TryParse(passMatch.Groups["tick"].Value, NumberStyles.HexNumber, provider, out tick))
                        {
                            throw new Exception("Illegal format");
                        }

                        ulong errorCount;
                        if (
                            !UInt64.TryParse(passMatch.Groups["errors"].Value, out errorCount))
                        {
                            throw new Exception("Illegal format");
                        }

                        var passItem = new PassRecord(pass, frame, offset, tick, errorCount);
                        line = passRegex.Replace(line, "", 1);

                        // do this just before last pass to ensure we got all errors
                        if (Passes.Count >= maxPass)
                        {
                            done = true;
                        }
                        else
                        {
                            Passes.Add(passItem);
                            ++totalPassCount;
                        }
                    }
                    else if (errMatch != null && errMatch.Success)
                    {
                        var lastpass = Passes.LastOrDefault();
                        if (lastpass == null)
                        {
                            continue;
                        }

                        uint offset;
                        if (
                            !UInt32.TryParse(errMatch.Groups["offset"].Value, NumberStyles.HexNumber, provider,
                                             out offset))
                        {
                            throw new Exception("Illegal format");
                        }
                        uint read;
                        if (!UInt32.TryParse(errMatch.Groups["read"].Value, NumberStyles.HexNumber, provider, out read))
                        {
                            throw new Exception("Illegal format");
                        }
                        uint desired;
                        if (
                            !UInt32.TryParse(errMatch.Groups["desired"].Value, NumberStyles.HexNumber, provider,
                                             out desired))
                        {
                            throw new Exception("Illegal format");
                        }

                        var errorType = Error.ErrorTypes.Erase;
                        if (errMatch.Groups["type"].Value == "E")
                        {
                            errorType = Error.ErrorTypes.Erase;
                        }
                        //else if (passMatch.Groups["type"].Value == "W")
                        //    errorType = Error.ErrorTypes.Write;
                        else
                        {
                            throw new Exception("Illegal format");
                        }
                        lastpass.Errors.Add(new Error(lastpass, offset, read, desired, errorType));
                        totalErrorCount++;
                        line = errorRegex.Replace(line, "", 1);
                    }
#if OLDMODE
                    else
                    {
                        var isErrorLine = true; // assume this line will be an error
                        if (fileLineAtLastErrorLine == lineCount - 1 && ErrorLines.Count > 0)
                        {
                            // back to back, pull out
                            var tempLine = ErrorLines.Last() + line;
                            isErrorLine &= !passRegex.IsMatch(tempLine);
                            isErrorLine &= !errorRegex.IsMatch(tempLine);

                            if (!isErrorLine)
                            {
                                // pull last one out and test it
                                line = tempLine;
                                ErrorLines.RemoveAt(ErrorLines.Count - 1);
                            }
                        }

                        if (isErrorLine)
                        {
                            ErrorLines.Add(line);
                            line = "";
                        }
                        fileLineAtLastErrorLine = lineCount;
                    } // error line
                }     // while line not all used up
            }
#else
                } // while line not all used up
                line1 = fileSplitter.Next(regexes, out matchIndex);
            } while (!done && !String.IsNullOrEmpty(line1))