Ejemplo n.º 1
0
        internal static async Task <T> AddAttachmentToController <T>(VismaNetAuthorization auth, string url, Stream input,
                                                                     string fileName) where T : class
        {
            var client = GetHttpClient(auth);

            input.Seek(0, SeekOrigin.Begin);
            using (var stream = new MemoryStream())
            {
                await input.CopyToAsync(stream);

                stream.Seek(0, SeekOrigin.Begin);
                var content = new StreamContent(stream);
                content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    FileName = fileName,
                    Name     = "v"
                };
                var request = new MultipartFormDataContent
                {
                    content
                };
                return(await client.PostMessage <T>(url, request));
            }
        }
Ejemplo n.º 2
0
        internal static async Task <List <DimensionSegment> > FetchDimension(string dimension,
                                                                             VismaNetAuthorization auth)
        {
            using (var webclient = GetHttpClient(auth))
            {
                var apiUrl = GetApiUrlForController(VismaNetControllers.Dimensions,
                                                    string.Format("/{0}", dimension.TrimStart('/')));
                try
                {
                    var container = await webclient.Get <DimensionContainer>(apiUrl);

                    return(container.segments);
                }
                catch (AggregateException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }
                catch (WebException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
 internal CashSaleData(VismaNetAuthorization auth)
     : base(auth)
 {
     ApiControllerUri = VismaNetControllers.CashSale;
 }
Ejemplo n.º 4
0
        /*[
         * "ACCGROUP","ACCOUNT","BIZACCT","CASHACCOUNT",
         * "CONTRACT","CONTRACTITEM","CUSTOMER","EMPLOYEE","INLOCATION",
         * "INSITE","INSUBITEM","INVENTORY","LOCATION","MLISTCD","PROJECT",
         * "PROTASK","SALESPER","SUBACCOUNT","TMCONTRACT","VENDOR"]
         * */


        public DimensionData(VismaNetAuthorization auth) : base(auth)
        {
        }
Ejemplo n.º 5
0
 public SubaccountData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Subaccount;
 }
Ejemplo n.º 6
0
 public ShipmentData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Shipments;
 }
Ejemplo n.º 7
0
 internal LocationData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Location;
 }
 /// <summary>
 ///     This constructor is called by the client to create the data source.
 /// </summary>
 public QueryableVismaNetCustomerInvoiceData(VismaNetAuthorization auth) : base(auth)
 {
     Provider   = new VismaNetQueryProvider(Authorization);
     Expression = Expression.Constant(this);
 }
Ejemplo n.º 9
0
 public AttributeData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Attribute;
 }
Ejemplo n.º 10
0
        internal static Task <List <T> > GetAllAsyncTask <T>(string apiControllerUri, VismaNetAuthorization authorization,
                                                             NameValueCollection parameters = null)
        {
            var webclient = GetHttpClient(authorization);
            var endpoint  = GetApiUrlForController(apiControllerUri, parameters: parameters);

            return(webclient.Get <List <T> >(endpoint));
        }
Ejemplo n.º 11
0
        public static async Task <List <T> > GetAllWithPagination <T>(string ApiControllerUri, VismaNetAuthorization Authorization, NameValueCollection parameters = null) where T : DtoPaginatedProviderBase, IProvideIdentificator
        {
            var firstPage = await GetAll <T>(ApiControllerUri, Authorization, CreatePagionationParameters(initialPageSize, 1, parameters));

            var rsp = new List <T>();

            if (firstPage == null)
            {
                return(rsp);
            }
            rsp.AddRange(firstPage);
            var count = firstPage.Sum(x => x.GetSubCount());

            if (firstPage.FirstOrDefault()?.metadata?.totalCount > count && count > 0)
            {
                var totalCount = firstPage[0].metadata.totalCount;
                var pageSize   = count;
                var pageCount  = totalCount / pageSize;
                var semaphore  = new SemaphoreSlim(VismaNet.MaxConcurrentRequests);
                var taskList   = new List <Task <List <T> > >();
                foreach (var page in Enumerable.Range(2, pageCount))
                {
                    await semaphore.WaitAsync();

                    taskList.Add(Task.Run(async() =>
                    {
                        try
                        {
                            return(await GetAll <T>(ApiControllerUri, Authorization, CreatePagionationParameters(pageSize, page, parameters)));
                        }
                        finally
                        {
                            semaphore.Release();
                        }
                    }));
                }
                var tasks = await Task.WhenAll(taskList);

                rsp.AddRange(tasks.SelectMany(x => x));
            }
            rsp.ForEach(x => x.InternalPrepareForUpdate());
            return(rsp.OrderBy(x => x.GetIdentificator()).ToList());
        }
Ejemplo n.º 12
0
 internal static async Task <List <ExchangeRate> > UpdateExchangeRate(ExchangeRate exchangeRate, VismaNetAuthorization auth)
 {
     var webClient = GetHttpClient(auth);
     {
         var apiUrl = GetApiUrlForController(VismaNetControllers.CurrencyRate, $"/");
         return(await webClient.Put <List <ExchangeRate> >(apiUrl, exchangeRate.ToDto(), $"{GetApiUrlForController(VismaNetControllers.CurrencyRate)}?toCurrency={exchangeRate.toCurrencyId.TrimStart('/')}&fromDate={exchangeRate.effectiveDate.ToString("yyyy-MM-dd")}&toDate={exchangeRate.effectiveDate.ToString("yyyy-MM-dd")}", true));
     }
 }
Ejemplo n.º 13
0
 internal static async Task <List <ExchangeRate> > FetchExchangeRates(string toCurrencyId, DateTime effectiveDate, VismaNetAuthorization auth)
 {
     var webClient = GetHttpClient(auth);
     {
         var apiUrl = GetApiUrlForController(VismaNetControllers.CurrencyRate, $"?toCurrency={toCurrencyId.TrimStart('/')}&fromDate={effectiveDate.ToString("yyyy-MM-dd")}&toDate={effectiveDate.ToString("yyyy-MM-dd")}");
         return(await webClient.Get <List <ExchangeRate> >(apiUrl));
     }
 }
Ejemplo n.º 14
0
 public BranchData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Branch;
 }
Ejemplo n.º 15
0
 public static async Task <List <Contact> > FetchContactsForCustomer(string customerNumber, VismaNetAuthorization authorization)
 {
     using (var webclient = GetHttpClient(authorization))
     {
         var apiUrl = GetApiUrlForController(VismaNetControllers.Customers);
         try
         {
             var fullUrl = $"{apiUrl}/{customerNumber}/contact";
             return(await webclient.Get <List <Contact> >(fullUrl));
         }
         catch (AggregateException e)
         {
             VismaNetExceptionHandler.HandleException(e);
         }
         catch (WebException e)
         {
             VismaNetExceptionHandler.HandleException(e);
         }
         return(null);
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 ///     This constructor is called by the client to create the data source.
 /// </summary>
 internal CustomerInvoiceData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.CustomerInvoice;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// This constructor is called by the client to create the data source.
 /// </summary>
 internal CustomerDocumentData(VismaNetAuthorization auth)
 {
     _authorization = auth;
 }
Ejemplo n.º 18
0
 public GeneralLedgerBalanceData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.GeneralLedgerBalanceV2;
 }
Ejemplo n.º 19
0
 public SalesOrderData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.SalesOrder;
 }
Ejemplo n.º 20
0
 internal SupplierInvoiceData(VismaNetAuthorization auth)
     : base(auth)
 {
     ApiControllerUri = VismaNetControllers.SupplierInvoices;
 }
Ejemplo n.º 21
0
 /// <summary>
 ///     This constructor is called by the client to create the data source.
 /// </summary>
 internal CreditNoteData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.CreditNote;
 }
Ejemplo n.º 22
0
        public static async Task <List <InventorySummary> > FetchInventorySummaryForItem(string itemNo,
                                                                                         VismaNetAuthorization authorization)
        {
            var webclient = GetHttpClient(authorization);
            {
                var apiUrl = GetApiUrlForController(VismaNetControllers.InventorySummary);
                try
                {
                    var fullUrl = $"{apiUrl}/{itemNo}";
                    return(await webclient.Get <List <InventorySummary> >(fullUrl));
                }
                catch (AggregateException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }
                catch (WebException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }

                return(null);
            }
        }
Ejemplo n.º 23
0
 internal ContactData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Contacts;
 }
Ejemplo n.º 24
0
        internal static async Task <List <CustomerDocument> > FetchCustomerDocumentsForCustomerCd(string customerNumber,
                                                                                                  VismaNetAuthorization authorization)
        {
            var webclient = GetHttpClient(authorization);
            {
                var endpoint = GetApiUrlForController(VismaNetControllers.Customers);
                try
                {
                    var url = $"{endpoint}/{customerNumber}/document";
                    return(await webclient.Get <List <CustomerDocument> >(url));
                }
                catch (AggregateException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }
                catch (WebException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }

                return(null);
            }
        }
Ejemplo n.º 25
0
 internal ProjectData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Project;
 }
Ejemplo n.º 26
0
 internal static async Task <List <CustomerInvoice> > FetchInvoicesForCustomerCd(string customerCd,
                                                                                 VismaNetAuthorization authorization)
 {
     var webclient = GetHttpClient(authorization);
     {
         var apiUrl  = GetApiUrlForController(VismaNetControllers.Customers);
         var fullUrl = $"{apiUrl}/{customerCd}/invoice";
         return(await webclient.Get <List <CustomerInvoice> >(fullUrl) ?? new List <CustomerInvoice>());
     }
 }
Ejemplo n.º 27
0
 public InventoryData(VismaNetAuthorization auth) : base(auth)
 {
     ApiControllerUri = VismaNetControllers.Inventory;
 }
Ejemplo n.º 28
0
 private static VismaNetHttpClient GetHttpClient(VismaNetAuthorization auth = null)
 {
     return(new VismaNetHttpClient(auth));
 }
Ejemplo n.º 29
0
 internal VismaNetHttpClient(VismaNetAuthorization auth = null)
 {
     authorization = auth;
 }
Ejemplo n.º 30
0
        public static async Task <List <CustomerSalesPrice> > FetchCustomerSalesPricesForItem(string itemNo,
                                                                                              VismaNetAuthorization authorization, PriceType priceType = PriceType.Undefined)
        {
            var webclient = GetHttpClient(authorization);
            {
                var apiUrl = GetApiUrlForController(VismaNetControllers.CustomerSalesPrices);
                try
                {
                    string fullUrl = string.Empty;
                    if (priceType == PriceType.Undefined)
                    {
                        fullUrl = $"{apiUrl}?inventoryId={itemNo}";
                    }
                    else
                    {
                        fullUrl = $"{apiUrl}?priceType={priceType.ToString()}&inventoryId={itemNo}";
                    }

                    return(await webclient.Get <List <CustomerSalesPrice> >(fullUrl));
                }
                catch (AggregateException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }
                catch (WebException e)
                {
                    VismaNetExceptionHandler.HandleException(e);
                }

                return(null);
            }
        }