예제 #1
0
        /// <summary>
        ///  Initialize the configuration settings from the configuration file
        /// </summary>
        /// <returns> if error return true else false </returns>
        public static bool InitializeConfiguration()
        {
            bool error = true;

            _automaticModeURL = string.Empty;
            LiveVideoControlConfiguration configurationObject = new LiveVideoControlConfiguration();

            try
            {
                string folder = HttpRuntime.AppDomainAppPath;
                _configurationFilePathAndName = System.IO.Path.Combine(folder, LiveVideoControlConfiguration.ConfigurationFileName);

                string message = "Reading the configuration file: " + _configurationFilePathAndName + Environment.NewLine;

                LogManager.WriteLog(
                    TraceType.INFO,
                    message,
                    "PIS.Ground.LiveVideoControl.LiveVideoControlConfiguration.InitializeConfiguration",
                    null,
                    EventIdEnum.LiveVideoControl);

                var serializer = new System.Xml.Serialization.XmlSerializer(typeof(LiveVideoControlConfiguration));

                using (var reader = new System.IO.StreamReader(_configurationFilePathAndName))
                {
                    configurationObject = (LiveVideoControlConfiguration)serializer.Deserialize(reader);
                }

                error = false;
            }
            catch (System.Exception ex)
            {
                LogManager.WriteLog(
                    TraceType.ERROR,
                    "Exception while storing the configuration to file: " +
                    LiveVideoControlConfiguration.ConfigurationFileName,
                    "PIS.Ground.LiveVideoControl.LiveVideoControlConfiguration.InitializeConfiguration",
                    ex,
                    EventIdEnum.LiveVideoControl);

                // In case of error, try to write a fresh configuration to the file.
                // If the file does not exists yet, it will be created.
                configurationObject.WriteToFile();
            }

            return(error);
        }
        /// <summary>
        /// Initializes the LiveVideoControl web service. This is only called once, when the service is
        /// instantiated.
        /// </summary>
        public static void Initialize()
        {
            if (!_initialized)
            {
                lock (_initializationLock)
                {
                    if (!_initialized)
                    {
                        try
                        {
                            _sessionManager = new SessionManager();

                            _notificationSender = new NotificationSender(_sessionManager);

                            _t2gManager = T2GManagerContainer.T2GManager;

                            LiveVideoControlConfiguration.InitializeConfiguration();

                            // Register a callback that will start streaming on new trains
                            _t2gManager.SubscribeToElementChangeNotification(
                                SubscriberId,
                                new EventHandler <ElementEventArgs>(OnElementInfoChanged));

                            _requestProcessor = new RequestProcessor();

                            _requestProcessor.SetT2GManager(_t2gManager, ConfigurationSettings.AppSettings["ApplicationId"]);
                            _requestProcessor.SetSessionMgr(_sessionManager);
                            _requestProcessor.SetNotificationSender(_notificationSender);

                            LoadConfiguration(new LiveVideoControlConfiguration());
                        }
                        catch (System.Exception e)
                        {
                            LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.Maintenance.MaintenanceService.Initialize", e, EventIdEnum.LiveVideoControl);
                        }

                        _initialized = true;
                    }
                }
            }
        }