Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public void Initialize(Platform platform)
        {
            SystemMonitor.CheckWarning(NewsSourcesUnsafe.Count == 0, "Manager already has assigned sources.");

            _platform = platform;

            _persistenceHelper = CreatePersistenceHelper(platform.Settings);
            if (_persistenceHelper == null)
            {
                SystemMonitor.Error("Failed to initialize the persistence helper for Platform News Manager.");
                return;
            }

            // Make sure this load is before the accept events, so that they do not cause adding failure.
            List <EventSource> sources = _persistenceHelper.SelectDynamicType <EventSource>(null, null);

            base.SourceAddedEvent   += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceAddedEvent);
            base.SourceRemovedEvent += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceRemovedEvent);

            if (sources != null)
            {
                foreach (EventSource source in sources)
                {                // Add the source to subscribe to it, than load items.
                    base.AddSource(source);

                    if (source.Enabled)
                    {
                        LoadSourceItemsFromPersistence(source);
                    }
                }
            }

            if (platform != null)
            {// Load the default sources.
                foreach (string feedAddress in platform.Settings.DefaultRSSFeeds)
                {
                    if (GetSourceByAddress(feedAddress) == null)
                    {
                        RssNewsSource newSource = new RssNewsSource();
                        newSource.Initialize(feedAddress);

                        AddSource(newSource);
                    }
                }
            }


            GeneralHelper.FireAndForget(UpdateFeeds);
        }
        /// <summary>
        /// 
        /// </summary>
        public void Initialize(Platform platform)
        {
            SystemMonitor.CheckWarning(NewsSourcesUnsafe.Count == 0, "Manager already has assigned sources.");

            _platform = platform;

            _persistenceHelper = CreatePersistenceHelper(platform.Settings);
            if (_persistenceHelper == null)
            {
                SystemMonitor.Error("Failed to initialize the persistence helper for Platform News Manager.");
                return;
            }

            // Make sure this load is before the accept events, so that they do not cause adding failure.
            List<EventSource> sources = _persistenceHelper.SelectDynamicType<EventSource>(null, null);

            base.SourceAddedEvent += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceAddedEvent);
            base.SourceRemovedEvent += new NewsSourceUpdateDelegate(PlatformNewsManager_SourceRemovedEvent);

            if (sources != null)
            {
                foreach (EventSource source in sources)
                {// Add the source to subscribe to it, than load items.
                    base.AddSource(source);

                    if (source.Enabled)
                    {
                        LoadSourceItemsFromPersistence(source);
                    }
                }
            }

            if (platform != null)
            {// Load the default sources.
                foreach (string feedAddress in platform.Settings.DefaultRSSFeeds)
                {
                    if (GetSourceByAddress(feedAddress) == null)
                    {
                        RssNewsSource newSource = new RssNewsSource();
                        newSource.Initialize(feedAddress);

                        AddSource(newSource);
                    }
                }
            }

            GeneralHelper.FireAndForget(UpdateFeeds);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        protected static SQLiteADOPersistenceHelper CreatePersistenceHelper(PlatformSettings settings)
        {
            SQLiteADOPersistenceHelper helper = new SQLiteADOPersistenceHelper();

            if (helper.Initialize(settings.GetMappedPath("DataStoreDBPath"), true) == false)
            {
                return(null);
            }

            if (helper.ContainsTable("DataStoreEntries") == false)
            {// Create the table structure.
                helper.ExecuteCommand(ForexPlatformPersistence.Properties.Settings.Default.DataStoreDBSchema);
            }

            helper.SetupTypeMapping(typeof(DataStoreEntry), "DataStoreEntries");

            return(helper);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Helper, creates the correspoding persistence helper.
        /// </summary>
        protected static SQLiteADOPersistenceHelper CreatePersistenceHelper(PlatformSettings settings)
        {
            SQLiteADOPersistenceHelper helper = new SQLiteADOPersistenceHelper();

            if (helper.Initialize(settings.GetMappedPath("EventsDBPath"), true) == false)
            {
                return(null);
            }

            if (helper.ContainsTable("Events") == false)
            {// Create the table structure.
                object result = helper.ExecuteCommand(ForexPlatformPersistence.Properties.Settings.Default.EventsDBSchema);
            }

            helper.SetupTypeMapping(typeof(EventSource), "EventSources");
            helper.SetupTypeMapping(typeof(EventBase), "Events");

            return(helper);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Helper, creates the persistence helper for the platform.
        /// </summary>
        protected static SQLiteADOPersistenceHelper CreatePlatformPersistenceHelper(PlatformSettings settings)
        {
            SQLiteADOPersistenceHelper helper = new SQLiteADOPersistenceHelper();
            if (helper.Initialize(settings.GetMappedPath("PlatformDBPath"), true) == false)
            {
                return null;
            }

            if (helper.ContainsTable("Platforms") == false)
            {// Create the table structure.
                helper.ExecuteCommand(ForexPlatformPersistence.Properties.Settings.Default.PlatformDBSchema);
            }

            helper.SetupTypeMapping(typeof(Platform), "Platforms");
            helper.SetupTypeMapping(typeof(PlatformComponent), "PlatformComponents");

            return helper;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The initialization of a platform consumes 2 main dataDelivery sources.
        /// The settings is used for primary, startup information (like where 
        /// is the persistence DB file etc.) and the information inside the 
        /// persistence is than on used to create components etc.
        /// </summary>
        public bool Initialize(PlatformSettings platformSettings)
        {
            TracerHelper.TraceEntry();

            SystemMonitor.CheckThrow(_settings == null, "Platform already initialized.");

            lock (this)
            {
                _settings = platformSettings;
                if (_persistenceHelper == null)
                {
                    _persistenceHelper = CreatePlatformPersistenceHelper(platformSettings);
                }
            }

            if (_persistenceHelper == null)
            {
                return false;
            }

            LoadModules(_settings);

            if (PersistenceHelper.Count<Platform>(new MatchExpression("Name", this.Name)) == 0)
            {// This is a new platform.
                lock (this)
                {
                    _guid = Guid.NewGuid();
                }

                if (PersistenceHelper.Insert<Platform>(this, null) == false)
                {
                    SystemMonitor.Error("Failed to persist new platform [" + this.Name + "]");
                    return false;
                }
            }
            else
            {// This is existing.
                // Now try to load self from persistance storage.
                bool selectionResult = PersistenceHelper.SelectScalar<Platform>(this, new MatchExpression("Name", this.Name));

                if (selectionResult == false)
                {// Failed to load self from DB.
                    return false;
                }
            }

            lock (this)
            {
                if (_serializationData.ContainsValue("diagnosticsMode"))
                {
                    _settings.DiagnosticsMode = _serializationData.GetBoolean("diagnosticsMode");
                }

                if (_serializationData.ContainsValue("uiSerializationInfo"))
                {
                    // The main serialization dataDelivery stores the UI orderInfo.
                    _uiSerializationInfo = _serializationData.GetValue<SerializationInfoEx>("uiSerializationInfo");
                }

                if (_serializationData.ContainsValue("componentSpecificSerializationInfo"))
                {
                    // The main serialization dataDelivery stores the UI orderInfo.
                    _componentSpecificSerializationInfo = _serializationData.GetValue<SerializationInfoEx>("componentSpecificSerializationInfo");
                }
            }

            //_server = new Arbiter.TransportIntegrationServer(_platformUri);
            //Arbiter.AddClient(_server);

            GeneralHelper.FireAndForget(delegate()
            {// LoadFromFile components.
                // Registering of components is better done outside the lock,
                // since components may launch requests to platform at initializations.

                _isLoading = true;

                // Components are stored in the PlatformComponents database, they are being serialized and the entire object is
                // persisted in the DB, as well as the type information for it and a reference to the platform instance it belongs to.
                List<long> failedSerializationsIds = new List<long>();
                List<PlatformComponent> components = PersistenceHelper.SelectSerializedType<PlatformComponent>(
                    new MatchExpression("PlatformId", this.Id), "Data", null, failedSerializationsIds);

                SortedList<int, List<PlatformComponent>> componentsByLevel = GetComponentsByLevel(components);

                GatherMandatoryComponents(componentsByLevel);

                foreach (int level in componentsByLevel.Keys)
                {// Register lower level components first.
                    foreach (PlatformComponent component in componentsByLevel[level])
                    {
                        if (DoRegisterComponent(component, true) == false
                            && component.Id.HasValue && ComponentDeserializationFailedEvent != null)
                        {
                            ComponentDeserializationFailedEvent(component.Id.Value, component.GetType().Name);
                        }
                    }
                }

                // Handle failed deserializations.
                foreach (int id in failedSerializationsIds)
                {
                    string typeName = "Unknown";

                    try
                    {// Extract the type of this entry.
                        List<object[]> result = PersistenceHelper.SelectColumns<PlatformComponent>(
                            new MatchExpression("Id", id), new string[] { "Type" }, 1 );

                        Type type = Type.GetType(result[0][0].ToString());

                        if (type != null)
                        {
                            typeName = type.Name;
                        }
                    }
                    catch(Exception ex)
                    {
                        SystemMonitor.Error("Failed to extract type information [" + ex.Message + "].");
                    }

                    if (ComponentDeserializationFailedEvent != null)
                    {
                        ComponentDeserializationFailedEvent(id, typeName);
                    }
                }

                _isLoading = false;
            });

            return true;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The initialization of a platform consumes 2 main dataDelivery sources.
        /// The settings is used for primary, startup information (like where
        /// is the persistence DB file etc.) and the information inside the
        /// persistence is than on used to create components etc.
        /// </summary>
        public bool Initialize(PlatformSettings platformSettings)
        {
            TracerHelper.TraceEntry();

            SystemMonitor.CheckThrow(_settings == null, "Platform already initialized.");

            lock (this)
            {
                _settings = platformSettings;
                if (_persistenceHelper == null)
                {
                    _persistenceHelper = CreatePlatformPersistenceHelper(platformSettings);
                }
            }

            if (_persistenceHelper == null)
            {
                return(false);
            }

            LoadModules(_settings);

            if (PersistenceHelper.Count <Platform>(new MatchExpression("Name", this.Name)) == 0)
            {// This is a new platform.
                lock (this)
                {
                    _guid = Guid.NewGuid();
                }

                if (PersistenceHelper.Insert <Platform>(this, null) == false)
                {
                    SystemMonitor.Error("Failed to persist new platform [" + this.Name + "]");
                    return(false);
                }
            }
            else
            {// This is existing.
                // Now try to load self from persistance storage.
                bool selectionResult = PersistenceHelper.SelectScalar <Platform>(this, new MatchExpression("Name", this.Name));

                if (selectionResult == false)
                {// Failed to load self from DB.
                    return(false);
                }
            }

            lock (this)
            {
                if (_serializationData.ContainsValue("diagnosticsMode"))
                {
                    _settings.DiagnosticsMode = _serializationData.GetBoolean("diagnosticsMode");
                }

                if (_serializationData.ContainsValue("uiSerializationInfo"))
                {
                    // The main serialization dataDelivery stores the UI orderInfo.
                    _uiSerializationInfo = _serializationData.GetValue <SerializationInfoEx>("uiSerializationInfo");
                }

                if (_serializationData.ContainsValue("componentSpecificSerializationInfo"))
                {
                    // The main serialization dataDelivery stores the UI orderInfo.
                    _componentSpecificSerializationInfo = _serializationData.GetValue <SerializationInfoEx>("componentSpecificSerializationInfo");
                }
            }

            //_server = new Arbiter.TransportIntegrationServer(_platformUri);
            //Arbiter.AddClient(_server);

            GeneralHelper.FireAndForget(delegate()
            {// LoadFromFile components.
             // Registering of components is better done outside the lock,
             // since components may launch requests to platform at initializations.

                _isLoading = true;

                // Components are stored in the PlatformComponents database, they are being serialized and the entire object is
                // persisted in the DB, as well as the type information for it and a reference to the platform instance it belongs to.
                List <long> failedSerializationsIds = new List <long>();
                List <PlatformComponent> components = PersistenceHelper.SelectSerializedType <PlatformComponent>(
                    new MatchExpression("PlatformId", this.Id), "Data", null, failedSerializationsIds);

                SortedList <int, List <PlatformComponent> > componentsByLevel = GetComponentsByLevel(components);

                GatherMandatoryComponents(componentsByLevel);

                foreach (int level in componentsByLevel.Keys)
                {// Register lower level components first.
                    foreach (PlatformComponent component in componentsByLevel[level])
                    {
                        if (DoRegisterComponent(component, true) == false &&
                            component.Id.HasValue && ComponentDeserializationFailedEvent != null)
                        {
                            ComponentDeserializationFailedEvent(component.Id.Value, component.GetType().Name);
                        }
                    }
                }

                // Handle failed deserializations.
                foreach (int id in failedSerializationsIds)
                {
                    string typeName = "Unknown";

                    try
                    {// Extract the type of this entry.
                        List <object[]> result = PersistenceHelper.SelectColumns <PlatformComponent>(
                            new MatchExpression("Id", id), new string[] { "Type" }, 1);

                        Type type = Type.GetType(result[0][0].ToString());

                        if (type != null)
                        {
                            typeName = type.Name;
                        }
                    }
                    catch (Exception ex)
                    {
                        SystemMonitor.Error("Failed to extract type information [" + ex.Message + "].");
                    }

                    if (ComponentDeserializationFailedEvent != null)
                    {
                        ComponentDeserializationFailedEvent(id, typeName);
                    }
                }

                _isLoading = false;
            });

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        public bool Initialize(PlatformSettings settings)
        {
            lock (this)
            {
                _persistenceHelper = CreatePersistenceHelper(settings);

                _dataStoreFilesFolder = settings.GetMappedPath("DataStoreFolder");
            }

            // Loading online data sources, currently not operating.
            //GeneralHelper.FireAndForget(
            //    delegate()
            //    {
            //        try
            //        {// Download online dataDelivery source entries.
            //            WebRequest request = WebRequest.Create(settings.DataStoreOnlineSourcesXml);
            //            request.Timeout = (int)TimeSpan.FromSeconds(15).TotalMilliseconds;

            //            TextReader reader = new StreamReader(request.GetResponse().GetResponseStream());

            //            // If you get an error here in DEBUG MODE, just ignore it, it is a bug in VS 2008.
            //            XmlSerializer serializer = new XmlSerializer(typeof(OnlineEntrySource[]));

            //            OnlineEntrySource[] sources = (OnlineEntrySource[])serializer.Deserialize(reader);

            //            lock (_onlineEntrySources)
            //            {// _onlineEntrySources contains serialized existing sources.
            //                _onlineEntrySources.AddRange(sources);
            //                sources = _onlineEntrySources.ToArray();
            //            }

            //            foreach (OnlineEntrySource source in sources)
            //            {
            //                if (OnlineEntrySourceAddedEvent != null)
            //                {
            //                    OnlineEntrySourceAddedEvent(this, source);
            //                }
            //            }

            //        }
            //        catch (Exception ex)
            //        {
            //            SystemMonitor.OperationError("Failed to obtain online data souces [" + ex.Message + "].", TracerItem.PriorityEnum.Low);
            //        }
            //    }
            //);

            if (Directory.Exists(_dataStoreFilesFolder) == false)
            {
                if (Directory.CreateDirectory(_dataStoreFilesFolder) == null)
                {
                    SystemMonitor.OperationError("Failed to create Data Store folder [" + settings.GetMappedPath("DataStoreFolder") + "]");
                    return false;
                }
            }

            List<DataStoreEntry> entries = _persistenceHelper.Select<DataStoreEntry>(null, null);
            foreach (DataStoreEntry entry in entries)
            {
                DoAddEntry(entry);
            }

            ChangeOperationalState(OperationalStateEnum.Operational);

            return true;
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        public bool Initialize(PlatformSettings settings)
        {
            lock (this)
            {
                _persistenceHelper = CreatePersistenceHelper(settings);

                _dataStoreFilesFolder = settings.GetMappedPath("DataStoreFolder");
            }

            // Loading online data sources, currently not operating.
            //GeneralHelper.FireAndForget(
            //    delegate()
            //    {
            //        try
            //        {// Download online dataDelivery source entries.
            //            WebRequest request = WebRequest.Create(settings.DataStoreOnlineSourcesXml);
            //            request.Timeout = (int)TimeSpan.FromSeconds(15).TotalMilliseconds;

            //            TextReader reader = new StreamReader(request.GetResponse().GetResponseStream());

            //            // If you get an error here in DEBUG MODE, just ignore it, it is a bug in VS 2008.
            //            XmlSerializer serializer = new XmlSerializer(typeof(OnlineEntrySource[]));

            //            OnlineEntrySource[] sources = (OnlineEntrySource[])serializer.Deserialize(reader);

            //            lock (_onlineEntrySources)
            //            {// _onlineEntrySources contains serialized existing sources.
            //                _onlineEntrySources.AddRange(sources);
            //                sources = _onlineEntrySources.ToArray();
            //            }

            //            foreach (OnlineEntrySource source in sources)
            //            {
            //                if (OnlineEntrySourceAddedEvent != null)
            //                {
            //                    OnlineEntrySourceAddedEvent(this, source);
            //                }
            //            }

            //        }
            //        catch (Exception ex)
            //        {
            //            SystemMonitor.OperationError("Failed to obtain online data souces [" + ex.Message + "].", TracerItem.PriorityEnum.Low);
            //        }
            //    }
            //);

            if (Directory.Exists(_dataStoreFilesFolder) == false)
            {
                if (Directory.CreateDirectory(_dataStoreFilesFolder) == null)
                {
                    SystemMonitor.OperationError("Failed to create Data Store folder [" + settings.GetMappedPath("DataStoreFolder") + "]");
                    return(false);
                }
            }

            List <DataStoreEntry> entries = _persistenceHelper.Select <DataStoreEntry>(null, null);

            foreach (DataStoreEntry entry in entries)
            {
                DoAddEntry(entry);
            }

            ChangeOperationalState(OperationalStateEnum.Operational);

            return(true);
        }