HandleUserData() публичный Метод

public HandleUserData ( String userDataFile ) : void
userDataFile String
Результат void
        /*
         * <include>
         *    http://myhost/user-data1
         *    http://myhost/user-data2
         * </include>
         *
         */
        override protected void Handle()
        {
            var urls      = this.AsMultiLinesWithoutTag;
            var validUrls = urls.Where(url =>
                                       url.ToLower().StartsWith("http://"));
            List <String> localUserData = new List <String>();

            foreach (String url in validUrls)
            {
                String filePath = String.Format("{0}\\{1}.txt",
                                                CloudInit.CloudInitDirectory, Guid.NewGuid().ToString().Substring(0, 8));
                try{
                    EucaUtil.Curl(url, filePath);
                    localUserData.Add(filePath);
                }catch (Exception ex) {
                    EucaLogger.Exception(String.Format("Failed to download from the include url {0}", url), ex);
                    continue;
                }
            }

            foreach (String userDataFile in localUserData)
            {
                UserDataHandler handler = null;
                try
                {
                    handler = UserDataHandlerFactory.Instance.GetHandler(userDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception("Unable to find the right handler for include file", ex);
                }

                try
                {
                    handler.HandleUserData(userDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception("Failed to handle the user data", ex);
                }
            }

            foreach (String userDataFile in localUserData)
            {
                File.Delete(userDataFile);
            }
        }
Пример #2
0
        public void Init()
        {
            string userDataFile = null;

            try
            {
                userDataFile = CloudInit.CloudInitDirectory + "\\user-data";
                EucaUtil.GetUserData(userDataFile);
                if (!File.Exists(userDataFile))
                {
                    throw new EucaException("User data file not found");
                }
                if ((new FileInfo(userDataFile)).Length <= 0)
                {
                    throw new EucaException("Invalid user data file");
                }
            }
            catch (Exception ex)
            {
                EucaLogger.Debug("Unable to download the user-data");
                throw ex;
            }

            // detect the contents
            UserDataHandler handler = null;

            try
            {
                handler = UserDataHandlerFactory.Instance.GetHandler(userDataFile);
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Unable to find the handler for matching user-data contents", ex);
                return;
            }
            // invoke handler
            try
            {
                handler.HandleUserData(userDataFile);
            }
            catch (Exception e)
            {
                EucaLogger.Exception("User data handler threw exception", e);
            }
            // return
        }