/// <summary> /// /// </summary> /// <param name="exportType">the export type (only for log)</param> /// <param name="url">url of http request</param> /// <param name="periodicexport">periodic export config</param> /// <param name="path">path</param> /// <param name="postDataIds">array of ids to export</param> /// <param name="fileNamePrefix">file name prefix</param> internal async void RunPeriodicExport(string exportType, string url, PeriodicExport periodicexport, string path, string[] postDataIds, string fileNamePrefix) { if (!string.IsNullOrEmpty(path)) { HttpResponseMessage response; Log.Debug($"--Export to {exportType}"); response = await KfApiManager.HttpClient.PostAsJsonAsync($"{KfApiManager.KfApiUrl}/{url}", new { data_ids = postDataIds }); if (response.IsSuccessStatusCode) { string filePath = path; string fileName = GetFileName(response, periodicexport.SpLibrary, Path.Combine(periodicexport.SpWebSiteUrl, filePath), fileNamePrefix); using (var ms = new MemoryStream()) { filePath = Path.Combine(periodicexport.LibraryName, filePath); Log.Debug($"-----Downloading file : {fileName} from kizeoForms"); await response.Content.CopyToAsync(ms); SendPeriodicExportToSpLibrary(ms, periodicexport.SpLibrary, filePath, fileName); } } else { TOOLS.LogErrorAndExitProgram($"Error loading the export : {exportType} in path : {path}"); } } else { TOOLS.LogErrorAndExitProgram($"le champ path de l'export {exportType} est vide"); } }
/// <summary> /// Get all paths in the config that's gonna be used to export into for a periodic export /// </summary> /// <param name="periodicExport">the periodic export</param> /// <returns>list of strings representing paths</returns> public static List <string> GetAllPeriodicExportsPath(PeriodicExport periodicExport) { List <string> allConfigPaths = new List <string>(); allConfigPaths.Add(periodicExport.ExcelListPath); allConfigPaths.Add(periodicExport.CsvPath); allConfigPaths.Add(periodicExport.CsvCustomPath); allConfigPaths.Add(periodicExport.ExcelListCustomPath); return(allConfigPaths); }
public static void ExportPeriodicly(string exportType, PeriodicExport periodicExport, bool toExport, int period, string path) { if (toExport) { if ((period == 1 || period == 3) && DateTime.Now.Hour == periodicExportHour) { ExportBetweenTwoDates(exportType, DateTime.Now.AddDays(-1), DateTime.Now, periodicExport.FormId, periodicExport, path); } if ((period == 2 || period == 3) && (DateTime.Now.DayOfWeek == DayOfWeek.Sunday) && DateTime.Now.Hour == periodicExportHour) { ExportBetweenTwoDates(exportType, DateTime.Now.AddDays(-7), DateTime.Now, periodicExport.FormId, periodicExport, path); } } }
/// <summary> /// Load sp library /// </summary> /// <param name="periodicExport">periodic export config</param> /// <returns></returns> public List LoadSpLibrary(PeriodicExport periodicExport) { var spLibrary = Context.Web.Lists.GetById(periodicExport.SpLibraryId); Context.Load(spLibrary); Context.Load(spLibrary, spl => spl.Title); lock (locky) { try { Context.ExecuteQuery(); periodicExport.SpWebSiteUrl = ($@"{spLibrary.ParentWebUrl}/{spLibrary.Title}"); periodicExport.LibraryName = spLibrary.Title; Log.Debug("-SharePoint library Succesfully Loaded"); return(spLibrary); } catch (Exception ex) { TOOLS.LogErrorAndExitProgram("Error while loading Sharepoint Library " + ex.Message); return(null); } } }
public static async void ExportBetweenTwoDates(string exportType, DateTime lower, DateTime upper, string formId, PeriodicExport periodicExport, string path) { AdvancedSearchReqViewModel req = new AdvancedSearchReqViewModel { Filters = new List <Filters> { new Filters { Type = "and", Components = new List <Components> { new Components { Field = "_update_time", Operator = ">", Value = $"{lower}" }, new Components { Field = "_update_time", Operator = "<", Value = $"{upper}" } } } } }; var response = await HttpClient.PostAsJsonAsync($"{Config.KizeoConfig.Url}/rest/v3/forms/{formId}/data/advanced", req); if (response.IsSuccessStatusCode) { AdvancedSearchResViewModel resp = await response.Content.ReadAsAsync <AdvancedSearchResViewModel>(); if (resp.RecordTotal > 0) { var filenamePrefix = $"{lower:dd-MM-yyyy} to {upper:dd-MM-yyyy}"; SpManager.RunPeriodicExport(exportType, $"rest/v3/forms/{formId}/data/multiple/excel", periodicExport, path, resp.data.Select(x => x.Id).ToArray(), filenamePrefix); } } }