private bool GetScoutFromRep(ScoutInfo scoutInfo)
        {
            logger.Log("fetching scout "+scoutInfo.Name +" v "+scoutInfo.DesiredVersion+" from reps");
            Dictionary<string, bool> repAvailability = AvailableOnRep(scoutInfo);
            if (!repAvailability.ContainsValue(true))
            {
                logger.Log("Can't find " + scoutInfo.DllName + " v" + scoutInfo.DesiredVersion + " on any rep.");
                return false;
            }

            foreach (Tuple<ScoutInfo,IScout> runningScoutTuple in runningScouts.Values)
            {
                if (runningScoutTuple.Item1.DllName.Equals(scoutInfo.DllName))
                    throw new Exception(String.Format("Attempted to fetch scout, with same binary name scout running. Running: ({0}, v {1}) Fetching: ({2}, v{3})",
                               runningScoutTuple.Item1.DllName, runningScoutTuple.Item1.DesiredVersion , scoutInfo.DllName, scoutInfo.DesiredVersion));
            }

            try
            {
                string baseDir = Constants.ScoutRoot + "\\" + scoutInfo.Name;

                CreateAddInDirectory(Constants.ScoutRoot, scoutInfo.Name);
                DownloadFile(repAvailability.FirstOrDefault(x => x.Value == true).Key, baseDir , scoutInfo.DllName + ".zip");
                UnpackZip(baseDir + "\\" + scoutInfo.DllName + ".zip", baseDir );
                
                File.Delete(baseDir + "\\" + scoutInfo.DllName + ".zip");
            }
            catch (Exception e)
            {
                logger.Log("Exception : " + e);
                return false;
            }
            return true; 
        }
        private Dictionary<string, bool> AvailableOnRep(ScoutInfo scoutInfo)
        {
            string[] URIs = Settings.RepositoryURIs.Split('|');
            String[] path = scoutInfo.DllName.Split('.');
            Dictionary<string, bool> retval = new Dictionary<string, bool>();

            foreach (string uri in URIs)
            {
                //logger.Log("Checking " + scoutInfo.DllName + " v" + scoutInfo.Version+ "  availability on Rep: " + uri);
                string zipuri = uri;

                //by default platform should point to the Latest on the repository if a version of the binary isn't specified
                string binaryversion = "Latest"; 
                if (scoutInfo.DesiredVersion != null && scoutInfo.DesiredVersion != Constants.UnknownHomeOSUpdateVersionValue)
                {
                    binaryversion = scoutInfo.DesiredVersion;
                }

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


                zipuri += '/' + binaryversion + '/' + scoutInfo.DllName + ".zip";

                if (UrlIsValid(zipuri))
                {
                    retval[zipuri] = true;
                    return retval;
                }
            }
            retval[""] = false;
            return retval;
        }
        public void StartScout(ScoutInfo sInfo)
        {
            lock (runningScouts)
            {
            if (runningScouts.ContainsKey(sInfo.Name))
            {
                logger.Log("Error: Scout {0} is already running; cannot start again", sInfo.Name);
                return;
            }

            string baseDir = Constants.ScoutRoot + "\\" + sInfo.DllName;
            string dllPath = baseDir + "\\" + sInfo.DllName + ".dll";
            string baseUrl = GetBaseUrl() + "/" + Constants.ScoutsSuffixWeb + "/" + sInfo.DllName;

            try
            {
                string dllFullPath = Path.GetFullPath(dllPath);

                Version vDesired = new Version(sInfo.DesiredVersion);

                if (!File.Exists(dllFullPath))
                {
                    logger.Log("{0} is not present locally. Will try to get version {1} from Repository", sInfo.Name, sInfo.DesiredVersion);

                    GetScoutFromRep(sInfo); // now attempt to start what we got (if we did)
                }
                else
                {
                    
                    Version vLocal = new Version(Utils.GetHomeOSUpdateVersion(dllFullPath + ".config", logger));

                    //if local version and desired versions differ ... 
                    if (vLocal.CompareTo(vDesired) != 0)
                    {
                        //if the desired version is unspecified, pick between the most recent of the latest-on-rep and local
                        if (vDesired.CompareTo(new Version(Constants.UnknownHomeOSUpdateVersionValue)) == 0)
                        {
                            Version vLatestOnRep = new Version(GetVersionFromRep(Settings.RepositoryURIs, sInfo.DllName));

                            if (vLatestOnRep.CompareTo(vLocal) > 0)
                            {
                                logger.Log("Local verison ({0}) is lower than the latest rep version ({1}) for {2}", vLocal.ToString(), vDesired.ToString(), sInfo.Name);

                                GetScoutFromRep(sInfo);
                            }
                            else
                            {
                                logger.Log("Local verison ({0}) is already latest for {1}", vLocal.ToString(), sInfo.Name);
                            }
                        }
                        //we a specific version is desired
                        else
                        {
                            logger.Log("Will try to get specific version {0} for {1} from Repository", sInfo.DesiredVersion, sInfo.Name);

                            GetScoutFromRep(sInfo); // now attempt to start what we got (if we did)
                        }
                    }
                    else
                    {
                        logger.Log("Local verison ({0}) is same as desired version for {1}. Starting that", vDesired.ToString(), sInfo.Name);
                    }
                }

                if (!File.Exists(dllFullPath))
                {
                    logger.Log("Error: Could not fine Scout {0} anywhere; not starting", sInfo.Name);
                    return;
                }

                var vAboutToRun = new Version(Utils.GetHomeOSUpdateVersion(dllFullPath + ".config", logger));

                if (vDesired.CompareTo(new Version(Constants.UnknownHomeOSUpdateVersionValue)) != 0 && vDesired.CompareTo(vAboutToRun) != 0)
                {
                    logger.Log("WARNING: couldn't get the desired version {0} for {1}. Starting {2}", vDesired.ToString(), sInfo.Name, vAboutToRun.ToString());
                }

                logger.Log("starting scout {0} (v{1}) using dll {2} at url {3}", sInfo.Name, vAboutToRun.ToString(), dllPath, baseUrl);

                System.Reflection.Assembly myLibrary = System.Reflection.Assembly.LoadFile(dllFullPath);
                Type myClass = (from type in myLibrary.GetExportedTypes()
                                where typeof(IScout).IsAssignableFrom(type)
                                select type)
                                .Single();

                var scout = (IScout)Activator.CreateInstance(myClass);

                scout.Init(baseUrl, baseDir, this, logger);

                sInfo.SetRunningVersion(vAboutToRun.ToString());

                runningScouts.Add(sInfo.Name, new Tuple<ScoutInfo, IScout>(sInfo, scout));
            }
            catch (Exception e)
            {
                logger.Log("Got exception while starting {0}: {1}", sInfo.Name, e.ToString());
            }
        }
        }
Exemple #4
0
        private Dictionary<string, bool> AvailableOnRep(ScoutInfo scoutInfo)
        {
            string[] URIs = Settings.RepositoryURIs.Split('|');
            String[] path = scoutInfo.DllName.Split('.');
            Dictionary<string, bool> retval = new Dictionary<string, bool>();

            foreach (string uri in URIs)
            {
                //logger.Log("Checking " + scoutInfo.DllName + " v" + scoutInfo.Version+ "  availability on Rep: " + uri);
                string zipuri = uri;

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

                zipuri += '/' + scoutInfo.Version + '/' + scoutInfo.DllName + ".zip";

                if (UrlIsValid(zipuri))
                {
                    retval[zipuri] = true;
                    return retval;
                }
            }
            retval[""] = false;
            return retval;
        }
Exemple #5
0
        public void StartScout(ScoutInfo sInfo)
        {
            lock (runningScouts)
            {
            if (runningScouts.ContainsKey(sInfo.Name))
            {
                logger.Log("Error: Scout {0} is already running; cannot start again");
                return;
            }

            string baseDir = Constants.ScoutRoot + "\\" + sInfo.Name;
                string dllPath = baseDir + "\\" + sInfo.DllName + ".dll";
            string baseUrl = GetBaseUrl() + "/" + Constants.ScoutsSuffixWeb + "/" + sInfo.Name;

            

            try
            {
                string dllFullPath = Path.GetFullPath(dllPath);

                if (!File.Exists(dllFullPath))
                    GetScoutFromRep(sInfo); // now attempt to start what we got (if we did)
                else
                {
                    string currentScoutVersion = GetHomeOSUpdateVersion(dllFullPath + ".config");
                    // we are using file versions for the Versioning and not Assembly versions because to read that 
                    // the assembly needs to be loaded. But unloading the assembly is a pain (in case of version mismatch)

                    if (!CompareModuleVersions(currentScoutVersion, sInfo.Version))
                        GetScoutFromRep(sInfo);// if we didn't get the right version, lets start what we have
                }

                logger.Log("starting scout {0} using dll {1} at url {2}", sInfo.Name, dllPath, baseUrl);

                System.Reflection.Assembly myLibrary = System.Reflection.Assembly.LoadFile(dllFullPath);
                Type myClass = (from type in myLibrary.GetExportedTypes()
                                where typeof(IScout).IsAssignableFrom(type)
                                select type)
                                .Single();

                var scout = (IScout)Activator.CreateInstance(myClass);


                scout.Init(baseUrl, baseDir, this, logger);

                runningScouts.Add(sInfo.Name, scout);
            }
            catch (Exception e)
            {
                logger.Log("Got exception while starting {0}: {1}", sInfo.Name, e.ToString());
            }
        }
        }
        public bool AddScout(ScoutInfo sInfo, bool writeToDisk = true)
        {
            lock (allScouts)
            {
                if (allScouts.ContainsKey(sInfo.Name))
                    return false;

                allScouts.Add(sInfo.Name, sInfo);

                if (writeToDisk)
                    WriteScoutsList();

                return true;
            }
        }
        private void ReadScoutsList()
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlReader xmlReader = XmlReader.Create(ScoutsFile, xmlReaderSettings);

            xmlDoc.Load(xmlReader);
            XmlElement root = xmlDoc.FirstChild as XmlElement;

            if (!root.Name.Equals("Scouts"))
                throw new Exception(ScoutsFile + " doesn't start with Scouts");

            foreach (XmlElement xmlDevice in root.ChildNodes)
            {
                if (!xmlDevice.Name.Equals("Scout"))
                    throw new Exception("child is not a Scout in " + ScoutsFile);

                string scoutName = xmlDevice.GetAttribute("Name");
                string driverBinaryName = xmlDevice.GetAttribute("DllName");
                string version = xmlDevice.GetAttribute("Version");
                driverBinaryName = driverBinaryName.Replace(".dll", "");
                

                ScoutInfo sInfo = new ScoutInfo(scoutName, driverBinaryName);

                if (!String.IsNullOrEmpty(version))
                    sInfo.SetDesiredVersion(version);
                else
                    sInfo.SetDesiredVersion(Constants.UnknownHomeOSUpdateVersionValue);

                allScouts.Add(scoutName, sInfo);
            }

            xmlReader.Close();
        }