Esempio n. 1
0
        private void ExecuteLocally(int instanceNumber, Proposal <string, DxStoreCommand> proposal)
        {
            if (!this.truncator.IsStarted)
            {
                this.truncator.Start();
            }
            DxStoreCommand       command          = proposal.value;
            bool                 isTracingEnabled = ExTraceGlobals.StoreWriteTracer.IsTraceEnabled(TraceType.DebugTrace);
            WellKnownCommandName cmdTypeId        = command.GetTypeId();

            this.instance.RunOperation("ExecuteCommandLocally :" + cmdTypeId, delegate
            {
                if (isTracingEnabled)
                {
                    ExTraceGlobals.StoreWriteTracer.TraceDebug((long)this.instance.IdentityHash, "{0}: Execute start: [Instance#{1}] {2}: {3}", new object[]
                    {
                        this.instance.Identity,
                        instanceNumber,
                        cmdTypeId,
                        command.GetDebugString()
                    });
                }
                this.ExecuteCommand(instanceNumber, command);
            }, LogOptions.LogException, null, null, null, delegate(Exception exception)
            {
                if (exception != null)
                {
                    if (ExTraceGlobals.StoreWriteTracer.IsTraceEnabled(TraceType.ErrorTrace))
                    {
                        ExTraceGlobals.StoreWriteTracer.TraceError((long)this.instance.IdentityHash, "{0}: Execute failed: [Instance#{1}] {2}: Error: {3}", new object[]
                        {
                            this.instance.Identity,
                            instanceNumber,
                            cmdTypeId,
                            exception.ToString()
                        });
                    }
                }
                else if (isTracingEnabled)
                {
                    ExTraceGlobals.StoreWriteTracer.TraceDebug <string, int, WellKnownCommandName>((long)this.instance.IdentityHash, "{0}: Execute success: [Instance#{1}] {2}", this.instance.Identity, instanceNumber, cmdTypeId);
                }
                this.NotifyInitiatorAsync(instanceNumber, command, exception);
            });
        }
Esempio n. 2
0
        private void ExecuteCommand(int instanceNumber, DxStoreCommand command)
        {
            WellKnownCommandName typeId = command.GetTypeId();
            bool flag = false;

            switch (typeId)
            {
            case WellKnownCommandName.CreateKey:
                {
                    DxStoreCommand.CreateKey createKey = command as DxStoreCommand.CreateKey;
                    if (createKey != null)
                    {
                        flag = true;
                        bool arg = this.localDataStore.CreateKey(new int?(instanceNumber), createKey.FullKeyName);
                        ExTraceGlobals.StoreWriteTracer.TraceDebug <string, bool>((long)this.instance.IdentityHash, "{0}: CreateKey - IsKeyCreated: {1}", this.instance.Identity, arg);
                    }
                    break;
                }

            case WellKnownCommandName.DeleteKey:
            {
                DxStoreCommand.DeleteKey deleteKey = command as DxStoreCommand.DeleteKey;
                if (deleteKey != null)
                {
                    flag = true;
                    bool arg2 = this.localDataStore.DeleteKey(new int?(instanceNumber), deleteKey.FullKeyName);
                    ExTraceGlobals.StoreWriteTracer.TraceDebug <string, bool>((long)this.instance.IdentityHash, "{0}: DeleteKey - IsFound: {1}", this.instance.Identity, arg2);
                }
                break;
            }

            case WellKnownCommandName.SetProperty:
            {
                DxStoreCommand.SetProperty setProperty = command as DxStoreCommand.SetProperty;
                if (setProperty != null)
                {
                    flag = true;
                    this.localDataStore.SetProperty(new int?(instanceNumber), setProperty.KeyName, setProperty.Name, setProperty.Value);
                }
                break;
            }

            case WellKnownCommandName.DeleteProperty:
            {
                DxStoreCommand.DeleteProperty deleteProperty = command as DxStoreCommand.DeleteProperty;
                if (deleteProperty != null)
                {
                    flag = true;
                    bool arg3 = this.localDataStore.DeleteProperty(new int?(instanceNumber), deleteProperty.KeyName, deleteProperty.Name);
                    ExTraceGlobals.StoreWriteTracer.TraceDebug <string, bool>((long)this.instance.IdentityHash, "{0}: DeleteProperty - IsFound: {1}", this.instance.Identity, arg3);
                }
                break;
            }

            case WellKnownCommandName.ExecuteBatch:
            {
                DxStoreCommand.ExecuteBatch executeBatch = command as DxStoreCommand.ExecuteBatch;
                if (executeBatch != null)
                {
                    flag = true;
                    this.localDataStore.ExecuteBatch(new int?(instanceNumber), executeBatch.KeyName, executeBatch.Commands);
                }
                break;
            }

            case WellKnownCommandName.ApplySnapshot:
            {
                DxStoreCommand.ApplySnapshot applySnapshot = command as DxStoreCommand.ApplySnapshot;
                if (applySnapshot != null)
                {
                    flag = true;
                    this.localDataStore.ApplySnapshot(applySnapshot.SnapshotInfo, new int?(instanceNumber));
                }
                break;
            }

            case WellKnownCommandName.PromoteToLeader:
            {
                DxStoreCommand.PromoteToLeader promoteToLeader = command as DxStoreCommand.PromoteToLeader;
                if (promoteToLeader != null)
                {
                    flag = true;
                    string        value         = string.Format("Promote to leader requested at {0}", promoteToLeader.TimeInitiated.ToShortString());
                    PropertyValue propertyValue = new PropertyValue(value);
                    this.localDataStore.SetProperty(new int?(instanceNumber), "Private\\NonStoreUpdates\\Promote", "Initiator-" + promoteToLeader.Initiator, propertyValue);
                }
                break;
            }

            case WellKnownCommandName.DummyCmd:
            {
                DxStoreCommand.DummyCommand dummyCommand = command as DxStoreCommand.DummyCommand;
                if (dummyCommand != null)
                {
                    flag = true;
                    string        value2         = string.Format("Constrained write test for original command {0}", dummyCommand.OriginalDbCommandId);
                    PropertyValue propertyValue2 = new PropertyValue(value2);
                    this.localDataStore.SetProperty(new int?(instanceNumber), "Private\\NonStoreUpdates\\Dummy", "Initiator-" + dummyCommand.Initiator, propertyValue2);
                }
                break;
            }
            }
            if (!flag)
            {
                ExTraceGlobals.StoreWriteTracer.TraceError <string, WellKnownCommandName, string>((long)this.instance.IdentityHash, "{0}: Unknown command {1} (Type: {2})", this.instance.Identity, typeId, command.GetType().Name);
                this.localDataStore.SetProperty(new int?(instanceNumber), "Private\\NonStoreUpdates\\UnknownCommands", "Initiator-" + command.Initiator, new PropertyValue(command.TimeInitiated.ToShortString()));
            }
        }