コード例 #1
0
 internal GalleryImageVersionData(ResourceIdentifier id, string name, ResourceType type, IDictionary <string, string> tags, Location location, GalleryImageVersionPublishingProfile publishingProfile, GalleryImageVersionPropertiesProvisioningState?provisioningState, GalleryImageVersionStorageProfile storageProfile, ReplicationStatus replicationStatus) : base(id, name, type, tags, location)
 {
     PublishingProfile = publishingProfile;
     ProvisioningState = provisioningState;
     StorageProfile    = storageProfile;
     ReplicationStatus = replicationStatus;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WriteableChangeBlockOperation"/> class.
 /// </summary>
 /// <param name="parentNode">Node where the block change is taking place.</param>
 /// <param name="propertyName">Block list property of <paramref name="parentNode"/> for which a block is changed.</param>
 /// <param name="blockIndex">Index of the changed block.</param>
 /// <param name="replication">New replication value.</param>
 /// <param name="handlerRedo">Handler to execute to redo the operation.</param>
 /// <param name="handlerUndo">Handler to execute to undo the operation.</param>
 /// <param name="isNested">True if the operation is nested within another more general one.</param>
 public WriteableChangeBlockOperation(INode parentNode, string propertyName, int blockIndex, ReplicationStatus replication, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
     : base(handlerRedo, handlerUndo, isNested)
 {
     ParentNode   = parentNode;
     PropertyName = propertyName;
     BlockIndex   = blockIndex;
     Replication  = replication;
 }
コード例 #3
0
        /// <summary>
        /// Changes the replication state of a block.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void ChangeReplication(WriteableChangeBlockOperation operation)
        {
            ReplicationStatus Replication = operation.Replication;
            int BlockIndex = operation.BlockIndex;

            Debug.Assert(BlockIndex >= 0 && BlockIndex < BlockStateList.Count);

            IWriteableBlockState BlockState = (IWriteableBlockState)BlockStateList[BlockIndex];

            NodeTreeHelperBlockList.SetReplication(BlockState.ChildBlock, Replication);

            operation.Update(BlockState);
        }
コード例 #4
0
        /// <summary>
        /// 将制定的数据复制到当前数据访问对象关联的数据库中
        /// </summary>
        /// <param name="log">事务日志实体</param>
        /// <returns>如果数据已经存在或者复制成功,返回真;如果遇到错误,返回假</returns>
        public bool DataReplication(MyCommandLogEntity log)
        {
            this.ErrorMessage  = string.Empty;
            this.CurrentStatus = ReplicationStatus.UnKnown;
            if (log.LogFlag > 0)
            {
                this.CurrentStatus = ReplicationStatus.Executed;
                return(true);
            }
            var query = this.NewQuery <MyCommandLogEntity>();

            if (query.ExistsEntity(log))
            {
                this.CurrentStatus = ReplicationStatus.LogExists;
                return(true);
            }
            else
            {
                string             errorMessage;
                MyCommandLogEntity newLog = new MyCommandLogEntity();
                newLog.CommandID     = log.CommandID;
                newLog.CommandName   = log.CommandName;
                newLog.CommandText   = log.CommandText;
                newLog.CommandType   = log.CommandType;
                newLog.ExecuteTime   = DateTime.Now; //新执行的时间
                newLog.LogFlag       = 2;            //表示已经复制到目标库的状态
                newLog.ParameterInfo = log.ParameterInfo;
                newLog.SQLType       = log.SQLType;
                newLog.LogTopic      = log.LogTopic;

                //log 可能映射了新的表名
                newLog.MapNewTableName(log.GetTableName());

                bool result = Transaction(ctx => {
                    query.Insert(newLog);

                    //解析得到真正的命令参数信息
                    var paras = log.ParseParameter(this.CurrentDataBase);
                    int count = this.CurrentDataBase.ExecuteNonQuery(log.CommandText, log.CommandType, paras);
                    //可以在此处考虑引发处理后事件
                    if (AfterReplications != null)
                    {
                        AfterReplications(this, new ReplicationEventArgs(log, count));
                    }
                }, out errorMessage);

                this.ErrorMessage  = errorMessage;
                this.CurrentStatus = result ? ReplicationStatus.Succeed : ReplicationStatus.Error;
                return(result);
            }
        }
コード例 #5
0
        /// <summary>
        /// Splits a block in two at the given index.
        /// </summary>
        /// <param name="inner">The inner where the block is split.</param>
        /// <param name="nodeIndex">Index of the last node to stay in the old block.</param>
        public virtual void SplitBlock(IWriteableBlockListInner inner, IWriteableBrowsingExistingBlockNodeIndex nodeIndex)
        {
            Contract.RequireNotNull(inner, out IWriteableBlockListInner Inner);
            Contract.RequireNotNull(nodeIndex, out IWriteableBrowsingExistingBlockNodeIndex NodeIndex);
            Debug.Assert(Inner.IsSplittable(NodeIndex));

            IWriteableBlockState BlockState  = (IWriteableBlockState)Inner.BlockStateList[NodeIndex.BlockIndex];
            ReplicationStatus    Replication = BlockState.ChildBlock.Replication;
            Pattern    NewPatternNode        = NodeHelper.CreateSimplePattern(BlockState.ChildBlock.ReplicationPattern.Text);
            Identifier NewSourceNode         = NodeHelper.CreateSimpleIdentifier(BlockState.ChildBlock.SourceIdentifier.Text);
            IBlock     NewBlock = NodeTreeHelperBlockList.CreateBlock(Inner.Owner.Node, Inner.PropertyName, Replication, NewPatternNode, NewSourceNode);

            Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoSplitBlock(operation);
            Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoSplitBlock(operation);
            WriteableSplitBlockOperation Operation   = CreateSplitBlockOperation(Inner.Owner.Node, Inner.PropertyName, NodeIndex.BlockIndex, NodeIndex.Index, NewBlock, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
コード例 #6
0
        //"http://10.0.2.2:4984/sync_gateway/";

        void StartSync()
        {
            try
            {
                Uri         _url   = new Uri(mSyncGatewayUrl);
                Replication puller = Manager.SharedInstance.GetDatabase("dbase").CreatePullReplication(_url);
                Replication pusher = Manager.SharedInstance.GetDatabase("dbase").CreatePushReplication(_url);
                puller.Continuous = true;
                pusher.Continuous = true;
                puller.Changed   += Puller_Changed;
                pusher.Changed   += Pusher_Changed;
                puller.Start();
                pusher.Start();
                ReplicationStatus x = puller.Status;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
コード例 #7
0
        private void WaitForReplicationStatus(AzureNetAppFilesManagementClient netAppMgmtClient, string targetState)
        {
            ReplicationStatus replicationStatus = new ReplicationStatus {
                Healthy = false, MirrorState = "Uninitialized"
            };
            int attempts = 0;

            do
            {
                try
                {
                    replicationStatus = netAppMgmtClient.Volumes.ReplicationStatusMethod(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.volumeName1ReplDest);
                }
                catch (CloudException ex)
                {
                    if (!ex.Message.Contains("the volume replication is: 'Creating'"))
                    {
                        throw;
                    }
                }
                Thread.Sleep(1);
            } while (replicationStatus.MirrorState != targetState);
            //sometimes they dont sync up right away
            if (!replicationStatus.Healthy.Value)
            {
                do
                {
                    replicationStatus = netAppMgmtClient.Volumes.ReplicationStatusMethod(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.volumeName1ReplDest);
                    attempts++;
                    if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record")
                    {
                        Thread.Sleep(1000);
                    }
                } while (replicationStatus.Healthy.Value || attempts == 10);
            }
            Assert.True(replicationStatus.Healthy);
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayoutChangeBlockOperation"/> class.
 /// </summary>
 /// <param name="parentNode">Node where the block change is taking place.</param>
 /// <param name="propertyName">Block list property of <paramref name="parentNode"/> for which a block is changed.</param>
 /// <param name="blockIndex">Index of the changed block.</param>
 /// <param name="replication">New replication value.</param>
 /// <param name="handlerRedo">Handler to execute to redo the operation.</param>
 /// <param name="handlerUndo">Handler to execute to undo the operation.</param>
 /// <param name="isNested">True if the operation is nested within another more general one.</param>
 public LayoutChangeBlockOperation(INode parentNode, string propertyName, int blockIndex, ReplicationStatus replication, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
     : base(parentNode, propertyName, blockIndex, replication, handlerRedo, handlerUndo, isNested)
 {
 }
コード例 #9
0
 /// <summary>
 /// Creates a IxxxChangeBlockOperation object.
 /// </summary>
 private protected override IWriteableChangeBlockOperation CreateChangeBlockOperation(ReplicationStatus replication, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
 {
     ControllerTools.AssertNoOverride(this, typeof(LayoutChangeBlockOperation));
     return(new LayoutChangeBlockOperation(ParentNode, PropertyName, BlockIndex, replication, handlerRedo, handlerUndo, isNested));
 }
コード例 #10
0
 void IWorkspaceWindow.EndReplicationProgress(ReplicationStatus replicationStatus)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
        /// <summary>
        /// Changes the replication state of a block.
        /// </summary>
        /// <param name="inner">The inner where the blok is changed.</param>
        /// <param name="blockIndex">Position of the block in the block list.</param>
        /// <param name="replication">New replication value.</param>
        public virtual void ChangeReplication(IWriteableBlockListInner inner, int blockIndex, ReplicationStatus replication)
        {
            Contract.RequireNotNull(inner, out IWriteableBlockListInner Inner);
            Debug.Assert(blockIndex >= 0 && blockIndex < Inner.BlockStateList.Count);

            System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoChangeReplication(operation);
            System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoChangeReplication(operation);
            WriteableChangeBlockOperation       Operation   = CreateChangeBlockOperation(Inner.Owner.Node, Inner.PropertyName, blockIndex, replication, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();
        }
コード例 #12
0
        internal static GalleryImageVersionData DeserializeGalleryImageVersionData(JsonElement element)
        {
            IDictionary <string, string> tags = default;
            Location           location       = default;
            ResourceIdentifier id             = default;
            string             name           = default;
            ResourceType       type           = default;
            Optional <GalleryImageVersionPublishingProfile>           publishingProfile = default;
            Optional <GalleryImageVersionPropertiesProvisioningState> provisioningState = default;
            Optional <GalleryImageVersionStorageProfile> storageProfile = default;
            Optional <ReplicationStatus> replicationStatus = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("publishingProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            publishingProfile = GalleryImageVersionPublishingProfile.DeserializeGalleryImageVersionPublishingProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new GalleryImageVersionPropertiesProvisioningState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("storageProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            storageProfile = GalleryImageVersionStorageProfile.DeserializeGalleryImageVersionStorageProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("replicationStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            replicationStatus = ReplicationStatus.DeserializeReplicationStatus(property0.Value);
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new GalleryImageVersionData(id, name, type, tags, location, publishingProfile.Value, Optional.ToNullable(provisioningState), storageProfile.Value, replicationStatus.Value));
        }
コード例 #13
0
 void IWorkspaceWindow.RefreshReplicationProgress(BranchReplicationData replicationData, ReplicationStatus replicationStatus, int current, int total)
 {
     throw new NotImplementedException();
 }
コード例 #14
0
 /// <summary>
 /// Creates a IxxxChangeBlockOperation object.
 /// </summary>
 private protected override WriteableChangeBlockOperation CreateChangeBlockOperation(Node parentNode, string propertyName, int blockIndex, ReplicationStatus replication, System.Action <IWriteableOperation> handlerRedo, System.Action <IWriteableOperation> handlerUndo, bool isNested)
 {
     ControllerTools.AssertNoOverride(this, Type.FromTypeof <LayoutController>());
     return(new LayoutChangeBlockOperation(parentNode, propertyName, blockIndex, replication, handlerRedo, handlerUndo, isNested));
 }
コード例 #15
0
        /// <summary>
        /// Checks if an existing block can have its replication status changed.
        /// </summary>
        /// <param name="inner">Inner to use to change the replication status upon return.</param>
        /// <param name="blockIndex">Index of the block that can be changed upon return.</param>
        /// <param name="replication">The current replication status upon return.</param>
        /// <returns>True if an existing block can have its replication status changed at the focus.</returns>
        public virtual bool IsReplicationModifiable(out IFocusBlockListInner inner, out int blockIndex, out ReplicationStatus replication)
        {
            inner       = null;
            blockIndex  = -1;
            replication = ReplicationStatus.Normal;

            bool IsModifiable = false;

            IFocusNodeState State = Focus.CellView.StateView.State;

            // Search recursively for a collection parent, up to 3 levels up.
            for (int i = 0; i < 3 && State != null; i++)
            {
                if (State is IFocusPatternState AsPatternState)
                {
                    IFocusBlockState     ParentBlock    = AsPatternState.ParentBlockState;
                    IFocusBlockListInner BlockListInner = ParentBlock.ParentInner as IFocusBlockListInner;
                    Debug.Assert(BlockListInner != null);

                    inner        = BlockListInner;
                    blockIndex   = inner.BlockStateList.IndexOf(ParentBlock);
                    replication  = ParentBlock.ChildBlock.Replication;
                    IsModifiable = true;
                    break;
                }
                else if (State is IFocusSourceState AsSourceState)
                {
                    IFocusBlockState     ParentBlock    = AsSourceState.ParentBlockState;
                    IFocusBlockListInner BlockListInner = ParentBlock.ParentInner as IFocusBlockListInner;
                    Debug.Assert(BlockListInner != null);

                    inner        = BlockListInner;
                    blockIndex   = inner.BlockStateList.IndexOf(ParentBlock);
                    replication  = ParentBlock.ChildBlock.Replication;
                    IsModifiable = true;
                    break;
                }
                else if (State.ParentInner is IFocusBlockListInner AsBlockListInner)
                {
                    inner = AsBlockListInner;
                    IFocusBrowsingExistingBlockNodeIndex ParentIndex = State.ParentIndex as IFocusBrowsingExistingBlockNodeIndex;
                    Debug.Assert(ParentIndex != null);
                    blockIndex   = ParentIndex.BlockIndex;
                    replication  = inner.BlockStateList[blockIndex].ChildBlock.Replication;
                    IsModifiable = true;
                    break;
                }

                State = State.ParentState;
            }

            return(IsModifiable);
        }
コード例 #16
0
 internal GalleryApplicationVersionData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, GalleryApplicationVersionPublishingProfile publishingProfile, GalleryProvisioningState?provisioningState, ReplicationStatus replicationStatus) : base(id, name, resourceType, systemData, tags, location)
 {
     PublishingProfile = publishingProfile;
     ProvisioningState = provisioningState;
     ReplicationStatus = replicationStatus;
 }
コード例 #17
0
 /// <summary>
 /// Creates a IxxxChangeBlockOperation object.
 /// </summary>
 private protected override IWriteableChangeBlockOperation CreateChangeBlockOperation(INode parentNode, string propertyName, int blockIndex, ReplicationStatus replication, Action <IWriteableOperation> handlerRedo, Action <IWriteableOperation> handlerUndo, bool isNested)
 {
     ControllerTools.AssertNoOverride(this, typeof(FocusController));
     return(new FocusChangeBlockOperation(parentNode, propertyName, blockIndex, replication, handlerRedo, handlerUndo, isNested));
 }
コード例 #18
0
 /// <summary>
 /// Creates a IxxxChangeBlockOperation object.
 /// </summary>
 private protected override WriteableChangeBlockOperation CreateChangeBlockOperation(ReplicationStatus replication, System.Action <IWriteableOperation> handlerRedo, System.Action <IWriteableOperation> handlerUndo, bool isNested)
 {
     ControllerTools.AssertNoOverride(this, Type.FromTypeof <FocusChangeBlockOperation>());
     return(new FocusChangeBlockOperation(ParentNode, PropertyName, BlockIndex, replication, handlerRedo, handlerUndo, isNested));
 }
コード例 #19
0
ファイル: Replicator.cs プロジェクト: EventStore/replicator
        public static async Task Replicate(
            IEventReader reader,
            SinkPipeOptions sinkPipeOptions,
            PreparePipelineOptions preparePipeOptions,
            ICheckpointStore checkpointStore,
            CancellationToken stoppingToken,
            bool restartWhenComplete = false
            )
        {
            ReplicationMetrics.SetCapacity(preparePipeOptions.BufferSize, sinkPipeOptions.BufferSize);

            var cts = new CancellationTokenSource();

            var linkedCts =
                CancellationTokenSource.CreateLinkedTokenSource(stoppingToken, cts.Token);

            var prepareChannel = Channel.CreateBounded <PrepareContext>(preparePipeOptions.BufferSize);
            var sinkChannel    = Channel.CreateBounded <SinkContext>(sinkPipeOptions.BufferSize);

            var readerPipe = new ReaderPipe(
                reader,
                checkpointStore,
                ctx => prepareChannel.Writer.WriteAsync(ctx, ctx.CancellationToken)
                );

            var preparePipe = new PreparePipe(
                preparePipeOptions.Filter,
                preparePipeOptions.Transform,
                ctx => sinkChannel.Writer.WriteAsync(ctx, ctx.CancellationToken)
                );
            var sinkPipe = new SinkPipe(sinkPipeOptions, checkpointStore);

            var prepareTask = CreateChannelShovel(
                "Prepare",
                prepareChannel,
                preparePipe.Send,
                ReplicationMetrics.PrepareChannelSize,
                linkedCts.Token
                );

            var writerTask = CreateChannelShovel(
                "Writer",
                sinkChannel,
                sinkPipe.Send,
                ReplicationMetrics.SinkChannelSize,
                CancellationToken.None
                );
            var reporter = Task.Run(Report, stoppingToken);

            while (true)
            {
                ReplicationStatus.Start();

                await readerPipe.Start(linkedCts.Token).ConfigureAwait(false);

                if (!restartWhenComplete)
                {
                    do
                    {
                        Log.Info("Closing the prepare channel...");
                        await Task.Delay(1000, CancellationToken.None).ConfigureAwait(false);
                    } while (!prepareChannel.Writer.TryComplete());
                }

                ReplicationStatus.Stop();

                while (sinkChannel.Reader.Count > 0)
                {
                    await checkpointStore.Flush(CancellationToken.None).ConfigureAwait(false);

                    Log.Info("Waiting for the sink pipe to exhaust ({Left} left)...", sinkChannel.Reader.Count);
                    await Task.Delay(1000, CancellationToken.None).ConfigureAwait(false);
                }

                Log.Info("Storing the last known checkpoint");
                await checkpointStore.Flush(CancellationToken.None).ConfigureAwait(false);

                if (linkedCts.IsCancellationRequested || !restartWhenComplete)
                {
                    sinkChannel.Writer.Complete();
                    break;
                }

                Log.Info("Will restart in 5 sec");
                await Task.Delay(5000, stoppingToken);
            }

            try {
                await prepareTask.ConfigureAwait(false);

                await writerTask.ConfigureAwait(false);

                await reporter.ConfigureAwait(false);
            }
            catch (OperationCanceledException) { }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Couchbase.Lite.ReplicationChangeEventArgs"/> class.
 /// </summary>
 /// <param name="sender">The <see cref="Couchbase.Lite.Replication"/> that raised the event.</param>
 /// <param name="transition">The transition that caused the state in the replication, if applicable</param>
 public ReplicationChangeEventArgs (Replication sender, ReplicationStateTransition transition)
 {
     _source = sender;
     _transition = transition;
     _changesCount = sender.ChangesCount;
     _completedChangesCount = sender.CompletedChangesCount;
     _status = sender.Status;
 }