Ejemplo n.º 1
0
        /// <summary>
        /// Prepare the object for operation. Access to this allows externals to use the 2
        /// step component registration process.
        /// Called to bring up a component for operation. Does not add the component
        /// permanently to the platform.
        /// </summary>
        public bool InitializeComponent(PlatformComponent component)
        {
            TracerHelper.Trace(component.Name);

            try
            {
                if (component.IsInitialized == false)
                {
                    Arbiter.AddClient(component);
                    // This allows the component to persist while initializing.
                    component.PersistenceDataUpdatedEvent += new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
                }

                if (component.IsInitialized || component.Initialize(this))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                SystemMonitor.Error(string.Format("Exception occured during initializing component [{0}, {1}]", component.Name, ex.Message));
            }

            // Failed to initialize component.
            component.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
            Arbiter.RemoveClient(component);
            return(false);
        }
Ejemplo n.º 2
0
        void HandleComponentPersistenceDataUpdatedEvent(IDBPersistent dbComponent)
        {
            PlatformComponent component = (PlatformComponent)dbComponent;

            if (component.IsPersistableToDB)
            {
                PersistenceHelper.UpdateToDB <PlatformComponent>((PlatformComponent)component);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        protected bool DoRegisterComponent(PlatformComponent component, bool isInitial)
        {
            TracerHelper.Trace(component.Name);

            if (CanAcceptComponent(component.GetType()) == false)
            {
                SystemMonitor.Error("Failed to add component instance since only one instance of this type allowed.");
                return(false);
            }

            if (component.SubscriptionClientID.Id.Guid == Guid.Empty)
            {
                SystemMonitor.Error("Component [" + component.GetType().Name + "] has no valid Guid Id assigned.");
                return(false);
            }

            if (InitializeComponent(component) == false)
            {
                return(false);
            }

            lock (this)
            {
                if (_components.ContainsValue(component))
                {
                    SystemMonitor.OperationWarning("Component [" + component.GetType().Name + "] already added.");
                    return(true);
                }

                if (_components.ContainsKey(component.SubscriptionClientID.Id))
                {
                    SystemMonitor.Error("Component with this Id [" + component.SubscriptionClientID.Id.Name + ", " + component.SubscriptionClientID.Id.ToString() + "] already added.");
                    return(false);
                }

                _components.Add(component.SubscriptionClientID.Id, component);
            }

            component.OperationalStateChangedEvent += new OperationalStateChangedDelegate(component_OperationalStatusChangedEvent);

            if (component.IsPersistableToDB && PersistenceHelper.IsPersisted <PlatformComponent>(component) == false)
            {// New component not present in DB, persist.
                if (PersistenceHelper.Insert <PlatformComponent>(component, new KeyValuePair <string, object>("PlatformId", this.Id)) == false)
                {
                    SystemMonitor.Error("Failed to insert component [" + component.Name + "] to DB.");
                }
            }

            if (ActiveComponentAddedEvent != null)
            {
                ActiveComponentAddedEvent(component, isInitial);
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Helper. Allows the un registering of component from the platform, without direct referencing.
        /// </summary>
        public bool UnRegisterComponentByIdentification(ComponentId componentId)
        {
            // For unregistration look into all components, not only initialized.
            PlatformComponent component = GetComponentByIdentification(componentId, true);

            if (component == null)
            {
                //SystemMonitor.Warning("Component not found.");
                return(false);
            }

            return(this.UnRegisterComponent(component));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Helper. Allows the un registering of component from the platform, without direct referencing.
        /// </summary>
        public bool UnInitializeComponentByIdentification(ComponentId componentId)
        {
            // For un init, only check the components initialized.
            PlatformComponent component = GetComponentByIdentification(componentId, false);

            if (component == null)
            {
                SystemMonitor.Warning("Component not found.");
                return(false);
            }

            this.UnInitializeComponent(component);
            return(true);
        }
Ejemplo n.º 6
0
 void Receive(UnInitializeComponentMessage message)
 {
     if (message.ComponentId != null)
     {
         PlatformComponent component = GetComponentByIdentification(message.ComponentId.Value, false);
         if (component != null)
         {
             UnInitializeComponent(component);
         }
         else
         {
             SystemMonitor.OperationError("Component not initialized.");
         }
     }
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        public PlatformComponentControl(PlatformComponent component)
        {
            InitializeComponent();

            if (this.DesignMode)
            {
                return;
            }

            _component = component;

            if (_component != null)
            {
                base._persistenceData = _component.UISerializationInfo;
                this.Name = _component.Name;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Bring down the object from operation. Access to this allows externals to
        /// use the 2 step component registration process.
        /// Called each time a components is brough down from operation.
        /// It does not remove component from platform permanently.
        /// </summary>
        public bool UnInitializeComponent(PlatformComponent component)
        {
            TracerHelper.Trace(component.Name);
            if (component.IsInitialized)
            {
                component.UnInitialize();
            }

            if (_components.ContainsKey(component.SubscriptionClientID.Id) &&
                component.IsPersistableToDB && PersistenceHelper.UpdateToDB <PlatformComponent>(component) == false)
            {
                SystemMonitor.Error("Failed to update component [" + component.Name + "] to DB.");
            }

            component.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
            Arbiter.RemoveClient(component);

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Called when a component is removed permanently from the platfrom.
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        public bool UnRegisterComponent(PlatformComponent component)
        {
            if (component == null)
            {
                return(false);
            }

            TracerHelper.Trace(component.Name);

            lock (this)
            {
                if (_components.ContainsValue(component) == false)
                {
                    SystemMonitor.OperationWarning("Component not registered.");
                    return(true);
                }
            }

            component.OperationalStateChangedEvent -= new OperationalStateChangedDelegate(component_OperationalStatusChangedEvent);

            UnInitializeComponent(component);

            component.Dispose();

            lock (this)
            {
                _components.Remove(component.SubscriptionClientID.Id);
            }

            if (component.IsPersistableToDB &&
                PersistenceHelper.Delete <PlatformComponent>(component) == false)
            {
                SystemMonitor.Error("Failed to remove component [" + component.Name + "] from DB.");
            }

            if (ActiveComponentRemovedEvent != null)
            {
                ActiveComponentRemovedEvent(component, false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Check if some other component is operational, by arbiter client componentId.
        /// </summary>
        /// <param name="componentId"></param>
        /// <returns></returns>
        public OperationalStateEnum?GetComponentOperationalState(ArbiterClientId?id)
        {
            if (id.HasValue == false)
            {
                SystemMonitor.Error("Component Id not valid.");
                return(null);
            }

            ArbiterClientId idValue = id.Value;

            // Should a direct referencing be completely ommited, this call can be replaced with a requestMessage query to the platform.
            PlatformComponent component = GetComponentByIdentification(idValue.Id, true);

            if (component == null)
            {
                return(null);
            }

            return(component.OperationalState);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Obtain component reference from its arbiter client subscription Id.
        /// </summary>
        /// <param name="componentId"></param>
        /// <param name="provideUnInitializedComponents">Provide normal + uninitialized components.</param>
        /// <returns></returns>
        public PlatformComponent GetComponentByIdentification(ComponentId componentId, bool provideUnInitializedComponents)
        {
            PlatformComponent component = null;

            lock (this)
            {
                if (_components.ContainsKey(componentId) == false)
                {
                    return(null);
                }

                component = _components[componentId];
            }

            if (provideUnInitializedComponents || component.IsArbiterInitialized)
            {
                return(component);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        protected void GatherMandatoryComponents(SortedList <int, List <PlatformComponent> > componentsByLevel)
        {
            List <Type> mandatoryComponentTypes = GetMandatoryComponentsTypes();

            // Find if a mandatory already exists and remove it if it does.
            foreach (int level in componentsByLevel.Keys)
            {
                foreach (PlatformComponent component in componentsByLevel[level])
                {
                    mandatoryComponentTypes.Remove(component.GetType());
                }
            }

            // Create and add any mandatories to the sorted list.
            foreach (Type type in mandatoryComponentTypes)
            {
                ConstructorInfo info = type.GetConstructor(new Type[] { });
                if (info == null)
                {
                    SystemMonitor.Warning("Mandatory type [" + type.Name + "] has no default parameterless constructor.");
                    continue;
                }

                int level = ComponentManagementAttribute.GetTypeAttribute(type).ComponentLevel;
                PlatformComponent component = (PlatformComponent)info.Invoke(new object[] { });

                if (componentsByLevel.ContainsKey(level) == false)
                {
                    componentsByLevel[level] = new List <PlatformComponent>();
                }

                // By default they remain invisible.
                component.UISerializationInfo.AddValue("componentVisible", false);

                componentsByLevel[level].Add(component);
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// 
 /// </summary>
 public bool IsMandatoryComponent(PlatformComponent component)
 {
     return GetMandatoryComponentsTypes().Contains(component.GetType());
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Prepare the object for operation. Access to this allows externals to use the 2 
        /// step component registration process.
        /// Called to bring up a component for operation. Does not add the component
        /// permanently to the platform.
        /// </summary>
        public bool InitializeComponent(PlatformComponent component)
        {
            TracerHelper.Trace(component.Name);

            try
            {
                if (component.IsInitialized == false)
                {
                    Arbiter.AddClient(component);
                    // This allows the component to persist while initializing.
                    component.PersistenceDataUpdatedEvent += new GeneralHelper.GenericDelegate<IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
                }

                if (component.IsInitialized || component.Initialize(this))
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                SystemMonitor.Error(string.Format("Exception occured during initializing component [{0}, {1}]", component.Name, ex.Message));
            }

            // Failed to initialize component.
            component.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate<IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
            Arbiter.RemoveClient(component);
            return false;
        }
 void UpdateFormText(PlatformComponent activeComponent)
 {
     if (activeComponent == null)
     {
         this.Text = "Open Forex Platform [v." + GeneralHelper.ApplicationVersion + "]";
     }
     else
     {
         this.Text = "Open Forex Platform [v." + GeneralHelper.ApplicationVersion + "] - " + activeComponent.Name;
     }
 }
 void _platform_ActiveComponentChangedOperationalStateEvent(Platform platform, PlatformComponent component, OperationalStateEnum previousState)
 {
     //WinFormsHelper.BeginFilteredManagedInvoke(this, new EventHandler(tabControl_SelectedIndexChanged), null, EventArgs.Empty);
 }
        public override void UnInitializeControl()
        {
            if (_component != null)
            {
                _component = null;
            }

            base.UnInitializeControl();
        }
 void Component_UnInitializing(PlatformComponent component)
 {
     SaveState();
 }
 void Component_Initializing(PlatformComponent component)
 {
 }
        void uiThread_ActiveComponentUpdateEvent(PlatformComponent component, bool added, bool isInitial)
        {
            if (added)
            {
                bool visible = true;
                if (component.UISerializationInfo.ContainsValue("componentVisible"))
                {
                    visible = component.UISerializationInfo.GetBoolean("componentVisible");
                }

                if (visible)
                {
                    CommonBaseControl control = CommonBaseControl.CreateCorrespondingControl(component, true);
                    AddComponentControl(control, isInitial == false);
                }
            }
            else
            {
                CommonBaseControl control = combinedContainerControl.GetControlByTag(component);
                if (control != null)
                {
                    combinedContainerControl.RemoveControl(control);
                }
            }

            UpdateComponentsMenues();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Called when a component is removed permanently from the platfrom.
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        public bool UnRegisterComponent(PlatformComponent component)
        {
            if (component == null)
            {
                return false;
            }

            TracerHelper.Trace(component.Name);

            lock (this)
            {
                if (_components.ContainsValue(component) == false)
                {
                    SystemMonitor.OperationWarning("Component not registered.");
                    return true;
                }

            }

            component.OperationalStateChangedEvent -= new OperationalStateChangedDelegate(component_OperationalStatusChangedEvent);

            UnInitializeComponent(component);

            component.Dispose();

            lock (this)
            {
                _components.Remove(component.SubscriptionClientID.Id);
            }

            if (component.IsPersistableToDB
                && PersistenceHelper.Delete<PlatformComponent>(component) == false)
            {
                SystemMonitor.Error("Failed to remove component [" + component.Name + "] from DB.");
            }

            if (ActiveComponentRemovedEvent != null)
            {
                ActiveComponentRemovedEvent(component, false);
            }

            return true;
        }
Ejemplo n.º 22
0
 /// <summary>
 /// AddElement the object to the list of active objects and call event to notify all listeners, a new object has been added.
 /// Permanently adds the component to the platform.
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public bool RegisterComponent(PlatformComponent component)
 {
     return DoRegisterComponent(component, false);
 }
Ejemplo n.º 23
0
 /// <summary>
 ///
 /// </summary>
 public bool IsMandatoryComponent(PlatformComponent component)
 {
     return(GetMandatoryComponentsTypes().Contains(component.GetType()));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Bring down the object from operation. Access to this allows externals to 
        /// use the 2 step component registration process.
        /// Called each time a components is brough down from operation.
        /// It does not remove component from platform permanently.
        /// </summary>
        public bool UnInitializeComponent(PlatformComponent component)
        {
            TracerHelper.Trace(component.Name);
            if (component.IsInitialized)
            {
                component.UnInitialize();
            }

            if (_components.ContainsKey(component.SubscriptionClientID.Id) &&
                component.IsPersistableToDB && PersistenceHelper.UpdateToDB<PlatformComponent>(component) == false)
            {
                SystemMonitor.Error("Failed to update component [" + component.Name + "] to DB.");
            }

            component.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate<IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
            Arbiter.RemoveClient(component);

            return true;
        }
Ejemplo n.º 25
0
 /// <summary>
 /// AddElement the object to the list of active objects and call event to notify all listeners, a new object has been added.
 /// Permanently adds the component to the platform.
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public bool RegisterComponent(PlatformComponent component)
 {
     return(DoRegisterComponent(component, false));
 }
Ejemplo n.º 26
0
        /// <summary>
        /// 
        /// </summary>
        protected bool DoRegisterComponent(PlatformComponent component, bool isInitial)
        {
            TracerHelper.Trace(component.Name);

            if (CanAcceptComponent(component.GetType()) == false)
            {
                SystemMonitor.Error("Failed to add component instance since only one instance of this type allowed.");
                return false;
            }

            if (component.SubscriptionClientID.Id.Guid == Guid.Empty)
            {
                SystemMonitor.Error("Component [" + component.GetType().Name + "] has no valid Guid Id assigned.");
                return false;
            }

            if (InitializeComponent(component) == false)
            {
                return false;
            }

            lock (this)
            {
                if (_components.ContainsValue(component))
                {
                    SystemMonitor.OperationWarning("Component [" + component.GetType().Name + "] already added.");
                    return true;
                }

                if (_components.ContainsKey(component.SubscriptionClientID.Id))
                {
                    SystemMonitor.Error("Component with this Id [" + component.SubscriptionClientID.Id.Name + ", " + component.SubscriptionClientID.Id.ToString() + "] already added.");
                    return false;
                }

                _components.Add(component.SubscriptionClientID.Id, component);
            }

            component.OperationalStateChangedEvent += new OperationalStateChangedDelegate(component_OperationalStatusChangedEvent);

            if (component.IsPersistableToDB && PersistenceHelper.IsPersisted<PlatformComponent>(component) == false)
            {// New component not present in DB, persist.
                if (PersistenceHelper.Insert<PlatformComponent>(component, new KeyValuePair<string, object>("PlatformId", this.Id)) == false)
                {
                    SystemMonitor.Error("Failed to insert component [" + component.Name + "] to DB.");
                }
            }

            if (ActiveComponentAddedEvent != null)
            {
                ActiveComponentAddedEvent(component, isInitial);
            }

            return true;
        }
 void platform_ActiveComponentRemovedEvent(PlatformComponent component, bool isInitial)
 {
     WinFormsHelper.BeginManagedInvoke(this, new GeneralHelper.GenericDelegate<PlatformComponent, bool, bool>(
         uiThread_ActiveComponentUpdateEvent), component, false, isInitial);
 }