Exemplo n.º 1
0
        /// <summary>
        /// Create a new sync relationship
        /// </summary>
        private SyncRelationship(RelationshipConfiguration configuration)
        {
            this.Adapters      = new List <AdapterBase>();
            this.Configuration = configuration;

            // Load parameters from config
            this.Description        = configuration.Description;
            this.Name               = configuration.Name;
            this.SyncScope          = configuration.Scope;
            this.SyncAttributes     = configuration.SyncAttributes;
            this.SendSyncJobReports = configuration.SendSyncReports;

            this.TriggerType             = configuration.TriggerConfiguration.TriggerType;
            this.TriggerScheduleInterval = configuration.TriggerConfiguration.ScheduleInterval;

            this.TriggerHourlyInterval            = this.Configuration.TriggerConfiguration.HourlyIntervalValue;
            this.TriggerHourlyMinutesPastSyncTime = this.Configuration.TriggerConfiguration.HourlyMinutesPastSyncTime;

            this.TriggerDailyIntervalValue = this.Configuration.TriggerConfiguration.DailyIntervalValue;
            this.TriggerDailyStartTime     = this.Configuration.TriggerConfiguration.DailyStartTime;

            this.TriggerWeeklyIntervalValue = this.Configuration.TriggerConfiguration.WeeklyIntervalValue;
            this.TriggerWeeklyStartTime     = this.Configuration.TriggerConfiguration.WeeklyStartTime;
            this.TriggerWeeklyDays          = this.Configuration.TriggerConfiguration.WeeklyDays;

            this.IsThrottlingEnabled   = configuration.ThrottlingConfiguration.IsEnabled;
            this.ThrottlingValue       = configuration.ThrottlingConfiguration.Value;
            this.ThrottlingScaleFactor = configuration.ThrottlingConfiguration.ScaleFactor;

            this.EncryptionMode = configuration.EncryptionConfiguration.Mode;
            this.EncryptionCertificateThumbprint = configuration.EncryptionConfiguration.CertificateThumbprint;

            this.State = SyncRelationshipState.NotInitialized;
        }
Exemplo n.º 2
0
        public static SyncRelationship Create()
        {
            var config = new RelationshipConfiguration
            {
                RelationshipId = Guid.NewGuid()
            };

            return(new SyncRelationship(config));
        }
Exemplo n.º 3
0
        public void Verify_that_relationship_configuration_can_be_created()
        {
            this.relationshipConfigurationViewModel.PossibleRules.Add(this.rule);

            this.relationshipConfigurationViewModel.SelectedRule = this.relationshipConfigurationViewModel.PossibleRules.First();

            var relConfig = new RelationshipConfiguration(this.relationshipConfigurationViewModel);

            Assert.AreEqual(this.rule.Iid, relConfig.SelectedRule);
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            base.Setup();

            this.relationshipConfiguration = new RelationshipConfiguration
            {
                SelectedRule = this.rule.Iid
            };

            this.relationshipConfigurationViewModel = new RelationshipConfigurationViewModel(this.session.Object, this.thingDialogNavigationService.Object, this.iteration, this.UpdateAction, null, this.relationshipConfiguration, ClassKind.Requirement, ClassKind.ElementUsage);
        }
Exemplo n.º 5
0
        public static void LogConfiguration(RelationshipConfiguration relationship)
        {
            Logger.Info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

            Logger.Info("Relationship:");
            Logger.Info("   Name: {0}", relationship.Name);
            Logger.Info("   Description: {0}", relationship.Description);
            Logger.Info("   Relationship Id: {0}", relationship.RelationshipId);
            Logger.Info("   Scope: {0}", relationship.Scope);
            Logger.Info("   Sync Attributes: {0}", relationship.SyncAttributes);

            Logger.Info("Trigger Configuration:");
            Logger.Info("   Trigger Type: {0}", relationship.TriggerConfiguration.TriggerType);
            if (relationship.TriggerConfiguration.TriggerType == SyncTriggerType.Scheduled)
            {
                Logger.Info("   Schedule Type: {0}", relationship.TriggerConfiguration.ScheduleInterval);
                if (relationship.TriggerConfiguration.ScheduleInterval == TriggerScheduleInterval.Hourly)
                {
                    Logger.Info("   Hourly Value: {0}", relationship.TriggerConfiguration.HourlyIntervalValue);
                    Logger.Info("   Minutes Past: {0}", relationship.TriggerConfiguration.HourlyMinutesPastSyncTime);
                }
            }

            Logger.Info("   Adapters: {0}", string.Join(",", relationship.Adapters.Select(a => a.Id)));

            foreach (AdapterConfiguration adapter in relationship.Adapters)
            {
                Logger.Info("Adapter {0}:", adapter.Id);
                Logger.Info("   Flags: {0}", JoinFlags <AdapterFlags>(adapter.Flags));
                Logger.Info("   Adapter Type Id: {0}", adapter.AdapterTypeId);
                Logger.Info("   Root Index Entry Id: {0}", adapter.RootIndexEntryId);

                OneDriveAdapterConfiguration oneDriveConfig = adapter as OneDriveAdapterConfiguration;
                if (oneDriveConfig != null)
                {
                    Logger.Info("   Target Path: {0}", oneDriveConfig.TargetPath);
                    Logger.Info("   Current Windows Live Id: {0}", oneDriveConfig.CurrentWindowsLiveId);
                    Logger.Info("   Latest Delta Token: {0}", oneDriveConfig.LatestDeltaToken);
                    Logger.Info("   User Id: {0}", oneDriveConfig.UserId);
                }

                WindowsFileSystemAdapterConfiguration windowsConfig =
                    adapter as WindowsFileSystemAdapterConfiguration;
                if (windowsConfig != null)
                {
                    Logger.Info("   Root Directory: {0}", windowsConfig.RootDirectory);
                }
            }
        }
Exemplo n.º 6
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            CandidatesConfiguration.Configure(builder);
            CommentsConfiguration.Configure(builder);
            ContactsConfiguration.Configure(builder);
            DepartmentsConfiguration.Configure(builder);
            FileAttachmentsConfiguration.Configure(builder);
            LanguagesConfiguration.Configure(builder);
            ProjectsConfiguration.Configure(builder);
            RelationshipConfiguration.Configure(builder);
            // UsersConfiguration.Configure(builder);
            VacanciesConfiguration.Configure(builder);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public virtual string ConstructRelationshipConfiguration(
            [NotNull] RelationshipConfiguration relationshipConfiguration)
        {
            Check.NotNull(relationshipConfiguration, nameof(relationshipConfiguration));

            var sb = new StringBuilder();

            sb.Append("Reference");
            sb.Append("(d => d.");
            sb.Append(relationshipConfiguration.DependentEndNavigationPropertyName);
            sb.Append(")");

            if (relationshipConfiguration.ForeignKey.IsUnique)
            {
                sb.Append(".InverseReference(");
            }
            else
            {
                sb.Append(".InverseCollection(");
            }
            if (!string.IsNullOrEmpty(relationshipConfiguration.PrincipalEndNavigationPropertyName))
            {
                sb.Append("p => p.");
                sb.Append(relationshipConfiguration.PrincipalEndNavigationPropertyName);
            }
            sb.Append(")");

            sb.Append(".ForeignKey");
            if (relationshipConfiguration.ForeignKey.IsUnique)
            {
                // If the relationship is 1:1 need to define to which end
                // the ForeignKey properties belong.
                sb.Append("<");
                sb.Append(relationshipConfiguration.EntityConfiguration.EntityType.DisplayName());
                sb.Append(">");
            }

            sb.Append("(d => ");
            sb.Append(GenerateLambdaToKey(relationshipConfiguration.ForeignKey.Properties, "d"));
            sb.Append(")");

            return(sb.ToString());
        }
Exemplo n.º 9
0
        public virtual void LayoutRelationshipConfigurationLines(
            [NotNull] IndentedStringBuilder sb,
            [NotNull] string entityLambdaIdentifier,
            [NotNull] RelationshipConfiguration rc,
            [NotNull] string dependentEndLambdaIdentifier,
            [NotNull] string principalEndLambdaIdentifier)
        {
            Check.NotNull(sb, nameof(sb));
            Check.NotEmpty(entityLambdaIdentifier, nameof(entityLambdaIdentifier));
            Check.NotNull(rc, nameof(rc));
            Check.NotEmpty(dependentEndLambdaIdentifier, nameof(dependentEndLambdaIdentifier));
            Check.NotEmpty(principalEndLambdaIdentifier, nameof(principalEndLambdaIdentifier));

            sb.Append(entityLambdaIdentifier);
            sb.Append("." + nameof(EntityTypeBuilder <EntityType> .HasOne) + "(");
            sb.Append(dependentEndLambdaIdentifier);
            sb.Append(" => ");
            sb.Append(dependentEndLambdaIdentifier);
            sb.Append(".");
            sb.Append(rc.DependentEndNavigationPropertyName);
            sb.AppendLine(")");

            using (sb.Indent())
            {
                var withMethodName = rc.ForeignKey.IsUnique
                    ? nameof(ReferenceNavigationBuilder <EntityType, EntityType> .WithOne)
                    : nameof(ReferenceNavigationBuilder <EntityType, EntityType> .WithMany);
                sb.Append("." + withMethodName + "(");
                if (!string.IsNullOrEmpty(rc.PrincipalEndNavigationPropertyName))
                {
                    sb.Append(principalEndLambdaIdentifier);
                    sb.Append(" => ");
                    sb.Append(principalEndLambdaIdentifier);
                    sb.Append(".");
                    sb.Append(rc.PrincipalEndNavigationPropertyName);
                }
                sb.AppendLine(")");

                if (!rc.ForeignKey.PrincipalKey.IsPrimaryKey())
                {
                    var hasPrincipalKeyMethodName = rc.ForeignKey.IsUnique
                        ? nameof(ReferenceReferenceBuilder <EntityType, EntityType> .HasPrincipalKey)
                        : nameof(ReferenceReferenceBuilder.HasPrincipalKey);
                    sb.Append("." + hasPrincipalKeyMethodName);
                    if (rc.ForeignKey.IsUnique)
                    {
                        // If the relationship is 1:1 need to define to which end
                        // the PrincipalKey properties belong.
                        sb.Append("<");
                        sb.Append(rc.ForeignKey.PrincipalEntityType.DisplayName());
                        sb.Append(">");
                    }
                    sb.Append("(")
                    .Append(principalEndLambdaIdentifier)
                    .Append(" => ")
                    .Append(GenerateLambdaToKey(rc.ForeignKey.PrincipalKey.Properties, principalEndLambdaIdentifier))
                    .AppendLine(")");
                }

                var hasForeignKeyMethodName = rc.ForeignKey.IsUnique
                    ? nameof(ReferenceReferenceBuilder <EntityType, EntityType> .HasForeignKey)
                    : nameof(ReferenceCollectionBuilder.HasForeignKey);
                sb.Append("." + hasForeignKeyMethodName);
                if (rc.ForeignKey.IsUnique)
                {
                    // If the relationship is 1:1 need to define to which end
                    // the ForeignKey properties belong.
                    sb.Append("<");
                    sb.Append(rc.EntityConfiguration.EntityType.DisplayName());
                    sb.Append(">");
                }

                sb.Append("(");
                sb.Append(dependentEndLambdaIdentifier);
                sb.Append(" => ");
                sb.Append(GenerateLambdaToKey(rc.ForeignKey.Properties, dependentEndLambdaIdentifier));
                sb.Append(")");

                var defaultOnDeleteAction = rc.ForeignKey.IsRequired
                    ? DeleteBehavior.Cascade
                    : DeleteBehavior.Restrict;

                if (rc.OnDeleteAction != defaultOnDeleteAction)
                {
                    sb.AppendLine();
                    var onDeleteMethodName = rc.ForeignKey.IsUnique
                        ? nameof(ReferenceReferenceBuilder.OnDelete)
                        : nameof(ReferenceCollectionBuilder.OnDelete);
                    sb.Append("." + onDeleteMethodName + "(");
                    sb.Append(CSharpUtilities.Instance.GenerateLiteral(rc.OnDeleteAction));
                    sb.Append(")");
                }

                var foreignKey = rc.ForeignKey as ForeignKey;
                if (foreignKey != null &&
                    foreignKey.Relational().Name !=
                    RelationalForeignKeyAnnotations.GetDefaultForeignKeyName(
                        foreignKey.DeclaringEntityType.Relational().TableName,
                        foreignKey.PrincipalEntityType.Relational().TableName,
                        foreignKey.Properties.Select(p => p.Name)))
                {
                    sb.AppendLine();
                    var hasConstraintMethodName = foreignKey.IsUnique
                        ? nameof(RelationalReferenceReferenceBuilderExtensions.HasConstraintName)
                        : nameof(RelationalReferenceCollectionBuilderExtensions.HasConstraintName);
                    sb.Append("." + hasConstraintMethodName + "(");
                    sb.Append(CSharpUtilities.Instance.DelimitString(foreignKey.Relational().Name));
                    sb.Append(")");
                }

                sb.AppendLine(";");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationshipConfigurationViewModel"/>
        /// </summary>
        /// <param name="session">The current session</param>
        /// <param name="thingDialogNavigationService">
        /// The <see cref="IThingDialogNavigationService"/> used to navigate to details dialog of a <see cref="Thing"/>
        /// </param>
        /// <param name="iteration">The current iteration</param>
        /// <param name="action">The action to perform on update</param>
        /// <param name="settings">The module settings</param>
        /// <param name="source">The source <see cref="RelationshipConfiguration"/></param>
        /// <param name="sourceY">The <see cref="ClassKind"/> of source Y</param>
        /// <param name="sourceX">The <see cref="ClassKind"/> of source X</param>
        public RelationshipConfigurationViewModel(ISession session,
                                                  IThingDialogNavigationService thingDialogNavigationService, Iteration iteration, Action action,
                                                  RelationshipMatrixPluginSettings settings, RelationshipConfiguration source, ClassKind?sourceY,
                                                  ClassKind?sourceX) : this(session,
                                                                            thingDialogNavigationService, iteration, action, settings)
        {
            this.PopulatePossibleRules(sourceY, sourceX);

            if (source.SelectedRule != null)
            {
                this.SelectedRule = this.PossibleRules.SingleOrDefault(x => x.Iid == source.SelectedRule);
            }
        }
Exemplo n.º 11
0
        public virtual string LayoutRelationshipConfigurationLine(
            [NotNull] RelationshipConfiguration rc,
            [NotNull] string dependentEndLambdaIdentifier,
            [NotNull] string principalEndLambdaIdentifier)
        {
            Check.NotNull(rc, nameof(rc));
            Check.NotEmpty(dependentEndLambdaIdentifier, nameof(dependentEndLambdaIdentifier));
            Check.NotEmpty(principalEndLambdaIdentifier, nameof(principalEndLambdaIdentifier));

            var sb = new StringBuilder();

            sb.Append("HasOne(");
            sb.Append(dependentEndLambdaIdentifier);
            sb.Append(" => ");
            sb.Append(dependentEndLambdaIdentifier);
            sb.Append(".");
            sb.Append(rc.DependentEndNavigationPropertyName);
            sb.Append(")");

            if (rc.ForeignKey.IsUnique)
            {
                sb.Append(".WithOne(");
            }
            else
            {
                sb.Append(".WithMany(");
            }
            if (!string.IsNullOrEmpty(rc.PrincipalEndNavigationPropertyName))
            {
                sb.Append(principalEndLambdaIdentifier);
                sb.Append(" => ");
                sb.Append(principalEndLambdaIdentifier);
                sb.Append(".");
                sb.Append(rc.PrincipalEndNavigationPropertyName);
            }
            sb.Append(")");

            if (!rc.ForeignKey.PrincipalKey.IsPrimaryKey())
            {
                sb.Append(".HasPrincipalKey");
                if (rc.ForeignKey.IsUnique)
                {
                    // If the relationship is 1:1 need to define to which end
                    // the PrincipalKey properties belong.
                    sb.Append("<");
                    sb.Append(rc.ForeignKey.PrincipalEntityType.DisplayName());
                    sb.Append(">");
                }
                sb.Append("(")
                .Append(principalEndLambdaIdentifier)
                .Append(" => ")
                .Append(GenerateLambdaToKey(rc.ForeignKey.PrincipalKey.Properties, principalEndLambdaIdentifier))
                .Append(")");
            }

            sb.Append(".HasForeignKey");
            if (rc.ForeignKey.IsUnique)
            {
                // If the relationship is 1:1 need to define to which end
                // the ForeignKey properties belong.
                sb.Append("<");
                sb.Append(rc.EntityConfiguration.EntityType.DisplayName());
                sb.Append(">");
            }

            sb.Append("(");
            sb.Append(dependentEndLambdaIdentifier);
            sb.Append(" => ");
            sb.Append(GenerateLambdaToKey(rc.ForeignKey.Properties, dependentEndLambdaIdentifier));
            sb.Append(")");

            var defaultOnDeleteAction = rc.ForeignKey.IsRequired
                ? DeleteBehavior.Cascade
                : DeleteBehavior.Restrict;

            if (rc.OnDeleteAction != defaultOnDeleteAction)
            {
                sb.Append(".OnDelete(");
                sb.Append(CSharpUtilities.Instance.GenerateLiteral(rc.OnDeleteAction));
                sb.Append(")");
            }

            return(sb.ToString());
        }