Beispiel #1
0
        public static IronRuntime GetDefaultIronRuntime(SPSite targetSite)
        {
            const string RuntimeKey = "IronSP_Runtime";

            using (new SPMonitoredScope("Retrieving IronRuntime"))
            {
                var runtime = TryGetFromAuthenticated(targetSite);
                runtime = TryGetFromHttpContext(RuntimeKey, runtime);

                if (runtime == null)
                {
                    using (new SPMonitoredScope("Checking IronHiveRegistry"))
                    {
                        Guid hiveId = IronHiveRegistry.Local.GetHiveForSite(targetSite.ID);
                        if (hiveId == Guid.Empty)
                        {
                            throw new InvalidOperationException(
                                      String.Format("There is no IronHive mapping for the site with id {0}", targetSite.ID));
                        }

                        if (!LivingRuntimes.ContainsKey(hiveId))
                        {
                            lock (_sync)
                            {
                                if (!LivingRuntimes.TryGetValue(hiveId, out runtime))
                                {
                                    using (new SPMonitoredScope("Creating IronRuntime"))
                                    {
                                        runtime = new IronRuntime(hiveId);
                                        runtime.Authenticate(targetSite.ID);
                                        LivingRuntimes[hiveId] = runtime;
                                        runtime.Initialize();
                                    }
                                }
                            }
                        }

                        runtime = LivingRuntimes[hiveId];
                        if (HttpContext.Current != null)
                        {
                            HttpContext.Current.Items[RuntimeKey] = runtime;
                        }
                    }
                }


                if (!runtime.IsInitialized)
                {
                    ShowUnavailable();
                }

                return(runtime);
            }
        }
Beispiel #2
0
 public void Dispose()
 {
     if (!IsDisposed)
     {
         IsDisposed = true;
         if (IronHive != null)
         {
             IronHive.Close();
         }
         if (_console != null)
         {
             _console.Dispose();
             _console = null;
         }
         LivingRuntimes.Remove(_hiveId);
     }
 }