コード例 #1
0
        /// <summary>
        /// Downloads an application package from a remote application store instance.
        /// </summary>
        /// <param name="storeEP">The application store endpoint.</param>
        /// <param name="appRef">The <see cref="AppRef" /> for the file.</param>
        /// <param name="path">The path to the output application package file.</param>
        private void DownloadPackage(MsgEP storeEP, AppRef appRef, string path)
        {
            StreamTransferSession session;

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

            session.Transfer();
        }
コード例 #2
0
        public void StreamTransferSession_Download_ErrorOnServer()
        {
            StreamTransferSession clientSession;
            LeafRouter            router;
            EnhancedMemoryStream  msClient;

            InitServer();

            router = null;
            try
            {
                SetConfig("DefBlockSize=1000");

                router = new LeafRouter();
                router.Start();
                router.Dispatcher.AddTarget(this);

                msServer = CreateStream(TransferSize);
                msClient = new EnhancedMemoryStream();

                simServerError = true;

                clientSession       = StreamTransferSession.ClientDownload(router, "logical://Test/Download", msClient);
                clientSession.Delay = 500;
                clientSession.Transfer();
                Assert.Fail("Expecting a SessionException");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(SessionException));
            }
            finally
            {
                if (router != null)
                {
                    router.Stop();
                }

                Config.SetConfig(null);
            }

            Thread.Sleep(1000);
            Assert.IsTrue(serverNotify);
            Assert.IsInstanceOfType(serverException, typeof(Exception));
        }
コード例 #3
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();
        }
コード例 #4
0
        public void StreamTransferSession_Download_Sync()
        {
            StreamTransferSession clientSession;
            LeafRouter            router;
            EnhancedMemoryStream  msClient;

            InitServer();

            router = null;
            try
            {
                SetConfig("DefBlockSize=1000");

                router = new LeafRouter();
                router.Start();
                router.Dispatcher.AddTarget(this);

                msServer = CreateStream(TransferSize);
                msClient = new EnhancedMemoryStream();

                clientSession      = StreamTransferSession.ClientDownload(router, "logical://Test/Download", msClient);
                clientSession.Args = "Download";
                clientSession.Transfer();

                Verify(msClient, TransferSize);
                Assert.IsTrue(serverNotify);
                Assert.IsNull(serverException);
                Assert.AreEqual("Download", serverArgs);
            }
            finally
            {
                if (router != null)
                {
                    router.Stop();
                }

                Config.SetConfig(null);
            }
        }
コード例 #5
0
        public void StreamTransferSession_WrongDirection_Download()
        {
            StreamTransferSession clientSession;
            LeafRouter            router;
            EnhancedMemoryStream  msClient;

            InitServer();

            router = null;
            try
            {
                SetConfig("DefBlockSize=1000");

                router = new LeafRouter();
                router.Start();
                router.Dispatcher.AddTarget(this);

                msServer = CreateStream(TransferSize);
                msClient = new EnhancedMemoryStream();

                clientSession = StreamTransferSession.ClientDownload(router, "logical://Test/Upload", msClient);
                clientSession.Transfer();
                Assert.Fail("Expected a SessionException");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(SessionException));
            }
            finally
            {
                if (router != null)
                {
                    router.Stop();
                }

                Config.SetConfig(null);
            }
        }
コード例 #6
0
        public void StreamTransferSession_Download_Async()
        {
            StreamTransferSession clientSession;
            LeafRouter            router;
            EnhancedMemoryStream  msClient;

            InitServer();

            router = null;
            try
            {
                SetConfig("DefBlockSize=1000");

                router = new LeafRouter();
                router.Start();
                router.Dispatcher.AddTarget(this);

                msServer = CreateStream(TransferSize);
                msClient = new EnhancedMemoryStream();

                clientSession = StreamTransferSession.ClientDownload(router, "logical://Test/Download", msClient);
                clientSession.BeginTransfer(new AsyncCallback(OnClientDone), clientSession);
                clientWait.WaitOne(TimeSpan.FromSeconds(30), false);

                Verify(msClient, TransferSize);
                Assert.IsTrue(serverNotify);
                Assert.IsNull(serverException);
            }
            finally
            {
                if (router != null)
                {
                    router.Stop();
                }

                Config.SetConfig(null);
            }
        }
コード例 #7
0
        /// <summary>
        /// Synchronizes the set of application packages held by this instance with
        /// the primary application store.
        /// </summary>
        private void SyncWithPrimary()
        {
            MsgEP primaryEP;

            if (mode == AppStoreMode.Primary)
            {
                return;     // This is the primary instance
            }
            primaryEP = this.PrimaryEP;
            if (primaryEP == null)
            {
                return;     // There is no known primary
            }
            // Synchronize

            Dictionary <AppRef, AppPackageInfo> primaryPackages;
            Dictionary <AppRef, AppPackageInfo> localPackages;

            primaryPackages = new Dictionary <AppRef, AppPackageInfo>();
            foreach (AppPackageInfo info in ListRemotePackages(primaryEP))
            {
                primaryPackages.Add(info.AppRef, info);
            }

            localPackages = new Dictionary <AppRef, AppPackageInfo>();
            foreach (AppPackageInfo info in packageFolder.GetPackages())
            {
                localPackages.Add(info.AppRef, info);
            }

            // Delete any packages present in the local folder that
            // are not present on the primary.

            foreach (AppPackageInfo info in localPackages.Values)
            {
                if (!primaryPackages.ContainsKey(info.AppRef))
                {
                    packageFolder.Remove(info.AppRef);
                }
            }

            // Download any packages found on the primary that are
            // not present locally or whose MD5 hash differs from
            // the local file.

            foreach (AppPackageInfo info in primaryPackages.Values)
            {
                bool           downloadPackage = false;
                AppPackageInfo localInfo;

                if (!localPackages.TryGetValue(info.AppRef, out localInfo))
                {
                    downloadPackage = true;
                }
                else
                {
                    downloadPackage = !Helper.ArrayEquals(info.MD5, localInfo.MD5);
                }

                if (downloadPackage)
                {
                    StreamTransferSession session;
                    string path;

                    path = packageFolder.BeginTransit(info.AppRef);

                    try
                    {
                        session      = StreamTransferSession.ClientDownload(router, primaryEP, path);
                        session.Args = "appref=" + info.AppRef.ToString();
                        session.Transfer();
                        packageFolder.EndTransit(path, true);
                    }
                    catch (Exception e)
                    {
                        packageFolder.EndTransit(path, false);

                        // I'm going to log the exception and then continue
                        // downloading any remaining packages.

                        SysLog.LogException(e);
                    }
                }
            }
        }