Beispiel #1
0
 public static List<Artist> GetSampleArtists(int qty = 1000) {
   var newArtists = new List<Artist>();
   for (int i = 1; i <= qty; i++) {
     newArtists.Add(new Artist { ArtistId = i, Name = "New Artist " + i });
   }
   return newArtists;
 }
Beispiel #2
0
 public IEnumerable<Question> GetListOfQuestion()
 {
     var ctx = new Context();
     List<Question> list = new List<Question>(); 
     ctx.Questions.ToList().ForEach(item=> list.Add(new Question(){ Text= item.Text, Id=item.Id}));
     return list;
 
 }
Beispiel #3
0
        public ActionResult LoadMore()
        {
            var result = new List<AddMoreModel>();

            for (int i = 0; i < 5; i++)
            {
                id++;
                result.Add(new AddMoreModel() { Name = string.Format("Name-{0}", id), Id = (id * 2).ToString(), Type = string.Format("type{0}",i.ToString()) });
            }
            return PartialView("LoadMore", result);
        }
Beispiel #4
0
 public JsonResult UpdateMailboxes(DateTime catalogDateTime)
 {
     UpdateMailboxesModel result = new UpdateMailboxesModel();
     result.CatalogTime = catalogDateTime;
     List<MailboxInfo> infos = new List<MailboxInfo>(24);
     for(int i = 0; i < 24; i++)
     {
         infos.Add(new MailboxInfo() { DisplayName = string.Format("DisplayName-{0}", i), MailAddress = string.Format("Address{0}@arcserve.com", i), RootFolderId = i.ToString() });
     }
     return Json(result);
 }
Beispiel #5
0
 public static List<Album> GetSampleAlbums(int qtyPerArtist = 5) {
   var sampleArtists = GetSampleArtists();
   var sampleAlbums = new List<Album>();
   int albumIdIndex = 1;
   foreach (var artist in sampleArtists) {
     var artistAlbums = new List<Album>();
     for (int i = 1; i <= qtyPerArtist; i++) {
       artistAlbums.Add(new Album { AlbumId = albumIdIndex, ArtistId = artist.ArtistId, Title = artist.Name + ": Super Awesome Album #" + i });
       albumIdIndex++;
     }
     sampleAlbums.AddRange(artistAlbums);
   }
   return sampleAlbums;
 }
Beispiel #6
0
 public static List<Track> GetSampleTracks(int qtyPerAlbum = 8) {
   var sampleAlbums = GetSampleAlbums();
   var sampleTracks = new List<Track>();
   int trackIdIndex = 1;
   foreach (var album in sampleAlbums) {
     var albumTracks = new List<Track>();
     for (int i = 1; i <= qtyPerAlbum; i++) {
       albumTracks.Add(new Track { TrackId = trackIdIndex, AlbumId = album.AlbumId, Name = "Album " + album.Title + "/Track " + i });
       trackIdIndex++;
     }
     sampleTracks.AddRange(albumTracks);
   }
   return sampleTracks;
 }
Beispiel #7
0
        public JsonResult UpdateMailboxes(DateTime catalogDateTime)
        {
            UpdateMailboxesModel result = new UpdateMailboxesModel();
            result.CatalogTime = catalogDateTime;

            var tree = new Tree();
            var allMailboxes = tree.GetAllMailbox();
            List<Item> infos = new List<Item>(allMailboxes.Count);
            foreach (var mailbox in allMailboxes)
            {
                infos.Add(new Item() { Id = mailbox.RootFolderId, DisplayName = mailbox.DisplayName, ChildCount = tree.GetChildCount(mailbox.RootFolderId), ItemType = "Mailbox", OtherInformation = mailbox});
            }

            result.Details = infos;
            return Json(result);
        }
Beispiel #8
0
 public static List<ArtistDocument> GetSampleArtistDocuments(int qty = 1000, int qtyAlbumsPerArtist = 5, int qtyTracksPerAlbum = 8) {
   var newArtists = new List<ArtistDocument>();
   int albumIdIndex = 1;
   int trackIdIndex = 1;
   for (int i = 1; i <= qty; i++) {
     var newArtist = new ArtistDocument { ArtistDocumentId = i, Name = "New Artist " + i };
     for (int j = 1; j <= qtyAlbumsPerArtist; j++) {
       var newAlbum = new AlbumDocument { AlbumId = albumIdIndex, ArtistId = newArtist.ArtistDocumentId, Title = newArtist.Name + ": Super Awesome Album #" + i };
       for (int k = 1; k <= qtyTracksPerAlbum; k++) {
         var newTrack = new Track { TrackId = trackIdIndex, AlbumId = newAlbum.AlbumId, Name = "Album " + newAlbum.Title + "/Track " + i };
         newAlbum.Tracks.Add(newTrack);
         trackIdIndex++;
       }
       newArtist.Albums.Add(newAlbum);
       albumIdIndex++;
     }
     newArtists.Add(newArtist);
   }
   return newArtists;
 }
            public IList<Claim> GetClaims()
            {
                IList<Claim> claims = new List<Claim>();
                claims.Add(new Claim(ClaimTypes.NameIdentifier, ProviderKey, null, LoginProvider));

                if (UserName != null)
                {
                    claims.Add(new Claim(ClaimTypes.Name, UserName, null, LoginProvider));
                }

                return claims;
            }
Beispiel #10
0
        public Tree()
        {
            _allMails = new List<MailboxInfo>(2);
            _allMails.Add(new MailboxInfo() { DisplayName = "user1", MailAddress = "*****@*****.**", RootFolderId = "Mailbox-1" });
            _allMails.Add(new MailboxInfo() { DisplayName = "user2", MailAddress = "*****@*****.**", RootFolderId = "Mailbox-2" });

            var folder1 = new FolderInfo() { DisplayName = "Inbox", FolderId = "Folder1-Inbox", ParentFolderId = "Mailbox-1", ChildFolderCount = 2, ChildItemCount = 12 };

            #region folder1 child items
            var item11 = new MailInfo() { DisplayName = "item11", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item11", Size = 100 };
            var item12 = new MailInfo() { DisplayName = "item12", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item12", Size = 101 };
            var item13 = new MailInfo() { DisplayName = "item13", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item13", Size = 1002 };
            var item14 = new MailInfo() { DisplayName = "item14", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item14", Size = 1003 };
            var item15 = new MailInfo() { DisplayName = "item15", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item15", Size = 1004 };
            var item16 = new MailInfo() { DisplayName = "item16", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item16", Size = 1005 };
            var item17 = new MailInfo() { DisplayName = "item17", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item17", Size = 1006 };
            var item18 = new MailInfo() { DisplayName = "item18", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item18", Size = 1007 };
            var item19 = new MailInfo() { DisplayName = "item19", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item19", Size = 1008 };
            var item110 = new MailInfo() { DisplayName = "item110", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item110", Size = 1009 };
            var item111 = new MailInfo() { DisplayName = "item111", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item111", Size = 10010 };
            var item112 = new MailInfo() { DisplayName = "item112", ParentFolderId = "Folder1-Inbox", CreateTime = DateTime.Now, ItemId = "folder1-item112", Size = 10011 };
            #endregion

            var folder11 = new FolderInfo() { DisplayName = "Inbox-Child1", FolderId = "Folder-Inbox-Child1", ParentFolderId = "Folder1-Inbox", ChildFolderCount = 0, ChildItemCount = 1 };
            #region folder11 child items
            var item11_1 = new MailInfo() { DisplayName = "item11_1", ParentFolderId = "Folder-Inbox-Child1", CreateTime = DateTime.Now, ItemId = "folder1-item11_1", Size = 100 };
            #endregion

            var folder12 = new FolderInfo() { DisplayName = "Inbox-Child2", FolderId = "Folder-Inbox-Child2", ParentFolderId = "Folder1-Inbox", ChildFolderCount = 1, ChildItemCount = 2 };
            #region folder11 child items
            var item12_1 = new MailInfo() { DisplayName = "item12_1", ParentFolderId = "Folder-Inbox-Child2", CreateTime = DateTime.Now, ItemId = "folder1-item12_1", Size = 102 };
            var item12_2 = new MailInfo() { DisplayName = "item12_2", ParentFolderId = "Folder-Inbox-Child2", CreateTime = DateTime.Now, ItemId = "folder1-item12_2", Size = 109 };
            #endregion

            var folder121 = new FolderInfo() { DisplayName = "Inbox-Child2-Child1", FolderId = "Folder-Inbox-Child2-Child1", ParentFolderId = "Folder-Inbox-Child2", ChildFolderCount = 0, ChildItemCount = 1 };
            #region folder11 child items
            var item121_1 = new MailInfo() { DisplayName = "item121_1", ParentFolderId = "Folder-Inbox-Child2-Child1", CreateTime = DateTime.Now, ItemId = "folder1-item121_1", Size = 102 };
            #endregion

            var folder2 = new FolderInfo() { DisplayName = "Inbox", FolderId = "Folder2-Inbox", ParentFolderId = "Mailbox-2", ChildFolderCount = 0, ChildItemCount = 2 };
            #region folder11 child items
            var item2_1 = new MailInfo() { DisplayName = "item2_1", ParentFolderId = "Folder2-Inbox", CreateTime = DateTime.Now, ItemId = "folder2-item2_1", Size = 102 };
            var item2_2 = new MailInfo() { DisplayName = "item2_2", ParentFolderId = "Folder2-Inbox", CreateTime = DateTime.Now, ItemId = "folder2-item2_2", Size = 109 };
            #endregion

            _folder2Children = new Dictionary<string, List<FolderInfo>>();
            List<FolderInfo> tempChildFolders = new List<FolderInfo>();
            tempChildFolders.Add(folder1);
            _folder2Children.Add("Mailbox-1", tempChildFolders);

            tempChildFolders = new List<FolderInfo>();
            tempChildFolders.Add(folder11);
            tempChildFolders.Add(folder12);
            _folder2Children.Add(folder1.FolderId, tempChildFolders);

            tempChildFolders = new List<FolderInfo>();
            tempChildFolders.Add(folder121);
            _folder2Children.Add(folder12.FolderId, tempChildFolders);

            tempChildFolders = new List<FolderInfo>();
            tempChildFolders.Add(folder2);
            _folder2Children.Add("Mailbox-2", tempChildFolders);

            _mailbox2Folders = new Dictionary<string, List<FolderInfo>>();
            List<FolderInfo> allFolders = new List<FolderInfo>();
            allFolders.Add(folder1);
            allFolders.Add(folder11);
            allFolders.Add(folder12);
            allFolders.Add(folder121);

            _mailbox2Folders.Add("Mailbox-1", allFolders);

            allFolders = new List<FolderInfo>();

            allFolders.Add(folder2);
            _mailbox2Folders.Add("Mailbox-2", allFolders);

            _folder2Mails = new Dictionary<string, List<MailInfo>>();
            var listFolder1 = new List<MailInfo>();
            listFolder1.Add(item11);
            listFolder1.Add(item12);
            listFolder1.Add(item13);
            listFolder1.Add(item14);
            listFolder1.Add(item15);
            listFolder1.Add(item16);
            listFolder1.Add(item17);
            listFolder1.Add(item18);
            listFolder1.Add(item19);
            listFolder1.Add(item110);
            listFolder1.Add(item111);
            listFolder1.Add(item112);
            _folder2Mails.Add(folder1.FolderId, listFolder1);

            listFolder1 = new List<MailInfo>();
            listFolder1.Add(item11_1);
            _folder2Mails.Add(folder11.FolderId, listFolder1);

            listFolder1 = new List<MailInfo>();
            listFolder1.Add(item12_1);
            listFolder1.Add(item12_2);
            _folder2Mails.Add(folder12.FolderId, listFolder1);

            listFolder1 = new List<MailInfo>();
            listFolder1.Add(item121_1);
            _folder2Mails.Add(folder121.FolderId, listFolder1);

            listFolder1 = new List<MailInfo>();
            listFolder1.Add(item2_1);
            listFolder1.Add(item2_2);
            _folder2Mails.Add(folder2.FolderId, listFolder1);

            _folder2TotalChildCount = new Dictionary<string, int>();
            _folder2TotalChildCount.Add("Mailbox-1", 1);
            _folder2TotalChildCount.Add(folder1.FolderId, folder1.ChildFolderCount + folder1.ChildItemCount);
            _folder2TotalChildCount.Add(folder11.FolderId, folder11.ChildItemCount + folder11.ChildFolderCount);
            _folder2TotalChildCount.Add(folder12.FolderId, folder12.ChildItemCount + folder12.ChildFolderCount);
            _folder2TotalChildCount.Add(folder121.FolderId, folder121.ChildItemCount + folder121.ChildFolderCount);

            _folder2TotalChildCount.Add("Mailbox-2", 2);
            _folder2TotalChildCount.Add(folder2.FolderId, folder2.ChildItemCount + folder2.ChildFolderCount);
        }
Beispiel #11
0
 private List<Item> GetContainer(string folderId, Tree tree)
 {
     var allRootFolder = tree.GetDirectFolder(folderId);
     List<Item> result = new List<Item>();
     foreach (var folder in allRootFolder)
     {
         var item = new Item() { Id = folder.FolderId, ChildCount = tree.GetChildCount(folder.FolderId), DisplayName = folder.DisplayName, ItemType = "Folder" };
         item.Container = GetContainer(folder.FolderId, tree);
         result.Add(item);
     }
     return result;
 }
Beispiel #12
0
        //public JsonResult UpdateFolders(DateTime catalogDateTime, string rootFolderId)
        //{
        //    UpdateMailboxesModel result = new UpdateMailboxesModel();
        //    result.CatalogTime = catalogDateTime;
        //    List<Item> infos = new List<Item>(24);
        //    string i = "0";
        //    var mailboxInfo0 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 2,
        //        ChildItemCount = 4
        //    };
        //    var mailboxInfo = mailboxInfo0;
        //    var item0 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    i = "01";
        //    var mailboxInfo01 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 0,
        //        ChildItemCount = 2,
        //        ParentFolderId = "0"
        //    };
        //    mailboxInfo = mailboxInfo01;
        //    var item01 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    i = "02";
        //    var mailboxInfo02 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 0,
        //        ChildItemCount = 2,
        //        ParentFolderId = "0"
        //    };
        //    mailboxInfo = mailboxInfo02;
        //    var item02 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    item0.Children = new List<Item>() { item01, item02 };
        //    i = "1";
        //    var mailboxInfo1 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 0,
        //        ChildItemCount = 1
        //    };
        //    mailboxInfo = mailboxInfo1;
        //    var item1 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    i = "2";
        //    var mailboxInfo2 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 1,
        //        ChildItemCount = 2,
        //    };
        //    mailboxInfo = mailboxInfo2;
        //    var item2 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    i = "21";
        //    var mailboxInfo21 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 2,
        //        ChildItemCount = 2,
        //        ParentFolderId = "2"
        //    };
        //    mailboxInfo = mailboxInfo21;
        //    var item21 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    item2.Children = new List<Item>() { item21 };
        //    i = "211";
        //    var mailboxInfo211 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 0,
        //        ChildItemCount = 1000,
        //        ParentFolderId = "21"
        //    };
        //    mailboxInfo = mailboxInfo211;
        //    var item211 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    i = "212";
        //    var mailboxInfo212 = new FolderInfo()
        //    {
        //        DisplayName = string.Format("Folder-DisplayName-{0}", i),
        //        MailboxAddress = string.Format("*****@*****.**", i),
        //        FolderId = i.ToString(),
        //        ChildFolderCount = 0,
        //        ChildItemCount = 2,
        //        ParentFolderId = "21"
        //    };
        //    mailboxInfo = mailboxInfo212;
        //    var item212 = new Item() { Id = mailboxInfo.FolderId, DisplayName = mailboxInfo.DisplayName, Count = mailboxInfo.ChildItemCount, OtherInformation = mailboxInfo };
        //    item21.Children = new List<Item>() { item211, item212 };
        //    infos.Add(item0);
        //    infos.Add(item1);
        //    infos.Add(item2);
        //    result.Details = infos;
        //    return Json(result);
        //}
        public JsonResult UpdateMails(string folderId, int pageIndex, int pageCount)
        {
            var tree = new Tree();
            var mails = tree.GetMails(folderId);
            int startIndex = pageIndex * pageCount;
            int endIndex = startIndex + pageCount;
            List<Item> result = new List<Item>(pageCount);
            while (startIndex < endIndex && startIndex < mails.Count)
            {
                var mailItem = mails[startIndex];
                var item = new Item() { Id = mailItem.ItemId, ChildCount = 0, DisplayName = mailItem.DisplayName, OtherInformation = mailItem };

                result.Add(item);

                startIndex++;
            }
            return Json(new MailResult() { Mails = result, TotalCount = mails.Count });
        }
        //POST
        public JsonResult GetNextPage(int currentPage, string pointType)
        {
            currentPage++;

            var profiles = _userRepo.GetAll().Where(ur => ur.IsAdmin == false);//.OrderBy(Skip(currentPage * pageSize).Take(pageSize);

            int userCount = profiles.Count();

            int maxPages = (userCount / pageSize);// +((userCount % pageSize) > 0 ? 1 : 0);

            bool pointTypeExists = false;

            ScoreboardJsonResult sjr = new ScoreboardJsonResult()
            {
                PageNum = currentPage,
                FinishedLoading = false
            };

            if (currentPage >= maxPages) sjr.FinishedLoading = true;

            foreach (PointType pt in _pointTypeRepo.GetAll())
            {
                pointTypeExists = (pt.Name == pointType);

                if (pointTypeExists) break;
            }

            List<ScoreboardUser> recordList = new List<ScoreboardUser>();
            foreach (var user in profiles)
            {
                ScoreboardUser newUser = new ScoreboardUser()
                {
                    Username = user.UserName,
                    Score = pointTypeExists ? user.ScoreFor(pointType) : user.TotalScore,
                    Milestones = new List<ScoreboardMilestone>()
                };

                foreach (CompletedTask ct in user.CompletedTask)
                {
                    if (ct.Task.IsMilestone)
                    {
                        newUser.Milestones.Add(new ScoreboardMilestone()
                        {
                            Name = ct.Task.Name,
                            Description = ct.Task.Description,
                            IconLink = ct.Task.IconLink
                        });
                    }
                }

                recordList.Add(newUser);
            }

            recordList.Sort(CompareByScore);

            recordList = recordList.Skip(currentPage * pageSize).Take(pageSize).ToList();

            sjr.Users = recordList;

            return Json(sjr, JsonRequestBehavior.AllowGet);
        }
        public JsonResult SearchUser(int currentPage, string pointType, string userName)
        {
            var profiles = _userRepo.GetAll().Where(ur => ur.IsAdmin == false);

            int userCount = profiles.Count();

            int maxPages = (userCount / pageSize) + ((userCount % pageSize) > 0 ? 1 : 0);

            ScoreboardJsonResult sjr = new ScoreboardJsonResult();

            sjr.FinishedLoading = true;

            bool pointTypeExists = false;
            foreach (PointType pt in _pointTypeRepo.GetAll())
            {
                pointTypeExists = (pt.Name == pointType);

                if (pointTypeExists) break;
            }

            List<ScoreboardUser> recordList = new List<ScoreboardUser>();
            foreach (var user in profiles)
            {
                ScoreboardUser newUser = new ScoreboardUser()
                {
                    Username = user.UserName,
                    Score = pointTypeExists ? user.ScoreFor(pointType) : user.TotalScore,
                    Milestones = new List<ScoreboardMilestone>()
                };

                foreach (CompletedTask ct in user.CompletedTask)
                {
                    if (ct.Task.IsMilestone)
                    {
                        newUser.Milestones.Add(new ScoreboardMilestone()
                        {
                            Name = ct.Task.Name,
                            Description = ct.Task.Description,
                            IconLink = ct.Task.IconLink
                        });
                    }
                }

                recordList.Add(newUser);
            }

            sjr.Users = recordList;

            sjr.Users.Sort(CompareByScore);

            int userIndex = sjr.Users.FindIndex(up => up.Username.Equals(userName));

            int userOnPage = (userIndex / pageSize);

            if (userOnPage > currentPage)
            {
                sjr.FinishedLoading = false;
                //Page that the user is on is not loaded
                sjr.Users = sjr.Users.Skip((currentPage + 1)* pageSize).Take((userOnPage - currentPage) * pageSize).ToList();
                sjr.PageNum = userOnPage;
            }
            else
            {
                sjr.Users = sjr.Users.Take(0).ToList();
                sjr.PageNum = currentPage;
            }

            sjr.UserIndex = userIndex;

            return Json(sjr, JsonRequestBehavior.AllowGet);
        }
Beispiel #15
0
    public void Run() {
      Console.WriteLine("Postgres Document Demo - TEST DATA");
      Console.WriteLine("====================================");
      Console.WriteLine("Initialize Test Db");

      var sw = new Stopwatch();

      sw.Start();
      _testDb = new PgChinookDb("biggy_test", dropCreateTables: true);
      sw.Stop();
      Console.WriteLine("Initialized and reset PG database in {0} MS", sw.ElapsedMilliseconds);

      Console.WriteLine("Write some complex artist documents, with nested albums and tracks, from sample data...");
      int qtyArtists = 1000;
      int qtyAlbumsPerArtist = 5;
      int qtyTracksPerAlbum = 8;
      var sampleArtistDocuments = SampleData.GetSampleArtistDocuments(qtyArtists, qtyAlbumsPerArtist, qtyTracksPerAlbum);

      sw.Reset();
      sw.Start();
      _testDb.ArtistDocuments.Add(sampleArtistDocuments);
      sw.Stop();
      Console.WriteLine("Wrote {0} artist document records in {1} ms", sampleArtistDocuments.Count, sw.ElapsedMilliseconds);
      Console.WriteLine("Total of {0} artists, {1} albums, and {2} tracks nested in artist documents",
                qtyArtists, qtyArtists * qtyAlbumsPerArtist, qtyArtists * qtyAlbumsPerArtist * qtyTracksPerAlbum);

      Console.WriteLine("");
      Console.WriteLine("Re-Initialize Db and read all that data from back-end...");

      sw.Reset();
      sw.Start();
      _testDb.LoadData();
      sw.Stop();
      Console.WriteLine("Read all data from store in {0} ms", sw.ElapsedMilliseconds);
      Console.WriteLine("{0} complex artist documents", _testDb.ArtistDocuments.Count);

      foreach (var artist in sampleArtistDocuments) {
        artist.Name = "UPDATED " + artist.ArtistDocumentId;
        artist.Albums.FirstOrDefault().Title = "UPDATED ALBUM";
      }

      sw.Reset();
      sw.Start();
      _testDb.ArtistDocuments.Update(sampleArtistDocuments);
      sw.Stop();
      Console.WriteLine("Updated {0} artist documents in {1} ms", sampleArtistDocuments.Count, sw.ElapsedMilliseconds);

      sw.Reset();
      sw.Start();
      _testDb.ArtistDocuments.Remove(sampleArtistDocuments);
      sw.Stop();
      Console.WriteLine("Removed {0} artist documents in {1} ms", sampleArtistDocuments.Count, sw.ElapsedMilliseconds);

      Console.WriteLine("");
      Console.WriteLine("Postgres Document Demo - CHINOOK DATA");
      Console.WriteLine("=======================================");

      Console.WriteLine("Now let's use some actual data from Chinook Db to build some documents...");

      sw.Reset();
      sw.Start();
      _chinookDb = new PgChinookDb("chinook-pg");
      sw.Stop();
      Console.WriteLine("Initialized Chinook data in {0} ms - loaded:", sw.ElapsedMilliseconds);
      Console.WriteLine("{0} Artists", _chinookDb.Artists.Count);
      Console.WriteLine("{0} Albums", _chinookDb.Albums.Count);
      Console.WriteLine("{0} Tracks", _chinookDb.Tracks.Count);

      Console.WriteLine("");
      Console.WriteLine("Nest chinook albums and tracks under artists complex documents and save");
      Console.WriteLine("=======================================================================");

      Console.WriteLine("");
      Console.WriteLine("Clear previous data from artist documents table...");
      int qtyRecordsToDelete = _testDb.ArtistDocuments.Count;

      sw.Start();
      _testDb.ArtistDocuments.Clear();
      sw.Stop();
      Console.WriteLine("tDeleted {0} artist document records in {1} ms", qtyRecordsToDelete, sw.ElapsedMilliseconds);

      Console.WriteLine("");
      Console.WriteLine("Create artist documents using chinook data...");

      sw.Reset();
      sw.Start();
      var artistDocumentsToAdd = new List<ArtistDocument>();

      // Read from Chinook db, and combine artist, album, and track info into documents:
      foreach (var artist in _chinookDb.Artists) {
        var newArtistDoc = new ArtistDocument { ArtistDocumentId = artist.ArtistId, Name = artist.Name };
        var artistAlbums = (from a in _chinookDb.Albums where a.ArtistId == artist.ArtistId select a).ToList();
        foreach (var album in artistAlbums) {
          var newAlbumDocument = new AlbumDocument { AlbumId = album.AlbumId, ArtistId = album.ArtistId, Title = album.Title };
          var albumTracks = from t in _chinookDb.Tracks where t.AlbumId == album.AlbumId select t;
          foreach (var track in albumTracks) {
            newAlbumDocument.Tracks.Add(new Track { TrackId = track.TrackId, AlbumId = newAlbumDocument.AlbumId, Name = track.Name });
          }
          newArtistDoc.Albums.Add(newAlbumDocument);
        }
        artistDocumentsToAdd.Add(newArtistDoc);
      }
      sw.Stop();
      Console.WriteLine("");
      Console.WriteLine("Read \r\n{0} artists, \r\n{1} albums, and \r\n{2} tracks \r\nfrom Chinook and assembled into complex artist documents in {3} ms",
        _chinookDb.Artists.Count, _chinookDb.Albums.Count, _chinookDb.Tracks.Count, sw.ElapsedMilliseconds);

      sw.Reset();
      sw.Start();
      _testDb.ArtistDocuments.Add(artistDocumentsToAdd);
      sw.Stop();
      Console.WriteLine("");
      Console.WriteLine("Wrote all {0} complex artist documents to PG Store in {1} ms", _testDb.ArtistDocuments.Count, sw.ElapsedMilliseconds);
    }
Beispiel #16
0
    public void Run() {

      Console.WriteLine("Postgres Perf");
      Console.WriteLine("=============");


      PgDropCreate.DropCreateAll(_pgDb);
      var pgStore = new PgRelationalStore<Artist>(_pgDb);
      var pgMemoryArtists = new List<Artist>();

      var pgNewArtists = new List<Artist>();
      for (int i = 1; i <= 10000; i++) {
        pgNewArtists.Add(new Artist { Name = "New Artist " + i });
      }

      var sw = new System.Diagnostics.Stopwatch();
      sw.Start();
      pgStore.Add(pgNewArtists);
      sw.Stop();
      Console.WriteLine("Added {0} new Artists in {1} ms", pgNewArtists.Count, sw.ElapsedMilliseconds);

      sw.Reset();
      sw.Start();
      var pgAllArtists = pgStore.TryLoadData();
      sw.Stop();
      Console.WriteLine("Read {0} Artists from DB in {1} ms", pgAllArtists.Count, sw.ElapsedMilliseconds);

      foreach (var artist in pgAllArtists) {
        artist.Name = "UPDATED";
      }

      sw.Reset();
      sw.Start();
      pgStore.Update(pgAllArtists);
      sw.Stop();
      Console.WriteLine("Updated {0} new Artists in {1} ms", pgAllArtists.Count, sw.ElapsedMilliseconds);

      sw.Reset();
      sw.Start();
      int pgHowMany = pgStore.Delete(pgAllArtists);
      sw.Stop();
      Console.WriteLine("Delted {0} new Artists in {1} ms", pgHowMany, sw.ElapsedMilliseconds);

      Console.WriteLine("SQLite Perf");
      Console.WriteLine("===========");

      sqliteDropCreate.DropCreateAll(_sqlitedb);
      var sqliteStore = new SqliteRelationalStore<Artist>(_sqlitedb);
      var sqliteMemoryArtists = new List<Artist>();

      var sqliteNewArtists = new List<Artist>();
      for (int i = 1; i <= 10000; i++) {
        sqliteNewArtists.Add(new Artist { Name = "New Artist " + i });
      }

      sw.Reset();
      sw.Start();
      sqliteStore.Add(sqliteNewArtists);
      sw.Stop();
      Console.WriteLine("Added {0} new Artists in {1} ms", sqliteNewArtists.Count, sw.ElapsedMilliseconds);

      sw.Reset();
      sw.Start();
      var sqliteAllArtists = sqliteStore.TryLoadData();
      sw.Stop();
      Console.WriteLine("Read {0} Artists from DB in {1} ms", sqliteAllArtists.Count, sw.ElapsedMilliseconds);

      foreach (var artist in sqliteAllArtists) {
        artist.Name = "UPDATED";
      }

      sw.Reset();
      sw.Start();
      sqliteStore.Update(sqliteAllArtists);
      sw.Stop();
      Console.WriteLine("Updated {0} new Artists in {1} ms", sqliteAllArtists.Count, sw.ElapsedMilliseconds);

      sw.Reset();
      sw.Start();
      int sqliteHowMany = sqliteStore.Delete(sqliteAllArtists);
      sw.Stop();
      Console.WriteLine("Delted {0} new Artists in {1} ms", sqliteHowMany, sw.ElapsedMilliseconds);
    }
        public IEnumerable<ExternalLoginViewModel> GetExternalLogins(string returnUrl, bool generateState = false)
        {
            IEnumerable<AuthenticationDescription> descriptions = Authentication.GetExternalAuthenticationTypes();
            List<ExternalLoginViewModel> logins = new List<ExternalLoginViewModel>();

            string state;

            if (generateState)
            {
                const int strengthInBits = 256;
                state = RandomOAuthStateGenerator.Generate(strengthInBits);
            }
            else
            {
                state = null;
            }

            foreach (AuthenticationDescription description in descriptions)
            {
                ExternalLoginViewModel login = new ExternalLoginViewModel
                {
                    Name = description.Caption,
                    Url = Url.Route("ExternalLogin", new
                    {
                        provider = description.AuthenticationType,
                        response_type = "token",
                        client_id = Startup.PublicClientId,
                        redirect_uri = new Uri(Request.RequestUri, returnUrl).AbsoluteUri,
                        state = state
                    }),
                    State = state
                };
                logins.Add(login);
            }

            return logins;
        }
        public ActionResult RemoveExternalLogins()
        {
            ICollection<OAuthAccount> accounts = OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name);
            List<ExternalLogin> externalLogins = new List<ExternalLogin>();
            foreach (OAuthAccount account in accounts)
            {
                AuthenticationClientData clientData = OAuthWebSecurity.GetOAuthClientData(account.Provider);

                externalLogins.Add(new ExternalLogin
                {
                    Provider = account.Provider,
                    ProviderDisplayName = clientData.DisplayName,
                    ProviderUserId = account.ProviderUserId,
                });
            }

            ViewBag.ShowRemoveButton = externalLogins.Count > 1 || OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));
            return PartialView("_RemoveExternalLoginsPartial", externalLogins);
        }
        public async Task<ManageInfoViewModel> GetManageInfo(string returnUrl, bool generateState = false)
        {
            IdentityUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user == null)
            {
                return null;
            }

            List<UserLoginInfoViewModel> logins = new List<UserLoginInfoViewModel>();

            foreach (IdentityUserLogin linkedAccount in user.Logins)
            {
                logins.Add(new UserLoginInfoViewModel
                {
                    LoginProvider = linkedAccount.LoginProvider,
                    ProviderKey = linkedAccount.ProviderKey
                });
            }

            if (user.PasswordHash != null)
            {
                logins.Add(new UserLoginInfoViewModel
                {
                    LoginProvider = LocalLoginProvider,
                    ProviderKey = user.UserName,
                });
            }

            return new ManageInfoViewModel
            {
                LocalLoginProvider = LocalLoginProvider,
                Email = user.UserName,
                Logins = logins,
                ExternalLoginProviders = GetExternalLogins(returnUrl, generateState)
            };
        }