/// <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); }