Ejemplo n.º 1
0
        public override string UpdateDatabaseRecord(DatabaseRecord record, long etag)
        {
            Watcher.AssertValidReplication();

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

            if (Watcher.TaskId == 0)
            {
                Watcher.TaskId = etag;
            }
            else
            {
                //modified watcher, remove the old one
                ExternalReplicationBase.RemoveExternalReplication(record.ExternalReplications, Watcher.TaskId);
            }
            //this covers the case of a new watcher and edit of an old watcher
            if (string.IsNullOrEmpty(Watcher.Name))
            {
                Watcher.Name = record.EnsureUniqueTaskName(Watcher.GetDefaultTaskName());
            }

            EnsureTaskNameIsNotUsed(record, Watcher.Name);
            record.ExternalReplications.Add(Watcher);
            return(null);
        }
        public override void UpdateDatabaseRecord(DatabaseRecord record, long etag)
        {
            Watcher.AssertValidReplication();

            if (Watcher == null)
            {
                return;
            }

            if (Watcher.TaskId == 0)
            {
                Watcher.TaskId = etag;
            }
            else
            {
                //modified watcher, remove the old one
                ExternalReplicationBase.RemoveExternalReplication(record.ExternalReplications, Watcher.TaskId);
            }
            //this covers the case of a new watcher and edit of an old watcher
            if (string.IsNullOrEmpty(Watcher.Name))
            {
                Watcher.Name = record.EnsureUniqueTaskName(Watcher.GetDefaultTaskName());
            }

            if (Watcher.Name.StartsWith(ServerWideExternalReplication.NamePrefix, StringComparison.OrdinalIgnoreCase))
            {
                var isNewTask = record.ExternalReplications.Exists(x => x.Name.Equals(Watcher.Name, StringComparison.OrdinalIgnoreCase));
                throw new InvalidOperationException($"Can't {(isNewTask ? "create" : "update")} task: '{Watcher.Name}'. " +
                                                    $"A regular (non server-wide) external replication name can't start with prefix '{ServerWideExternalReplication.NamePrefix}'");
            }

            EnsureTaskNameIsNotUsed(record, Watcher.Name);

            record.ExternalReplications.Add(Watcher);
        }