示例#1
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
            var user          = new ApplicationUser()
            {
                UserName = Email.Text, Email = Email.Text
            };
            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

                MPAiSQLite context = new MPAiSQLite();
                context.AddUser(user.UserName);

                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Output JSON file
            string json;

            // Connect to database class and call query method.
            MPAiSQLite  context  = new MPAiSQLite();
            List <Word> wordList = context.GenerateWordList();

            // Create an array of strings representing the words retreived from the database.
            String[] wordNames = new String[wordList.Count];
            for (int i = 0; i < wordList.Count; i++)
            {
                wordNames[i] = wordList[i].WordName.Replace("_", " ");
            }

            // Create a JSON file containing the words in the correct format.
            if (wordList.Count == 0)
            {
                json = "nothing";
            }
            else
            {
                json = JsonConvert.SerializeObject(wordNames, Formatting.Indented);
            }

            // Output result as JSON
            Response.Clear();
            Response.ContentType = "application/json; charset=utf-8";
            Response.Write(json);
            Response.End();
        }
示例#3
0
文件: Startup.cs 项目: sabflik/MPAi
 public void Configuration(IAppBuilder app)
 {
     // Set up authentication.
     ConfigureAuth(app);
     // Initialise database. This could take some time, so is called on startup.
     MPAiSQLite initialDB = new MPAiSQLite();
 }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get target word name and category from server.
            string name     = Request.Form["wordName"];
            string category = Request.Form["wordCategory"];

            Debug.WriteLine("Count: " + Request.Form.Count);
            Debug.WriteLine("respond: " + name);
            Debug.WriteLine("Category: " + category);

            // Create list of recording objects.
            MPAiSQLite       context       = new MPAiSQLite();
            List <Recording> recordingList = context.GenerateRecordingList(name, category);

            // make a new Dataset containing recordings.
            // This way was selected as it serialises into JSON well.
            DataSet newDataSet = new DataSet("newDataSet");

            newDataSet.Namespace = "MPAi_WebApp";
            DataTable  newDataTable = new DataTable("resultJsonTable");
            DataColumn nameColumn   = new DataColumn("name", typeof(string));

            newDataTable.Columns.Add(nameColumn);
            DataColumn categoryColumn = new DataColumn("category", typeof(string));

            newDataTable.Columns.Add(categoryColumn);
            DataColumn pathColumn = new DataColumn("path", typeof(string));

            newDataTable.Columns.Add(pathColumn);
            newDataSet.Tables.Add(newDataTable);

            // Add each recording object to the DataTable.
            foreach (Recording r in recordingList)
            {
                DataRow newRow = newDataTable.NewRow();
                newRow["name"]     = r.Word.WordName;
                newRow["category"] = Enum.GetName(typeof(Speaker), r.Speaker);
                newRow["path"]     = Path.Combine("audio", Path.GetFileName(r.FilePath));
                newDataTable.Rows.Add(newRow);
            }

            // Serialise the DataTable
            string newJson;

            if (newDataTable.Rows.Count == 0)
            {
                newJson = "nothing";
            }
            else
            {
                newJson = JsonConvert.SerializeObject(newDataSet, Formatting.Indented);
            }

            // Output result as JSON
            Response.Clear();
            Response.ContentType = "application/json; charset=utf-8";
            Response.Write(newJson);
            Response.End();
        }
示例#5
0
文件: Save.aspx.cs 项目: sabflik/MPAi
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (string upload in Request.Files)
            {
                // Get target word
                string targetWord = Request.Form["target"];

                // Upload audio file
                string dictionary = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"uploads");
                Directory.CreateDirectory(dictionary);
                var file = Request.Files[upload];
                if (file == null)
                {
                    continue;
                }
                string recordingPath = Path.Combine(dictionary, Request.Form["fileName"]);
                file.SaveAs(recordingPath);

                // Analyse audio file
                HTKEngine engine = new HTKEngine();
                Dictionary <string, string> htkResult = engine.Recognize(recordingPath).ToDictionary(x => x.Key, x => x.Value);

                Console.WriteLine(recordingPath);

                // Convert results to JSON
                string result = "";
                if (htkResult.Count == 0)
                {
                    result = "nothing";
                }
                else
                {
                    result = htkResult.Values.ToArray()[0];
                }
                // Add scores to database.
                MPAiSQLite context = new MPAiSQLite();
                context.SaveScore(System.Web.HttpContext.Current.User.Identity.Name, targetWord.ToLower(), (int)(Math.Round(SimilarityAlgorithm.DamereauLevensheinDistanceAlgorithm(Request.Form["target"], result) * 100, 0)));

                // Output result as JSON.
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write(GetResponse(Request.Form["target"], result));
                Response.End();
            }
        }
示例#6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Retrieve the list of scores from the database.
            MPAiSQLite   context   = new MPAiSQLite();
            List <Score> scoreList = context.GenerateScoreList(HttpContext.Current.User.Identity.Name);

            // Calculate current score (That is, the average score in the donut)
            double totalScores = 0;

            foreach (Score s in scoreList)
            {
                totalScores += s.Percentage;
            }
            double currentScore = Math.Round(totalScores / scoreList.Count());  // Change this line to alter the calculation.

            // make a new Dataset - chosen for how well it serialises into JSON.
            DataSet newDataSet = new DataSet("newDataSet");

            newDataSet.Namespace = "MPAi_WebApp";

            // Current average score table
            DataTable  donutDataTable     = new DataTable("donutScore");
            DataColumn currentScoreColumn = new DataColumn("donutScore");

            donutDataTable.Columns.Add(currentScoreColumn);
            newDataSet.Tables.Add(donutDataTable);

            // Add the average score to the table.
            DataRow donutRow = donutDataTable.NewRow();

            donutRow["donutScore"] = currentScore;
            donutDataTable.Rows.Add(donutRow);

            // Scores over time table
            DataTable  scoresDataTable = new DataTable("scores");
            DataColumn timeColumn      = new DataColumn("time", typeof(string));

            scoresDataTable.Columns.Add(timeColumn);
            DataColumn scoreColumn = new DataColumn("score", typeof(string));

            scoresDataTable.Columns.Add(scoreColumn);
            newDataSet.Tables.Add(scoresDataTable);

            // Add the scores over time to the table.
            foreach (Score s in scoreList)
            {
                DataRow newRow = scoresDataTable.NewRow();
                newRow["time"]  = s.Date.ToString();
                newRow["score"] = s.Percentage;
                scoresDataTable.Rows.Add(newRow);
            }

            // Serialise the data into JSON.
            string newJson;

            if (scoresDataTable.Rows.Count == 0)
            {
                newJson = "nothing";
            }
            else
            {
                newJson = JsonConvert.SerializeObject(newDataSet, Formatting.Indented);
            }

            // Output result as JSON.
            Response.Clear();
            Response.ContentType = "application/json; charset=utf-8";
            Response.Write(newJson);
            Response.End();
        }