public IActionResult SaveForm([FromBody] FormString theFormString)
        {
            var hashValue = Convert
                            .ToString(BitConverter.ToInt64(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(
                                                                                           theFormString.name + "__" + theFormString.stuId + "__" + DateTime.Now.ToString("o"))), 0), 16)
                            .ToUpper();

            var theSavedForm = new SavedForm
            {
                theForm   = theFormString,
                savedTime = DateTime.Now
            };

            theSavedForm.token = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                            password: theSavedForm.savedTime.ToString("o"),
                                                            salt: Encoding.UTF8.GetBytes(hashValue),
                                                            prf: KeyDerivationPrf.HMACSHA256,
                                                            iterationCount: 10000,
                                                            numBytesRequested: 256 / 8));

            var possibleRepeatForm = new SavedForm();

            if (!_memoryCache.TryGetValue(hashValue, out possibleRepeatForm))
            {
                _memoryCache.Set(hashValue, theSavedForm, TimeSpan.FromMinutes(30));
            }

            HttpContext.Session.Clear();

            HttpContext.Session.SetString("name", theSavedForm.theForm.name);
            HttpContext.Session.SetString("stuId", theSavedForm.theForm.stuId);
            HttpContext.Session.SetString("savedHashValue", hashValue);

            return(new ObjectResult(DateTime.Now.ToString("G")));
        }
        public IActionResult GetSavedForm()
        {
            var inputName           = HttpContext.Session.GetString("name");
            var inputId             = HttpContext.Session.GetString("stuId");
            var inputSavedHashValue = HttpContext.Session.GetString("savedHashValue");
            var theSavedForm        = new SavedForm();

            if (_memoryCache.TryGetValue(inputSavedHashValue, out theSavedForm))
            {
                if (theSavedForm.theForm.name == inputName &&
                    theSavedForm.theForm.stuId == inputId &&
                    theSavedForm.token == Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                                     password: theSavedForm.savedTime.ToString("o"),
                                                                     salt: Encoding.UTF8.GetBytes(inputSavedHashValue),
                                                                     prf: KeyDerivationPrf.HMACSHA256,
                                                                     iterationCount: 10000,
                                                                     numBytesRequested: 256 / 8)))
                {
                    //_memoryCache.Remove(inputSavedHashValue);
                    return(new ObjectResult(theSavedForm.theForm));
                }
            }

            return(new ObjectResult(""));
        }
예제 #3
0
        //PERMITE LA GENERACION DEL FORMULARIO
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            StatusControl.Text = "Estatus";
            Estatico.setUp(Consola);
            Hashtable clasesPreanalizadas = new Hashtable();

            if (Editor.TabCount > 0)
            {
                //RichTextBox principal = (RichTextBox)Editor.TabPages[Editor.SelectedIndex].Controls[0].Controls[1];
                this.archivo = Editor.TabPages[Editor.SelectedIndex].Name;

                FastColoredTextBox principal = (FastColoredTextBox)Editor.TabPages[Editor.SelectedIndex].Controls[0].Controls[0];
                String             cadena    = principal.Text;//PARA QUE TODO ESTE EN MINUSCULAS Y NO TENGA CLAVOS CON LA COMPROBACION DE NOMBRES
                Progreso.Value     = 40;
                StatusControl.Text = "Iniciando Proceso...";
                System.Threading.Thread.Sleep(200);
                Analizador an = new Analizador(cadena, this.ProyectoPath, archivo);
                if (an.analizar())//SI SE ANALIZA LA CADENA...
                {
                    // PROCEDE A INTENTAR CAPTURAR LA INFO...
                    if (Estatico.NumeroErroes() > 0) //SO EXISTEN ERRORES ANTES DE CAPTURAR LA INFO...
                    {
                        //REVISAR...
                        Progreso.Value     = 0;
                        StatusControl.Text = "Proceso Interrumpido!";
                        Estatico.consolaSalida.AppendText("\n>> Proceso detenido, Errores detectados...");
                        MessageBox.Show("Existen: " + Estatico.NumeroErroes() + " en La cadena! Revisalos en el reporte", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else//SINO PROCEDER A CAPTURA LA INFORMACION
                    {
                        CapturarInformacion(an, clasesPreanalizadas);
                        ///////////////////////////////////////////////////////
                        Progreso.Value     = 100;
                        StatusControl.Text = "Proceso Terminado!";
                        System.Threading.Thread.Sleep(200);
                        Progreso.Value = 0;
                        ///////////////////////////////////////////////////////
                        if (Estatico.resps.Count > 0)
                        {
                            String nombre = Microsoft.VisualBasic.Interaction.InputBox("Nombre Del Formulario A Guardar: ", "Nuevo Form", "", 100, 100);
                            if (!nombre.Equals(""))
                            {
                                SavedForm s = new SavedForm(nombre, Estatico.resps);
                                if (s.writeForm())
                                {
                                    MessageBox.Show("Formulario: " + nombre + " Almacenado!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show("No se almaceno el formulario!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        //AQUI DEBO DE PREGUNTAR SI EN CASO HAY UN PROBLEMA CON LAS ADVERTENCIAS
                    }
                }
                else//SI NO SE PUEDE, ENTONCES EL ERROR ES FATAL... REVISAR
                {
                    MessageBox.Show("No se logro Analizar la cadena de entrada", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                errorLabel.Text    = Convert.ToString(Estatico.NumeroErroes());
                warningsLabel.Text = Convert.ToString(Estatico.NumeroAdvertencias());
            }
        }