Пример #1
0
 public void WriteError(string error)
 {
     if (_IO == null)
     {
         return;
     }
     _IO.WriteError(error);
 }
Пример #2
0
        /// <summary>
        /// Check Required Properties
        /// </summary>
        /// <param name="obj">Object to check</param>
        /// <param name="cmd">Command</param>
        /// <param name="error">Variable for capture the error fail</param>
        /// <returns>Return true if OK, false if not</returns>
        public static bool CheckRequiredProperties(object obj, CommandLayer cmd, out string error)
        {
            error = null;
            Type fileInfoType = typeof(FileInfo);
            Type dirInfoType  = typeof(DirectoryInfo);

            foreach (PropertyInfo pi in ReflectionHelper.GetProperties(obj, true, true, true))
            {
                ConfigurableProperty c = pi.GetCustomAttribute <ConfigurableProperty>();
                if (c == null)
                {
                    continue;
                }

                object val = pi.GetValue(obj, null);

                if (val == null)
                {
                    if (c.Optional)
                    {
                        continue;
                    }

                    error = Lang.Get("Require_Set_Property", pi.Name);
                    return(false);
                }
                else
                {
                    if (pi.PropertyType == fileInfoType)
                    {
                        RequireExistsAttribute c2 = pi.GetCustomAttribute <RequireExistsAttribute>();
                        if (c2 != null && !c2.IsValid(val))
                        {
                            error = Lang.Get("File_Defined_Not_Exists", pi.Name);
                            return(false);
                        }
                    }
                    else
                    {
                        if (pi.PropertyType == dirInfoType)
                        {
                            // Check directory
                            DirectoryInfo di = (DirectoryInfo)val;
                            di.Refresh();
                            if (!di.Exists)
                            {
                                if (cmd == null)
                                {
                                    // Por si acaso
                                    error = Lang.Get("Folder_Required", di.FullName);
                                    return(false);
                                }

                                cmd.WriteLine(Lang.Get("Folder_Required_Ask", di.FullName));
                                if (!(bool)ConvertHelper.ConvertTo(cmd.ReadLine(null, null), typeof(bool)))
                                {
                                    error = Lang.Get("Folder_Required", di.FullName);
                                    return(false);
                                }

                                try { di.Create(); }
                                catch (Exception e) { cmd.WriteError(e.ToString()); }
                            }
                        }
                    }
                }
            }

            return(error == null);
        }
Пример #3
0
        bool CheckModule(bool checkRequieredProperties, EModuleType expected)
        {
            if (_Current == null)
            {
                _IO.WriteError(Lang.Get("Require_Module"));
                return(false);
            }

            if (expected != EModuleType.None)
            {
                if (_Current.ModuleType != expected)
                {
                    _IO.WriteError(Lang.Get("Require_Module_Type", expected.ToString()));
                    return(false);
                }
            }

            string error;

            if (checkRequieredProperties && !_Current.CheckRequiredProperties(_IO, out error))
            {
                _Current.WriteInfo(error);
                return(false);
            }
            return(true);
        }