Last active
August 29, 2015 14:16
-
-
Save JRondeau16/a00229db5b47d49b7c56 to your computer and use it in GitHub Desktop.
Decompiled ExportToXml Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore; | |
using Sitecore.Data; | |
using Sitecore.Data.Items; | |
using Sitecore.Diagnostics; | |
using Sitecore.Form.Core.Configuration; | |
using Sitecore.Form.Core.DatViewer.Data; | |
using Sitecore.Form.Core.Pipelines.Export; | |
using Sitecore.Form.Core.Utility; | |
using Sitecore.Forms.Core.Commands; | |
using Sitecore.Forms.Core.Data; | |
using Sitecore.Forms.Data; | |
using Sitecore.Globalization; | |
using Sitecore.Jobs; | |
using Sitecore.Pipelines; | |
using Sitecore.Shell.Applications.Dialogs.ProgressBoxes; | |
using Sitecore.Shell.Framework.Commands; | |
using Sitecore.Text; | |
using Sitecore.Web.UI.Sheer; | |
using Sitecore.Web.UI.WebControls; | |
using Sitecore.Web.UI.XamlSharp.Continuations; | |
using System.Collections.Generic; | |
using System.Collections.Specialized; | |
using System.Threading; | |
namespace Sitecore.Forms.Core.Commands.Export | |
{ | |
public class ExportToXml : DataCommand, ISupportsContinuation | |
{ | |
public override void Execute(CommandContext context) | |
{ | |
Assert.ArgumentNotNull((object) context, "context"); | |
string str1 = context.Parameters["items"]; | |
string str2 = context.Parameters["mode"]; | |
if (string.IsNullOrEmpty(str1) && (string.IsNullOrEmpty(str2) || str2 != "all") || str2 == "all" && int.Parse(context.Parameters["count"]) == 0) | |
{ | |
SheerResponse.Alert(ResourceManager.Localize("SELECT_ITEM_FIRST")); | |
} | |
else | |
{ | |
Item obj = context.Items[0]; //this is the form item that you are viewing | |
NameValueCollection parameters = new NameValueCollection(); | |
this.AddParameters(parameters); | |
parameters["id"] = obj.ID.ToString(); | |
parameters["la"] = obj.Language.Name; | |
parameters["vs"] = obj.Version.Number.ToString(); | |
parameters["db"] = obj.Database.Name; | |
parameters["items"] = context.Parameters["items"] ?? string.Empty; //context.Parameters["items"] is a pipe delimited list of form submission ids AKA your selected records | |
parameters["mode"] = context.Parameters["mode"] ?? string.Empty; | |
parameters["fields"] = context.Parameters["fields"]; | |
parameters["view"] = context.Parameters["view"]; | |
parameters["tempfile"] = WebUtil.GetTempFileName(); //This is the temporary file that houses our content | |
ContinuationManager.Current.Start((ISupportsContinuation) this, "Run", new ClientPipelineArgs(parameters)); | |
} | |
} | |
protected virtual void AddParameters(NameValueCollection parameters) | |
{ | |
parameters["filename"] = "export.xml"; | |
parameters["contentType"] = "text/xml"; | |
parameters["exportProcessor"] = "exportToXml"; | |
} | |
protected virtual void Export(params object[] clientArgs) | |
{ | |
ClientPipelineArgs clientPipelineArgs = (ClientPipelineArgs) clientArgs[0]; | |
Job job = Context.Job; | |
if (job != null) | |
job.Status.LogInfo(ResourceManager.Localize("READING_DATA_FROM_DATABASE")); | |
IEnumerable<IForm> entries = this.GetEntries(ID.Parse(clientPipelineArgs.Parameters["id"]), clientPipelineArgs.Parameters["items"], clientPipelineArgs.Parameters["mode"] == "all", clientPipelineArgs.Parameters["view"] == "archive"); | |
ExportArgs exportArgs = new ExportArgs(new FormItem(Database.GetItem(new ItemUri(clientPipelineArgs.Parameters["id"], Language.Parse(clientPipelineArgs.Parameters["la"]), Version.Parse(clientPipelineArgs.Parameters["vs"]), clientPipelineArgs.Parameters["db"]))), new FormPacket(entries), clientPipelineArgs.Parameters["tempfile"], clientPipelineArgs.Parameters["contentType"]); | |
exportArgs.Parameters.Add("contextUser", clientPipelineArgs.Parameters["contextUser"]); | |
Thread.Sleep(2000); | |
CorePipeline.Run(this.GetProcessorName(), (PipelineArgs) exportArgs); | |
} | |
protected virtual string GetName() | |
{ | |
return ResourceManager.Localize("EXPORT_RECORDS_TO_XML"); | |
} | |
protected virtual string GetProcessorName() | |
{ | |
return "exportToXml"; | |
} | |
protected virtual void Run(ClientPipelineArgs args) | |
{ | |
Assert.ArgumentNotNull((object) args, "args"); | |
if (args.IsPostBack) | |
{ | |
if (!args.HasResult) | |
return; | |
FormRegistryUtil.SetExportRestriction(args.Parameters["id"], args.Result); | |
args.Parameters.Add("contextUser", Context.User.Name); | |
ProgressBox.Execute(ResourceManager.Localize("EXPORTING_DATA"), this.GetName(), "Software/16x16/text_code_colored.png", new ProgressBoxMethod(this.Export), "forms:export:completed(filename=" + args.Parameters["filename"] + ",contentType=" + args.Parameters["contentType"] + ",tempfile=" + args.Parameters["tempfile"] + ")", (object) args); | |
} | |
else | |
{ | |
UrlString urlString = new UrlString(UIUtil.GetUri("control:Forms.SelectFields")); | |
urlString.Append("id", args.Parameters["id"]); | |
urlString.Append("la", args.Parameters["la"]); | |
urlString.Append("vs", args.Parameters["vs"]); | |
urlString.Append("db", args.Parameters["db"]); | |
urlString.Append("prefix", FormRegistryUtil.exportPrefix); | |
urlString.Append("fields", args.Parameters["fields"]); | |
SheerResponse.ShowModalDialog(urlString.ToString(), string.Empty, string.Empty, ResourceManager.Localize("SELECT_FIELDS_FOR_EXPORT"), true); | |
args.WaitForPostBack(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment