Esempio n. 1
0
        public static async Task GenerateAsync(Dispatcher dispatcher, ConfigPage page)
        {
            var manager = page.Manager;

            if (!manager.IsGenerating)
            {
                var tok = new GenerationToken(dispatcher, page);

                manager.IsGenerating = true;
                try
                {
                    manager.TimeTaken = TimeSpan.Zero;
                    manager.Notifications.Clear(page);
                    manager.ProcessDurations.Clear();

                    await GenerateAsync(tok);

                    Update(tok, page);
                }
                finally
                {
                    manager.IsGenerating = false;
                    manager.TimeTaken    = tok.Duration;
                }
            }
        }
        public static string Decrypt(string word)
        {
            byte[] bytesToBeDecrypted = Convert.FromBase64String(word);
            var    wordDecrypted      = Encoding.UTF8.GetString(GenerationToken.AES_Decrypt(bytesToBeDecrypted));

            return(wordDecrypted);
        }
Esempio n. 3
0
        static void Update(GenerationToken tok, ConfigPage page)
        {
            var resultPages = page.ResultPages.ToArray();

            foreach (var result in tok.Results)
            {
                result.AddOrUpdatePage(page, resultPages);
            }

            RemoveRemaining(resultPages);

            page.DirtySince = null;
        }
Esempio n. 4
0
        static void GenerateCore(GenerationToken tok)
        {
            var generator = GeneratorFactory.NewGenerator(tok.GeneratorType);
            var start     = DateTime.Now;

            try
            {
                using (var reader = new StringReader(tok.Config))
                {
                    if (generator.Load(reader, tok, new Environment(tok.Filename)))
                    {
                        using (var writer = new StringWriter())
                        {
                            generator.Write(writer);
                            tok.Results.Add(new CodeResultToken(writer.ToString(), ".g.cs"));
                        }

                        foreach (var file in generator.AdditionalFiles)
                        {
                            if (file.IsBinary)
                            {
                                tok.Results.Add(WriteBinary(file));
                            }
                            else
                            {
                                tok.Results.Add(WriteText(file));
                            }
                        }
                    }
                    else
                    {
                        tok.Results.Add(new CodeResultToken(string.Empty, ".g.cs"));
                    }
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                tok.AddError(1, 1, 1, 1, "KA-BOOM!!!");
                tok.Results.Add(new CodeResultToken(ex.ToString(), ".g.cs"));
            }
#pragma warning restore CA1031 // Do not catch general exception types

            var end = DateTime.Now;
            tok.Duration = end - start;

            generator.ReportPerformance(tok);
        }
Esempio n. 5
0
        /// <summary>
        /// Get User connected
        /// </summary>
        /// <param name="token"></param>
        /// <param name="ip"></param>
        /// <param name="userAgent"></param>
        /// <returns></returns>
        public static UserMobile GetUserConnected(string token, string ip, string userAgent)
        {
            bool result = false;

            try
            {
                var tokenKey = HttpUtility.HtmlEncode(token).Replace("&quot;", string.Empty).Trim();
                // Base64 decode the string, obtaining the token:username:timeStamp.
                string key = Encoding.UTF8.GetString(Convert.FromBase64String(tokenKey));
                // Split the parts.
                string[] parts = key.Split(new char[] { ':' });
                if (parts.Length == 3)
                {
                    // Get the hash message, username, and timestamp.
                    string   hash      = parts[0];
                    string   username  = parts[1];
                    long     ticks     = long.Parse(parts[2]);
                    DateTime timeStamp = new DateTime(ticks);

                    // Check if user in UsersMobile Table
                    Context c           = new Context();
                    var     userConnect = username.Split('@')[0];
                    var     user        = c.UsersMobile.FirstOrDefault(u => u.User_Name.ToLower().Contains(userConnect));

                    if (user.User_Name.ToLower().Contains(userConnect))
                    {
                        string password = user.Password;
                        // Hash the message with the key to generate a token.
                        string computedToken = GenerationToken.GenerateToken(username, password, ip, userAgent, ticks);
                        // Compare the computed token with the one supplied and ensure they match.
                        result = (tokenKey == computedToken);
                        if (result)
                        {
                            return(user);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new UserMobile());
        }
Esempio n. 6
0
 static Task GenerateAsync(GenerationToken tok)
 {
     return(Task.Run(() => GenerateCore(tok)));
 }