public accountController()
 {
     uow = new UnitOfWork();
 }
 public accountController(UnitOfWork UnitOfWork)
 {
     uow = UnitOfWork;
 }
 public static void PushTextFiles()
 {
     try
     {
         string filePath = FilePath;
         string repoPath = RepoPath;
         if (Directory.Exists(filePath) && Directory.Exists(repoPath))
         {
             logger.Debug("Writing texts to " + filePath);
             using (UnitOfWork uow = new UnitOfWork())
             {
                 var texts = uow.tc.Texts;
                 foreach (var text in texts)
                 {
                     string textPath = Path.Combine(filePath, text.UrlTitle + ".md");
                     File.WriteAllText(textPath, text.CraftTextString());
                     GitHelper.AddUpdateFile(textPath, repoPath);
                 }
                 GitHelper.CommitChanges("Changes from website", repoPath);
                 string headSha = GitHelper.GetHeadCommitSha(repoPath);
                 uow.tc.Settings.First().HeadSha = headSha;
                 uow.tc.SaveChanges();
                 logger.Debug("Git head is now at " + headSha);
             }
         }
         else
             logger.Debug("Missing TextFiles path or git repo");
     }
     catch (Exception ex)
     {
         logger.ErrorException("Failed to push texts to file", ex);
     }
 }
 public static void PullTextFiles()
 {
     try
     {
         string filePath = FilePath;
         string repoPath = RepoPath;
         if (Directory.Exists(filePath) && Directory.Exists(repoPath))
         {
             logger.Debug("Pulling texts from " + filePath);
             using (UnitOfWork uow = new UnitOfWork())
             {
                 string headSha = GitHelper.GetHeadCommitSha(repoPath);
                 if (uow.tc.Settings.First().HeadSha != headSha)
                 {
                     foreach (var file in Directory.GetFiles(filePath))
                     {
                         try
                         {
                             string fileData = File.ReadAllText(file);
                             string urlTitle = Path.GetFileNameWithoutExtension(file);
                             Text model = fileData.ToText();
                             var text = uow.tc.Texts.Where(d => d.UrlTitle == urlTitle).FirstOrDefault();
                             if (text != null)
                             {
                                 text.Posted = model.Posted;
                                 text.Title = model.Title;
                                 text.Article = model.Article;
                                 text.Updated = DateTime.Now;
                                 logger.Debug("Updated " + text.Title);
                             }
                             else
                             {
                                 Text newText = new Text()
                                 {
                                     Article = model.Article,
                                     Posted = model.Posted,
                                     Title = model.Title,
                                     UrlTitle = urlTitle,
                                     Updated = DateTime.Now
                                 };
                                 uow.tc.Texts.Add(newText);
                                 logger.Debug("Added " + newText.Title);
                             }
                         }
                         catch (Exception ex)
                         {
                             logger.ErrorException("Failed to update text file " + file, ex);
                         }
                     }
                     uow.tc.Settings.First().HeadSha = headSha;
                     uow.tc.SaveChanges();
                     logger.Debug("Successfully completed pull");
                 }
                 else
                     logger.Debug("HEAD is same as last pull");
             }
         }
         else
             logger.Debug("Missing TextFiles path or git repo");
     }
     catch (Exception ex)
     {
         logger.ErrorException("Failed to update text files", ex);
     }
 }
 public textController(UnitOfWork UnitOfWork)
 {
     uow = UnitOfWork;
 }
        private void AuthenticateUser(IDictionary<string, string> SocketCookies, IWebSocketConnection socket)
        {
            try
            {
                if (SocketCookies.Any(d => d.Key == ".ASPXAUTH"))
                {
                    var userData = System.Web.Security.FormsAuthentication.Decrypt(SocketCookies[".ASPXAUTH"]);
                    if (!userData.Expired)
                    {

                        QuizMessage msg = new QuizMessage()
                        {
                            Type = "SetName",
                            Message = userData.Name
                        };
                        string setUser = new JavaScriptSerializer().Serialize(msg);
                        socket.Send(setUser);
                        using (UnitOfWork uow = new UnitOfWork())
                        {
                            var userProfile = uow.uc.UserProfiles.FirstOrDefault(d => d.UserName == userData.Name);
                            if (userProfile != null)
                            {
                                var gameProfile = uow.qg.UserGameProfiles.FirstOrDefault(d => d.AccountModelUserId == userProfile.UserId);
                                if (gameProfile == null)
                                {
                                    UserGameProfile newProfile = new UserGameProfile()
                                    {
                                        AccountModelUserId = userProfile.UserId,
                                        Attempts = 0,
                                        CorrectAnswers = 0,
                                        LastTimeSeen = DateTime.Now,
                                        Points = 0
                                    };
                                    uow.qg.UserGameProfiles.Add(newProfile);
                                    uow.qg.SaveChanges();
                                    gameProfile = newProfile;
                                }
                                else
                                {
                                    gameProfile.LastTimeSeen = DateTime.Now;
                                }
                                uow.qg.SaveChanges();
                            }
                        }
                        QuizGame.Instance.UserJoin(socket.ConnectionInfo.Id, userData.Name);
                    }
                }
                else
                {
                    Random random = new Random();
                    int userid = random.Next(0, 1000);
                    while (QuizGame.Instance.Users.Any(d => d.UserName == "Guest" + userid.ToString()))
                        userid = random.Next(0, 1000);
                    string username = "******" + userid.ToString();
                    QuizMessage msg = new QuizMessage()
                    {
                        Type = "SetName",
                        Message = username
                    };
                    string setUser = new JavaScriptSerializer().Serialize(msg);
                    socket.Send(setUser);
                    QuizGame.Instance.UserJoin(socket.ConnectionInfo.Id, username);
                }
            }
            catch (Exception ex)
            {
                logger.DebugException("AuthenticateUser", ex);
            }
        }
 public photosController(UnitOfWork UnitOfWork)
 {
     uow = UnitOfWork;
 }
 public textController()
 {
     uow = new UnitOfWork();
 }
 public photosController()
 {
     uow = new UnitOfWork();
 }
 public guideController(UnitOfWork UnitOfWork)
 {
     uow = UnitOfWork;
 }
 public guideController()
 {
     uow = new UnitOfWork();
 }
Exemple #12
0
 private QuizGame()
 {
     uow = new UnitOfWork();
 }
Exemple #13
0
        public override string OnQualifyUrl(string url)
        {
            if (url.StartsWith("GetPhoto", StringComparison.CurrentCultureIgnoreCase))
            {
                using (UnitOfWork uow = new UnitOfWork())
                {
                    string photoid = url.ToLower().Replace("getphoto=", "");
                    var photo = uow.pr.GetPhoto(jcms.TextWallPhotoAlbum, photoid);
                    var resultUrl = "photonotfound";
                    try
                    {
                        resultUrl = photo.Media.Content.Attributes["url"].ToString();
                    }
                    catch { }
                    return resultUrl;
                }
            }
            else if (url.StartsWith("~"))
            {
                if (RequestContext != null)
                    return UrlHelper.GenerateContentUrl(url, RequestContext.HttpContext);
                else
                    return url;
            }
            else if (url.Contains(','))
            {
                string action = "", controller = "", query = "", finalurl = "";
                var urlParts = url.Split(',');
                if (urlParts.Length == 2)
                {
                    action = urlParts[0];
                    controller = urlParts[1];
                    if (RequestContext != null)
                        finalurl = UrlHelper.GenerateUrl("Default", action, controller, null, RouteTable.Routes, RequestContext, false);
                    else
                        finalurl = controller + "/" + action;

                }
                if (urlParts.Length >= 3)
                {
                    action = urlParts[0];
                    controller = urlParts[1];
                    query = "?";
                    for (int i = 2; i < urlParts.Length; i++)
                    {
                        if (urlParts[i].Contains('='))
                        {
                            query += urlParts[i];
                            if (i != (urlParts.Length - 1))
                                query += "&";
                        }
                        else
                            query += "/" + urlParts[i];
                    }
                    if (RequestContext != null)
                        finalurl = UrlHelper.GenerateUrl("Default", action, controller, null, RouteTable.Routes, RequestContext, false) + query;
                    else
                        finalurl = controller + "/" + action + query;
                }
                return finalurl;
            }
            else
                return base.OnQualifyUrl(url);
        }