/// <summary>
 /// Shows the scripting data as xml.
 /// </summary>
 /// <param name="scriptingData"> The ScriptingData type.</param>
 public void ShowScriptingDataXml(ScriptingApplication scriptingData)
 {
     this.EditorText = scriptingData.ToXml();
 }
        /// <summary>
        /// Creates a new ScriptingApplicationPackage.
        /// </summary>
        /// <param name="application"> The scripting application.</param>
        /// <param name="arguments"> The application arguments.</param>
        /// <param name="filePath"> The output file path.</param>
        /// <param name="doEncrypt"> Sets the encrypttion setting for a scripting application.</param>
        public static void CreatePackage(ScriptingApplication application, ScriptingApplicationArgs arguments, string filePath, bool doEncrypt)
        {
            try
            {
                if ( application.Header.ApplicationID == null )
                {
                    application.Header.ApplicationID = System.Guid.NewGuid().ToString();
                }

                // Get all FileReference elements.
                FileReference[] fileReferences = application.GetFileReferences();
                string applicationPath = System.Windows.Forms.Application.UserAppDataPath;

                string temp = applicationPath + "/temp/";

                if ( !Directory.Exists(temp) )
                {
                    Directory.CreateDirectory(temp);
                }

                C1.C1Zip.C1ZipFile zipFile = new C1.C1Zip.C1ZipFile();
                zipFile.Create(filePath);
                zipFile.Open(filePath);

                string argumentsFileName = application.Header.ApplicationID + "-applicationArguments.xml";

                FileReference argumentsFileReference = new FileReference(argumentsFileName);
                application.Header.ScriptingApplicationArgumentsReference = argumentsFileReference;

                // Add Scripting Application
                string xml = string.Empty;
                if ( doEncrypt )
                {
                    xml = application.Encrypt();
                }
                else
                {
                    xml = application.ToXml();
                }

                MemoryStream mem = new MemoryStream(System.Text.Encoding.UTF8.GetByteCount(xml));
                StreamWriter writer =  new StreamWriter(mem, System.Text.Encoding.UTF8);
                writer.Write(xml);
                writer.Flush();
                mem.Position = 0;
                zipFile.Entries.Add(writer.BaseStream, application.Header.ApplicationID);
                writer.Close();

                string argsXml = "None";
                if ( arguments != null )
                {
                    // Add Scripting Application Arguments
                    argsXml = arguments.ToXml();
                }
                mem = new MemoryStream(System.Text.Encoding.UTF8.GetByteCount(argsXml));
                writer =  new StreamWriter(mem, System.Text.Encoding.UTF8);
                writer.Write(argsXml);
                writer.Flush();
                mem.Position = 0;
                zipFile.Entries.Add(writer.BaseStream, argumentsFileName);
                writer.Close();

                FileReference[] customTransforms = application.GetCustomTransforms();

                // add custom transforms
                foreach ( FileReference reference in customTransforms )
                {
                    if ( File.Exists(reference.FileName) )
                    {
                        FileInfo fileInfo = new FileInfo(reference.FileName);
                        zipFile.Entries.Add(reference.FileName, fileInfo.Name);
                    }
                }

                MemoryStream stream = new MemoryStream();
                stream.Write(new byte[] {0}, 0, 1);
                zipFile.Entries.Add(stream, "CustomTransformsSeparator");
                stream.Close();

                // add file references that are not custom transforms
                foreach ( FileReference reference in fileReferences )
                {
                    if ( File.Exists(reference.FileName) )
                    {
                        FileInfo fileInfo = new FileInfo(reference.FileName);
                        zipFile.Entries.Add(reference.FileName, fileInfo.Name);
                    }
                }

                zipFile.Close();
            }
            catch
            {
                throw;
            }
        }