Esempio n. 1
0
        public void AppStoreMsgs_Query()
        {
            EnhancedStream es = new EnhancedMemoryStream();
            AppStoreQuery  msgIn, msgOut;

            msgOut = new AppStoreQuery(AppStoreQuery.GetPrimaryCmd, AppRef.Parse("appref://myapps/theapp.zip?version=1.2.3.4"));

            Msg.Save(es, msgOut);
            es.Position = 0;
            msgIn       = (AppStoreQuery)Msg.Load(es);

            Assert.IsNotNull(msgIn);
            Assert.AreEqual(AppStoreQuery.GetPrimaryCmd, msgIn.Command);
            Assert.AreEqual(AppRef.Parse("appref://myapps/theapp.zip?version=1.2.3.4"), msgIn.AppRef);
        }
Esempio n. 2
0
        public void OnMsg(AppStoreQuery msg)
        {
            if (netFail)
            {
                return;
            }

            var ack = new AppStoreAck();

            try
            {
                switch (msg.Command)
                {
                case AppStoreQuery.GetPrimaryCmd:

                    ack.StoreEP = this.PrimaryEP;
                    break;

                case AppStoreQuery.ListCmd:

                    ack.Packages = packageFolder.GetPackages();
                    break;

                case AppStoreQuery.RemoveCmd:

                    packageFolder.Remove(msg.AppRef);
                    break;

                case AppStoreQuery.SyncCmd:

                    using (TimedLock.Lock(syncLock))
                    {
                        this.forceSync       = true;
                        this.primaryPollTime = SysTime.Now;
                    }
                    break;

                case AppStoreQuery.DownloadCmd:

                    ack.StoreEP = cluster.InstanceEP;

                    MsgEP           primaryEP;
                    PendingDownload pending;

                    using (TimedLock.Lock(syncLock))
                    {
                        if (packageFolder.GetPackageInfo(msg.AppRef) != null)
                        {
                            break;      // The package is ready for downloading
                        }
                        if (mode == AppStoreMode.Primary || this.PrimaryEP == null)
                        {
                            throw SessionException.Create(null, "Package [{0}] cannot be found.", msg.AppRef);
                        }

                        primaryEP = this.PrimaryEP;
                        downloads.TryGetValue(msg.AppRef, out pending);
                    }

                    if (pending != null)
                    {
                        // A download is already pending for this package so wait
                        // for it to complete.

                        pending.Wait();
                    }
                    else
                    {
                        // Try downloading the requested package from the primary
                        // application store.

                        string transitPath = null;

                        pending = new PendingDownload(msg.AppRef);
                        using (TimedLock.Lock(syncLock))
                            downloads.Add(msg.AppRef, pending);

                        try
                        {
                            transitPath = packageFolder.BeginTransit(msg.AppRef);
                            DownloadPackage(primaryEP, msg.AppRef, transitPath);
                            packageFolder.EndTransit(transitPath, true);

                            pending.Done(null);
                        }
                        catch (Exception e)
                        {
                            packageFolder.EndTransit(transitPath, false);
                            pending.Done(e);
                            throw;
                        }
                        finally
                        {
                            using (TimedLock.Lock(syncLock))
                            {
                                try
                                {
                                    downloads.Remove(msg.AppRef);
                                }
                                catch
                                {
                                    // Ignore errors
                                }
                            }
                        }
                    }
                    break;

                default:

                    throw SessionException.Create("Unexpected AppStore command [{0}].", msg.Command);
                }
            }
            catch (Exception e)
            {
                ack.Exception = e.Message;
                SysLog.LogException(e);
            }

            router.ReplyTo(msg, ack);
        }