public IHttpActionResult Import()
        {
            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());
                }

                foreach (string name in HttpContext.Current.Request.Files)
                {
                    var postFile = HttpContext.Current.Request.Files[name];

                    if (postFile == null)
                    {
                        return(BadRequest("Could not read zip from body"));
                    }

                    var filePath = Context.UtilsApi.GetTemporaryFilesPath("poll.zip");
                    PollUtils.DeleteFileIfExists(filePath);

                    if (!PollUtils.EqualsIgnoreCase(Path.GetExtension(postFile.FileName), ".zip"))
                    {
                        return(BadRequest("zip file extension is not correct"));
                    }

                    postFile.SaveAs(filePath);

                    var directoryPath = Context.UtilsApi.GetTemporaryFilesPath("poll");
                    PollUtils.DeleteDirectoryIfExists(directoryPath);
                    Context.UtilsApi.ExtractZip(filePath, directoryPath);

                    var isHistoric = PollBox.IsHistoric(directoryPath);
                    PollBox.ImportFields(pollInfo.SiteId, pollInfo.Id, directoryPath, isHistoric);

                    //FieldManager.Import(pollInfo.SiteId, pollInfo.Id, filePath);
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public static void DeleteTemplate(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            var directoryPath = GetTemplatesDirectoryPath();
            var templatePath  = PollUtils.PathCombine(directoryPath, name);

            PollUtils.DeleteDirectoryIfExists(templatePath);
        }
        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 #4
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);
            }
        }