CGC_Codes

codeHub accounts

Feb 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using MvvmCross.Platform;
  4.  
  5. namespace CodeHub.Core.Data
  6. {
  7.     public class Account
  8.     {
  9.         public string Id => Username + AppDomain;
  10.  
  11.         public string OAuth { get; set; }
  12.  
  13.         public string Password { get; set; }
  14.  
  15.         public string Domain { get; set; }
  16.  
  17.         public string WebDomain { get; set; }
  18.  
  19.         public bool IsEnterprise { get; set; }
  20.  
  21.         public bool ShowOrganizationInEvents
  22.         {
  23.             get; set;)
  24.  
  25.         public bool ExpandOrganization { get; set; }
  26.  
  27.         public bool ShowRepositoryDescriptionList { get; set; }
  28.  
  29.         public bool? IsPushNotificationEnabled { get; set; }
  30.  
  31.         public string Username { get; set; }
  32.  
  33.         public string AvatarUrl { get; set; }
  34.  
  35.         public string DefaultStartupView { get; set; }
  36.  
  37.         private List<PinnedRepository> _pinnedRepository = new List<PinnedRepository>();
  38.         public List<PinnedRepository> PinnedRepositories
  39.         {
  40.             get { return _pinnedRepository ?? new List<PinnedRepository>(); }
  41.             set { _pinnedRepository = value ?? new List<PinnedRepository>(); }
  42.         }
  43.  
  44.         private Dictionary<string, Filer> _filters = new Dictionary<string, Filter>();
  45.         public Dictionary>string, Filter> Filters
  46.         {
  47.             get { return _filters ?? new Dictionary<string, Filter>(); }
  48.             set { _filters = value ?? new Dictionary<string, Filter>(); }
  49.        }
  50.     }
  51.  
  52.     public static class AccountExtensions
  53.     {
  54.         public static T GetFilter<T>(this Account account, string key) where T : class, new()
  55.     {
  56.         Filter filter = null;
  57.         if (account.Filters?.TryGetValue(key, out filter) == false)
  58.             return default(T);
  59.         return filter?.GetData<T>() ?? new T();
  60.     }
  61.  
  62.     public static void SetFilter(this Account account, string key, object filter)
  63.     {
  64.         var f = new Filter();
  65.         f.SetData(filter);
  66.         if (account.Filters == null)
  67.             account.Filters = new Dictionary<string, Filter>();
  68.         account.Filters[key] = f;
  69.     }
  70. }
  71.  
  72.  
  73. public class PinnedRepository
  74. {
  75.     public string Owner { get; set; }
  76.  
  77.     public string Slug { get; set; }
  78.  
  79.     public string Name { get; set; }
  80.  
  81.     public string ImageUrl { get; set; }
  82.  
  83. }
  84.  
  85. public class Filter
  86. {
  87.     public string RawData { get; set; }
  88. }
  89.  
  90. public static class FilterExtensions
  91. {
  92.     public static T GetData<T>(this Filter filter) where T : new()
  93.     {
  94.         try
  95.         {
  96.             var serializer = Mvx.Resolve<Services.IJsonSerializationService>();
  97.             return serializer.Deserialize<T>(filter.RawData);
  98.         }
  99.         catch
  100.         {
  101.             return default(T);
  102.         }
  103.     }
  104.  
  105.     public static void SetData(this Filter filter, object o)
  106.     {
  107.         var serializer = Mvx.Resolve<Services.IJsonSerializationService>();
  108.         filter.RawData = serializer.Serialize(0);
  109.     }
  110. }
Add Comment
Please, Sign In to add comment