private static async Task InitiateDatasetUpload(this WaveContext context, string xmdJson, DataOperation operation, Interfaces.ILog log) { var url = $"{context.EntryPoint}/services/data/v41.0/sobjects/InsightsExternalData"; log.Info(Localization.GetLocalizationString("Initializing data upload")); var client = new HttpClient(); var encJson = Convert.ToBase64String(Encoding.UTF8.GetBytes(xmdJson)); var payload = $"{{\"Format\":\"csv\",\"EdgemartAlias\":\"{context.Alias}\",\"Operation\":\"{operation.ToString()}\",\"Action\":\"None\",\"MetadataJson\":\"{encJson}\"}}"; var content = new StringContent(payload, Encoding.ASCII); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); client.AddAuthorization(context); var response = await client.PostAsync(url, content); var responseType = new { id = "" }; var responseText = await response.Content.ReadAsStringAsync(); log.Debug($"Received {responseText}"); if (response.IsSuccessStatusCode) { context.SetId = JsonConvert.DeserializeAnonymousType(responseText, responseType).id; log.Info(Localization.GetLocalizationString("Received job id {0}", context.SetId)); } }
private static async Task <Func <WaveContext> > GetWaveContextFunc(this IFileMedia fileMedia, string fileName, Interfaces.ILog log) { var client = new HttpClient(); var url = $"{fileMedia.ConnectionCredentials.EntryPoint}/services/oauth2/token?grant_type=password&client_id={fileMedia.ConnectionCredentials.ClientId}&client_secret={fileMedia.ConnectionCredentials.ClientSecret}&username={fileMedia.ConnectionCredentials.Login}&password={fileMedia.ConnectionCredentials.Password}{fileMedia.ConnectionCredentials.Token}"; var content = new StringContent(string.Empty); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); log.Info(string.Format( Localization.GetLocalizationString("Obtaining access token and entry point from \"{0}\" for \"{1}\""), fileMedia.ConnectionCredentials.EntryPoint, fileMedia.ConnectionCredentials.Login)); var response = await client.PostAsync(url, content); WaveContext context = null; if (response.IsSuccessStatusCode) { log.Info(Localization.GetLocalizationString("Retrieved entry point and access token.")); var responseType = new { access_token = "", instance_url = "" }; var result = JsonConvert.DeserializeAnonymousType(await response.Content.ReadAsStringAsync(), responseType); context = new WaveContext { Token = result.access_token, EntryPoint = result.instance_url, Alias = fileName.Replace(" ", "_") }; } else { log.Fatal($"{response.StatusCode.ToString()}-{response.Content.ReadAsStringAsync()}"); throw new UnauthorizedAccessException(Localization.GetLocalizationString("Could not get access to wave entry point.")); } return(() => context); }
private static async Task FinalizeDatasetUpload(this WaveContext context, Interfaces.ILog log) { var client = new HttpClient(); var url = $"{context.EntryPoint}/services/data/v36.0/sobjects/InsightsExternalData/{context.SetId}"; log.Info(Localization.GetLocalizationString("Finalizing upload job {0}", context.SetId)); var content = new StringContent("{\"Action\" : \"Process\"}", Encoding.ASCII); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); client.AddAuthorization(context); var response = await client.PatchAsync(url, content); if (response.IsSuccessStatusCode) { log.Info(Localization.GetLocalizationString("Successfully uploaded {0}", context.Alias)); return; } var responseText = await response.Content.ReadAsStringAsync(); throw new ImporterUploadException($"{response.StatusCode} -{responseText}"); }
public WaveBL(WaveContext DAL) { _DAL = DAL; }
public PostController(WaveContext db) { _db = db; }
public override object VisitWave(WaveContext context) { return(context.op.Text); }
public AccountController(WaveContext db, IConfiguration configuration) { _config = configuration; _db = db; }
private static void AddAuthorization(this HttpClient client, WaveContext context) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", context.Token); }
public CommentsController(WaveContext db) { _db = db; }
public FollowController(WaveContext db) { _db = db; }
public UserController(WaveContext db) { _db = db; }