public static object GetScopeService(IScope scope, Type type, bool checkHandler) { if ((scope == null) || (type == null)) { return(null); } object service = scope.GetService(type); if ((service == null) && checkHandler) { for (IScope scope2 = scope; scope2 != null; scope2 = scope2.Parent) { IScopeHandler o = scope2.Handler; if (type.IsInstanceOfType(o)) { return(o); } if (!scope2.HasParent) { return(service); } } } return(service); }
public CredentialDiagnosticScope(ClientDiagnostics diagnostics, string name, TokenRequestContext context, IScopeHandler scopeHandler) { _name = name; _scope = scopeHandler.CreateScope(diagnostics, name); _context = context; _scopeHandler = scopeHandler; }
/// <summary> /// Returns scope service by service type. /// </summary> /// <param name="scope">The scope service belongs to.</param> /// <param name="type">Service type.</param> /// <param name="checkHandler">Indicates whether to check the scope's handler for the requested service.</param> /// <returns>Service object.</returns> public static object GetScopeService(IScope scope, Type type, bool checkHandler) { if (scope == null || type == null) { return(null); } object service = scope.GetService(type); if (service != null) { return(service); } if (checkHandler) { IScope current = scope; while (current != null) { IScopeHandler scopeHandler = current.Handler; if (type.IsInstanceOfType(scopeHandler)) { service = scopeHandler; break; } if (!current.HasParent) { break; } current = current.Parent; } } return(service); }
public CredentialDiagnosticScope StartGetTokenScope(string fullyQualifiedMethod, TokenRequestContext context) { IScopeHandler scopeHandler = _groupScopeHandler ?? _defaultScopeHandler; CredentialDiagnosticScope scope = new CredentialDiagnosticScope(fullyQualifiedMethod, context, scopeHandler); scope.Start(); return(scope); }
private CredentialPipeline(TokenCredentialOptions options) { AuthorityHost = options.AuthorityHost; HttpPipeline = HttpPipelineBuilder.Build(options, Array.Empty <HttpPipelinePolicy>(), Array.Empty <HttpPipelinePolicy>(), new CredentialResponseClassifier()); Diagnostics = new ClientDiagnostics(options); _defaultScopeHandler = new ScopeHandler(Diagnostics); }
/// <summary> /// Returns stream aware scope handler or null if scope is null. /// </summary> /// <returns>IStreamAwareScopeHandler implementation.</returns> protected IStreamAwareScopeHandler GetStreamAwareHandler() { if (_scope != null) { IScopeHandler handler = _scope.Handler; if (handler is IStreamAwareScopeHandler) { return(handler as IStreamAwareScopeHandler); } } return(null); }
public void Disconnect(IConnection connection) { IClient key = connection.Client; if (this._clients.ContainsKey(key)) { Exception exception; CopyOnWriteArraySet <IConnection> set = this._clients[key]; set.Remove(connection); IScopeHandler handler = null; if (this.HasHandler) { handler = this.Handler; try { handler.Disconnect(connection, this); } catch (Exception exception1) { exception = exception1; if ((log != null) && log.get_IsErrorEnabled()) { log.Error(string.Concat(new object[] { "Error while executing \"disconnect\" for connection ", connection, " on handler ", handler }), exception); } } } if (set.Count == 0) { this._clients.Remove(key); if (handler != null) { try { handler.Leave(key, this); } catch (Exception exception2) { exception = exception2; if ((log != null) && log.get_IsErrorEnabled()) { log.Error(string.Concat(new object[] { "Error while executing \"leave\" for client ", key, " on handler ", handler }), exception); } } } } this.RemoveEventListener(connection); } if (base.HasParent) { this.Parent.Disconnect(connection); } }
public static void InvokeCall(RtmpConnection connection, IServiceCall serviceCall) { IScope scope = connection.Scope; if (scope.HasHandler) { IScopeHandler handler = scope.Handler; if (!handler.ServiceCall(connection, serviceCall)) { // What do do here? Return an error? return; } } IScopeContext context = scope.Context; context.ServiceInvoker.Invoke(serviceCall, scope); }
public void Disconnect(IConnection connection) { // We call the disconnect handlers in reverse order they were called // during connection, i.e. roomDisconnect is called before // appDisconnect. IClient client = connection.Client; if (_clients.ContainsKey(client)) { CopyOnWriteArraySet <IConnection> connections = _clients[client]; connections.Remove(connection); IScopeHandler handler = null; if (HasHandler) { handler = this.Handler; try { handler.Disconnect(connection, this); } catch (Exception) { } } if (connections.Count == 0) { _clients.Remove(client); if (handler != null) { try { // there may be a timeout here ? handler.Leave(client, this); } catch (Exception) { } } } RemoveEventListener(connection); } if (HasParent) { this.Parent.Disconnect(connection); } }
public override void Start() { try { string str; IPEndPoint point; if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Start")); } IGlobalScope globalScope = base.GetMessageBroker().GlobalScope; if (FluorineContext.Current != null) { str = Path.Combine(FluorineContext.Current.ApplicationBaseDirectory, "apps"); } else { str = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "apps"); } if (Directory.Exists(str)) { foreach (string str2 in Directory.GetDirectories(str)) { DirectoryInfo info = new DirectoryInfo(str2); string name = info.Name; ApplicationConfiguration appConfig = ApplicationConfiguration.Load(Path.Combine(str2, "app.config")); WebScope scope2 = new WebScope(this, globalScope, appConfig); ScopeContext context = new ScopeContext("/" + name, globalScope.Context.ClientRegistry, globalScope.Context.ScopeResolver, globalScope.Context.ServiceInvoker, null); scope2.Context = context; IScopeHandler handler = ObjectFactory.CreateInstance(appConfig.ApplicationHandler.Type) as IScopeHandler; if (handler == null) { log.Error(__Res.GetString("Type_InitError", new object[] { appConfig.ApplicationHandler.Type })); } scope2.Handler = handler; scope2.SetContextPath("/" + name); scope2.Register(); } } this._rtmpServer = new RtmpServer(this); UriBase uri = base._channelSettings.GetUri(); int port = 0x78f; if ((uri.Port != null) && (uri.Port != string.Empty)) { port = Convert.ToInt32(uri.Port); } if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Starting", new object[] { port.ToString() })); } if (base._channelSettings.BindAddress != null) { point = new IPEndPoint(IPAddress.Parse(base._channelSettings.BindAddress), port); } else { point = new IPEndPoint(IPAddress.Any, port); } this._rtmpServer.AddListener(point); this._rtmpServer.OnError += new ErrorHandler(this.OnError); this._rtmpServer.Start(); if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Started")); } } catch (Exception exception) { if (log.get_IsFatalEnabled()) { log.Fatal("RtmpEndpoint failed", exception); } } }
public override void Start() { try { if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Start)); } //Each Application has its own Scope hierarchy and the root scope is WebScope. //There's a global scope that aims to provide common resource sharing across Applications namely GlobalScope. //The GlobalScope is the parent of all WebScopes. //Other scopes in between are all instances of Scope. Each scope takes a name. //The GlobalScope is named "default". //The WebScope is named per Application context name. //The Scope is named per path name. IGlobalScope globalScope = GetMessageBroker().GlobalScope; string baseDirectory; if (FluorineContext.Current != null) { baseDirectory = Path.Combine(FluorineContext.Current.ApplicationBaseDirectory, "apps"); } else { baseDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "apps"); } if (Directory.Exists(baseDirectory)) { foreach (string appDirectory in Directory.GetDirectories(baseDirectory)) { DirectoryInfo directoryInfo = new DirectoryInfo(appDirectory); string appName = directoryInfo.Name; string appConfigFile = Path.Combine(appDirectory, "app.config"); ApplicationConfiguration configuration = ApplicationConfiguration.Load(appConfigFile); WebScope scope = new WebScope(this, globalScope, configuration); // Create context for the WebScope and initialize ScopeContext scopeContext = new ScopeContext("/" + appName, globalScope.Context.ClientRegistry, globalScope.Context.ScopeResolver, globalScope.Context.ServiceInvoker, null); // Store context in scope scope.Context = scopeContext; // ApplicationAdapter IFlexFactory factory = GetMessageBroker().GetFactory(configuration.ApplicationHandler.Factory); FactoryInstance factoryInstance = factory.CreateFactoryInstance(this.Id, null); if (factoryInstance == null) { string msg = string.Format("Missing factory {0}", configuration.ApplicationHandler.Factory); log.Fatal(msg); throw new NotSupportedException(msg); } factoryInstance.Source = configuration.ApplicationHandler.Type; object applicationHandlerInstance = factoryInstance.Lookup(); IScopeHandler scopeHandler = applicationHandlerInstance as IScopeHandler; if (scopeHandler == null) { log.Error(__Res.GetString(__Res.Type_InitError, configuration.ApplicationHandler.Type)); throw new TypeInitializationException(configuration.ApplicationHandler.Type, null); } scope.Handler = scopeHandler; // Make available as "/<directoryName>" and allow access from all hosts scope.SetContextPath("/" + appName); // Register WebScope in server scope.Register(); } } _rtmpServer = new RtmpServer(this); UriBase uri = this.ChannelDefinition.GetUri(); if (uri.Protocol == "http" || uri.Protocol == "https") { log.Info(string.Format("Rtmp endpoint was not started, specified protocol: {0}", uri.Protocol)); return; } int port = 1935; if (uri.Port != null && uri.Port != string.Empty) { try { port = System.Convert.ToInt32(uri.Port); } catch (FormatException ex) { log.Error("Invalid port", ex); return; } } if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Starting, port.ToString())); } IPEndPoint ipEndPoint; if (this.ChannelDefinition.Properties.BindAddress != null) { IPAddress ipAddress = IPAddress.Parse(this.ChannelDefinition.Properties.BindAddress); ipEndPoint = new IPEndPoint(ipAddress, port); } else { ipEndPoint = new IPEndPoint(IPAddress.Any, port); } _rtmpServer.AddListener(ipEndPoint); _rtmpServer.OnError += new ErrorHandler(OnError); _rtmpServer.Start(); if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Started)); } } catch (Exception ex) { if (log.IsFatalEnabled) { log.Fatal("RtmpEndpoint failed", ex); } } }
public StructVariableBuilder(IScopeHandler scopeHandler, IVarContextHandler contextHandler) : base(scopeHandler, contextHandler) { }
public static DefinedMethodProvider GetDefinedMethod(ParseInfo parseInfo, IScopeHandler scopeHandler, FunctionContext context, IDefinedTypeInitializer containingType) => new DefinedMethodProvider(parseInfo, scopeHandler, context, containingType);
public VarBuilder(IScopeHandler scopeHandler, IVarContextHandler contextHandler) { _scopeHandler = scopeHandler; _contextHandler = contextHandler; }
public ScopeController(IScopeHandler handler) { _handler = handler; }
public StructValueVariable(IScopeHandler scopeHandler, IVarContextHandler contextHandler) : base(scopeHandler, contextHandler) { _canInferType = true; }
private DefinedMethodProvider(ParseInfo parseInfo, IScopeHandler scopeProvider, FunctionContext context, IDefinedTypeInitializer containingType) { _parseInfo = parseInfo; Context = context; ContainingType = containingType; CallInfo = new CallInfo(new RecursiveCallHandler(this, context.Subroutine || context.Attributes.Recursive), parseInfo.Script, ContentReady); DocRange nameRange = context.Identifier.Range; // Get the attributes. var attributes = new GenericAttributeAppender(AttributeType.Ref, AttributeType.In, AttributeType.GlobalVar, AttributeType.PlayerVar); AttributesGetter.GetAttributes(parseInfo.Script.Diagnostics, context.Attributes, attributes); // Set the attributes. Static = attributes.IsStatic; Recursive = attributes.IsRecursive; Virtual = attributes.IsVirtual; AccessLevel = attributes.Accessor; Recursive = attributes.IsRecursive; // Get subroutine info. if (context.Subroutine) { IsSubroutine = true; SubroutineName = context.Subroutine.Text.RemoveQuotes(); SubroutineDefaultGlobal = !context.PlayerVar; } // Setup the scope. var containingScope = scopeProvider.GetScope(Static); containingScope.MethodContainer = true; _methodScope = containingScope.Child(true); // Get the generics. GenericTypes = AnonymousType.GetGenerics(parseInfo, context.TypeArguments, this); foreach (var type in GenericTypes) { _methodScope.AddType(new GenericCodeTypeInitializer(type)); } // Get the type. if (!context.Type.IsVoid) { ReturnType = TypeFromContext.GetCodeTypeFromContext(parseInfo, _methodScope, context.Type); } // Setup the parameters. ParameterProviders = ParameterProvider.GetParameterProviders(parseInfo, _methodScope, context.Parameters, IsSubroutine); ParameterTypes = ParameterProviders.Select(p => p.Type).ToArray(); // Override if (attributes.IsOverride) { OverridingFunction = (DefinedMethodInstance)scopeProvider.GetOverridenFunction(parseInfo.TranslateInfo, new FunctionOverrideInfo(Name, ParameterTypes)); if (OverridingFunction == null) { SemanticsHelper.CouldNotOverride(parseInfo, nameRange, "method"); } } // Check conflicts and add to scope. scopeProvider.CheckConflict(parseInfo, new(Name, ParameterTypes), nameRange); scopeProvider.Add(GetDefaultInstance(scopeProvider.DefinedIn()), Static); // Add LSP elements // Hover parseInfo.Script.AddHover(nameRange, GetLabel(parseInfo.TranslateInfo, LabelInfo.Hover)); // 'references' code lens parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Function, DefinedAt.range)); // Rename & go-to-definition parseInfo.Script.Elements.AddDeclarationCall(this, new DeclarationCall(nameRange, true)); // todo: 'override' code lens // if (Attributes.IsOverrideable) // parseInfo.Script.AddCodeLensRange(new ImplementsCodeLensRange(this, parseInfo.Script, CodeLensSourceType.Function, nameRange)); // Add the CallInfo to the recursion check. parseInfo.TranslateInfo.GetComponent <RecursionCheckComponent>().AddCheck(CallInfo); // Queue content for staged initiation. parseInfo.TranslateInfo.StagedInitiation.On(this); }
/// <summary> /// Disconnects the specified connection. /// </summary> /// <param name="connection">The connection.</param> public void Disconnect(IConnection connection) { // We call the disconnect handlers in reverse order they were called during connection, i.e. roomDisconnect is called before appDisconnect. IClient client = connection.Client; if (client == null) { // Early bail out RemoveEventListener(connection); _connectionStats.Decrement(); if (HasParent) { Parent.Disconnect(connection); } return; } if (_clients.ContainsKey(client)) { CopyOnWriteArraySet <IConnection> connections = _clients[client]; connections.Remove(connection); IScopeHandler handler = null; if (HasHandler) { handler = Handler; try { handler.Disconnect(connection, this); } catch (Exception ex) { #if !SILVERLIGHT if (log != null && log.IsErrorEnabled) { log.Error("Error while executing \"disconnect\" for connection " + connection + " on handler " + handler, ex); } #endif } } if (connections.Count == 0) { _clients.Remove(client); _clientStats.Decrement(); if (handler != null) { try { // there may be a timeout here ? handler.Leave(client, this); } catch (Exception ex) { #if !SILVERLIGHT if (log != null && log.IsErrorEnabled) { log.Error("Error while executing \"leave\" for client " + client + " on handler " + handler, ex); } #endif } } } RemoveEventListener(connection); _connectionStats.Decrement(); } if (HasParent) { Parent.Disconnect(connection); } }
public ClassVariable(IScopeHandler scopeHandler, IVarContextHandler contextHandler) : base(scopeHandler, contextHandler) { }