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

/sipsorcery-core/SIPSorcery.AppServer.DialPlan/DialPlanFacades/DialPlanLookupFacade.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 169 lines | 111 code | 22 blank | 36 comment | 10 complexity | 7556864c553c08d5bd0f6f9a5cd0bf61 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. // ============================================================================
  2. // FileName: DialPlanLookupFacade.cs
  3. //
  4. // Description:
  5. // Facade class to allow dial plan scripts to retrieve data from user populated lookup
  6. // tables. Typically used in dial plan wizard scenarios.
  7. //
  8. // Author(s):
  9. // Aaron Clauson
  10. //
  11. // History:
  12. // 04 Feb 2011 Aaron Clauson Created.
  13. //
  14. // License:
  15. // This software is licensed under the BSD License http://www.opensource.org/licenses/bsd-license.php
  16. //
  17. // Copyright (c) 2011 Aaron Clauson (aaron@sipsorcery.com), SIP Sorcery Pty Ltd
  18. // All rights reserved.
  19. //
  20. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that
  21. // the following conditions are met:
  22. //
  23. // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  24. // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  25. // disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of SIP Sorcery Ltd.
  26. // nor the names of its contributors may be used to endorse or promote products derived from this software without specific
  27. // prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  30. // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  31. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  32. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  33. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. // POSSIBILITY OF SUCH DAMAGE.
  36. // ============================================================================
  37. using System;
  38. using System.Collections.Generic;
  39. using System.Linq;
  40. using System.Text;
  41. using SIPSorcery.SIP;
  42. using SIPSorcery.SIP.App;
  43. using SIPSorcery.SIP.App.Entities;
  44. using SIPSorcery.Sys;
  45. using log4net;
  46. namespace SIPSorcery.AppServer.DialPlan
  47. {
  48. public class DialPlanLookupFacade
  49. {
  50. private static ILog logger = AppState.logger;
  51. private SIPMonitorLogDelegate LogToMonitor;
  52. private string m_owner;
  53. public DialPlanLookupFacade(SIPMonitorLogDelegate logDelegate, string owner)
  54. {
  55. LogToMonitor = logDelegate;
  56. m_owner = owner;
  57. }
  58. public DialPlanSettings GetSettings()
  59. {
  60. List<SIPDialplanLookup> lookups = GetLookups();
  61. List<SIPDialplanRoute> routes = GetRoutes();
  62. Dictionary<string, SIPDialplanProvider> providers = GetProviders();
  63. SIPDialplanOption options = GetOptions();
  64. return new DialPlanSettings(lookups, routes, providers, options);
  65. }
  66. public List<SIPDialplanLookup> GetLookups()
  67. {
  68. try
  69. {
  70. var dialplanLookupEntities = new SIPSorceryAppEntities();
  71. return (from lookup in dialplanLookupEntities.SIPDialplanLookups
  72. where lookup.owner == m_owner
  73. select lookup).ToList();
  74. }
  75. catch (Exception excp)
  76. {
  77. logger.Error("Exception GetLookups. " + excp.Message);
  78. return null;
  79. }
  80. }
  81. public List<SIPDialplanRoute> GetRoutes()
  82. {
  83. try
  84. {
  85. var appEntities = new SIPSorceryAppEntities();
  86. var routes = (from route in appEntities.SIPDialplanRoutes
  87. where route.owner == m_owner
  88. select route).ToList();
  89. if (routes != null && routes.Count > 0)
  90. {
  91. List<SIPDialplanRoute> routesList = new List<SIPDialplanRoute>();
  92. foreach (SIPDialplanRoute route in routes)
  93. {
  94. routesList.Add(route);
  95. }
  96. return routesList;
  97. }
  98. return null;
  99. }
  100. catch (Exception excp)
  101. {
  102. logger.Error("Exception GetRoutes. " + excp.Message);
  103. return null;
  104. }
  105. }
  106. public Dictionary<string, SIPDialplanProvider> GetProviders()
  107. {
  108. try
  109. {
  110. var appEntities = new SIPSorceryAppEntities();
  111. var providers = (from provider in appEntities.SIPDialplanProviders
  112. where provider.owner == m_owner
  113. select provider).ToList();
  114. if (providers != null && providers.Count > 0)
  115. {
  116. Dictionary<string, SIPDialplanProvider> providersList = new Dictionary<string, SIPDialplanProvider>();
  117. foreach (SIPDialplanProvider provider in providers)
  118. {
  119. providersList.Add(provider.providername, provider);
  120. }
  121. return providersList;
  122. }
  123. return null;
  124. }
  125. catch (Exception excp)
  126. {
  127. logger.Error("Exception GetProviders. " + excp.Message);
  128. return null;
  129. }
  130. }
  131. public SIPDialplanOption GetOptions()
  132. {
  133. try
  134. {
  135. var appEntities = new SIPSorceryAppEntities();
  136. return (from option in appEntities.SIPDialplanOptions
  137. where option.owner == m_owner
  138. select option).FirstOrDefault();
  139. }
  140. catch (Exception excp)
  141. {
  142. logger.Error("Exception GetOptions. " + excp.Message);
  143. return null;
  144. }
  145. }
  146. }
  147. }