Пример #1
0
        /// <summary>
        /// Uploads an application package to a remote application store instance.
        /// </summary>
        /// <param name="storeEP">
        /// The application store endpoint or <c>null</c> to query any
        /// application store instance in the cluster.
        /// </param>
        /// <param name="appRef">The <see cref="AppRef" /> for the file.</param>
        /// <param name="path">The path to the application package file.</param>
        public void UploadPackage(MsgEP storeEP, AppRef appRef, string path)
        {
            StreamTransferSession session;

            if (storeEP == null)
            {
                storeEP = settings.ClusterEP;
            }

            session      = StreamTransferSession.ClientUpload(router, storeEP, path);
            session.Args = "appref=" + appRef.ToString();

            session.Transfer();
        }
Пример #2
0
        /// <summary>
        /// Downloads an application package from a remote application store instance.
        /// </summary>
        /// <param name="storeEP">
        /// The application store endpoint or <c>null</c> to query any
        /// application store instance in the cluster.
        /// </param>
        /// <param name="appRef">The <see cref="AppRef" /> for the file.</param>
        /// <param name="path">The path to the output application package file.</param>
        public void DownloadPackage(MsgEP storeEP, AppRef appRef, string path)
        {
            StreamTransferSession session;
            AppStoreAck           ack;

            if (storeEP == null)
            {
                storeEP = settings.ClusterEP;
            }

            ack     = (AppStoreAck)router.Query(storeEP, new AppStoreQuery(AppStoreQuery.DownloadCmd, appRef));
            storeEP = ack.StoreEP;

            session      = StreamTransferSession.ClientDownload(router, storeEP, path);
            session.Args = "appref=" + appRef.ToString();

            session.Transfer();
        }
Пример #3
0
        /// <summary>
        /// Private create constructor.
        /// </summary>
        /// <param name="path">The package path on the file system.</param>
        /// <param name="appRef">The package's <see cref="AppRef" />.</param>
        /// <param name="settings">The package metadata settings (or <c>null</c>).</param>
        /// <remarks>
        /// <note>
        /// No <b>Package.ini</b> entry will be created if <paramref name="settings" />
        /// is passed as <c>null</c>.
        /// </note>
        /// </remarks>
        private AppPackage(string path, AppRef appRef, ArgCollection settings)
        {
            this.path       = path;
            this.readMode   = false;
            this.appRef     = appRef;
            this.zipArchive = null;
            this.settings   = null;
            this.md5Hash    = null;

            // Create the archive

            Helper.CreateFileTree(path);
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            zipOutput = new ZipOutputStream(new FileStream(path, FileMode.Create, FileAccess.ReadWrite));
            zipOutput.SetLevel(9);

            if (settings != null)
            {
                // Generate the Package.ini file and save it to the archive.

                StreamWriter writer;
                MemoryStream ms;
                ZipEntry     entry;
                DateTime     utcNow;

                utcNow = DateTime.UtcNow;
                ms     = new MemoryStream();
                writer = new StreamWriter(ms);

                try
                {
                    writer.WriteLine("// Application Package Metadata");
                    writer.WriteLine("//");
                    writer.WriteLine("// Generated by: {0} v{1}", Path.GetFileName(Helper.GetAssemblyPath(Assembly.GetExecutingAssembly())), Helper.GetVersion(Assembly.GetExecutingAssembly()));
                    writer.WriteLine("// Create Date:  {0}", Helper.ToInternetDate(utcNow));
                    writer.WriteLine();

                    writer.WriteLine("#section AppPackage");
                    writer.WriteLine();
                    writer.WriteLine("    appref = {0}", appRef.ToString());

                    foreach (string key in settings)
                    {
                        writer.WriteLine("    {0} = {1}", key, settings[key]);
                    }

                    writer.WriteLine();
                    writer.WriteLine("#endsection");
                    writer.WriteLine();
                    writer.Flush();

                    entry          = new ZipEntry("Package.ini");
                    entry.DateTime = utcNow;
                    zipOutput.PutNextEntry(entry);
                    zipOutput.Write(ms.GetBuffer(), 0, (int)ms.Length);
                }
                finally
                {
                    writer.Close();
                }
            }
        }