예제 #1
0
        /// <summary>
        /// Opens an excel file.
        /// </summary>
        /// <param name="path">File path.</param>
        public void OpenFile(string path)
        {
            WaitHelper.WaitFor(() => FileHelper.IsFileReady(path), 20);

            _workbook = RetryUtils.RetryIfThrown <COMException, Workbook>(() => _excelApp.Workbooks.Open(path),
                                                                          ConfigHelper.DefaultRetriesNumber, () => _workbook.Close());
        }
예제 #2
0
        /// <summary>
        /// Gets first worksheet.
        /// </summary>
        /// <returns>The worksheet.</returns>
        public Worksheet GetFirstWorksheet()
        {
            var worksheet = RetryUtils.RetryIfThrown <COMException, Worksheet>(() => (Worksheet)_workbook.Worksheets.Item[1],
                                                                               ConfigHelper.DefaultRetriesNumber, () => _workbook.Close());

            return(worksheet);
        }
        public async Task <(decimal?, bool)> GetProductPrice(string shopID, string productID)
        {
            var productPriceQuery = @"
                query($shopId:Uuid!,$productType: String){shop(id: $shopId) {product(productType: $productType) { sellingPrice}}}";
            var queryVariables    = new
            {
                shopId      = shopID,
                productType = productID
            };

            try
            {
                var graphQLProductPriceData = await RetryUtils.RetryIfThrown <Exception, GraphQLResponse <GraphQLProductPriceData> >(async() =>
                                                                                                                                     await SendQueryAsync <GraphQLProductPriceData>(
                                                                                                                                         _clientUrl,
                                                                                                                                         productPriceQuery,
                                                                                                                                         queryVariables
                                                                                                                                         ), 10, 250, 1000);

                if (graphQLProductPriceData.Errors != null)
                {
                    _logger.LogWarning(ExceptionEvents.GenerateEventId(LoggerEventType.GraphQLClientQuery), $"Query error: {JsonConvert.SerializeObject(graphQLProductPriceData.Errors)}");
                    return(graphQLProductPriceData.Data?.Shop?.Product?.SellingPrice, false);
                }
                return(graphQLProductPriceData.Data?.Shop?.Product?.SellingPrice, true);
            }
            catch (Exception e)
            {
                var eventID = new EventId(0, $"Get Product Price: {shopID} , {productID}");
                _logger.LogError(eventID, e, "Error while getting product price");
                return(null, false);
            }
        }
        public async Task <ShopsData> GetShopsData()
        {
            var shopsDataQuery = @"{  shops { id }  productTypes { name }}";

            _logger.LogInformation("Fetching shops data...");

            try
            {
                var qraphQLShopsData = await RetryUtils.RetryIfThrown <Exception, GraphQLResponse <GraphQLShopsData> >(async() =>
                                                                                                                       await SendQueryAsync <GraphQLShopsData>(_clientUrl, shopsDataQuery), 10, 250, 1000);

                var shopsData = new ShopsData()
                {
                    ProductsIDs = qraphQLShopsData.Data.ProductTypes.Select(x => x.Name).ToList(),
                    ShopsIDs    = qraphQLShopsData.Data.Shops.Select(x => x.Id).ToList()
                };
                if (qraphQLShopsData.Errors != null)
                {
                    _logger.LogWarning($"Fetched shops data with warnings: {qraphQLShopsData.Errors}");

                    return(shopsData);
                }

                _logger.LogInformation("Fetched shops data successfully");
                return(shopsData);
            }
            catch (Exception e)
            {
                _logger.LogError(ExceptionEvents.GenerateEventId(LoggerEventType.GraphQLClient), e, "Error while getting shop data");
                return(null);
            }
        }
예제 #5
0
 /// <summary>
 /// Sets a column values for selected rows.
 /// </summary>
 /// <param name="worksheet">The worksheet.</param>
 /// <param name="values">Key - number of row, value - value to set.</param>
 /// <param name="columnNumber">Number of column to set.</param>
 public void SetColumnValues(Worksheet worksheet, Dictionary <int, string> values, int columnNumber)
 {
     foreach (var value in values)
     {
         RetryUtils.RetryIfThrown <COMException, string>(() => worksheet.Cells[value.Key, columnNumber].Value = value.Value,
                                                         ConfigHelper.DefaultRetriesNumber, () => _workbook.Close());
     }
 }
예제 #6
0
        public void PerformAs(User user)
        {
            Element.WithId(id).CanBeFoundOnThePageBy(user);
            try
            {
                Log.Action($"clicking the element with id {this.id}");

                RetryUtils.RetryIfThrown <Exception, Boolean>(() =>
                {
                    return(ClickElement(user, id));
                }, 10, 250);
            }
            catch (Exception)
            {
                throw Log.Exception($"Unable to click on the element with id:  {this.id}");
            }
        }
예제 #7
0
 /// <summary>
 /// Saves a workbook and close it.
 /// </summary>
 public void SaveWorkbookAndClose()
 {
     RetryUtils.RetryIfThrown <COMException>(() => _workbook.Save(), ConfigHelper.DefaultRetriesNumber);
     RetryUtils.RetryIfThrown <COMException>(() => _workbook.Close(), ConfigHelper.DefaultRetriesNumber);
 }