public ActionResult TestEndpoint() { string responseStatus; string responseMessage; var response = new ResponseModel(); var transactionModel = EndpointHelper.GetModelFromRequest(Request.InputStream); // TODO: input string log if (EndpointHelper.CheckTransactionModelHash(transactionModel)) { var repository = new TestRepository(); var result = repository.SaveReservation(transactionModel.Reservation); responseStatus = result ? "SUCCESS" : "FAILED"; responseMessage = result ? "data saved" : "save data error"; } else { responseStatus = "FAILED"; responseMessage = "invalid hash"; } response.TransactionId = transactionModel.TransactionId; response.ResponseStatus = responseStatus; response.ResponseMessage = responseMessage; // TODO: response log return(Content(JsonConvert.SerializeObject(response))); }
private void OpenServiceHost() { _host = new ServiceHost(typeof(RemoteDesktopTestService)); _host.AddServiceEndpoint(typeof(IRemoteDesktopTestService), new NetTcpBinding(), EndpointHelper.GetEndpointUri("localhost", EndpointHelper.DefaultPort)); _host.Open(); }
void RegisterEndpointWideDefaults() { var endpointHelper = new EndpointHelper(new StackTrace()); if (endpointVersion == null) { endpointVersion = endpointHelper.GetEndpointVersion(); } if (endpointName == null) { endpointName = endpointHelper.GetDefaultEndpointName(); } Settings.SetDefault("EndpointName", endpointName); Settings.SetDefault("TypesToScan", scannedTypes); Settings.SetDefault("EndpointVersion", endpointVersion); Settings.SetDefault("Endpoint.SendOnly", false); Settings.SetDefault("Transactions.Enabled", true); Settings.SetDefault("Transactions.IsolationLevel", IsolationLevel.ReadCommitted); Settings.SetDefault("Transactions.DefaultTimeout", TransactionManager.DefaultTimeout); Settings.SetDefault("Transactions.SuppressDistributedTransactions", false); Settings.SetDefault("Transactions.DoNotWrapHandlersExecutionInATransactionScope", false); Settings.SetDefault <IConfigurationSource>(configurationSourceToUse); }
public void Parse_Localhost_With_Port() { var ep = EndpointHelper.ParseEndPoint("localhost:1234"); Assert.Equal(1234, ep.Port); Assert.Equal(IPAddress.Loopback, ep.Address); }
public void Invalid_Addresses_Should_Throw() { Assert.Throws <ArgumentNullException>(() => EndpointHelper.ParseEndPoint(null)); Assert.Throws <ArgumentException>(() => EndpointHelper.ParseEndPoint("address:port")); Assert.Throws <SocketException>(() => EndpointHelper.ParseEndPoint("1234.56.78.9:1111")); Assert.Throws <ArgumentOutOfRangeException>(() => EndpointHelper.ParseEndPoint("10.0.10.10:987654")); }
public void Parse_IP_With_Port() { var ep = EndpointHelper.ParseEndPoint("10.0.10.20:1234"); Assert.Equal(1234, ep.Port); Assert.Equal(new byte[] { 10, 0, 10, 20 }, ep.Address.GetAddressBytes()); }
public void Parse_IP_Without_Port() { var ep = EndpointHelper.ParseEndPoint("10.0.10.10", 11211); Assert.Equal(11211, ep.Port); Assert.Equal(new byte[] { 10, 0, 10, 10 }, ep.Address.GetAddressBytes()); }
public void Parse_Localhost_Without_Port() { var ep = EndpointHelper.ParseEndPoint("localhost", 11211); Assert.Equal(11211, ep.Port); Assert.Equal(IPAddress.Loopback, ep.Address); }
public void Initialize() { Guid invalidSessionId = Guid.NewGuid(); _endpointHelper = new EndpointHelper(); _endpointHelper.Setup().SetAuthenticationToken(invalidSessionId.ToString()); }
/// <summary> /// Creates the configuration object /// </summary> internal Configure BuildConfiguration() { if (scannedTypes == null) { var directoryToScan = AppDomain.CurrentDomain.BaseDirectory; if (HttpRuntime.AppDomainAppId != null) { directoryToScan = HttpRuntime.BinDirectory; } ScanAssembliesInDirectory(directoryToScan); } scannedTypes = scannedTypes.Union(Configure.GetAllowedTypes(Assembly.GetExecutingAssembly())).ToList(); if (HttpRuntime.AppDomainAppId == null) { var baseDirectory = directory ?? AppDomain.CurrentDomain.BaseDirectory; var hostPath = Path.Combine(baseDirectory, "NServiceBus.Host.exe"); if (File.Exists(hostPath)) { scannedTypes = scannedTypes.Union(Configure.GetAllowedTypes(Assembly.LoadFrom(hostPath))).ToList(); } } Settings.SetDefault("TypesToScan", scannedTypes); Configure.ActivateAndInvoke <INeedInitialization>(scannedTypes, t => t.Customize(this)); UseTransportExtensions.SetupTransport(this); var container = customBuilder ?? new AutofacObjectBuilder(); Settings.SetDefault <IConfigurationSource>(configurationSourceToUse); var endpointHelper = new EndpointHelper(new StackTrace()); if (endpointVersion == null) { endpointVersion = endpointHelper.GetEndpointVersion(); } if (endpointName == null) { endpointName = endpointHelper.GetDefaultEndpointName(); } Settings.SetDefault("EndpointName", endpointName); Settings.SetDefault("EndpointVersion", endpointVersion); if (publicReturnAddress != null) { Settings.SetDefault("PublicReturnAddress", publicReturnAddress); } container.RegisterSingleton(typeof(Conventions), conventionsBuilder.Conventions); Settings.SetDefault <Conventions>(conventionsBuilder.Conventions); return(new Configure(Settings, container, registrations, Pipeline)); }
private void ConnectToService() { var binding = new NetTcpBinding(); var remoteAddress = EndpointHelper.GetEndpointUri(_server.Name, EndpointHelper.DefaultPort); _channelFactory = new ChannelFactory <IRemoteDesktopTestService>(binding, remoteAddress); _testService = _channelFactory.CreateChannel(); }
public void EndpointHelperDoesNotThrowsErrorWithValidPlatformRegionCombination(Platform platform, Region region) { //Given var helper = new EndpointHelper(); //When/Then Assert.DoesNotThrow(delegate { helper.GetUrl("/status", platform, region); }); }
public void EndpointHelperRequiresResource() { //Given var helper = new EndpointHelper(); //When Assert.Throws <System.ArgumentException>(delegate { helper.GetUrl(string.Empty); }); }
public void Initialize() { _fakeAccountHelper = new FakeAccountHelper(); Guid expiredSessionId = _fakeAccountHelper.GenerateValidExpiredCredentials(); _endpointHelper = new EndpointHelper(); _endpointHelper.Setup().SetAuthenticationToken(expiredSessionId.ToString()); }
public void EndpointHelperThrowsErrorWithInvalidPlatformRegionCombination(Platform platform, Region region) { //Given var helper = new EndpointHelper(); //When/Then Assert.Throws <System.ArgumentException>(delegate { helper.GetUrl("/status", platform, region); }); }
public static async Task <string> WriteRecordAsync(IApiClient apiClient, Schema schema, Record record, IServerStreamWriter <RecordAck> responseStream) { // debug Logger.Debug($"Starting timer for {record.RecordId}"); var timer = Stopwatch.StartNew(); try { var endpoint = EndpointHelper.GetEndpointForSchema(schema); if (endpoint == null) { throw new Exception($"Endpoint {schema.Id} does not exist"); } // debug Logger.Debug(JsonConvert.SerializeObject(record, Formatting.Indented)); // semaphore await WriteSemaphoreSlim.WaitAsync(); // write records var errorMessage = await endpoint.WriteRecordAsync(apiClient, schema, record, responseStream); if (!string.IsNullOrWhiteSpace(errorMessage)) { Logger.Error(new Exception(errorMessage), errorMessage); } timer.Stop(); Logger.Debug($"Acknowledged Record {record.RecordId} time: {timer.ElapsedMilliseconds}"); return(""); } catch (Exception e) { Logger.Error(e, $"Error writing record {e.Message}"); // send ack var ack = new RecordAck { CorrelationId = record.CorrelationId, Error = e.Message }; await responseStream.WriteAsync(ack); timer.Stop(); Logger.Debug($"Failed Record {record.RecordId} time: {timer.ElapsedMilliseconds}"); return(e.Message); } finally { WriteSemaphoreSlim.Release(); } }
public Plugin(HttpClient client = null) { _injectedClient = client ?? new HttpClient(); _server = new ServerStatus { Connected = false, WriteConfigured = false }; _endpointHelper = new EndpointHelper(); }
public void EndpointHelperAcceptsRegionArgument() { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl("/status", region: Region.NorthAmerica); //Then Assert.True(url.Contains("na"), "url does not contain 'na': {0}", url); }
public void EndpointHelperProvidesDefaultPlatform() { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl("/status"); //Then Assert.True(url.Contains("pc")); }
public void EndpointHelperAcceptsPlatformArgument() { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl("/status", Platform.Xbox); //Then Assert.True(url.Contains("xbox")); }
public void EndpointHelperAddsLeadingSlashIfMissing() { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl("status"); //Then Assert.True(url.Contains("/status")); }
public void EndpointHelperFormatsUrl(string resource, Platform platform, Region region, string expected) { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl(resource, platform, region); //Then Assert.AreEqual(expected, url); }
public void EndpointHelperAcceptsResource() { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl("/status"); //Then Assert.True(url.EndsWith("/status")); }
public void Initialize() { _fakeAccountHelper = new FakeAccountHelper(); Guid validSessionId = _fakeAccountHelper.GenerateValidCredentials(); _endpointHelper = new EndpointHelper(); _inviteLink = _endpointHelper.Setup() .SetAuthenticationToken(validSessionId.ToString()) .CreateHouseholdInviteLink() .ReturnHouseholdLink(); }
public void EndpointHelperProvidesDefaultRegion() { //Given var helper = new EndpointHelper(); //When var url = helper.GetUrl("/status"); //Then Assert.True(url.Contains("eu"), "url does not contain 'eu': {0}", url); }
public void Initialize() { _fakeAccountHelper = new FakeAccountHelper(); Guid validSessionId = _fakeAccountHelper.GenerateValidCredentials(); _endpointHelper = new EndpointHelper(); _endpointHelper.Setup() .SetAuthenticationToken(validSessionId.ToString()); _getHouseholdResponse = _endpointHelper.GetHousehold(); }
private async void GetAccountInfoAsync() { try { OperationResult result = await EndpointHelper.GetAccountInfo(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private async void StartServiceAsync() { try { OperationResult result = await EndpointHelper.StartServiceAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Attempt to remove a node from the connected network nodes by given the ipAddress. /// </summary> /// <param name="ipAddress"></param> /// <returns>Delete successfully or not</returns> public async Task <bool> RemovePeerAsync(string ipAddress) { if (!EndpointHelper.TryParse(ipAddress, out var endpoint)) { return(false); } var url = GetRequestUrl(_baseUrl, $"api/net/peer?address={endpoint}"); return(await _httpService.DeleteResponseAsObjectAsync <bool>(url)); }
/// <summary> /// Deletes a record from the RJG Website /// </summary> /// <param name="schema"></param> /// <param name="record"></param> /// <param name="endpointHelper"></param> /// <param name="client"></param> /// <returns></returns> public static async Task <string> DeleteRecord(Schema schema, Record record, EndpointHelper endpointHelper, RequestHelper client) { Dictionary <string, object> recObj; var endpoint = endpointHelper.GetEndpointForName(schema.Id); if (String.IsNullOrEmpty(endpoint.MetaDataPath)) { try { recObj = JsonConvert.DeserializeObject <Dictionary <string, object> >(record.DataJson); if (recObj.ContainsKey("id")) { if (recObj["id"] != null) { // delete record // try each endpoint foreach (var path in endpoint.ReadPaths) { try { var uri = String.Format("{0}/{1}", path, recObj["id"]); var response = await client.DeleteAsync(uri); response.EnsureSuccessStatusCode(); Logger.Info("Deleted 1 record."); return(""); } catch (Exception e) { Logger.Error(e, e.Message); } } } return("Could not delete record with no id."); } return("Key 'id' not found on requested record to delete."); } catch (Exception e) { Logger.Error(e, e.Message); return(e.Message); } } // code for modifying forms would go here if needed but currently is not needed return("Write backs are only supported for Classes."); }