public override void SelectFromProxyHandler(SelectMessageReader request) { List <List <long> > cellIds = request.cellIds; //利用发送来的信息构造condition Table table = new Table(request.columnNameList, request.columnTypeList); Condition con = new Condition(table, request.condition); List <List <long> > result = new List <List <long> >(); List <Thread> threads = new List <Thread>(); foreach (List <long> cellId in cellIds) { if (Global.CloudStorage.GetServerIdByCellId(cellId[0]) == Global.MyServerId) //这一行第一列存储于本服务器 { //每行开一个线程处理 RowMessage rm = new RowMessage(); rm.cellId = cellId; rm.con = con; rm.types = request.columnTypeList; rm.usedIndex = request.usedIndex; rm.result = result; Thread thread = new Thread(new ParameterizedThreadStart(filter)); threads.Add(thread); thread.Start(rm); } } foreach (Thread thr in threads) { thr.Join(); } //此时已经处理完结果 Global.CloudStorage.SelectFromServerToDatabaseProxy(0, new SelectResultResponseWriter(Global.MyServerId, result)); }
public override void TruncateFromProxyHandler(TruncateMessageReader request) { List <List <long> > cellIds = request.cellIds; List <Thread> threads = new List <Thread>(); foreach (List <long> cellId in cellIds) { if (Global.CloudStorage.GetServerIdByCellId(cellId[0]) == Global.MyServerId) //这一行第一列存储于本服务器 { RowMessage rm = new RowMessage(); rm.cellId = cellId; //每行开一个线程处理 Thread thread = new Thread(new ParameterizedThreadStart(TruncateThread)); threads.Add(thread); thread.Start(rm); } } foreach (Thread thr in threads) { thr.Join(); } //此时已经处理完结果 Global.CloudStorage.TruncateFromServerToDatabaseProxy(0, new TruncateResponceWriter(Global.MyServerId)); }
private void TruncateThread(Object rowMessage) { RowMessage rm = (RowMessage)rowMessage; foreach (long id in rm.cellId) { Global.LocalStorage.RemoveCell(id); } }
public async Task MessagePublishedToBue(string message) { object rowmessage = new RowMessage { Message = message }; await StartEndpoint.endpointInstance.Publish(rowmessage, new PublishOptions()) .ConfigureAwait(false); }
private void DeleteThread(Object rowMessage) { RowMessage rm = (RowMessage)rowMessage; List <Element> row = Global.CloudStorage.GetRowToDatabaseServer( Global.CloudStorage.GetServerIdByCellId(rm.cellId[0]), new GetRowMessageWriter(rm.cellId)).row; List <Object> values = FieldType.getValues(row, rm.types); if (rm.con.getResult(values)) { rm.result.Add(rm.cellId); } foreach (long id in rm.cellId) { Global.LocalStorage.RemoveCell(id); } }
/// <summary> /// 在线程内对某一行进行判断 /// </summary> /// <param name="cellId"></param> private void filter(Object rowMessage) { RowMessage rm = (RowMessage)rowMessage; List <Element> row = Global.CloudStorage.GetRowToDatabaseServer( Global.CloudStorage.GetServerIdByCellId(rm.cellId[0]), new GetRowMessageWriter(rm.cellId)).row; List <Object> values = FieldType.getValues(row, rm.types); if (rm.con.getResult(values)) { List <long> cellId = new List <long>(); foreach (int index in rm.usedIndex) { cellId.Add(rm.cellId[index]); } rm.result.Add(cellId); } }
public static WorldMessage ToWorldMessage(WorldData worldData) { int xLenght = worldData.TileArray.GetLength(0); int yLenght = worldData.TileArray.GetLength(1); WorldMessage worldMessage = new WorldMessage(); for (int y = 0; y < yLenght; y++) { RowMessage rowMessage = new RowMessage(); for (int x = 0; x < xLenght; x++) { TileDataMessage tileDataMessage = new TileDataMessage(); TileData tileData = worldData.TileArray[x, y]; tileDataMessage.tileType = (int)tileData.TileType; tileDataMessage.enemyCount = tileData.EnemyCount; rowMessage.rows.Add(tileDataMessage); } worldMessage.TileArray.Add(rowMessage); } return(worldMessage); }
// MessagePublishedToBus static async Task MessagePublishedToBus(string message, string EndpointName) { var endpointConfiguration = new EndpointConfiguration(EndpointName); endpointConfiguration.EnableInstallers(); endpointConfiguration.SendFailedMessagesTo("error"); // Transport endpointConfiguration.UseTransport <MsmqTransport>(); // Persistence var persistence = endpointConfiguration.UsePersistence <SqlPersistence>(); var connection = @"Data Source=RIPANPC\SqlExpress;Initial Catalog=TestMsmqDB;UID=sa;Password=Password123;Integrated Security=True"; persistence.SqlVariant(SqlVariant.MsSqlServer); persistence.ConnectionBuilder( connectionBuilder: () => { return(new SqlConnection(connection)); }); var subscriptions = persistence.SubscriptionSettings(); subscriptions.CacheFor(TimeSpan.FromDays(1)); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); var rowmessage = new RowMessage { Message = message }; await endpointInstance.Publish(rowmessage) .ConfigureAwait(false); await endpointInstance.Stop() .ConfigureAwait(false); }