Exemplo n.º 1
0
        protected void validationAPI()
        {
            var t = this.GetType();
            List <ParameterMethodAttribute> attributes = new List <ParameterMethodAttribute>();

            foreach (var methodInfo in t.GetMethods(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static))
            {
                foreach (var attribute in methodInfo.GetCustomAttributes(true))
                {
                    if (!(attribute is ParameterMethodAttribute))
                    {
                        continue;
                    }
                    var paramAttr = attribute as ParameterMethodAttribute;
                    if (!attributes.Exists(x => x.VariableName == paramAttr.VariableName))
                    {
                        attributes.Add(paramAttr);
                    }
                }
            }
            var validResult = OperationsAPI.IsValid(attributes);

            if (!validResult.Key)
            {
                var strException = "Настройка API не валидны.Нужно заполнить следующие поля API:";
                foreach (var s in validResult.Value)
                {
                    strException += "\n" + s.ToUpper();
                }
                throw new Exception(strException);
            }
        }
        public static bool checkProcedure(SqlConnection connection, DirectionsEnum direction)
        {
            var ret      = true;
            var procName = "";

            switch (direction)
            {
            case DirectionsEnum.Import:
            {
                OperationsAPI.IsValid("ImportReplicaProcedure");
                procName = OperationsAPI.ImportReplicaProcedure;
                break;
            }

            case DirectionsEnum.Export:
            {
                OperationsAPI.IsValid("ExportReplicaProcedure");
                procName = OperationsAPI.ExportReplicaProcedure;
                break;
            }
            }

            var command = new SqlCommand();

            command.Connection  = connection;
            command.CommandText = string.Format("select COUNT(*) from [{1}].[sys].[procedures] where name ='{0}'", procName, connection.Database);

            try
            {
                command.Connection.Open();
                var countQuery = (int)command.ExecuteScalar();
                if (countQuery == 0)
                {
                    ret = false;
                }
            }
            catch
            {
                ret = false;
            }

            return(ret);
        }