Exemplo n.º 1
0
 /// <summary>
 /// Set initial state information to this component, allow to accept dataDelivery before initialization begins.
 /// </summary>
 /// <param name="dataDelivery"></param>
 /// <returns></returns>
 public bool SetInitialState(PlatformSettings data)
 {
     lock (this)
     {
         return(OnSetInitialState(data));
     }
 }
Exemplo n.º 2
0
        protected override bool OnSetInitialState(PlatformSettings data)
        {
            if (base.OnSetInitialState(data) == false)
            {
                return(false);
            }

            _filesFolder = data.GetMappedFolder("FilesFolder");
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public static ADOPersistenceHelper CreatePersistenceHelper(PlatformSettings settings)
        {
            ADOPersistenceHelper helper = new ADOPersistenceHelper();

            if (helper.Initialize(settings.GetMappedFolder("PersistencePath")) == false)
            {
                return(null);
            }

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


            return(helper);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        protected void LoadModules(PlatformSettings platformSettings)
        {
            List <string> loadingModules = new List <string>();

            string[] optionalModules = platformSettings.GetString("OptionalModules").Replace("\r", string.Empty).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            loadingModules.AddRange(optionalModules);

            string[] externalModules = platformSettings.GetString("ExternalModules").Replace("\r", string.Empty).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            loadingModules.AddRange(externalModules);

            // Load the external optional references for the solution.
            // Loaded assemblies are attached as runtime references to the main application assembly.
            foreach (string referenceName in loadingModules)
            {
                string filePath = GeneralHelper.MapRelativeFilePathToExecutingDirectory(referenceName);
                string operationResultMessage = string.Empty;

                Assembly assembly = null;
                try
                {
                    // If you get a *warning* here (LoadFromContext) ignore it.
                    // Using LoadFrom is important, since it will also allow to find
                    // the newly loaded assemblies references, if they are in its folder.
                    assembly = Assembly.LoadFrom(filePath);

                    Type[] types = assembly.GetTypes();
                }
                catch (Exception ex)
                {
                    operationResultMessage = ex.Message;
                }

                if (assembly != null)
                {
                    ReflectionHelper.AddDynamicReferencedAssembly(Assembly.GetEntryAssembly(), assembly);
                }
                else
                {
                    SystemMonitor.OperationWarning("Failed to load external dynamic module [" + referenceName + ", " + filePath + "; " + operationResultMessage + "]", TracerItem.PriorityEnum.Low);
                }
            }

            //AppDomain.CurrentDomain.DynamicDirectory
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            //AppDomain.CurrentDomain.
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        public bool Initialize(PlatformSettings settings)
        {
            lock (this)
            {
                _persistenceHelper = Platform.CreatePersistenceHelper(settings);
                _persistenceHelper.SetupTypeMapping(typeof(DataStoreEntry), "DataStoreEntries", null);
                _dataStoreFilesFolder = settings.GetMappedFolder("DataStoreFolder");
            }

            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.GetMappedFolder("DataStoreFolder") + "]");
                    return(false);
                }
            }

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

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

            ChangeOperationalState(OperationalStateEnum.Operational);

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        public bool Initialize(PlatformSettings settings)
        {
            lock (this)
            {
                _persistenceHelper = Platform.CreatePersistenceHelper(settings);
                _persistenceHelper.SetupTypeMapping(typeof(DataStoreEntry), "DataStoreEntries", null);
                _dataStoreFilesFolder = settings.GetMappedFolder("DataStoreFolder");
            }

            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.GetMappedFolder("DataStoreFolder") + "]");
                    return false;
                }
            }

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

            ChangeOperationalState(OperationalStateEnum.Operational);

            return true;
        }
 /// <summary>
 /// This is called only one time in the lifetime of the source (just after creation, before very first init). 
 /// It allows it to read dataDelivery from settings, if it needs to.
 /// </summary>
 /// <param name="dataDelivery"></param>
 /// <returns></returns>
 protected override bool OnSetInitialState(PlatformSettings data)
 {
     return true;
 }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        protected void LoadModules(PlatformSettings platformSettings)
        {
            List<string> loadingModules = new List<string>();
            string[] optionalModules = platformSettings.GetString("OptionalModules").Replace("\r", string.Empty).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            loadingModules.AddRange(optionalModules);

            string[] externalModules = platformSettings.GetString("ExternalModules").Replace("\r", string.Empty).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            loadingModules.AddRange(externalModules);

            // Load the external optional references for the solution.
            // Loaded assemblies are attached as runtime references to the main application assembly.
            foreach (string referenceName in loadingModules)
            {
                string filePath = GeneralHelper.MapRelativeFilePathToExecutingDirectory(referenceName);
                string operationResultMessage = string.Empty;

                Assembly assembly = null;
                try
                {
                    // If you get a *warning* here (LoadFromContext) ignore it.
                    // Using LoadFrom is important, since it will also allow to find
                    // the newly loaded assemblies references, if they are in its folder.
                    assembly = Assembly.LoadFrom(filePath);

                    Type[] types = assembly.GetTypes();
                }
                catch (Exception ex)
                {
                    operationResultMessage = ex.Message;
                }

                if (assembly != null)
                {
                    ReflectionHelper.AddDynamicReferencedAssembly(Assembly.GetEntryAssembly(), assembly);
                }
                else
                {
                    SystemMonitor.OperationWarning("Failed to load external dynamic module [" + referenceName + ", " + filePath + "; " + operationResultMessage + "]", TracerItem.PriorityEnum.Low);
                }
            }

            //AppDomain.CurrentDomain.DynamicDirectory
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            //AppDomain.CurrentDomain.
        }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
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;
        }
 protected virtual bool OnSetInitialState(PlatformSettings data)
 {
     return true;
 }
 /// <summary>
 /// Set initial state information to this component, allow to accept dataDelivery before initialization begins.
 /// </summary>
 /// <param name="dataDelivery"></param>
 /// <returns></returns>
 public bool SetInitialState(PlatformSettings data)
 {
     lock (this)
     {
         return OnSetInitialState(data);
     }
 }
Exemplo n.º 15
0
 protected virtual bool OnSetInitialState(PlatformSettings data)
 {
     return(true);
 }
Exemplo n.º 16
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 = CreatePersistenceHelper(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);
        }
Exemplo n.º 17
0
 /// <summary>
 /// This is called only one time in the lifetime of the source (just after creation, before very first init).
 /// It allows it to read dataDelivery from settings, if it needs to.
 /// </summary>
 /// <param name="dataDelivery"></param>
 /// <returns></returns>
 protected override bool OnSetInitialState(PlatformSettings data)
 {
     return(true);
 }
        protected override bool OnSetInitialState(PlatformSettings data)
        {
            if (base.OnSetInitialState(data) == false)
            {
                return false;
            }

            _filesFolder = data.GetMappedFolder("FilesFolder");
            return true;
        }
Exemplo n.º 19
0
        /// <summary>
        /// 
        /// </summary>
        public static ADOPersistenceHelper CreatePersistenceHelper(PlatformSettings settings)
        {
            ADOPersistenceHelper helper = new ADOPersistenceHelper();
            if (helper.Initialize(settings.GetMappedFolder("PersistencePath")) == false)
            {
                return null;
            }

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

            return helper;
        }