Ejemplo n.º 1
0
        private Dictionary<string,bool> AvailableOnRep(ModuleInfo moduleInfo)
        {
            string[] URIs = Settings.RepositoryURIs.Split('|'); 
            String[] path = moduleInfo.BinaryName().Split('.');
            Dictionary<string, bool> retval = new Dictionary<string,bool>();

            foreach (string uri in URIs)
            {
                //logger.Log("Checking " + moduleInfo.BinaryName() + " v" + moduleInfo.GetVersion() + "  availability on Rep: " + uri);

                //string zipuri = uri +'/' + path[0] + '/' + path[1] + '/' + path[2] + '/' + path[3] + '/' + moduleInfo.GetVersion() + '/' + moduleInfo.BinaryName() + ".zip";

                string zipuri = uri;

                foreach (string pathElement in path)
                    zipuri += "/" + pathElement;

                zipuri += '/' + moduleInfo.GetVersion() + '/' + moduleInfo.BinaryName() + ".zip";

                if (UrlIsValid(zipuri))
                {
                    retval[zipuri]=true;
                    return retval;
                }
            }
            retval[""] = false;
            return retval;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts a module given its token
        /// 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 = GetHomeOSUpdateVersion(GetAddInConfigFilepath(moduleInfo.BinaryName()));
            if (!CompareModuleVersions(moduleInfo.GetVersion(), moduleVersion))
            {
                logger.Log("WARNING: Starting an inexact match for {0}", moduleInfo.FriendlyName());
                moduleInfo.SetVersion(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;
        }
Ejemplo n.º 3
0
        private bool GetAddInFromRep(ModuleInfo moduleInfo , bool rebuild = true)
        {

            Dictionary<string,bool> repAvailability = AvailableOnRep(moduleInfo) ; 
            if (!repAvailability.ContainsValue(true))
            {
                logger.Log("Can't find "+moduleInfo.BinaryName() + " v"+moduleInfo.GetVersion()+" on any rep.");
                return false;
            }

            // on fetching the binaries of a module existing older versions shall be overwritten
            // making sure older version module is not running.
            foreach (ModuleInfo runningModuleInfo in runningModules.Values)
            {
                if (runningModuleInfo.BinaryName().Equals(moduleInfo.BinaryName()))
                    throw new Exception(String.Format("Attempted to fetch module, with same binary name module running. Running: ({0}, v {1}) Fetching: ({2}, v{3})", runningModuleInfo.BinaryName(), runningModuleInfo.GetVersion() , moduleInfo.BinaryName() , moduleInfo.GetVersion()));
            }

            //unloading addin
            AddInToken removeToken = null;
            foreach (AddInToken t in allAddinTokens)
            {
                if (t.Name.Equals(moduleInfo.BinaryName()))
                {
                    removeToken = t;
                    break;
                }
            }
            allAddinTokens.Remove(removeToken);
            removeToken = null;
            GC.Collect();
            try
            {
                CreateAddInDirectory(Constants.AddInRoot + "\\AddIns\\", moduleInfo.BinaryName());
                GetAddInZip(repAvailability.FirstOrDefault(x => x.Value == true).Key, Constants.AddInRoot + "\\AddIns\\" + moduleInfo.BinaryName(), moduleInfo.BinaryName() + ".zip");
                UnpackZip(Constants.AddInRoot + "\\AddIns\\" + moduleInfo.BinaryName() + "\\" + moduleInfo.BinaryName() + ".zip", Constants.AddInRoot + "\\AddIns\\" + moduleInfo.BinaryName());
                if(rebuild)
                    rebuildAddInTokens();

                File.Delete(Constants.AddInRoot + "\\AddIns\\" + moduleInfo.BinaryName() + "\\" + moduleInfo.BinaryName() + ".zip");

            }
            catch (Exception e)
            {
                logger.Log("Exception : " + e);
                return false;
            }
            return true; 




        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts a module by searching for a matching token
        /// </summary>
        /// <param name="moduleInfo">The ModuleInfo for the module to start</param>
        public VModule StartModule(ModuleInfo moduleInfo, bool exactlyMatchVersions = false)
        {
            VModule startedModule = null;

            foreach (AddInToken token in allAddinTokens)
            {
                if (token.Name.Equals(moduleInfo.BinaryName()) &&
                    (!exactlyMatchVersions || CompareModuleVersions(moduleInfo.GetVersion(), GetHomeOSUpdateVersion(GetAddInConfigFilepath(moduleInfo.BinaryName())))))
                {
                    if (startedModule != null)
                    {
                        logger.Log("WARNING: Found multiple matching tokens for " + moduleInfo.ToString());
                        continue;
                    }

                    try
                    {
                        startedModule = StartModule(moduleInfo, token);
                    }
                    catch (Exception exception)
                    {
                        logger.Log("Could not start module {0}: {1}", moduleInfo.ToString(), exception.ToString());
                        return null;
                    }
                }
            }

            //we ran something, lets return it
            if (startedModule != null)
                return startedModule;

            //we didn't run anything.
            //if we were doing exact match on versions, this could be because we didn't find an exact match
            if (exactlyMatchVersions)
            {
                logger.Log("No exact-match-version token found for Module: Binary name: " + moduleInfo.BinaryName() + ", App Name: " + moduleInfo.AppName() + ", Version: " + moduleInfo.GetVersion());

                //try to get an exact match from the homestore
                GetAddInFromRep(moduleInfo);

                //maybe, we got the right version, maybe we didn't; in any case, lets now run what we can find, without being strict about version numbers
                return StartModule(moduleInfo, false);
            }
            else
            {
                logger.Log("No matching token at all found for Module: Binary name: " + moduleInfo.BinaryName() + ", App Name: " + moduleInfo.AppName() + ", Version: " + moduleInfo.GetVersion());
                return null;
            }
        }