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())); } }
public void BecomeLeader(TimeSpan timeout) { DxStoreCommand.PromoteToLeader promoteToLeader = new DxStoreCommand.PromoteToLeader(); promoteToLeader.Initialize(this.self, null); this.ReplicateCommand(promoteToLeader, true, new TimeSpan?(timeout)); }