Beispiel #1
0
        public static SyncRelationship Load(Guid relationshipId)
        {
            string relationshipDir           = Path.Combine(Global.AppDataRoot, relationshipId.ToString("N"));
            RelationshipConfiguration config = RelationshipConfiguration.Load(relationshipDir);

            Logger.RelationshipLoaded(
                config.RelationshipId,
                new Dictionary <string, object>()
            {
                { "Name", config.Name },
                { "RelationshipId", config.RelationshipId },
                { "InitiallyCreatedUtc", config.InitiallyCreatedUtc },
                { "Scope", config.Scope }
            });

            SyncRelationship relationship = new SyncRelationship(config);

            // Get the adapters from the configuration for this relationship
            foreach (AdapterConfiguration adapterConfig in config.Adapters)
            {
                // Get the adapter registration information for this type of adapter
                AdapterRegistration registration =
                    AdapterRegistry.GetRegistrationByTypeId(adapterConfig.AdapterTypeId);

                if (registration == null)
                {
                    throw new Exception("No adapter registration found with TypeId " + adapterConfig.AdapterTypeId);
                }

                // Create the adapter object based on its config from the database
                AdapterBase adapter = (AdapterBase)Activator.CreateInstance(
                    registration.AdapterType,
                    relationship,
                    adapterConfig);

                relationship.Adapters.Add(adapter);

                // Load adapter-specific configuration settings
                adapter.LoadConfiguration();
            }

            return(relationship);
        }