public IHttpActionResult Export()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var pollInfo = PollManager.GetPollInfo(request);
                if (pollInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId))
                {
                    return(Unauthorized());
                }

                //var fileName = FieldManager.Export(pollInfo.Id);\

                var fileName      = "表单字段.zip";
                var filePath      = Context.UtilsApi.GetTemporaryFilesPath(fileName);
                var directoryPath = Context.UtilsApi.GetTemporaryFilesPath("PollFields");

                PollUtils.DeleteDirectoryIfExists(directoryPath);
                PollUtils.CreateDirectoryIfNotExists(directoryPath);

                PollBox.ExportFields(pollInfo.Id, directoryPath);

                Context.UtilsApi.CreateZip(filePath, directoryPath);

                var url = Context.UtilsApi.GetRootUrl($"SiteFiles/TemporaryFiles/{fileName}");

                return(Ok(new
                {
                    Value = url
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        public static void ExportFields(int pollId, string styleDirectoryPath)
        {
            PollUtils.DeleteDirectoryIfExists(styleDirectoryPath);
            PollUtils.CreateDirectoryIfNotExists(styleDirectoryPath);

            var fieldInfoList = FieldManager.GetFieldInfoList(pollId);

            foreach (var fieldInfo in fieldInfoList)
            {
                var filePath = PollUtils.PathCombine(styleDirectoryPath, fieldInfo.Id + ".xml");
                var feed     = ExportFieldInfo(fieldInfo);
                if (fieldInfo.Items != null && fieldInfo.Items.Count > 0)
                {
                    foreach (var itemInfo in fieldInfo.Items)
                    {
                        var entry = ExportTableStyleItemInfo(itemInfo);
                        feed.Entries.Add(entry);
                    }
                }
                feed.Save(filePath);
            }
        }