public async Task <IActionResult> Create([FromForm] DTO.File file) { try { byte[] content; using (MemoryStream stream = new MemoryStream()) { file.LogFile.CopyTo(stream); content = stream.ToArray(); } string response = await ApiClientHelper.ExecuteMultipartPostAsync($"{ApiClientHelper.FileUploadUrl}", content); DTO.Import import = JsonConvert.DeserializeObject <DTO.Import>(response); messageType = "success"; message = $"File imported with {import.SuccessCount} rows successfuly processed, and {import.ErrorCount} rows with error."; } catch (Exception ex) { messageType = "error"; message = $"Something went wrong: {ex.Message}"; } finally { ((Controller)this).DisplayTempData(messageType, message); } return(RedirectToAction("Index")); }
public async Task <IEnumerable <Photo> > GetByAlbumId(int albumId) { var url = $@"albums/{albumId}/photos"; var photos = await ApiClientHelper.GetAll <Photo>(url); return(photos); }
public async Task DataGrid_EndToEnd_ReadTotal() { var workspaceId = Config.WorkSpaceId; var auditQuery = new AuditQuery { ActionTypes = new List <AuditActionId> { AuditActionId.DocumentQuery }, StartTime = DateTime.MinValue, EndTime = DateTime.UtcNow, WorkspaceId = workspaceId }; // However we grab this for testing... var apiClientHelper = new ApiClientHelper(); var auditLogObjectManager = apiClientHelper.GetKeplerServiceReference <IExternalAuditLogObjectManager>(); //using (var auditLogObjectManager = TestUtilities.GetServicesManager().CreateProxy<IExternalAuditLogObjectManager>(ExecutionIdentity.System)) // Mock it up for the implementation var mockFactory = new Mock <IAuditLogObjectManagerFactory>(); mockFactory.Setup(m => m.GetManager()).Returns(() => auditLogObjectManager.Value); var dataGridWorkspaceAuditService = DataGridEndToEnd.SetUpWorkspaceAuditService(mockFactory.Object); var result = await dataGridWorkspaceAuditService.ReadTotalAuditsForHourAsync(workspaceId, auditQuery.StartTime, auditQuery.EndTime, auditQuery.ActionTypes); Assert.Pass($"Test Passed - ResultCount {result}"); }
public async Task <IEnumerable <Comment> > GetByPhotoId(int photoId) { var url = $@"posts/{photoId}/comments"; var comments = await ApiClientHelper.GetAll <Comment>(url); return(comments); }
public async Task <IActionResult> Edit(long importId, int page, [FromForm] DTO.LogRowMismatch entity) { try { string responseData = await ApiClientHelper.ExecutePostAsync($"{ApiClientHelper.LogRowMismatchesUrl}", JsonConvert.SerializeObject(entity, new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat, NullValueHandling = NullValueHandling.Ignore })); bool converted = bool.Parse(responseData); messageType = (converted ? "success" : "warning"); message = $"Log row{ (converted ? "" : " not") } converted to Row."; } catch (Exception ex) { messageType = "error"; message = $"Something went wrong: {ex.Message}"; } finally { ((Controller)this).DisplayTempData(messageType, message); } return(RedirectToAction("index", new { importId = importId, page = page })); }
// GET: LogRowMismatches public async Task <IActionResult> Index(DTO.LogRow entity = null, long importId = 0, int page = 0) { if (null == entity) { entity = new DTO.LogRow(); } string[] data = { $"importId={HttpUtility.UrlEncode(importId.ToString())}", $"ipAddress={HttpUtility.UrlEncode(entity.IpAddress)}", $"responseCode={HttpUtility.UrlEncode(entity.ResponseCode.ToString())}", $"when={HttpUtility.UrlEncode(entity.Date.ToString())}", $"userAgent={HttpUtility.UrlEncode(entity.UserAgent)}", $"method={HttpUtility.UrlEncode(entity.Method.ToString())}", $"page={HttpUtility.UrlEncode(page.ToString())}" }; string responseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.LogRowFilter}?{string.Join("&", data)}"); string userAgentsResponseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.UserAgentsUrl}"); ViewBag.UserAgents = JsonConvert.DeserializeObject <List <DTO.UserAgent> >(userAgentsResponseData).Select(i => new SelectListItem { Text = i.Name, Value = i.Name }); ViewBag.Methods = SettingsManager.Current.HttpMethods; return(View(JsonConvert.DeserializeObject <List <DTO.LogRow> >(responseData))); }
public async Task <IEnumerable <Album> > GetAllAlbums() { var url = "albums"; var albums = await ApiClientHelper.GetAll <Album>(url); return(albums); }
public async Task InvokeAsync(HttpContext httpContext) { var filtered = new string[] { ".png", ".jpg", ".js", ".css", ".map", "sockjs-node" }; foreach (var filter in filtered) { if (httpContext.Request.Path.Value.Contains(filter)) { await _next(httpContext); return; } } var isFromProxtNginx = httpContext.Request.Headers["X-NginX-Proxy"].Any() ? Convert.ToBoolean(httpContext.Request.Headers["X-NginX-Proxy"]) : false; if (isFromProxtNginx) { var externalHostName = httpContext.Request.Headers["ExternalHost"].ToString().RemovePreFix("http://", "https://").RemovePostFix("/"); var tenant = await ApiClientHelper.GetTenantFromExternalDomain(externalHostName); if (tenant == null) { await httpContext.Response.WriteAsync("Pastikan Anda memasukan Url Website yang benar."); } httpContext.Items.Add(HttpContextConstant.TENANCY_NAME, tenant.TenancyName); } else { var domainFormatConfiguration = AppSettingConfigurationHelper.GetSection("DomainFormat").Value; var hostName = httpContext.Request.Headers["Host"].ToString().RemovePreFix("http://", "https://").RemovePostFix("/"); var domainFormat = domainFormatConfiguration.RemovePreFix("http://", "https://").Split(':')[0].RemovePostFix("/"); var result = new FormattedStringValueExtracter().Extract(hostName, domainFormat, true, '/'); var tenancyName = string.Empty; if (!result.IsMatch || !result.Matches.Any()) { await httpContext.Response.WriteAsync("Pastikan Anda memasukan Url Website yang benar."); } tenancyName = result.Matches[0].Value; if (string.Equals(tenancyName, "www", StringComparison.OrdinalIgnoreCase)) { await httpContext.Response.WriteAsync("Pastikan Anda memasukan Url Website yang benar."); } if (await ApiClientHelper.TenantIsExist(tenancyName) == false) { await httpContext.Response.WriteAsync("Pastikan Anda memasukan Url Website yang benar."); } httpContext.Items.Add(HttpContextConstant.TENANCY_NAME, tenancyName); } await _next(httpContext); }
public async Task PingAsync() { var apiClientHelper = new ApiClientHelper(); var auditLogObjectManager = apiClientHelper.GetKeplerServiceReference <IExternalAuditLogObjectManager>(); using (var proxy = auditLogObjectManager.Value) { var result = await proxy.PingAsync(); } }
public async Task <IActionResult> Delete(long?id, long importId, int page) { if (id == null) { return(NotFound()); } await ApiClientHelper.ExecuteDeleteAsync($"{ApiClientHelper.LogRowUrl}/{id}"); ((Controller)this).DisplayTempData("warning", $"Log row deleted successfuly."); return(RedirectToAction("index", new { importId = importId, page = page })); }
public void Setup() { var apiClientHelper = new ApiClientHelper(); this.agentManagerProxy = apiClientHelper.GetKeplerServiceReference <IAgentManager>().Value; var connectionFactory = TestUtilities.GetIntegrationConnectionFactory(); var agentRepository = new AgentRepository(connectionFactory); var logger = TestUtilities.GetMockLogger(); this.agentManagerService = new AgentManagerService(this.agentManagerProxy, agentRepository, logger.Object); }
// GET: LogRowMismatches/Delete/5?importId={0}&page={1} public async Task <IActionResult> Delete(long?id, long importId, int page) { if (id == null) { ((Controller)this).DisplayTempData("warning", "Sorry! We can't find this Log Error you are trying to delete! Maybe you've already deleted it, didn't you?"); return(Redirect(Request.Headers["Referer"].ToString())); } await ApiClientHelper.ExecuteDeleteAsync($"{ApiClientHelper.LogRowMismatchesUrl}/{id}"); ((Controller)this).DisplayTempData("warning", $"Log row with error deleted successfuly."); return(RedirectToAction("index", new { importId = importId, page = page })); }
// GET: Imports/Detail/5 public async Task <IActionResult> Detail(long?id) { if (id == null) { return(NotFound()); } string responseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.ImportsUrl}/{id}"); DTO.Import import = JsonConvert.DeserializeObject <DTO.Import>(responseData); if (import == null) { return(NotFound()); } return(View(import)); }
// GET: LogRowMismatches/Edit/5 public async Task <IActionResult> Edit(long?id, long importId, int page) { if (id == null) { return(NotFound()); } string responseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.LogRowMismatchesUrl}/{id}"); DTO.LogRowMismatch row = JsonConvert.DeserializeObject <DTO.LogRowMismatch>(responseData); if (row == null) { return(NotFound()); } return(View(row)); }
// GET: Imports public async Task <IActionResult> Index(DTO.Import entity = null) { if (null == entity) { entity = new DTO.Import(); } string[] data = { $"success={HttpUtility.UrlEncode(entity.SuccessCount.ToString())}", $"error={HttpUtility.UrlEncode(entity.ErrorCount.ToString())}", $"fileName={HttpUtility.UrlEncode(entity.FileName)}", $"when={HttpUtility.UrlEncode(entity.When.ToString("MM-dd-yyyy hh:mm:ss"))}" }; string responseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.ImportsFilter}?{string.Join("&", data)}"); return(View(JsonConvert.DeserializeObject <List <DTO.Import> >(responseData))); }
// GET: LogRowMismatches public async Task <IActionResult> Index(DTO.LogRowMismatch entity = null, long importId = 0, int page = 0) { if (null == entity) { entity = new DTO.LogRowMismatch(); } string[] data = { $"importId={HttpUtility.UrlEncode(importId.ToString())}", $"exception={HttpUtility.UrlEncode(entity.ThrownException)}", $"row={HttpUtility.UrlEncode(entity.Row)}", $"page={HttpUtility.UrlEncode(page.ToString())}" }; string responseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.LogRowMismatchesFilter}?{string.Join("&", data)}"); return(View(JsonConvert.DeserializeObject <List <DTO.LogRowMismatch> >(responseData))); }
public async Task <IActionResult> Edit(long?id, long importId, int page) { if (id == null) { return(NotFound()); } string responseData = await ApiClientHelper.ExecuteGetAsync($"{ApiClientHelper.LogRowUrl}/{id}"); DTO.LogRow row = JsonConvert.DeserializeObject <DTO.LogRow>(responseData); if (row == null) { return(NotFound()); } ViewBag.Methods = SettingsManager.Current.HttpMethods; ViewBag.UtcOffsetRange = SettingsManager.Current.UtcOffsetRange; return(View(row)); }
public async Task ExecuteAsync() { var apiClientHelper = new ApiClientHelper(); var auditLogObjectManager = apiClientHelper.GetKeplerServiceReference <IExternalAuditLogObjectManager>(); using (var proxy = auditLogObjectManager.Value) { var pivotSettings = new PivotSettings() { ObjectSetQuery = new Query( "(('Action' IN CHOICE [1057247])) AND (('Timestamp' >= 0001-01-01T00:00:00.00Z)) AND (('Timestamp' <= 2018-07-24T18:47:21.59Z))", new List <Sort>()), ArtifactTypeID = 1057150, GroupBy = new FieldRef(1057179) }; var result = await proxy.ExecuteAsync(1039923, pivotSettings, new CancellationToken(), new NonCapturingProgress <string>()); } }
public async Task DataGrid_EndToEnd_ReadAudits() { var workspaceId = Config.WorkSpaceId; var auditQuery = new AuditQuery { ActionTypes = new List <AuditActionId> { AuditActionId.DocumentQuery }, StartTime = DateTime.MinValue, EndTime = DateTime.UtcNow, WorkspaceId = workspaceId }; var queryBatch = new AuditQueryBatch { Query = auditQuery, Size = 50, Start = 0 }; // However we grab this for testing... var apiClientHelper = new ApiClientHelper(); var auditLogObjectManager = apiClientHelper.GetKeplerServiceReference <IExternalAuditLogObjectManager>(); // Mock it up for the implementation var mockFactory = new Mock <IAuditLogObjectManagerFactory>(); mockFactory.Setup(m => m.GetManager()).Returns(() => auditLogObjectManager.Value); var dataGridWorkspaceAuditService = DataGridEndToEnd.SetUpWorkspaceAuditService(mockFactory.Object); var result = await dataGridWorkspaceAuditService.ReadAuditsAsync(workspaceId, auditQuery.StartTime, auditQuery.EndTime, auditQuery.ActionTypes, queryBatch.Size, queryBatch.Start); var resultMessages = result.Select( r => $"AuditId: {r.AuditID}, UserId {r.UserID}, Action: {r.Action}, ArtifactID: {r.ArtifactID}, ExecutionTime: {r.ExecutionTime}, WorkspaceId: {r.WorkspaceId}, TimeStamp: {r.TimeStamp}, Details: {r.Details}"); var finalMessage = string.Join("||", resultMessages); Assert.Pass($"Test Passed - ResultCount {result.Count} -- {finalMessage}"); }
public static Task <dynamic> SavePhoneLink(PhoneLink phoneLink) { var taskCompletionSource = new TaskCompletionSource <dynamic>(); var request = new RestRequest("/v1/calendar/phone-link", Method.POST, DataFormat.Json); request.AddParameter("application/json", JsonConvert.SerializeObject(new { phoneNumber = phoneLink.PhoneNumber == "none" ? null : phoneLink.PhoneNumber, calendarId = phoneLink.CalendarId }), ParameterType.RequestBody); ApiClientHelper.Check(); ApiClientHelper.Client.ExecuteAsync <dynamic>(request, response => { ApiClientHelper.HandleException(response); taskCompletionSource.SetResult(null); }); return(taskCompletionSource.Task); }
public async Task <IActionResult> Create(int importId, [FromForm] DTO.LogRow logRow) { try { string responseData = await ApiClientHelper.ExecutePostAsync($"{ApiClientHelper.LogRowUrl}", JsonConvert.SerializeObject(logRow, new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat, NullValueHandling = NullValueHandling.Ignore })); messageType = "success"; message = $"Log Row successfuly added!"; } catch (Exception ex) { messageType = "error"; message = $"Something went wrong: {ex.Message}"; } finally { ((Controller)this).DisplayTempData(messageType, message); } return(RedirectToAction("Index", new { importId = importId })); }
public static Task <List <TwilioPhoneNumber> > GetNumbers() { return(ApiClientHelper.AsyncCall <List <TwilioPhoneNumber> >("/v1/twilio/numbers", Method.GET)); }
public static Task <List <Organization> > GetOrganizations() { return(ApiClientHelper.AsyncCall <List <Organization> >("/v1/organization", Method.GET)); }
public static void InitCurrencyList() { CurrencyList = VinaApp.CurrencyList ?? ApiClientHelper.GetExchangeRate(); }
public static Task <List <Calendar> > GetAllByOrganizationId(string organizationId) { return(ApiClientHelper.AsyncCall <List <Calendar> >($"/v1/calendar/all/{organizationId}", Method.GET)); }
public async Task <string> Index() { var tenancyName = HttpContext.GetTenancyName(); return(await ApiClientHelper.GetApiKey(tenancyName)); }