PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/facebook.Linq/Web/FacebookConfiguration.cs

https://bitbucket.org/assaframan/facebooklinq
C# | 95 lines | 65 code | 12 blank | 18 comment | 13 complexity | 513ebecacbabd176893f8133ea3078d0 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. namespace facebook.Web
  7. {
  8. /// <summary>
  9. /// Configures the Facebook API
  10. /// </summary>
  11. class FacebookConfiguration
  12. {
  13. static FacebookConfiguration _Current;
  14. static object _Entrance = new object();
  15. public static FacebookConfiguration Current
  16. {
  17. get
  18. {
  19. if (_Current == null)
  20. {
  21. lock (_Entrance)
  22. {
  23. if (_Current == null)
  24. {
  25. _Current = new FacebookConfiguration();
  26. _Current.Load(ConfigurationManager.AppSettings);
  27. }
  28. }
  29. }
  30. return _Current;
  31. }
  32. }
  33. private void Load(System.Collections.Specialized.NameValueCollection settings)
  34. {
  35. APIKey = settings["facebook.Linq.APIKey"];
  36. Secret = settings["facebook.Linq.Secret"];
  37. ApplicationID = settings["facebook.Linq.ApplicationID"];
  38. UseTesterKey = settings["facebook.Linq.UseTesterKey"] == "true";
  39. DefaultPage = settings["facebook.Linq.DefaultPage"];
  40. Validate();
  41. }
  42. /// <summary>
  43. /// Facebook API Application Key (Length should be 32 chars)
  44. /// </summary>
  45. public string APIKey { get; set; }
  46. /// <summary>
  47. /// Facebook API Application Secret (Length should be 32 chars)
  48. /// </summary>
  49. public string Secret { get; set; }
  50. /// <summary>
  51. /// Facebook Application ID
  52. /// </summary>
  53. public string ApplicationID { get; set; }
  54. /// <summary>
  55. /// When set, the Facebook Application Tester application will be used. If you don't have a facebook application of your own, turn this on
  56. /// </summary>
  57. public bool UseTesterKey { get; set; }
  58. /// <summary>
  59. /// Default facebook entrance page that will be displayed when the user browses to the application
  60. /// </summary>
  61. public string DefaultPage { get; set; }
  62. #region IValidatableConfiguration Members
  63. public void Validate()
  64. {
  65. if (UseTesterKey)
  66. {
  67. APIKey = "56776198fcd674ec896ad3d76bdde346";
  68. Secret = "f5983f1fd433d6d64f8f3317e57cd528";
  69. ApplicationID = "39301909849";
  70. }
  71. else
  72. {
  73. if (APIKey.IsNullOrEmpty() || APIKey.Length != 32)
  74. throw new Exception("Bad or missing Facebook facebook.Linq.APIKey");
  75. if (Secret.IsNullOrEmpty() || Secret.Length != 32)
  76. throw new Exception("Bad or missing Facebook facebook.Linq.Secret");
  77. if (ApplicationID.IsNullOrEmpty())
  78. throw new Exception("Missing Facebook facebook.Linq.ApplicationID");
  79. }
  80. }
  81. #endregion
  82. }
  83. }