Exemplo n.º 1
0
 public Component GetOrCreateComponent(Guid accountId, GetOrCreateComponentRequestData data)
 {
     if (data == null)
     {
         throw new ParameterRequiredException("Request.Data");
     }
     return(GetOrCreateComponentInternal(accountId, data, false));
 }
Exemplo n.º 2
0
        public GetOrCreateComponentResponse GetOrCreateComponent(Guid accountId, GetOrCreateComponentRequestData data)
        {
            var request = GetRequest <GetOrCreateComponentRequest>(accountId);

            request.Data = data;
            var dispatcher = DispatcherHelper.GetDispatcherService();

            return(dispatcher.GetOrCreateComponent(request));
        }
Exemplo n.º 3
0
        public static Core.Api.ComponentInfo GetTestApplicationComponent(TestAccountInfo accountInfo)
        {
            var componentTypeId = CreateRandomComponentTypeId(accountInfo.Id);
            var data            = new GetOrCreateComponentRequestData()
            {
                SystemName        = "test component systemName",
                DisplayName       = "test component dispay name",
                TypeId            = componentTypeId,
                ParentComponentId = accountInfo.RootId
            };
            var dispatcher = GetDispatcherClient();
            var response   = dispatcher.GetOrCreateComponent(accountInfo.Id, data);

            return(response.Data.Component);
        }
Exemplo n.º 4
0
        public Core.Api.ComponentInfo CreateTestApplicationComponent()
        {
            var componentTypeId = TestHelper.CreateRandomComponentTypeId(Id);
            var data            = new GetOrCreateComponentRequestData()
            {
                SystemName        = "test component systemName " + Guid.NewGuid(),
                DisplayName       = "test component dispay name " + Guid.NewGuid(),
                TypeId            = componentTypeId,
                ParentComponentId = RootId
            };
            var dispatcher = GetDispatcherClient();
            var response   = dispatcher.GetOrCreateComponent(Id, data);

            return(response.Data.Component);
        }
Exemplo n.º 5
0
        public Component CreateComponent(Guid accountId, CreateComponentRequestData data)
        {
            if (data == null)
            {
                throw new ParameterRequiredException("Request.Data");
            }
            var data2 = new GetOrCreateComponentRequestData()
            {
                DisplayName       = data.DisplayName,
                SystemName        = data.SystemName,
                TypeId            = data.TypeId,
                ParentComponentId = data.ParentComponentId,
                Version           = data.Version,
                Properties        = data.Properties
            };

            return(GetOrCreateComponentInternal(accountId, data2, true));
        }
Exemplo n.º 6
0
        public Component GetOrCreateComponentInternal(Guid accountId, GetOrCreateComponentRequestData data, bool createNew)
        {
            if (data == null)
            {
                throw new ParameterRequiredException("Request.Data");
            }
            if (data.TypeId == null)
            {
                throw new ParameterRequiredException("Request.Data.TypeId");
            }
            if (string.IsNullOrEmpty(data.SystemName))
            {
                throw new ParameterRequiredException("data.SystemName");
            }

            if (data.ParentComponentId == null)
            {
                data.ParentComponentId = GetRootId(accountId);
            }

            var componentId = data.NewId ?? Guid.NewGuid();
            var systemName  = data.SystemName;

            var properties = ApiConverter.GetComponentProperties(data.Properties);

            var accountDbContext    = Context.GetAccountDbContext(accountId);
            var componentRepository = accountDbContext.GetComponentRepository();
            var lockObj             = LockObject.ForComponent(systemName);

            lock (lockObj)
            {
                // ищем в детях
                var  component = componentRepository.GetChild(data.ParentComponentId.Value, systemName);
                bool isExists  = true;
                if (component == null)
                {
                    // ищем в папках
                    var parent = componentRepository.GetById(data.ParentComponentId.Value);
                    component = FindBySystemName(parent, systemName);
                    if (component == null)
                    {
                        // Проверим лимит
                        var checker          = AccountLimitsCheckerManager.GetCheckerForAccount(accountId);
                        var limitCheckResult = checker.CheckMaxComponents(accountDbContext);
                        if (!limitCheckResult.Success)
                        {
                            throw new OverLimitException(limitCheckResult.Message);
                        }

                        // создаем новый
                        component = Add(
                            accountId,
                            componentId,
                            data.ParentComponentId.Value,
                            data.DisplayName ?? systemName,
                            systemName,
                            data.TypeId.Value);

                        isExists = false;
                        checker.RefreshComponentsCount();
                    }
                }

                if (isExists && createNew)
                {
                    throw new ResponseCodeException(
                              ResponseCode.ParameterError,
                              "Компонент с таким системным именем уже существует");
                }

                // обновим версию
                if (string.IsNullOrEmpty(data.Version) == false)
                {
                    component.Version = data.Version;
                }

                // обновим свойства
                foreach (var property in properties)
                {
                    component.SetProperty(property);
                }
                accountDbContext.SaveChanges();
                return(component);
            }
        }