/// <summary> /// Issues a capability /// </summary> /// <param name="module">The module that is asking for the capability</param> /// <param name="targetPort">The port for which the capability is being requested</param> /// <param name="userName">The name of the user on behalf of which the capability is being requested</param> /// <param name="password">The password of the user</param> /// <returns>The issued capability</returns> public VCapability GetCapability(VModule requestingModule, VPort targetPort, string username, string password) { // .... //check if the user is valid, the module exists, and the port is registered // .... if (!username.Equals(Constants.UserSystem.Name) && config.ValidUserUntil(username, password) < DateTime.Now) return null; if (!runningModules.ContainsKey(requestingModule)) return null; //if (!config.allPorts.ContainsKey(targetPort.GetInfo())) // return null; if (!registeredPorts.ContainsKey(targetPort)) return null; string portName = targetPort.GetInfo().GetFriendlyName(); DateTime allowedUntil = (Settings.EnforcePolicies) ? policyEngine.AllowAccess(portName, requestingModule.GetInfo().FriendlyName(), username) : DateTime.MaxValue; if (allowedUntil < DateTime.Now) { return null; } Capability capability = new Capability("platform", allowedUntil); if (RemoteInstallCapability(capability, targetPort)) { return capability; } else { return null; } }
private void AddInCleanup(VModule moduleStopped) { //cleanup if (Constants.ModuleIsolationLevel == ModuleIsolationModes.AppDomain) { logger.Log("AppDomain cleanup for "+ moduleStopped.GetInfo().AppName()); bool done = false; AddInController aiController = AddInController.GetAddInController(moduleStopped); SafeThread t = new SafeThread(delegate() { while (!done) { try { aiController.Shutdown(); done = true; } catch (CannotUnloadAppDomainException) { logger.Log("AppDomain Unload did not succeed. Retrying."); System.Threading.Thread.Sleep(1000); // keep trying to unload until it gets unloaded } } }, moduleStopped.ToString()+"-UnloadingAppDomain", logger); t.Start(); t.Join(TimeSpan.FromMilliseconds(Settings.MaxFinallyBlockExecutionTime)); if(t.IsAlive()) t.Abort(); } else if (Constants.ModuleIsolationLevel == ModuleIsolationModes.Process) { //TODO: test this AddInController aiController = AddInController.GetAddInController(moduleStopped); aiController.Shutdown(); } else if (Constants.ModuleIsolationLevel == ModuleIsolationModes.NoAddInAppDomain) { // TODO handle cleanup here } else {// Globals.ModuleIsolationLevel == ModuleIsolationModes.None // TODO handle cleanup here } }
/// <summary> /// Issues a portinfo object /// </summary> /// <param name="moduleFacingName">The local name used by the owning module for this port</param> /// <param name="module">The owning module</param> /// <returns></returns> public VPortInfo GetPortInfo(string moduleFacingName, VModule module) { PortInfo targetPortInfo = new PortInfo(moduleFacingName, module.GetInfo()); //if matching portInfo exists, return that object //NB: we cannot return targetPortInfo itself because that is a different object (which does not have location and other things set) VPortInfo matchingPortInfo = config.GetMatchingPortInfo(targetPortInfo); if (matchingPortInfo != null) return matchingPortInfo; //this is not a port that we've seen before //make up a friendly name for this port as well as a location targetPortInfo.SetFriendlyName(moduleFacingName + " - " + module.GetInfo().FriendlyName()); targetPortInfo.SetLocation(config.RootLocation); config.AddUnconfiguredPort(targetPortInfo); return targetPortInfo; }
private void RemovePortFromConfig(VPort port , VModule module) { PortInfo targetPortInfo = new PortInfo(port.GetInfo().ModuleFacingName(), module.GetInfo()); PortInfo matchingPortInfo = config.GetMatchingPortInfo(targetPortInfo); if (matchingPortInfo == null) { } else { config.RemovePort(matchingPortInfo); } }
public bool StopModule(VModule moduleToStop) { //*** try { SafeThread t = new SafeThread(delegate() { moduleToStop.Stop(); }, moduleToStop.GetInfo().AppName() + "stop thread", logger); // invoke stop on the module t.Start(); t.Join(TimeSpan.FromMilliseconds(Settings.MaxStopExecutionTime)); if (t.IsAlive()) t.Abort(); ModuleFinished(moduleToStop); // dereg its ports broadcast ports' dereg; wipe module off data structures AddInCleanup(moduleToStop); // addin cleanup return true; } catch (Exception e) { logger.Log("Exception in stopping of module: " + e); return false; } //*** }