public Router(CommandReader commandReader, CommandWriter commandWriter) { _commandReader = commandReader; _commandWriter = commandWriter; CommandReader.MessageReceived += CommandReader_MessageReceived; }
public void UpdateEntity() { var connection = TestConfiguration.GetConnection(); var writer = new CommandWriter <TestModel>(connection); var reader = new EntityReader <TestModel>(connection); var entity = new TestModel { Title = "UpdateEntityCommandTests.UpdateEntity" }; writer.Write(new[] { new AddEntityCommand <TestModel>(new EntityEntry <TestModel>(entity, EntityEntryState.Added)) }); var updatedEntity = new TestModel { Id = entity.Id, Title = "UpdateEntityCommandTests.UpdateEntity-Updated" }; writer.Write(new[] { new UpdateEntityCommand <TestModel>(new EntityEntry <TestModel>(updatedEntity, EntityEntryState.Updated)) }); var dbEntity = reader.AsQueryable().Where(e => e.Id == entity.Id).FirstOrDefault(); Assert.AreEqual("UpdateEntityCommandTests.UpdateEntity-Updated", dbEntity.Title); }
public void RemoveEntity() { var connection = TestConfiguration.GetConnection(); var writer = new CommandWriter <TestModel>(connection); var reader = new EntityReader <TestModel>(connection); var entity = new TestModel { Title = "RemoveEntityByIdCommandTests.RemoveEntity" }; writer.Write(new[] { new AddEntityCommand <TestModel>(new EntityEntry <TestModel>(entity, EntityEntryState.Added)) }); writer.Write(new[] { new RemoveEntityByIdCommand <TestModel>(entity.Id) }); var dbEntity = reader.AsQueryable().Where(e => e.Id == entity.Id).FirstOrDefault(); Assert.IsNull(dbEntity); }
static async Task Main(string[] args) { var cts = new CancellationTokenSource(10000); var file = new DstFile(File.OpenRead(args[0])); await file.Read(cts.Token); File.WriteAllText("out.txt", CommandWriter.Write(file), Encoding.UTF8); File.WriteAllText("out.svg", SvgWriter.Write(file), Encoding.UTF8); }
public async Task SetAsync <T>(string cacheKey, CacheEntry <T> cacheEntry) { await TryConfigureIndexes(); var command = new SetCommand(new DbCachedEntry { CacheKey = cacheKey, Expiry = cacheEntry.Expiry, Value = cacheEntry.Value }); await CommandWriter.WriteAsync(new[] { command }); }
public void AddEntity() { var connection = TestConfiguration.GetConnection(); var writer = new CommandWriter <TestModel>(connection); var entity = new TestModel { Title = "AddEntityCommandTests.AddEntity" }; writer.Write(new[] { new AddEntityCommand <TestModel>(new EntityEntry <TestModel>(entity, EntityEntryState.Added)) }); Assert.IsNotNull(entity.Id); }
public void CreateEntryWorkTaskModelWithNulls() { var client = CreateClient("QAS.Multiplatform.Demo.edmx"); var feedReader = new ResponseReader(client.GetSchemaAsync().Result); var commandWriter = new CommandWriter(client.GetSchemaAsync().Result); string xml = GetResourceAsString("WorkTaskModelWithNulls.xml"); var document = XDocument.Parse(xml).Root; var row = feedReader.GetData(xml).Single(); var entry = commandWriter.CreateEntry("WorkTaskModel", row).Entry; AssertElementsCountEqual(document, entry, "m", "properties"); AssertElementsContentEqual(document, entry, "d", "Id"); AssertElementsContentEqual(document, entry, "d", "StartDate", false); AssertElementsContentEqual(document, entry, "d", "EndDate", false); AssertElementsContentEqual(document, entry, "d", "State"); AssertElementsContentEqual(document, entry, "d", "WorkerId"); AssertElementsContentEqual(document, entry, "d", "CustomerId"); }
public void CreateEntryCustomerWithAddress() { var feedReader = new ResponseReader(_client.GetSchemaAsync().Result); var commandWriter = new CommandWriter(_client.GetSchemaAsync().Result); string xml = GetResourceAsString("SingleCustomerWithAddress.xml"); var document = XDocument.Parse(xml).Root; var row = feedReader.GetData(xml).Single(); var entry = commandWriter.CreateEntry("Customers", row).Entry; AssertElementsCountEqual(document, entry, "m", "properties"); AssertElementsContentEqual(document, entry, "d", "CustomerID"); AssertElementsContentEqual(document, entry, "d", "CompanyName"); AssertElementsContentEqual(document, entry, "d", "Address"); AssertElementsContentEqual(document, entry, "d", "Type"); AssertElementsContentEqual(document, entry, "d", "City1"); AssertElementsContentEqual(document, entry, "d", "Region"); AssertElementsContentEqual(document, entry, "d", "PostalCode"); AssertElementsContentEqual(document, entry, "d", "Country"); }
public void RemoveEntities() { var connection = TestConfiguration.GetConnection(); var writer = new CommandWriter <TestModel>(connection); var reader = new EntityReader <TestModel>(connection); var entities = new[] { new TestModel { Title = "RemoveEntityRangeCommandTests.RemoveEntities", DateTime = DateTime.UtcNow.AddDays(-1) }, new TestModel { Title = "RemoveEntityRangeCommandTests.RemoveEntities", DateTime = DateTime.UtcNow.AddDays(1) } }; writer.Write(new[] { new AddEntityCommand <TestModel>(new EntityEntry <TestModel>(entities[0], EntityEntryState.Added)), new AddEntityCommand <TestModel>(new EntityEntry <TestModel>(entities[1], EntityEntryState.Added)) }); writer.Write(new[] { new RemoveEntityRangeCommand <TestModel>(e => e.DateTime < DateTime.UtcNow) }); var removedEntity = reader.AsQueryable().Where(e => e.Id == entities[0].Id).FirstOrDefault(); Assert.IsNull(removedEntity); var nonRemovedEntity = reader.AsQueryable().Where(e => e.Id == entities[1].Id).FirstOrDefault(); Assert.IsNotNull(nonRemovedEntity); }
public async Task LoginAsync(UserStatus initialStatus = UserStatus.Online) { await @lock.WriterLockAsync(); try { if (IsLoggedIn) return; IConnection connection = null; ConnectionStream stream = null; CommandReader reader = null; CommandWriter writer = null; ResponseTracker responseTracker = null; IConnectableObservable<Command> commands = null; IDisposable commandsDisposable = null; int transferCount = 0; SocketEndPoint endPoint = SocketEndPoint.Parse("messenger.hotmail.com:1863"); string authTicket = null; while (authTicket == null) { connection = new SocketConnection(); await connection.ConnectAsync(endPoint); stream = new ConnectionStream(connection); writer = new CommandWriter(stream); reader = new CommandReader(stream, new Dictionary<string, Type> { { "VER", typeof(VersionCommand) }, { "CVR", typeof(ClientVersionCommand) }, { "USR", typeof(AuthenticateCommand) }, { "XFR", typeof(TransferCommand) }, { "SYN", typeof(SynchronizeCommand) }, { "SBS", typeof(SbsCommand) }, { "MSG", typeof(MessageCommand) }, { "LST", typeof(UserCommand) }, { "LSG", typeof(GroupCommand) }, { "BPR", typeof(UserPropertyCommand) }, { "BLP", typeof(PrivacySettingCommand) }, { "GTC", typeof(PrivacySettingCommand) }, { "CHG", typeof(ChangeStatusCommand) }, { "UBX", typeof(BroadcastCommand) }, { "PRP", typeof(LocalPropertyCommand) }, { "NLN", typeof(UserOnlineCommand) }, { "ILN", typeof(InitialUserOnlineCommand) }, { "FLN", typeof(UserOfflineCommand) }, { "UUX", typeof(SendBroadcastCommand) }, { "NOT", typeof(NotificationCommand) }, { "QNG", typeof(PingCommand) }, { "CHL", typeof(ChallengeCommand) }, { "ADC", typeof(AddContactCommand) }, { "REM", typeof(RemoveContactCommand) }, { "ADG", typeof(AddGroupCommand) }, { "RMG", typeof(RemoveGroupCommand) }, { "REG", typeof(RenameGroupCommand) }, { "QRY", typeof(AcceptChallengeCommand) }, { "RNG", typeof(RingCommand) }, { "SBP", typeof(ChangeUserPropertyCommand) }, { "IMS", typeof(EnableIMCommand) }, }); commands = reader.GetReadObservable().Publish(); responseTracker = new ResponseTracker(writer, commands); commandsDisposable = commands.Connect(); var versionCommand = new VersionCommand("MSNP12"); var versionResponse = await responseTracker.GetResponseAsync<VersionCommand>(versionCommand, defaultTimeout); if (versionResponse.Versions.Length == 0) throw new ProtocolNotAcceptedException(); var clientVersionCommand = new ClientVersionCommand { LocaleId = "0x0409", OsType = "winnt", OsVersion = "5.0", Architecture = "1386", LibraryName = "MSMSGS", ClientVersion = "5.0.0482", ClientName = "WindowsMessenger", LoginName = credentials.LoginName, }; await responseTracker.GetResponseAsync<ClientVersionCommand>(clientVersionCommand, defaultTimeout); var userCommand = new AuthenticateCommand("TWN", "I", credentials.LoginName); var userResponse = await responseTracker.GetResponseAsync(userCommand, new Type[] { typeof(AuthenticateCommand), typeof(TransferCommand) }, defaultTimeout); if (userResponse is AuthenticateCommand) { authTicket = (userResponse as AuthenticateCommand).Argument; } else if (userResponse is TransferCommand) { TransferCommand transferResponse = userResponse as TransferCommand; if (transferCount > 3) throw new InvalidOperationException("The maximum number of redirects has been reached."); transferCount++; endPoint = SocketEndPoint.Parse(transferResponse.Host); commandsDisposable.Dispose(); reader.Close(); writer.Close(); connection.Dispose(); } } PassportAuthentication auth = new PassportAuthentication(); string authToken = await auth.GetToken(credentials.LoginName, credentials.Password, authTicket); var authCommand = new AuthenticateCommand("TWN", "S", authToken); var authResponse = await responseTracker.GetResponseAsync<AuthenticateCommand>(authCommand, defaultTimeout); var synCommand = new SynchronizeCommand(syncTimeStamp1 ?? "0", syncTimeStamp2 ?? "0"); var synResponse = await responseTracker.GetResponseAsync<SynchronizeCommand>(synCommand, defaultTimeout); IDisposable syncCommandsSubscription = null; List<Command> syncCommands = null; if (synResponse.TimeStamp1 != syncTimeStamp1 || synResponse.TimeStamp2 != syncTimeStamp2) { syncCommands = new List<Command>(); Type[] syncTypes = new Type[] { typeof(MessageCommand), typeof(UserCommand), typeof(GroupCommand), typeof(LocalPropertyCommand), typeof(PrivacySettingCommand), }; syncCommandsSubscription = commands .Where(c => syncTypes.Contains(c.GetType())) .Catch(Observable.Empty<Command>()) .Subscribe(c => syncCommands.Add(c)); //if we're expecting users/groups, wait for them before we proceed if (synResponse.UserCount + synResponse.GroupCount > 0) { await commands .Where(c => c is UserCommand || c is GroupCommand) .Take(synResponse.UserCount + synResponse.GroupCount) .Timeout(defaultTimeout); } } UserCapabilities capabilities = 0; MSNObject displayPicture = MSNObject.Empty; if (LocalUser != null) { capabilities = LocalUser.Capabilities; displayPicture = LocalUser.DisplayPicture; } Command changeStatusCommand = new ChangeStatusCommand(User.StatusToString(UserStatus.Online), (uint)capabilities, displayPicture != MSNObject.Empty ? displayPicture.ToString() : "0"); await responseTracker.GetResponseAsync(changeStatusCommand, defaultTimeout); if (syncCommandsSubscription != null) syncCommandsSubscription.Dispose(); this.writer = writer; this.reader = reader; this.stream = stream; this.connection = connection; this.responseTracker = responseTracker; this.commands = commands; this.commandsDisposable = commandsDisposable; if (LocalUser == null) { LocalUser = new LocalUser(this, credentials.LoginName); userCache.Add(credentials.LoginName, new WeakReference(LocalUser)); } LocalUser.Status = initialStatus; SyncEvents syncEvents = null; if (syncCommands != null) { syncTimeStamp1 = synResponse.TimeStamp1; syncTimeStamp2 = synResponse.TimeStamp2; syncEvents = ProcessSyncCommands(syncCommands); } var commandsSafe = commands .Catch<Command, ConnectionErrorException>(tx => Observable.Empty<Command>()); commandsSafe.OfType<MessageCommand>().Subscribe(cmd => HandleMessages(cmd, connection)); commandsSafe.OfType<RingCommand>().Subscribe(cmd => HandleRings(cmd, connection)); commandsSafe.OfType<BroadcastCommand>().Subscribe(cmd => HandleBroadcasts(cmd, connection)); commandsSafe.OfType<NotificationCommand>().Subscribe(cmd => HandleNotifications(cmd, connection)); commandsSafe.OfType<AddContactCommand>().Subscribe(cmd => HandleNewUsers(cmd, connection)); commandsSafe.OfType<OutCommand>().Subscribe(cmd => HandleOut(cmd, connection)); commandsSafe.OfType<ChallengeCommand>().Subscribe(cmd => HandleChallenges(cmd, connection)); commandsSafe.OfType<UserOnlineCommand>().Subscribe(cmd => HandleOnlineUsers(cmd, connection)); commandsSafe.OfType<InitialUserOnlineCommand>().Subscribe(cmd => HandleOnlineUsers(cmd, connection)); commandsSafe.OfType<UserOfflineCommand>().Subscribe(cmd => HandleOfflineUsers(cmd, connection)); connection.Error += connection_Error; IsLoggedIn = true; OnLoggedIn(); OnUserStatusChanged(new UserStatusEventArgs(LocalUser, initialStatus, UserStatus.Offline, true)); if (syncEvents != null) RaiseSyncEvents(syncEvents); } finally { @lock.WriterRelease(); } }
void LogoutInner(LogoutReason reason, ConnectionErrorException connectionError) { if (!IsLoggedIn) return; connection.Error -= connection_Error; commandsDisposable.Dispose(); connection.Close(); reader = null; writer = null; connection = null; responseTracker = null; var statusChangeEvents = new List<UserStatusEventArgs>(); foreach (User user in UserLists.ForwardList.Users.Where(u => u.Status != UserStatus.Offline)) { UserStatus prevStatus = user.Status; user.Status = UserStatus.Offline; statusChangeEvents.Add(new UserStatusEventArgs(user, UserStatus.Offline, prevStatus, false)); } IsLoggedIn = false; OnLoggedOut(new LoggedOutEventArgs(reason, connectionError)); foreach (UserStatusEventArgs e in statusChangeEvents) OnUserStatusChanged(e); }
private static void Main(string[] args) { var file = new AssemblyWriter(); var meta = new AssemblyInfo { Version = "1.0.0.0", ID = Guid.NewGuid() }; file.AddMeta(meta); var typeinfo = file.CreateSection(AssemblySections.TypeInfo); var debuginfo = file.CreateSection(AssemblySections.DebugInfo); var ro = file.CreateSection(AssemblySections.ReadOnly); var data = file.CreateSection(AssemblySections.Code); ro.Raw = BitConverter.GetBytes(0x2A); var ass = new CommandWriter(); //inc-method at 0 ass.Add(OpCode.LOAD, (int)Registers.A, 0x2A); ass.Add(OpCode.INC, (int)Registers.A); ass.Add(OpCode.LOADRO, 0x0, (int)Registers.D); ass.Add(OpCode.PUSHRO, 0x0); ass.Add(OpCode.PUSHL, 9); ass.Add(OpCode.OUT, 0xABC, 2); // change foreground ass.Add(OpCode.PUSHL, 10); ass.Add(OpCode.OUT, 0xABC, 3); // change background ass.Add(OpCode.PUSHL, 'e'); ass.Add(OpCode.OUT, 0xABC, 1); // write e to console ass.Add(OpCode.PUSHL, ':'); ass.Add(OpCode.OUT, 0xABC, 1); // write : to console var inputloop = ass.MakeLabel(); ass.Add(OpCode.IN, 0xABC1, (int)Registers.C); // wait for input char // ass.Add(OpCode.JMP, inputloop); ass.Add(OpCode.PUSHL, '\n'); // write new line to console ass.Add(OpCode.OUT, 0xABC, 1); var loop = ass.MakeLabel(); ass.Add(OpCode.MOV, (int)Registers.ACC, (int)Registers.A); ass.Add(OpCode.INT, 0x123); // print registers ass.Add(OpCode.OUT, 0xABC, 0); //clear console //ass.Add(OpCode.JMP, loop); ass.Add(OpCode.OUT, 0xABC, 4); // Reset colors //Beep ass.Add(OpCode.PUSHL, 15000); ass.Add(OpCode.PUSHL, 1500); ass.Add(OpCode.OUT, 0xABC, 5); //.Add(OpCode.CALL, loop); data.Raw = ass.Save(); var vm = new VirtualMachine(Assembly.Load(file.Save())); vm.Run(); Utils.PrintRegisters(vm.Register); Console.WriteLine("Register: " + vm.ViewMemoryOf <Register>().ToHex()); Console.WriteLine("Stack: " + vm.ViewMemoryOf <Stack>().ToHex()); Console.ReadLine(); }
public async Task EvictAsync(string cacheKey) { await TryConfigureIndexes(); await CommandWriter.WriteAsync(new[] { new EvictCommand(cacheKey) }); }
public async Task CleanupAsync() { await TryConfigureIndexes(); await CommandWriter.WriteAsync(new[] { new CleanupCommand() }); }
public MongoDbCacheLayer(IMongoDbConnection connection) { EntityReader = new EntityReader <DbCachedEntry>(connection); CommandWriter = new CommandWriter <DbCachedEntry>(connection); IndexWriter = new EntityIndexWriter <DbCachedEntry>(connection); }
internal void Send(MqttCommand command) { ICommandWriter writer = new CommandWriter(); writer.Send(Connection, command); }