Beispiel #1
0
        /// <summary>
        /// Upload periodicly reports to sharepoint library
        /// </summary>
        public static void RunPeriodicExports()
        {
            foreach (var periodicExport in Config.PeriodicExports)
            {
                string formId = periodicExport.FormId;
                Log.Debug($"-Processing form : {formId}");

                Log.Debug($"-Loading Sharepoint library");
                periodicExport.SpLibrary = SpManager.LoadSpLibrary(periodicExport);

                var allSpPaths     = SpManager.GetAllLibraryFolders(periodicExport.SpLibrary, periodicExport.SpWebSiteUrl);
                var allExportPaths = GetAllPeriodicExportsPath(periodicExport);

                Log.Warn("Creating All Folders hierarchy");
                foreach (var path in allExportPaths)
                {
                    if (!string.IsNullOrEmpty(path) && !string.IsNullOrWhiteSpace(path) && !allSpPaths.Contains(path))
                    {
                        Log.Warn($"Creating path : {path}");
                        TOOLS.CreateSpPath(Context, path, periodicExport.SpLibrary);
                        allSpPaths.Add(path);
                    }
                }

                ExportPeriodicly("CSV", periodicExport, periodicExport.ToCsv, periodicExport.CsvPeriod, periodicExport.CsvPath);
                ExportPeriodicly("CSV Custom", periodicExport, periodicExport.ToCsvCustom, periodicExport.CsvCustomPeriod, periodicExport.CsvCustomPath);
                ExportPeriodicly("Excel List", periodicExport, periodicExport.ToExcelList, periodicExport.ExcelListPeriod, periodicExport.ExcelListPath);
                ExportPeriodicly("ExcelList Custom", periodicExport, periodicExport.ToExcelListCustom, periodicExport.ExcelListCustomPeriod, periodicExport.ExcelListCustomPath);
            }
        }
Beispiel #2
0
        /// <summary>
        /// upload repports to sharepoint library acording to config file
        /// </summary>
        /// <returns></returns>
        public static async Task UploadExportsToSpLibraries()
        {
            Log.Info($"Uploading exports to SharePoint's library");

            FormDatasRespViewModel formData = null;
            HttpResponseMessage    response;
            MarkDataReqViewModel   dataToMark;
            string formId;

            foreach (var formToSpLibrary in Config.FormsToSpLibraries)
            {
                string marker = KfApiManager.CreateKFMarker(formToSpLibrary.FormId, formToSpLibrary.SpLibraryId);
                formId     = formToSpLibrary.FormId;
                dataToMark = new MarkDataReqViewModel();

                Log.Debug($"-Processing form : {formId}");
                response = await HttpClient.GetAsync($"{Config.KizeoConfig.Url}/rest/v3/forms/{formId}/data/unread/{marker}/50?includeupdated");

                if (response.IsSuccessStatusCode)
                {
                    Log.Debug($"-Loading Sharepoint's library");
                    formToSpLibrary.SpLibrary = SpManager.LoadSpLibrary(formToSpLibrary);

                    formData = await response.Content.ReadAsAsync <FormDatasRespViewModel>();

                    if (formData.Data == null)
                    {
                        TOOLS.LogErrorAndExitProgram($"Can not find a form for id {formId}, check if this is a valid id.");
                    }

                    Log.Debug($"{formData.Data.Count} Data retrieved successfully from form");

                    var allSpPaths = SpManager.GetAllLibraryFolders(formToSpLibrary.SpLibrary, formToSpLibrary.SpWebSiteUrl);

                    foreach (var data in formData.Data)
                    {
                        Log.Debug($"-Processing data : {data.Id}");
                        var allExportPaths = await GetAllExportsPath(data, formToSpLibrary);

                        Log.Warn("Creating All Folders hierarchy");
                        foreach (var path in allExportPaths)
                        {
                            if (!string.IsNullOrEmpty(path) && !string.IsNullOrWhiteSpace(path) && !allSpPaths.Contains(path))
                            {
                                Log.Warn($"Creating path : {path}");
                                TOOLS.CreateSpPath(Context, path, formToSpLibrary.SpLibrary);
                                allSpPaths.Add(path);
                            }
                        }

                        Log.Debug($"--Processing data : {data.Id}");

                        SpManager.RunExport("PDF", $"rest/v3/forms/{formId}/data/{data.Id}/pdf", formToSpLibrary.ToStandardPdf, formToSpLibrary, data, formToSpLibrary.StandardPdfPath);
                        SpManager.RunExport("Excel", $"rest/v3/forms/{formId}/data/multiple/excel", formToSpLibrary.ToExcelList, formToSpLibrary, data, formToSpLibrary.ExcelListPath, new string[] { data.Id });
                        SpManager.RunExport("CSV", $"rest/v3/forms/{formId}/data/multiple/csv", formToSpLibrary.ToCsv, formToSpLibrary, data, formToSpLibrary.CsvPath, new string[] { data.Id });
                        SpManager.RunExport("CSV_Custom", $"rest/v3/forms/{formId}/data/multiple/csv_custom", formToSpLibrary.ToCsvCustom, formToSpLibrary, data, formToSpLibrary.CsvCustomPath, new string[] { data.Id });
                        SpManager.RunExport("Excel_Custom", $"rest/v3/forms/{formId}/data/multiple/excel_custom", formToSpLibrary.ToExcelListCustom, formToSpLibrary, data, formToSpLibrary.ExcelListCustomPath, new string[] { data.Id });

                        if (formToSpLibrary.Exports != null && formToSpLibrary.Exports.Count > 0)
                        {
                            foreach (var export in formToSpLibrary.Exports)
                            {
                                Log.Debug($"---Processing export : {export.Id}");

                                SpManager.RunExport("Initial Type", $"rest/v3/forms/{formId}/data/{data.Id}/exports/{export.Id}", export.ToInitialType, formToSpLibrary, data, export.initialTypePath);
                                SpManager.RunExport("Pdf Type", $"rest/v3/forms/{formId}/data/{data.Id}/exports/{export.Id}/pdf", export.ToPdf, formToSpLibrary, data, export.PdfPath);
                            }
                        }

                        dataToMark.Ids.Add(data.Id);
                    }

                    if (dataToMark.Ids.Count > 0)
                    {
                        response = await HttpClient.PostAsJsonAsync($"{Config.KizeoConfig.Url}/rest/v3/forms/{formId}/markasreadbyaction/{marker}", dataToMark);

                        Log.Debug($"-{dataToMark.Ids.Count} data marked");
                    }
                }
            }
        }