private static async Task <bool> I_GetUpdate <ValueType, KeyType>( this IAsyncOprations Client, Table <ValueType, KeyType> Table, Action <ValueType> MakeingUpdate, Action <KeyType> Deleted, bool IsPartOfTable) where KeyType : IComparable <KeyType> { if (Table._UpdateAble == null) { Table._UpdateAble = new UpdateAbles <KeyType>( Table.BasicActions.UpdateCode, Table.BasicActions.Items.Select((c) => (Table.GetKey(c.Value), c.UpdateCode))); } var Result = false; await Client.SendData(Table.UpdateAble.UpdateCode.Value); //1 var LastUpdateCode = await Client.GetData <ulong>(); //2 if (Table.UpdateAble.UpdateCode.Value != LastUpdateCode) { var ServerItemsCount = await Client.GetData <int>();//3 var Remote = new IRemoteUpdateReciver <ValueType, KeyType>( Client, Table, null, null, IsPartOfTable, ServerItemsCount); await Client.Remote(Remote, async (Remote) => await Remote.MakeUpdate(LastUpdateCode)); } return(Result); }
private static async Task I_SendUpdate <ValueType, KeyType> (this IAsyncOprations Client, Table <ValueType, KeyType> Table, UpdateAble <KeyType>[] UpdateCodes, Func <KeyType, Task <ValueType> > GetItem, bool IsPartOfTable) where KeyType : IComparable <KeyType> { var LastUpdateCode = await Client.GetData <ulong>(); //1 await Client.SendData(Table.UpdateAble.UpdateCode.Value); //2 if (Table.UpdateAble.UpdateCode < LastUpdateCode) { LastUpdateCode = 0; } if (Table.UpdateAble.UpdateCode != LastUpdateCode) { await Client.SendData(Table.UpdateAble.UpdateCodes.Length);//3 var Remote = new IRemoteUpdateSender <ValueType, KeyType>( Client, Table, UpdateCodes, GetItem, IsPartOfTable); await Client.Remote(Remote); } }
public async Task Response() { while (await Link.GetCondition()) { var ServiceName = await Link.GetData <AddressType>(); var Pos = System.Array.BinarySearch(ServicesAddress, ServiceName); await Services[Pos](); } }
public async Task Response(AddressType EndResponse) { while (true) { var ServiceAddress = await Link.GetData <AddressType>(); if (ServiceAddress.Equals(EndResponse)) { return; } await Services[ServiceAddress](); } }
public IRemoteUpdateSender( IAsyncOprations Client, Table <ValueType, KeyType> Table, UpdateAble <KeyType>[] UpdateCodes, Func <KeyType, Task <ValueType> > GetItem, bool IsPartOfTable) { this.Client = Client; this.Table = Table; this.UpdateCodes = UpdateCodes; this.GetItem = GetItem; this.IsPartOfTable = IsPartOfTable; if (IsPartOfTable) { PartTable = (PartOfTable <ValueType, KeyType>)Table; ParentTable = PartTable.Parent; Table.MoveRelations = ParentTable.MoveRelations; } GetUpdateCodeAtPos = async(c) => UpdateCodes[c].UpdateCode; IsExistAtParent = async(c) => ParentTable.IsExist(c); Func <UpdateAble <KeyType>[], Task> SendUpdate = async(MyUpCodes) => { var IsPartOfTable = this.IsPartOfTable; var len = MyUpCodes.Length; await Client.SendData(len); for (int i = 0; i < len; i++) { var MyUpCode = MyUpCodes[i]; await Client.SendData(MyUpCode.UpdateCode); if (IsPartOfTable) { await Client.SendData(ParentTable.UpdateAble[MyUpCode.Key].UpdateCode); } } for (int i = 0; i < len; i++) { if (await Client.GetData <bool>()) { await Client.SendData(await GetItem(MyUpCodes[i].Key)); } } }; UpdateFromPosToUpCode = async(Pos, ClientUpCode) => { var MyUpCodes = UpdateCodes. Skip(Pos). TakeWhile((c) => ClientUpCode >= c.UpdateCode).ToArray(); await SendUpdate(MyUpCodes); }; UpdateFromPosToEnd = async(Pos) => { var MyUpCodes = UpdateCodes.Skip(Pos).ToArray(); await SendUpdate(MyUpCodes); }; #if DEBUG_UpdateAble Debuger = async() => { await Client.SendData(Table.UpdateAble.UpdateCodes); //1 await Client.SendData(Table.KeysInfo.Keys.ToArray()); //2 }; #endif }
public IRemoteUpdateReciver( IAsyncOprations Client, Table <ValueType, KeyType> Table, UpdateAble <KeyType>[] UpdateCodes, Func <KeyType, Task <ValueType> > GetItem, bool IsPartOfTable, int ServerItemsCount) : base(Client, Table, UpdateCodes, GetItem, IsPartOfTable) { this.ServerItemsCount = ServerItemsCount; EndPos = Math.Min(Table.UpdateAble.UpdateCodes.Length, ServerItemsCount) - 1; UpdateFromPosToUpCode = async(Pos, ClientUpCode) => { await UpdateNextItems(); }; UpdateFromPosToEnd = async(Pos) => { await UpdateNextItems(); }; #if DEBUG_UpdateAble Debuger = async() => { { var ClientUpdates = Table.UpdateAble.UpdateCodes; var ServerUpdates = await Client.GetData(ClientUpdates);//1 if (ServerUpdates.Length != ClientUpdates.Length) { throw new FormatException("Updates are wrong. Count is Wrong."); } for (int i = 0; i < ServerUpdates.Length; i++) { var ClientUpdate = ClientUpdates[i]; var ServerUpdate = ServerUpdates[i]; if (ClientUpdate.Key.CompareTo(ServerUpdate.Key) != 0) { throw new FormatException("Updates are wrong. key is wrong."); } if (ClientUpdate.UpdateCode != ServerUpdate.UpdateCode) { throw new FormatException("Updates are wrong. Update Code is wrong."); } } } { var ClientDatas = Table.KeysInfo.Keys.ToArray(); var ServerDatas = await Client.GetData(ClientDatas);//2 if (ServerDatas.Length != ClientDatas.Length) { throw new FormatException("Updates are wrong. Count is Wrong."); } for (int i = 0; i < ServerDatas.Length; i++) { var ClientData = ClientDatas[i]; var ServerData = ServerDatas[i]; if (ClientData.CompareTo(ServerData) != 0) { throw new FormatException("Updates are wrong. key is wrong."); } } } }; #endif }