private async Task <object> SendChainFromWebSockets(AspNetWebSocketContext context) { var handler = new BlockChainHandler(); byte[] buffer = new byte[1024 * 1024]; ChainSerializer chainSerializer = new ChainSerializer(); var encode_tuple = chainSerializer.Encode(connector.GetLocalChain().BlockChain); ArraySegment <byte> segment = new ArraySegment <byte>(chainSerializer.ConcateByteArray(encode_tuple)); WebSocket socket = context.WebSocket; try { handler.OnOpen(); WebSocketReceiveResult receiveResult; while (socket.State == WebSocketState.Open) { do { receiveResult = await socket.ReceiveAsync( segment, CancellationToken.None); if (receiveResult.MessageType == WebSocketMessageType.Close) { await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); } } while (!receiveResult.EndOfMessage); await socket.SendAsync(segment, WebSocketMessageType.Binary, true, CancellationToken.None); } } catch (Exception ex) { log.Error("Error when respond blockchain " + ex.Message); throw new InvalidBlockException("Error when respond blockchain "); } finally { handler.OnClose(); } var processTask = handler.ProcessWebSocketRequestAsync(context); return(processTask); }
public SimpleKinClient() { _deviceInfo = new Information("KinCsharpClient", "Samsung9+", "Samsung", "Android"); _marketPlaceClient = new MarketPlaceClient("https://api.developers.kinecosystem.com/v1", _deviceInfo, AuthorizationHeaderValueGetter); Config config = _marketPlaceClient.Config().Result; UserId = Guid.NewGuid().ToString(); _keyPair = KeyPair.Random(); Dictionary <string, JwtSecurityKey> kinsKeys = new Dictionary <string, JwtSecurityKey>(); foreach (KeyValuePair <string, JwtKey> configJwtKey in config.JwtKeys) { kinsKeys.Add(configJwtKey.Key, new JwtSecurityKey(configJwtKey.Value.Algorithm, configJwtKey.Value.Key)); } _marketPlaceJwtProvider = new JwtProvider("kin", kinsKeys); _blockChainHandler = new BlockChainHandler(config); }
public SimpleKinClient(string horizonUrl, string networkId, string appId) { _deviceInfo = new Information("Kinny", "RYZENBBY", "Chrome", "Windows", "1.0.0"); _marketPlaceClient = new MarketPlaceClient("https://api.developers.kinecosystem.com/v1", _deviceInfo, AuthorizationHeaderValueGetter); Config config = _marketPlaceClient.Config().Result; Dictionary <string, JwtSecurityKey> kinsKeys = new Dictionary <string, JwtSecurityKey>(); foreach (KeyValuePair <string, JwtKey> configJwtKey in config.JwtKeys) { kinsKeys.Add(configJwtKey.Key, new JwtSecurityKey(configJwtKey.Value.Algorithm, configJwtKey.Value.Key)); } UserId = Guid.NewGuid().ToString(); _keyPair = KeyPair.Random(); _marketPlaceJwtProvider = new JwtProvider("kin", kinsKeys); _blockChainHandler = new BlockChainHandler(horizonUrl, networkId, appId); }
public BlockchainData(ref BlockChainHandler blockChainHandler) { this.prescriptions = new List <Prescription>(); this.BlockChainHandler = blockChainHandler; }
public static void Generate(ReportType reportType, ReportExt reportExt, DateTime begin, DateTime end, int personID, ref BlockChainHandler blockChainHandler) { WrongDataHandler dataHandler = new WrongDataHandler(); uIData = new UIData(reportExt, begin, end, personID, reportType); blockchainData = new BlockchainData(ref blockChainHandler); switch (uIData.ReportType) { case ReportType.PrescriptionsReport: if (dataHandler.WrongDataNotification(blockchainData.GetPrescriptionListForPatient(uIData.PersonID))) { throw new WrongDataHandler("Patient does not have any prescriptions"); } break; case ReportType.SoldMedicamentsReport: if (dataHandler.WrongDataNotification(blockchainData.GetPrescriptionListForPharmacist(uIData.PersonID))) { throw new WrongDataHandler("Pharmacist does not have any sold medicaments"); } break; default: throw new NotImplementedException(); } switch (uIData.FileFormat) { case ReportExt.PDF: GenerateFile generatePDF = new GeneratePDF(uIData.ReportType, blockchainData, uIData.PersonID, uIData.Begin, uIData.End); break; case ReportExt.CSV: GenerateFile generateCSV = new GenerateCSV(uIData.ReportType, blockchainData, uIData.PersonID, uIData.Begin, uIData.End); break; default: throw new NotImplementedException(); } }