Exemple #1
0
        /// <summary>
        /// Attempt to make a connection to the Galaxy
        /// </summary>
        /// <returns></returns>
        public bool Connect(string GRNodeName, string GalaxyName, string UserName, string Password)
        {
            GRAccessApp grAccess;
            IGalaxy     galaxy;
            IGalaxies   galaxies;

            try
            {
                // Instantiate the GR Access App
                grAccess = new GRAccessApp();

                log.Debug("Retrieving Galaxies for " + GRNodeName);

                // Get a list of the available galaxies
                galaxies = grAccess.QueryGalaxies(GRNodeName);

                log.Debug("Getting Galaxy Reference for " + GalaxyName);

                //Get a reference to the Galaxy
                galaxy = galaxies[GalaxyName];

                log.Debug("Checking for Success");

                // Check to make sure we have a good reference to the Galaxy
                if (galaxy == null || !grAccess.CommandResult.Successful)
                {
                    throw new Exception(GalaxyName + " is not a legal Galaxy on " + GRNodeName);
                }

                log.Debug("Logging in with Username " + UserName);

                // Attempt to Login
                galaxy.LoginEx(UserName, Password, false);

                log.Debug("Checking for login success");

                //Check for success
                if (!galaxy.CommandResult.Successful)
                {
                    throw new Exception("Galaxy Login Failed");
                }

                // If we made it to hear we're good!
                log.Info("Login Succeeded");

                // Set the local reference
                this.Galaxy = galaxy;

                // return the connected status
                return(this.Connected);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // Создание Galaxy из шаблона
        public static void CreateGalaxyFromTemplate(string galaxyTemplateName, string galaxyName, string nodeName = null)
        {
            _grAccessApp = new GRAccessApp();
            _grAccessApp.CreateGalaxyFromTemplate(galaxyTemplateName, galaxyName, nodeName);
            ICommandResult commandResult = _grAccessApp.CommandResult;

            if (!commandResult.Successful)
            {
                throw new Exception(string.Format($"Не удалось создать галактику {galaxyName}! Причина {commandResult.Text}-{commandResult.CustomMessage}"));
            }
        }
        //Созданеи Galaxy
        public static IGalaxy CreateAndGetGalaxy(string galaxyName, string GRNodeName   = null, bool enableSecurity = true,
                                                 EAuthenticationMode AuthenticationMode = EAuthenticationMode.osAuthenticationMode, string osUserName = null)
        {
            _grAccessApp = new GRAccessApp();
            _grAccessApp.CreateGalaxy(galaxyName, GRNodeName, enableSecurity, AuthenticationMode, osUserName);
            ICommandResult commandResult = _grAccessApp.CommandResult;

            if (!commandResult.Successful)
            {
                throw new Exception(string.Format($"Не удалось создать галактику {galaxyName}! Причина {commandResult.Text}-{commandResult.CustomMessage}"));
            }
            return(GetGalaxy(galaxyName, GRNodeName));
        }
        //получение Galaxy по имени
        public static IGalaxy GetGalaxy(string galaxyName, string nodeName)
        {
            if (string.IsNullOrEmpty(galaxyName))
            {
                throw new ArgumentException(nameof(galaxyName));
            }
            _grAccessApp = null;
            _grAccessApp = new GRAccessApp();
            var galaxies = _grAccessApp.QueryGalaxies(nodeName);

            GalaxyExceptions.ThrowIfNoSuccess(_grAccessApp.CommandResult);
            IGalaxy galaxy = galaxies[galaxyName];

            GalaxyExceptions.ThrowIfNoSuccess(_grAccessApp.CommandResult);
            return(galaxy == null ? throw new GalaxyObjectNotFoundException(galaxyName) : galaxy);
        }
 // Получание спика галактик нa GRNode
 public static IGalaxies GetGalaxies(string nodeName = null)
 {
     _grAccessApp = new GRAccessApp();
     return(_grAccessApp.QueryGalaxies(nodeName) ?? throw new GalaxyExceptions($"Отстувуют Galaxy на {nodeName}", _grAccessApp.CommandResult));
 }