Example #1
0
        /// <summary>
        /// Check version definition for the directory
        /// </summary>
        /// <param name="defItem">The directory definition</param>
        /// <returns>True if successful, false otherwise.</returns>
        public static BoolMessageItem <VersionDefItem> CheckEnv(VersionDefItem defItem)
        {
            VersionDefEnv def    = defItem as VersionDefEnv;
            string        envVal = EnvironmentHelper.GetEnv(def.Name);

            envVal = VersionHelper.Translate(envVal);
            string message = string.Empty;
            bool   success = true;
            bool   isEmpty = string.IsNullOrEmpty(envVal);

            // Empty value.
            if (isEmpty)
            {
                message = string.Format("EnvironmentVariable '{0}' is not set.", def.Name);
                if (def.IsRequired)
                {
                    success = false;
                }
            }

            // Expected values do not match and the value is required.
            if (isEmpty && def.IsRequired && string.Compare(envVal, def.EnvValue, true) != 0)
            {
                message = string.Format("EnvironmentVariable '{0}' does not match '{1}'.", def.EnvValue);
                success = false;
            }

            return(new BoolMessageItem <VersionDefItem>(def, success, message));
        }
Example #2
0
 /// <summary>
 /// Execute the check.
 /// </summary>
 public override BoolMessageItem Execute()
 {
     try
     {
         Initialize();
         bool   passed  = true;
         string message = string.Empty;
         for (int ndx = 0; ndx < _ctx.Definition.Components.Count; ndx++)
         {
             VersionDefItem defItem = _ctx.Definition.Components[ndx];
             var            result  = Check(defItem);
             StoreResult(result);
             if (!result.Success)
             {
                 passed  = false;
                 message = "One or more Version checks failed.";
             }
         }
         _checkResult = new BoolMessageItem(null, passed, message);
         WriteDefinitionResult();
     }
     catch (Exception ex)
     {
         _checkResult = new BoolMessageItem(null, false, ex.Message + Environment.NewLine + ex.StackTrace);
     }
     return(_checkResult);
 }
Example #3
0
        /// <summary>
        /// Check version definition for the directory
        /// </summary>
        /// <param name="defItem">The directory definition</param>
        /// <returns>True if successful, false otherwise.</returns>
        public static BoolMessageItem <VersionDefItem> CheckFile(VersionDefItem defItem)
        {
            VersionDefFile def = defItem as VersionDefFile;

            if (def.Path.Contains("sojara-config-cj-base-clean-arc8-eod-prod.xml"))
            {
                Console.WriteLine("testing");
            }
            bool   success  = true;
            string filePath = VersionHelper.Translate(def.Path);
            bool   exists   = File.Exists(filePath);
            string message  = string.Empty;

            // Exists.
            if (!exists && def.Requirement == VersionRequirement.Required)
            {
                message = string.Format("File '{0}' does not exist.", filePath);
                return(new BoolMessageItem <VersionDefItem>(defItem, false, message));
            }

            // Same version?
            if (!string.IsNullOrEmpty(def.VersionReq))
            {
                string fileVersion = FileUtils.GetVersion(filePath);
                if (string.Compare(def.VersionReq, fileVersion, true) != 0)
                {
                    success  = false;
                    message += Environment.NewLine + string.Format("File version '{0}' does not match expected version '{1}'.", fileVersion, def.VersionReq);
                }
            }
            // Same date ?
            if (!string.IsNullOrEmpty(def.DateReq))
            {
                DateTime fileDateTime     = File.GetLastWriteTime(filePath);
                DateTime expectedDateTime = DateTime.Parse(def.DateReq);
                if (fileDateTime.Date.CompareTo(expectedDateTime.Date) != 0)
                {
                    string fileDate = fileDateTime.ToString();
                    success  = false;
                    message += Environment.NewLine + string.Format("File Date '{0}' does not match expected date '{1}'.", fileDate, def.DateReq);
                }
            }

            // Same size ?
            if (!string.IsNullOrEmpty(def.SizeReq))
            {
                FileInfo fileInfo         = new FileInfo(filePath);
                long     expectedFileSize = Convert.ToInt64(def.SizeReq);
                if (fileInfo.Length != expectedFileSize)
                {
                    success  = false;
                    message += Environment.NewLine + string.Format("File Size '{0}' does not match expected size '{1}'.", fileInfo.Length, expectedFileSize);
                }
            }

            return(new BoolMessageItem <VersionDefItem>(defItem, success, message));
        }
Example #4
0
        /// <summary>
        /// Check version definition for the directory
        /// </summary>
        /// <param name="defItem">The directory definition</param>
        /// <returns>True if successful, false otherwise.</returns>
        public static BoolMessageItem <VersionDefItem> CheckDir(VersionDefItem defItem)
        {
            VersionDefDir dirDef  = defItem as VersionDefDir;
            string        dir     = VersionHelper.Translate(dirDef.Path);
            bool          success = Directory.Exists(dir);
            string        message = string.Empty;

            if (!success)
            {
                message = string.Format("Directory '{0}' does not exist.", dir);
            }

            return(new BoolMessageItem <VersionDefItem>(defItem, success, message));
        }
Example #5
0
        /// <summary>
        /// Check the definition.
        /// </summary>
        /// <param name="defItem"></param>
        /// <returns></returns>
        public virtual BoolMessageItem <VersionDefItem> Check(VersionDefItem defItem)
        {
            // Valid definition item.
            string key = defItem.GetType().Name;

            if (!_handlerMap.ContainsKey(key))
            {
                return(new BoolMessageItem <VersionDefItem>(defItem, false, "Unknown version definition item : " + defItem.ToString()));
            }

            // Get handler
            Func <VersionDefItem, BoolMessageItem <VersionDefItem> > handler = _handlerMap[key];

            // Check.
            BoolMessageItem <VersionDefItem> result = handler(defItem);

            // Notify subscribers.
            if (_notifyCallback != null)
            {
                _notifyCallback(result);
            }

            return(result);
        }
Example #6
0
 /// <summary>
 /// Check version definition for the directory
 /// </summary>
 /// <param name="defItem">The directory definition</param>
 /// <returns>True if successful, false otherwise.</returns>
 public static BoolMessageItem <VersionDefItem> CheckDrive(VersionDefItem defItem)
 {
     return(new BoolMessageItem <VersionDefItem>(defItem, false, string.Empty));
 }