public List<string> InstallAppWeb(string appName) { try { logger.Log("UICalled:InstallAppWeb " + appName); HomeStoreApp app = homeStoreInfo.GetHomeStoreAppByName(appName); if (app == null) { logger.Log("HomeStore app {0} was not found", appName); return new List<string>() { "HomeStore app not found" }; } //by default, we make the app auto start ModuleInfo moduleInfo = new ModuleInfo(app.AppName, app.AppName, app.BinaryName, null, true); moduleInfo.SetManifest(app.Manifest); if (String.IsNullOrWhiteSpace(app.Version)) moduleInfo.SetRunningVersion(Common.Constants.UnknownHomeOSUpdateVersionValue); else moduleInfo.SetRunningVersion(app.Version); AccessRule accessRule = new AccessRule(); accessRule.ModuleName = moduleInfo.FriendlyName(); accessRule.RuleName = "Access for " + moduleInfo.FriendlyName(); accessRule.UserGroup = "everyone"; accessRule.AccessMode = AccessMode.Allow; accessRule.DeviceList = new List<string> { "*" }; accessRule.TimeList = new List<TimeOfWeek> { new TimeOfWeek(-1, 0, 2400) }; accessRule.Priority = 0; platform.AddAccessRule(accessRule); //we now call startmodule: if we don't already have the binaries, this will download them as well var startedModule = platform.StartModule(moduleInfo, true); if (startedModule != null) { //add this to our configuration config.AddModule(moduleInfo); return new List<string>() { "" }; } else { //remove the rule we just added, since we are not starting the module platform.RemoveAccessRulesForModule(moduleInfo.FriendlyName()); return new List<string>() { "Could not start module. Perhaps because we didn't find the right binaries" }; } } catch (Exception e) { logger.Log("Exception in InstallAppWeb: " + e.ToString()); return new List<string>() { "Got exception: " + e.Message }; } }
/// <summary> /// Starts a module given its token /// We don't do this anymore: Has the side effect of updating the moduleInfo object's version to what was exactly ran /// </summary> /// <param name="moduleInfo"></param> /// <param name="token"></param> /// <returns></returns> private VModule StartModule(ModuleInfo moduleInfo, AddInToken token) { VModule startedModule = null; string moduleVersion = Utils.GetHomeOSUpdateVersion(Utils.GetAddInConfigFilepath(moduleInfo.BinaryName()), logger); if (!CompareModuleVersions(moduleInfo.GetDesiredVersion(), moduleVersion)) { logger.Log("WARNING: Starting an inexact match for {0}", moduleInfo.FriendlyName()); } moduleInfo.SetRunningVersion(moduleVersion); switch (Constants.ModuleIsolationLevel) { case ModuleIsolationModes.AppDomain: // AppDomain addInAppDomain = AppDomain.CreateDomain(moduleInfo.BinaryName()); // startedModule = token.Activate<VModule>(addInAppDomain); // Adding upfront, to check if the module is already running. // So that token is not re-activated if not needed - rayman if (runningModules.Values.Contains(moduleInfo)) throw new Exception(string.Format("Attempted to run duplicate module. New = {0}. Old = {1}", moduleInfo, moduleInfo)); startedModule = token.Activate<VModule>(AddInSecurityLevel.FullTrust); //AddInController ainController = AddInController.GetAddInController(startedModule); //AppDomain domain = ainController.AppDomain; break; case ModuleIsolationModes.Process: AddInProcess addInProc = new AddInProcess(); startedModule = token.Activate<VModule>(addInProc, AddInSecurityLevel.FullTrust); break; case ModuleIsolationModes.NoAddInAppDomain: //this requires putting Views.dll in the directory with AppBenchmarker.dll //the simplest way to do that is to just add AppBenchmarker as a reference //AppDomainSetup ads = new AppDomainSetup(); //ads.ApplicationBase = Environment.CurrentDirectory;//AddInRoot + "\\AddIns\\" + "AppBenchmarker"; var ad = AppDomain.CreateDomain(moduleInfo.FriendlyName());//, null, ads); startedModule = (VModule)ad.CreateInstanceAndUnwrap("AppBenchmarker", "AppBenchmarker.Benchmarker"); break; case ModuleIsolationModes.None: //this requires adding AppBenchmarker and ModuleBase projects as References //startedModule = (VModule)new AppBenchmarker.Benchmarker(); //if (moduleInfo.BinaryName().Equals("AppCamera")) // startedModule = (VModule)new AppCamera.CameraController(); //else if (moduleInfo.BinaryName().Equals("DriverFoscam")) // startedModule = (VModule)new DriverFoscam.DriverFoscam(); //else // logger.Log("Unknown module: {0}", moduleInfo.BinaryName()); break; } if (moduleInfo.WorkingDir() == null) moduleInfo.SetWorkingDir(Settings.ModuleWorkingDirBase + "\\" + moduleInfo.FriendlyName()); if (String.IsNullOrEmpty(moduleInfo.BaseURL())) moduleInfo.SetBaseURL(GetBaseUrl() + "/" + moduleInfo.FriendlyName()); if (string.IsNullOrEmpty(moduleInfo.BinaryDir())) moduleInfo.SetBinaryDir(Constants.AddInRoot + "\\AddIns\\" + moduleInfo.BinaryName()); int secret = GetNewSecret(); startedModule.Initialize(this, logger, moduleInfo, secret); lock (this) { //check if we already have this module running foreach (ModuleInfo runningModuleInfo in runningModules.Values) { if (runningModuleInfo.Equals(moduleInfo)) { //moduleThread.Abort(); throw new Exception(string.Format("Attempted to run duplicate module. New = {0}. Old = {1}", moduleInfo, moduleInfo)); } } runningModules[startedModule] = moduleInfo; } SafeThread moduleThread = new SafeThread(delegate() { startedModule.Start(); }, moduleInfo.FriendlyName(), logger); moduleThread.Start(); return startedModule; }