Пример #1
0
        //Создаем и возвращаем экземпляр из указанного шаблона - добавлять area или нет ????
        public IInstance CreateInstance(string tagName, ITemplate template, string containerName = null)
        {
            if (string.IsNullOrWhiteSpace(tagName))
            {
                throw new ArgumentException(nameof(tagName));
            }
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }
            IInstance instance = template.CreateInstance(tagName, true);

            if (instance == null)
            {
                string msg = string.Format($"Объект с именем {tagName} не создан! " +
                                           _galaxy.CommandResult != null && !_galaxy.CommandResult.Successful ? _galaxy.CommandResult.Text + " "
                                           + _galaxy.CommandResult.CustomMessage :
                                           "Возможно такой объект уже существует.");
                throw new GalaxyCannotCreateInstanceException(tagName, msg, template, template.CommandResult);
            }
            if (!string.IsNullOrWhiteSpace(containerName))
            {
                try
                {
                    ((IgObject)instance).CheckOutWithCheckStatus();
                    instance.Container = containerName;
                    var text = instance.CommandResult.Text + " - " + instance.CommandResult.CustomMessage;
                    GalaxyExceptions.ThrowIfNoSuccess(instance.CommandResult, $"Ошибка при назначении объекту {tagName} контейнера {containerName}\n");
                }
                catch { throw; }
                finally
                {
                    ((IgObject)instance).SaveAndCheckIn($"Установка для объекта {tagName} Container={containerName}");
                }
            }
            GalaxyExceptions.ThrowIfNoSuccess(CommandResult);

            return(instance);
        }
Пример #2
0
        // Возвращает экземпляры производыне от заданного шаблона
        public IgObjects GetInstancesDerividedFrom(string tagName)
        {
            IgObjects gobjects = null;

            try
            {
                if (string.IsNullOrEmpty(tagName))
                {
                    throw new ArgumentNullException(nameof(tagName));
                }
                gobjects = _galaxy.QueryObjects(EgObjectIsTemplateOrInstance.gObjectIsInstance, EConditionType.derivedOrInstantiatedFrom, tagName, EMatch.MatchCondition);
                GalaxyExceptions.ThrowIfNoSuccess(CommandResult);
                return(gobjects);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                gobjects = null;
                GC.Collect();
            }
        }