Ejemplo n.º 1
0
        public object GetLaunchPacket()
        {
            var baseUrl            = GlobalAttributesCache.Value("PublicApplicationRoot");
            var site               = MobileHelper.GetCurrentApplicationSite();
            var additionalSettings = site?.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>();
            var person             = GetPerson();
            var deviceData         = Request.GetHeader("X-Rock-DeviceData").FromJsonOrNull <DeviceData>();

            if (additionalSettings == null || !additionalSettings.LastDeploymentDate.HasValue)
            {
                return(NotFound());
            }

            var launchPacket = new LaunchPackage
            {
                LatestVersionId     = ( int )(additionalSettings.LastDeploymentDate.Value.ToJavascriptMilliseconds() / 1000),
                IsSiteAdministrator = site.IsAuthorized(Authorization.EDIT, person)
            };

            if (deviceData.DeviceType == DeviceType.Phone)
            {
                launchPacket.LatestVersionSettingsUrl = additionalSettings.PhoneUpdatePackageUrl;
            }
            else if (deviceData.DeviceType == DeviceType.Tablet)
            {
                launchPacket.LatestVersionSettingsUrl = additionalSettings.TabletUpdatePackageUrl;
            }
            else
            {
                return(NotFound());
            }

            if (person != null)
            {
                var principal = ControllerContext.Request.GetUserPrincipal();

                launchPacket.CurrentPerson           = MobileHelper.GetMobilePerson(person, site);
                launchPacket.CurrentPerson.AuthToken = MobileHelper.GetAuthenticationToken(principal.Identity.Name);
            }

            return(launchPacket);
        }
Ejemplo n.º 2
0
 private void Launch(object state)
 {
     try
     {
         using (LaunchPackage package = (LaunchPackage)state)
         {
             try
             {
                 string workDir   = Path.GetDirectoryName(_RequestHandlerFullPath);
                 string exeFile   = _RequestHandlerFullPath;
                 string arguments = String.Format("/env:{0} /hiid:{1} /reqid:{2}",
                                                  EnvHelper.EnvName(package.Client.ClientInfo.ConfigEnv),
                                                  HostInstance ?? "Default",
                                                  package.Request.RequestId);
                 ProcessStartInfo psi = new ProcessStartInfo(exeFile, arguments);
                 psi.WorkingDirectory = workDir;
                 psi.UseShellExecute  = true; // default - no io redir
                 psi.ErrorDialog      = true;
                 psi.WindowStyle      = ProcessWindowStyle.Normal;
                 //psi.UserName = xxx;
                 //psi.Password = xxx;
                 Process p = new Process();
                 p.StartInfo = psi;
                 if (p.Start())
                 {
                     Logger.LogDebug("{0} Started: {1} {2}", package.Request.RequestId, exeFile, arguments);
                     while (!p.WaitForExit(5000)) // 5 seconds
                     {
                         Logger.LogDebug("{0} Running...", package.Request.RequestId);
                     }
                     // exit codes:
                     //   1  success
                     //   0  failed (exception was published)
                     //  -1  catastrophic failure (logged to local file)
                     //  -2  catastrophic failure (logged to console only)
                     int      exitCode = p.ExitCode;
                     TimeSpan duration = p.ExitTime - p.StartTime;
                     Logger.LogDebug("{0} Stopped: ExitCode={1} (Duration={2})", package.Request.RequestId, exitCode, duration);
                     if (exitCode < 0)
                     {
                         // request handler failed to publish faulted request status - so we do it here
                         throw new ApplicationException(String.Format("Request '{0}' terminated abnormally: {1}", package.Request.RequestId, exitCode));
                     }
                 }
                 else
                 {
                     throw new ApplicationException(String.Format("Request '{0}' failed to start.", package.Request.RequestId));
                 }
             }
             catch (Exception ex)
             {
                 Logger.Log(ex);
                 package.Request.Status      = RequestStatusEnum.Faulted;
                 package.Request.FaultDetail = new ExceptionDetail(ex);
                 PublishWorkerResponse(package.Client, package.Request, HostInstance);
             }
         }
     }
     finally
     {
         Interlocked.Decrement(ref _HandlersExecuting);
         Interlocked.Increment(ref _HandlersAvailable);
         Interlocked.Increment(ref _AvailabilityChangeCount);
         _EventQueue.Dispatch(null);
     }
 }