Beispiel #1
0
 public void LaunchApplication(System.Security.Principal.WindowsIdentity user, string host, RedirectionApplication redirectApp)
 {
     try
     {
         ApplicationItem appInfo = _service.GetApplicationInfo(redirectApp.InternalName, _service.GetUser(user), host, "", null, null, null, redirectApp.FarmName);
         if (!string.IsNullOrEmpty(appInfo.ContentAddress))
         {
             String address = appInfo.ContentAddress;
             if (address != null)
             {
                 this.Page.Response.Redirect(address);
             }
         }
         else
         {
             string app = _service.LaunchApplication(redirectApp.InternalName, _service.GetUser(user), host, "", redirectApp.FarmName);
             this.Page.Response.Clear();
             this.Page.Response.ClearContent();
             this.Page.Response.ClearHeaders();
             this.Page.Response.ContentType = "application/x-ica";
             this.Page.Response.AddHeader("Content-Type", "application/x-ica");
             this.Page.Response.BinaryWrite(this.Page.Response.ContentEncoding.GetBytes(app));
             this.Page.Response.End();
         }
     }
     catch (ThreadAbortException)
     {
         //Do nothing
     }
     catch (Exception ex)
     {
         SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Extentrix", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
         PageLogger.Error("An error occured during launch application", ex);
     }
 }
        public void launchApplication(Credentials user, string application, string host, string farmName)
        {
            try
            {
                var validationCode = LicenseManager.CheckLicense(MacAddress);
                //var validationCode = LicenseValidationCode.Ok;
                switch (validationCode)
                {
                case LicenseValidationCode.Ok:
                    Logger.Default.Info(LogLocation, "License has been validated successeful.");
                    break;

                case LicenseValidationCode.SoonBeExpired:
                    Logger.Default.Info(LogLocation, "License will expire at " + LicenseManager.LicenseExpirationDate);
                    break;

                case LicenseValidationCode.Expired:
                    Logger.Default.Info(LogLocation, "License expired.");
                    break;

                case LicenseValidationCode.NotValid:
                    Logger.Default.Info(LogLocation, "License is not valid.");
                    break;
                }

                if ((validationCode != LicenseValidationCode.NotValid) &&
                    (validationCode != LicenseValidationCode.Expired))
                {
                    ApplicationItem appInfo = service.GetApplicationInfo(application, user, host, "", null, null, null, farmName);
                    if (!string.IsNullOrEmpty(appInfo.ContentAddress))
                    {
                        String address = appInfo.ContentAddress;
                        if (address != null)
                        {
                            this.Page.Response.Redirect(address);
                        }
                    }
                    else
                    {
                        string app = service.LaunchApplication(application, user, host, "", farmName);

                        /*this.Page.Response.Clear();
                         * this.Page.Response.ClearContent();
                         * this.Page.Response.ClearHeaders();
                         * this.Page.Response.ContentType = "application/x-ica";*/
                        //this.Page.Response.AddHeader("Content-disposition", "attachment; filename=launch.ica");

                        /* this.Page.Response.BinaryWrite(this.Page.Response.ContentEncoding.GetBytes(app));
                         * this.Page.Response.End();*/
                        string folderPath = SPUtility.GetGenericSetupPath("ISAPI\\Extentrix");


                        var fileName = string.Format("{0}_{1}.ica", Regex.Replace(SPContext.Current.Web.CurrentUser.LoginName, @"[#:.\\/|]", "_"), application);
                        var path     = Path.Combine(folderPath, fileName);

                        using (StreamWriter icaFile = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.ReadWrite)))
                        {
                            icaFile.Write(app);
                            if (!string.IsNullOrEmpty(DefaultIcaFile))
                            {
                                icaFile.Write(DefaultIcaFile);
                            }
                            icaFile.Flush();
                            icaFile.Close();
                        }

                        this.Page.Response.Redirect("/_vti_bin/Extentrix/" + fileName);
                    }
                }
                else
                {
                    Controls.Add(Page.LoadControl(_ascxLicenseValidPath));
                }
            }
            catch (ThreadAbortException)
            {
                //Do nothing
            }
            catch (Exception e)
            {
                Logger.Default.Error(LogLocation, "User - " + Page.Request.LogonUserIdentity.Name + " ; Error = " + e.Message, e);
                Controls.Add(Page.LoadControl(_ascxErrPath));
                //Controls.Add(Page.LoadControl(_ascxPath));
            }
        }