private FileInfo GetStreamFile(IScope scope, string name) { IStreamableFileFactory scopeService = ScopeUtils.GetScopeService(scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory; if ((name.IndexOf(':') == -1) && (name.IndexOf('.') == -1)) { name = "flv:" + name; } log.Info(string.Concat(new object[] { "GetStreamFile factory: ", scopeService, " name: ", name })); foreach (IStreamableFileService service in scopeService.GetServices()) { if (name.StartsWith(service.Prefix + ':')) { name = service.PrepareFilename(name); break; } } IStreamFilenameGenerator generator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; string fileName = generator.GenerateFilename(scope, name, GenerationType.PLAYBACK); if (generator.ResolvesToAbsolutePath) { return(new FileInfo(fileName)); } return(scope.Context.GetResource(fileName).File); }
public void OnPipeConnectionEvent(PipeConnectionEvent evt) { switch (evt.Type) { case PipeConnectionEvent.CONSUMER_CONNECT_PULL: case PipeConnectionEvent.CONSUMER_CONNECT_PUSH: case PipeConnectionEvent.PROVIDER_CONNECT_PULL: case PipeConnectionEvent.PROVIDER_CONNECT_PUSH: _compCounter++; break; case PipeConnectionEvent.CONSUMER_DISCONNECT: case PipeConnectionEvent.PROVIDER_DISCONNECT: _compCounter--; if (_compCounter <= 0) { // XXX should we synchronize parent before removing? if (HasParent) { IProviderService providerService = ScopeUtils.GetScopeService(this.Parent, typeof(IProviderService)) as IProviderService; providerService.UnregisterBroadcastStream(Parent, Name); } _hasRemoved = true; } break; default: throw new NotSupportedException("Event type not supported: " + evt.Type); } }
private void Init() { IStreamableFileFactory scopeService = ScopeUtils.GetScopeService(this._scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory; string directoryName = Path.GetDirectoryName(this._file.FullName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (!this._file.Exists) { using (this._file.Create()) { } } IStreamableFile streamableFile = scopeService.GetService(this._file).GetStreamableFile(this._file); if ((this._mode == null) || this._mode.Equals("record")) { this._writer = streamableFile.GetWriter(); } else { if (!this._mode.Equals("append")) { throw new NotSupportedException("Illegal mode type: " + this._mode); } this._writer = streamableFile.GetAppendWriter(); } }
public void OnPipeConnectionEvent(PipeConnectionEvent evt) { switch (evt.Type) { case 0: case 1: case 3: case 4: this._compCounter++; break; case 2: case 5: this._compCounter--; if (this._compCounter <= 0) { if (base.HasParent) { (ScopeUtils.GetScopeService(this.Parent, typeof(IProviderService)) as IProviderService).UnregisterBroadcastStream(this.Parent, this.Name); } this._hasRemoved = true; } break; default: throw new NotSupportedException("Event type not supported: " + evt.Type); } }
private FileInfo GetStreamFile(IScope scope, String name) { IStreamableFileFactory factory = ScopeUtils.GetScopeService(scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory; if (name.IndexOf(':') == -1 && name.IndexOf('.') == -1) { // Default to .flv files if no prefix and no extension is given. name = "flv:" + name; } log.Info("GetStreamFile factory: " + factory + " name: " + name); foreach (IStreamableFileService service in factory.GetServices()) { if (name.StartsWith(service.Prefix + ':')) { name = service.PrepareFilename(name); break; } } IStreamFilenameGenerator filenameGenerator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; string filename = filenameGenerator.GenerateFilename(scope, name, GenerationType.PLAYBACK); FileInfo file; if (filenameGenerator.ResolvesToAbsolutePath) { file = new FileInfo(filename); } else { file = scope.Context.GetResource(filename).File; } return(file); }
/// <summary> /// Disconnects client from scope. Can be applied to both application scope /// and scopes of lower level. /// </summary> /// <param name="client">Client object.</param> /// <param name="scope">Scope object.</param> public override void Leave(IClient client, IScope scope) { if (ScopeUtils.IsApplication(scope)) AppLeave(client, scope); else if (ScopeUtils.IsRoom(scope)) RoomLeave(client, scope); base.Leave(client, scope); }
public virtual void RemoveEventListener(IEventListener listener) { this._listeners.Remove(listener); if ((!this._keepOnDisconnect && ScopeUtils.IsRoom(this)) && (this._listeners.Count == 0)) { this._parent.RemoveChildScope(this); } }
/// <summary> /// Stops scope handling (that is, stops application if given scope is app /// level scope and stops room handling if given scope has lower scope level). /// </summary> /// <param name="scope">Scope to stop.</param> public override void Stop(IScope scope) { if(ScopeUtils.IsApplication(scope)) AppStop(scope); else if (ScopeUtils.IsRoom(scope)) RoomStop(scope); base.Stop(scope); }
protected override void OnSharedObject(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, SharedObjectMessage message) { ISharedObject sharedObject = null; string name = message.Name; IScope scope = connection.Scope; bool isPersistent = message.IsPersistent; if (scope == null) { SharedObjectMessage message2; if (connection.ObjectEncoding == ObjectEncoding.AMF0) { message2 = new SharedObjectMessage(name, 0, isPersistent); } else { message2 = new FlexSharedObjectMessage(name, 0, isPersistent); } message2.AddEvent(new SharedObjectEvent(SharedObjectEventType.CLIENT_STATUS, "SharedObject.NoObjectFound", "error")); connection.GetChannel(3).Write(message2); } else { ISharedObjectService scopeService = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectService)) as ISharedObjectService; if (!scopeService.HasSharedObject(scope, name)) { ISharedObjectSecurityService service2 = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectSecurityService)) as ISharedObjectSecurityService; if (service2 != null) { IEnumerator sharedObjectSecurity = service2.GetSharedObjectSecurity(); while (sharedObjectSecurity.MoveNext()) { ISharedObjectSecurity current = sharedObjectSecurity.Current as ISharedObjectSecurity; if (!current.IsCreationAllowed(scope, name, isPersistent)) { SendSOCreationFailed(connection, name, isPersistent); return; } } } if (!scopeService.CreateSharedObject(scope, name, isPersistent)) { SendSOCreationFailed(connection, name, isPersistent); return; } } sharedObject = scopeService.GetSharedObject(scope, name); if (sharedObject.IsPersistentObject != isPersistent) { log.Debug(string.Format("Shared object '{0}' persistence mismatch", name)); SendSOPersistenceMismatch(connection, name, isPersistent); } else { sharedObject.DispatchEvent(message); } } }
public void TestSplitSimple() { var split = ScopeUtils.Split("a b c").ToList(); Assert.AreEqual(3, split.Count); Assert.AreEqual("a", split[0]); Assert.AreEqual("b", split[1]); Assert.AreEqual("c", split[2]); }
/// <summary> /// Remove event listener from this observable. /// </summary> /// <param name="listener">Event listener.</param> public virtual void RemoveEventListener(IEventListener listener) { _listeners.Remove(listener); if (!_keepOnDisconnect && ScopeUtils.IsRoom(this) && _listeners.Count == 0) { // Delete empty rooms _parent.RemoveChildScope(this); } }
public void TestSplitComplex() { var split = ScopeUtils.Split("scope1 r2/scope https://foo.com/.default").ToList(); Assert.AreEqual(3, split.Count); Assert.AreEqual("scope1", split[0]); Assert.AreEqual("r2/scope", split[1]); Assert.AreEqual("https://foo.com/.default", split[2]); }
/// <summary> /// Returns security handlers for this shared object or null if none are found. /// </summary> /// <returns>Collection of ISharedObjectSecurity objects.</returns> private IEnumerator GetSecurityHandlers() { ISharedObjectSecurityService security = ScopeUtils.GetScopeService(this.Parent, typeof(ISharedObjectSecurityService)) as ISharedObjectSecurityService; if (security == null) { return(null); } return(security.GetSharedObjectSecurity()); }
public void GetExactScopesMatchedAccessTokenTest() { var atItem = Credential.CreateAccessToken( MsalTestConstants.HomeAccountId, MsalTestConstants.ProductionPrefNetworkEnvironment, new Uri(MsalTestConstants.AuthorityTestTenant).GetRealm(), MsalTestConstants.ClientId, ScopeUtils.JoinScopes(MsalTestConstants.Scope), TimeUtils.GetSecondsFromEpochNow(), TimeUtils.GetSecondsFromEpochNow() + MsalCacheV2TestConstants.ValidExpiresIn, TimeUtils.GetSecondsFromEpochNow() + MsalCacheV2TestConstants.ValidExtendedExpiresIn, TheSecret, string.Empty); _storageWorker.WriteCredentials( new List <Credential> { atItem }); using (var httpManager = new MockHttpManager()) { var serviceBundle = ServiceBundle.CreateWithCustomHttpManager(httpManager); var cacheManager = new CacheManager( _storageManager, new AuthenticationRequestParameters { Account = MsalTestConstants.User, // TODO: In MSALC++, the request parameters only really needs the // Authority URI itself since the cache isn't meant to // do ANY network calls. // So it would be great if we could reduce the complexity/dependencies // here and do any of the validated authority cache / instance discovery // outside of the context of the authentication parameters and // cache interaction and just track the authority we're using... // AccountId = MsalTestConstants.HomeAccountId, // Authority = new Uri(MsalTestConstants.AuthorityTestTenant), Authority = Authority.CreateAuthority( serviceBundle, MsalTestConstants.AuthorityTestTenant, false), ClientId = MsalTestConstants.ClientId, Scope = new SortedSet <string>(MsalCacheV2TestConstants.Scope) // todo(mzuber): WHY SORTED SET? }); Assert.IsTrue(cacheManager.TryReadCache(out var tokenResponse, out var accountResponse)); Assert.IsNotNull(tokenResponse); Assert.IsNull(accountResponse); Assert.AreEqual(TheSecret, tokenResponse.AccessToken); } }
/// <summary> /// Starts scope. Scope can be both application or room level. /// </summary> /// <param name="scope">Scope object.</param> /// <returns>true if scope can be started, false otherwise.</returns> public override bool Start(IScope scope) { if(!base.Start(scope)) return false; if(ScopeUtils.IsApplication(scope)) return AppStart(scope); else if (ScopeUtils.IsRoom(scope)) return RoomStart(scope); else return false; }
/// <summary> /// Adds client to scope. Scope can be both application or room. Can be /// applied to both application scope and scopes of lower level. /// </summary> /// <param name="client">Client object.</param> /// <param name="scope">Scope object.</param> /// <returns>true to allow, false to deny join.</returns> public override bool Join(IClient client, IScope scope) { if(!base.Join(client, scope)) return false; if(ScopeUtils.IsApplication(scope)) return AppJoin(client, scope); else if (ScopeUtils.IsRoom(scope)) return RoomJoin(client, scope); else return false; }
public void TestJoinSimple() { string joined = ScopeUtils.Join( new List <string> { "a", "b", "c" }); Assert.AreEqual("a b c", joined); }
public void SimpleWorkflowWithArgsAndVar() { var sequence = Load(TestXamls.SimpleWorkflowWithArgsAndVar); var writeLine2 = (WriteLine)sequence.Activities.Last(); var to2 = sequence.Activities[1].RuntimeArguments[1]; var myVar = sequence.Variables[0]; var locations = ScopeUtils.GetCompatibleLocations(writeLine2, IsCompatible, ArgumentsFilter); locations.Locals.ShouldBe(new LocationReference[] { myVar }.Concat(sequence.Parent.RuntimeArguments)); locations.ReachableArguments.ShouldBe(new[] { new ReachableArgument(to2, to2.Owner, sequence) }); }
public override void Stop(IScope scope) { if (ScopeUtils.IsApplication(scope)) { this.AppStop(scope); } else if (ScopeUtils.IsRoom(scope)) { this.RoomStop(scope); } base.Stop(scope); }
public override bool Start(IScope scope) { if (!base.Start(scope)) { return(false); } if (ScopeUtils.IsApplication(scope)) { return(this.AppStart(scope)); } return(ScopeUtils.IsRoom(scope) && this.RoomStart(scope)); }
public void TestJoinComplex() { string joined = ScopeUtils.Join( new List <string> { "scope1", "r2/scope2", "https://foo.com/.default" }); Assert.AreEqual("scope1 r2/scope2 https://foo.com/.default", joined); }
public override bool Join(IClient client, IScope scope) { if (!base.Join(client, scope)) { return(false); } if (ScopeUtils.IsApplication(scope)) { return(this.AppJoin(client, scope)); } return(ScopeUtils.IsRoom(scope) && this.RoomJoin(client, scope)); }
internal HashSet <string> SplitAndNormalizeScopes(string target) { var scopes = ScopeUtils.SplitScopes(target); var normalizedScopes = new HashSet <string>(); foreach (string scope in scopes) { normalizedScopes.Add(NormalizeKey(scope)); } return(normalizedScopes); }
/// <summary> /// Returns disconnection result for given scope and parameters. /// Whether the scope is room or application level scope, this method distinguishes it and acts accordingly. /// </summary> /// <param name="connection">Connection object.</param> /// <param name="scope">true if disconnect is successful, false otherwise.</param> public override void Disconnect(IConnection connection, IScope scope) { if (ScopeUtils.IsApplication(scope)) { AppDisconnect(connection); } else if (ScopeUtils.IsRoom(scope)) { RoomDisconnect(connection); } base.Disconnect(connection, scope); }
public void GSuiteSendMailGetLocations() { LoadCustomAssemblies(); var root = Load(TestXamls.GSuiteSendMail); var gScope = root.Activities[0] as dynamic; var sendEmail = gScope.Body.Handler.Activities[0]; var ex = Record.Exception(() => ScopeUtils.GetCompatibleLocations(sendEmail as Activity, x => true, arg => arg.Direction != ArgumentDirection.In)); Assert.Null(ex); }
public MsalTokenResponse ToMsalTokenResponse() { return(new MsalTokenResponse { AccessToken = AccessToken, ExpiresIn = Convert.ToInt64(DateTime.UtcNow.Subtract(ExpiresOn).TotalSeconds), ExtendedExpiresIn = Convert.ToInt64(DateTime.UtcNow.Subtract(ExtendedExpiresOn).TotalSeconds), Claims = string.Empty, ClientInfo = RawClientInfo, IdToken = IdToken.ToString(), RefreshToken = RefreshToken, Scope = ScopeUtils.JoinScopes(GrantedScopes), TokenType = "whatgoeshere", // TODO: figure out MsalTokenResponse TokenType value(s) }); }
/// <summary> /// Returns connection result for given scope and parameters. /// Whether the scope is room or application level scope, this method distinguishes it and acts accordingly. /// </summary> /// <param name="connection">Connection object.</param> /// <param name="scope">Scope object.</param> /// <param name="parameters">List of params passed to connection handler.</param> /// <returns>true if connect is successful, false otherwise.</returns> public override bool Connect(IConnection connection, IScope scope, object[] parameters) { if( !base.Connect (connection, scope, parameters) ) return false; bool success = false; if(ScopeUtils.IsApplication(scope)) { success = AppConnect(connection, parameters); } else if (ScopeUtils.IsRoom(scope)) { success = RoomConnect(connection, parameters); } return success; }
protected override void OnSharedObject(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, SharedObjectMessage message) { ISharedObject so = null; string name = message.Name; IScope scope = connection.Scope; bool persistent = message.IsPersistent; if (scope == null) { // The scope already has been deleted. SendSOCreationFailed(connection, name, persistent); return; } ISharedObjectService sharedObjectService = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectService)) as ISharedObjectService; if (!sharedObjectService.HasSharedObject(scope, name)) { ISharedObjectSecurityService securityService = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectSecurityService)) as ISharedObjectSecurityService; if (securityService != null) { // Check handlers to see if creation is allowed IEnumerator enumerator = securityService.GetSharedObjectSecurity(); while (enumerator.MoveNext()) { ISharedObjectSecurity handler = enumerator.Current as ISharedObjectSecurity; if (!handler.IsCreationAllowed(scope, name, persistent)) { SendSOCreationFailed(connection, name, persistent); return; } } } if (!sharedObjectService.CreateSharedObject(scope, name, persistent)) { SendSOCreationFailed(connection, name, persistent); return; } } so = sharedObjectService.GetSharedObject(scope, name); if (so.IsPersistentObject != persistent) { log.Debug(string.Format("Shared object '{0}' persistence mismatch", name)); SendSOPersistenceMismatch(connection, name, persistent); return; } so.DispatchEvent(message); }
public TokenResponse(IdToken idToken, Credential accessToken, Credential refreshToken) { IdToken = idToken ?? new IdToken(string.Empty); if (accessToken != null) { AccessToken = accessToken.Secret; ExpiresOn = DateTime.UtcNow; // TODO: ToTimePoint(accessToken.ExpiresOn) ExtendedExpiresOn = DateTime.UtcNow; // TODO: ToTimePoint(accessToken.ExtendedExpiresOn) GrantedScopes = ScopeUtils.SplitScopes(accessToken.Target); } if (refreshToken != null) { RefreshToken = refreshToken.Secret; } }
private void Init() { IStreamableFileService service = ((IStreamableFileFactory)ScopeUtils.GetScopeService(this._scope, typeof(IStreamableFileFactory))).GetService(this._file); if (service == null) { log.Error("No service found for " + this._file.FullName); } else { this._reader = service.GetStreamableFile(this._file).GetReader(); if (this._start > 0) { this.Seek(this._start); } } }