public void OnMsg(AppStoreMsg msg) { if (netFail) { return; } try { switch (msg.Command) { case AppStoreQuery.RemoveCmd: packageFolder.Remove(msg.AppRef); break; case AppStoreQuery.SyncCmd: using (TimedLock.Lock(syncLock)) { this.forceSync = true; this.primaryPollTime = SysTime.Now; } break; default: throw SessionException.Create("Unexpected AppStore command [{0}].", msg.Command); } } catch (Exception e) { SysLog.LogException(e); } }
public void OnMsg(ReliableTransferMsg msg) { if (netFail) { return; } StreamTransferSession session; ArgCollection args; AppRef appRef; AppPackageInfo packageInfo; string path; args = ArgCollection.Parse(msg.Args); appRef = AppRef.Parse(args["appref"]); if (msg.Direction == TransferDirection.Upload) { path = packageFolder.BeginTransit(appRef); session = StreamTransferSession.ServerUpload(router, msg, path); session.BeginTransfer(onTransfer, new TransferInfo(session, path, msg.Direction)); } else { packageInfo = packageFolder.GetPackageInfo(appRef); if (packageInfo == null) { throw SessionException.Create(null, "Package [{0}] cannot be found.", appRef); } path = packageInfo.FullPath; session = StreamTransferSession.ServerDownload(router, msg, path); session.BeginTransfer(onTransfer, new TransferInfo(session, path, msg.Direction)); } }
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); }