public static OwinServer CreateOwinServer(Uri url) { lock (OwinServers) { if (OwinServers.All(e => e.Port != url.Port)) { OwinServer owinServer = new OwinServer(); try { owinServer.InitService(url.ToString()); OwinServers.Add(new OwinServerCounter() { OwinServer = owinServer, Port = url.Port }); } catch (Exception e) { throw new FunctionsFactoryException("Owin server initialization failed", e); } } var owinserverCounter = OwinServers.First(e => e.Port == url.Port); owinserverCounter.AddRef(); return(owinserverCounter.OwinServer); } }
public static void UnRegisterOwinServer(OwinServer owinServer) { lock (OwinServers) { var owinserverCounter = OwinServers.FirstOrDefault(e => e.OwinServer == owinServer); if (owinserverCounter != null) { var count = owinserverCounter.Release(); if (count == 0) { owinServer.Dispose(); OwinServers.Remove(owinserverCounter); } } } }