コード例 #1
0
        /// <summary>
        /// Run an export : download the file and send it to sharePoint
        /// </summary>
        /// <param name="exportType"> Export type used only for logging </param>
        /// <param name="url"> Url of the request that is going to be executed </param>
        /// <param name="isToExport"> Boolean to export or not</param>
        /// <param name="formToSpLibrary"> Form to sp library to get config data </param>
        /// <param name="data"> The data that holds the dataId and the formId</param>
        /// <param name="path"> the kizeoforms expresion ## ## that controls where the file will be sent </param>
        /// <param name="postDataIds">Ids of the data that is going to be exported</param>
        public async void RunExport(string exportType, string url, bool isToExport, FormToSpLibrary formToSpLibrary, FormData data, string path, string[] postDataIds = null)
        {
            if (isToExport)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    HttpResponseMessage response;

                    Log.Debug($"--Export to {exportType}");

                    if (postDataIds == null)
                    {
                        response = await KfApiManager.HttpClient.GetAsync($"{KfApiManager.KfApiUrl}/{url}");
                    }
                    else
                    {
                        response = await KfApiManager.HttpClient.PostAsJsonAsync($"{KfApiManager.KfApiUrl}/{url}", new { data_ids = postDataIds });
                    }

                    if (response.IsSuccessStatusCode)
                    {
                        string filePath = (await KfApiManager.TransformText(data.FormID, data.Id, path)).First();
                        string fileName = GetFileName(response, formToSpLibrary.SpLibrary, Path.Combine(formToSpLibrary.SpWebSiteUrl, filePath), "");

                        using (var ms = new MemoryStream())
                        {
                            filePath = Path.Combine(formToSpLibrary.LibraryName, filePath);
                            Log.Debug($"-----Downloading file : {fileName} from kizeoForms");
                            await response.Content.CopyToAsync(ms);

                            SendToSpLibrary(ms, formToSpLibrary.SpLibrary, formToSpLibrary.MetaData, data, 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");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Load SharePoint Library
        /// </summary>
        /// <param name="formToSpLibrary">form to sp library config</param>
        /// <returns></returns>
        public List LoadSpLibrary(FormToSpLibrary formToSpLibrary)
        {
            var spLibrary = Context.Web.Lists.GetById(formToSpLibrary.SpLibraryId);

            Context.Load(spLibrary);
            Context.Load(spLibrary, spl => spl.Title);

            lock (locky)
            {
                try
                {
                    Context.ExecuteQuery();
                    formToSpLibrary.SpWebSiteUrl = ($@"{spLibrary.ParentWebUrl}/{spLibrary.Title}");
                    formToSpLibrary.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);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Get All paths in the config file for an formToSpLibrary config
        /// </summary>
        /// <param name="data"> the data thas holds dataId and FormId</param>
        /// <param name="formToSpLibrary">The formToSpLibrary config where paths will be retrieved</param>
        /// <returns></returns>
        public async static Task <LockedHashset <string> > GetAllExportsPath(FormData data, FormToSpLibrary formToSpLibrary)
        {
            LockedHashset <string> allConfigPaths = new LockedHashset <string>();

            if (formToSpLibrary.ToStandardPdf)
            {
                allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, formToSpLibrary.StandardPdfPath)).First());
            }
            if (formToSpLibrary.ToExcelList)
            {
                allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, formToSpLibrary.ExcelListPath)).First());
            }
            if (formToSpLibrary.ToCsv)
            {
                allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, formToSpLibrary.CsvPath)).First());
            }
            if (formToSpLibrary.ToCsvCustom)
            {
                allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, formToSpLibrary.CsvCustomPath)).First());
            }
            if (formToSpLibrary.ToExcelListCustom)
            {
                allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, formToSpLibrary.ExcelListCustomPath)).First());
            }

            if (formToSpLibrary.Exports != null && formToSpLibrary.Exports.Count > 0)
            {
                var pdfPaths = formToSpLibrary.Exports.Where(e => e.ToPdf).Select(e => e.PdfPath).ToList();

                foreach (var pdfPath in pdfPaths)
                {
                    allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, pdfPath)).First());
                }

                var initialTypepaths = formToSpLibrary.Exports.Where(e => e.ToInitialType).Select(e => e.initialTypePath).ToList();
                foreach (var initialTypePath in initialTypepaths)
                {
                    allConfigPaths.Add((await KfApiManager.TransformText(data.FormID, data.Id, initialTypePath)).First());
                }
            }

            return(allConfigPaths);
        }