ContentManagementModule.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #region Header
  28. // ContentManagementModule.cs
  29. // User: bongiojp
  30. #endregion Header
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Threading;
  34. using OpenMetaverse;
  35. using Nini.Config;
  36. using OpenSim;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.Environment.Interfaces;
  39. using OpenSim.Region.Environment.Scenes;
  40. using OpenSim.Region.Physics.Manager;
  41. using log4net;
  42. namespace OpenSim.Region.Environment.Modules.ContentManagement
  43. {
  44. public class ContentManagementModule : IRegionModule
  45. {
  46. #region Static Fields
  47. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  48. #endregion Static Fields
  49. #region Fields
  50. bool initialised = false;
  51. CMController m_control = null;
  52. bool m_enabled = false;
  53. CMModel m_model = null;
  54. bool m_posted = false;
  55. CMView m_view = null;
  56. #endregion Fields
  57. #region Public Properties
  58. public bool IsSharedModule
  59. {
  60. get { return true; }
  61. }
  62. public string Name
  63. {
  64. get { return "ContentManagementModule"; }
  65. }
  66. #endregion Public Properties
  67. #region Public Methods
  68. public void Close()
  69. {
  70. }
  71. public void Initialise(Scene scene, IConfigSource source)
  72. {
  73. string databaseDir = "./";
  74. string database = "FileSystemDatabase";
  75. int channel = 345;
  76. try
  77. {
  78. if (source.Configs["CMS"] == null)
  79. return;
  80. m_enabled = source.Configs["CMS"].GetBoolean("enabled", false);
  81. databaseDir = source.Configs["CMS"].GetString("directory", databaseDir);
  82. database = source.Configs["CMS"].GetString("database", database);
  83. channel = source.Configs["CMS"].GetInt("channel", channel);
  84. if (database != "FileSystemDatabase" && database != "GitDatabase")
  85. {
  86. m_log.ErrorFormat("[Content Management]: The Database attribute must be defined as either FileSystemDatabase or GitDatabase");
  87. m_enabled = false;
  88. }
  89. }
  90. catch (Exception e)
  91. {
  92. m_log.ErrorFormat("[Content Management]: Exception thrown while reading parameters from configuration file. Message: " + e);
  93. m_enabled = false;
  94. }
  95. if (!m_enabled)
  96. {
  97. m_log.Info("[Content Management]: Content Management System is not Enabled.");
  98. return;
  99. }
  100. lock (this)
  101. {
  102. if (!initialised) //only init once
  103. {
  104. m_view = new CMView();
  105. m_model = new CMModel();
  106. m_control = new CMController(m_model, m_view, scene, channel);
  107. m_model.Initialise(database);
  108. m_view.Initialise(m_model);
  109. initialised = true;
  110. m_model.InitialiseDatabase(scene, databaseDir);
  111. }
  112. else
  113. {
  114. m_model.InitialiseDatabase(scene, databaseDir);
  115. m_control.RegisterNewRegion(scene);
  116. }
  117. }
  118. }
  119. public void PostInitialise()
  120. {
  121. if (! m_enabled)
  122. return;
  123. lock (this)
  124. {
  125. if (!m_posted) //only post once
  126. {
  127. m_model.PostInitialise();
  128. m_posted = true;
  129. }
  130. }
  131. }
  132. #endregion Public Methods
  133. }
  134. }