コード例 #1
0
        public async Task <ResultObject <HardwareItemResponse> > FillHardwareItem(string type, string id)
        {
            var result = ResultObject <HardwareItemResponse> .Create();

            HardwareItemResponse response = null;

            try
            {
                var item = await parser.ParseItem(new CitilinkParserSettings($"{type}/{id}"), type);

                var serviceResult = await service.AddHardwareItem(item);

                if (!serviceResult.IsSuccess)
                {
                    return(result.AddErrors(serviceResult.Errors));
                }

                response = serviceResult.Value;
            }
            catch (Exception ex)
            {
                result.AddError(ex);
            }

            return(result.SetValue(response));
        }
コード例 #2
0
        public async Task <ResultObject <IEnumerable <HardwareItemResponse> > > FillHardwareItems(string type, int start, int end)
        {
            var result = ResultObject <IEnumerable <HardwareItemResponse> > .Create();

            var list = new List <HardwareItemResponse>();

            try
            {
                var items = await parser.ParseItems(new CitilinkParserSettings(type, start, end), type);

                foreach (var item in items)
                {
                    var serviceResult = await service.AddHardwareItem(item);

                    if (!serviceResult.IsSuccess)
                    {
                        result.AddErrors(serviceResult.Errors);
                        continue;
                    }

                    list.Add(serviceResult.Value);
                }
            }
            catch (Exception ex)
            {
                result.AddError(ex);
            }

            return(result.SetValue(list));
        }
コード例 #3
0
        /// <summary>
        /// Возвращает коллекцию необходимых компьютерных деталей
        /// </summary>
        /// <param name="pagination">Параметры постраничной навигации</param>
        /// <param name="selecting">Параметры выбора деталей</param>
        /// <returns></returns>
        public async Task <ResultObject <IEnumerable <HardwareItemResponse> > > GetHardwareItem(
            Pagination pagination,
            SelectingHardware selecting)
        {
            var result = ResultObject <IEnumerable <HardwareItemResponse> > .Create();

            IEnumerable <HardwareItemEntity> takeEntities = null;

            try
            {
                var entities = await GetHardwareItemByType(selecting.Type);

                takeEntities = (await SelectHardware(entities, selecting.СompatibilityProperties))
                               .Pagination(pagination)
                               .ToArray();
            }
            catch (Exception ex)
            {
                return(result.AddError(ex));
            }

            var response = mapper.Map <HardwareItemResponse[]>(takeEntities);

            return(result.SetValue(response));
        }
コード例 #4
0
        private async Task Run()
        {
            if (IsRunning)
            {
                return;
            }

            try
            {
                await EnsureNuGetPackages().ConfigureAwait(true);
            }
            catch (Exception)
            {
                IsRunning = false;
                throw;
            }

            Reset();

            await MainViewModel.AutoSaveOpenDocuments().ConfigureAwait(true);

            SetIsRunning(true);

            var results = new ObservableCollection <ResultObject>();

            ResultsInternal = results;

            var cancellationToken = _cts.Token;

            HookDumped(results, cancellationToken);
            try
            {
                var code = await GetCode(cancellationToken).ConfigureAwait(true);

                var errorResult = await _executionHost.ExecuteAsync(code).ConfigureAwait(true);

                _onError?.Invoke(errorResult);
                if (errorResult != null)
                {
                    results.Add(errorResult);
                }
            }
            catch (CompilationErrorException ex)
            {
                foreach (var diagnostic in ex.Diagnostics)
                {
                    results.Add(ResultObject.Create(diagnostic));
                }
            }
            catch (Exception ex)
            {
                AddResult(ex, results, cancellationToken);
            }
            finally
            {
                SetIsRunning(false);
            }
        }
コード例 #5
0
 private void AddResult(object o, ObservableCollection <ResultObject> results, CancellationToken cancellationToken)
 {
     _dispatcher.InvokeAsync(() =>
     {
         var list = o as IList <ResultObject>;
         if (list != null)
         {
             foreach (var resultObject in list)
             {
                 results.Add(resultObject);
             }
         }
         else
         {
             results.Add(ResultObject.Create(o));
         }
     }, DispatcherPriority.SystemIdle, cancellationToken);
 }
コード例 #6
0
 public void Dump(DumpData data)
 {
     try
     {
         DumpResultObject(ResultObject.Create(data.Object, data.Quotas, data.Header));
     }
     catch (Exception ex)
     {
         try
         {
             Console.WriteLine("Error during Dump: " + ex.Message);
         }
         catch
         {
             // ignore
         }
     }
 }
コード例 #7
0
ファイル: ExecutionHost.cs プロジェクト: ghc4/RoslynPad
            private void OnDumped(DumpData data)
            {
                var currentCount = _dumpCount++;

                if (currentCount >= MaxDumpsPerSession)
                {
                    if (currentCount == MaxDumpsPerSession)
                    {
                        EnqueueDump(ResultObject.Create("<max results reached>", DumpQuotas.Default));
                    }

                    return;
                }

                var resultObject = ResultObject.Create(data.Object, data.Quotas, data.Header);

                EnqueueDump(resultObject);
            }
コード例 #8
0
        /// <summary>
        /// Добавляет новую деталь в базу, в случае если изготовитель или тип детали отсутствует в базе,
        /// он будет добавлен автоматически
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ResultObject <HardwareItemResponse> > AddHardwareItem(HardwareItemRequest request)
        {
            var result = ResultObject <HardwareItemResponse> .Create();

            var mapEntity = mapper.Map <HardwareItemEntity>(request);

            HardwareItemEntity entity = null;

            try
            {
                await MapPropertyRequest(mapEntity, request.PropertysItems);

                var manufacturerEntity = await GetOrCreateEntity(container.ManufacturerRepository, request.Manufacturer);

                mapEntity.Manufacturer = manufacturerEntity;

                var hardwareTypeEntity = await GetOrCreateEntity(container.HardwareTypeRepository, request.HardwareType);

                mapEntity.HardwareType = hardwareTypeEntity;

                entity = await container.HardwareItemRepository.AddAsync(mapEntity);

                await container.SaveAsync();
            }
            catch (Exception ex)
            {
                if (entity != null)
                {
                    await container.HardwareItemRepository.RemoveAsync(entity);
                }

                return(result.AddError(ex));
            }

            var response = mapper.Map <HardwareItemResponse>(entity);

            return(result.SetValue(response));
        }
コード例 #9
0
        public void Dump(DumpData data)
        {
            if (!CanDump())
            {
                return;
            }

            try
            {
                DumpResultObject(ResultObject.Create(data.Object, data.Quotas, data.Header));
            }
            catch (Exception ex)
            {
                try
                {
                    DumpMessage("Error during Dump: " + ex.Message);
                }
                catch
                {
                    // ignore
                }
            }
        }
コード例 #10
0
        private async Task CompileAndSave()
        {
            var saveDialog = _serviceLocator.GetInstance <ISaveFileDialog>();

            saveDialog.OverwritePrompt = true;
            saveDialog.AddExtension    = true;
            saveDialog.Filter          = "Libraries|*.dll|Executables|*.exe";
            saveDialog.DefaultExt      = "dll";
            if (saveDialog.Show() != true)
            {
                return;
            }

            var code = await GetCode(CancellationToken.None).ConfigureAwait(true);

            var results = new ObservableCollection <ResultObject>();

            ResultsInternal = results;

            HookDumped(results, CancellationToken.None);

            try
            {
                await Task.Run(() => _executionHost.CompileAndSave(code, saveDialog.FileName)).ConfigureAwait(true);
            }
            catch (CompilationErrorException ex)
            {
                foreach (var diagnostic in ex.Diagnostics)
                {
                    results.Add(ResultObject.Create(diagnostic));
                }
            }
            catch (Exception ex)
            {
                AddResult(ex, results, CancellationToken.None);
            }
        }
コード例 #11
0
        /// <summary>
        /// Изменяет данные указанного объекта
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ResultObject <HardwareItemResponse> > UpdateHardwareItem(HardwareItemRequest request)
        {
            var result = ResultObject <HardwareItemResponse> .Create();

            var entity = await container.HardwareItemRepository.GetFullObject(request.Id);

            if (entity == null)
            {
                return(result.AddError(new Exception($"The specified object could not be found: Id = {request.Id}")));
            }

            try
            {
                /// Мапит в entity, игнорируя связи, новый объект который мы получили
                mapper.Map(request, entity);

                /// Удаляет старые связи детали к характеристикам
                entity.PropertysItems.Clear();
                await MapPropertyRequest(entity, request.PropertysItems);

                var manufacturerEntity = await GetOrCreateEntity(container.ManufacturerRepository, request.Manufacturer);

                entity.Manufacturer = manufacturerEntity;

                var hardwareTypeEntity = await GetOrCreateEntity(container.HardwareTypeRepository, request.HardwareType);

                entity.HardwareType = hardwareTypeEntity;

                await container.SaveAsync();
            }
            catch (Exception ex)
            {
                return(result.AddError(ex));
            }

            return(result);
        }
コード例 #12
0
        public async Task <ResultObject <HardwareItemResponse> > DeleteHardwareItem(int id)
        {
            var result = ResultObject <HardwareItemResponse> .Create();

            var entity = await container.HardwareItemRepository.GetFullObject(id);

            if (entity == null)
            {
                return(result.AddError(new Exception($"The specified object could not be found: Id = {id}")));
            }

            try
            {
                await container.HardwareItemRepository.RemoveAsync(entity);

                await container.SaveAsync();
            }
            catch (Exception ex)
            {
                return(result.AddError(ex));
            }

            return(result);
        }
コード例 #13
0
 private void OnDumped(DumpData data)
 {
     EnqueueResult(ResultObject.Create(data.Object, data.Quotas, data.Header));
 }
コード例 #14
0
ファイル: ExecutionHost.cs プロジェクト: dmetzgar/RoslynPad
 private void OnDumped(object o, string header)
 {
     _dumpQueue.Enqueue(ResultObject.Create(o, header));
     _dumpLock.Release();
 }
コード例 #15
0
 private void OnDumped(object o, string header)
 {
     EnqueueResult(ResultObject.Create(o, header));
 }