Esempio n. 1
0
        public static void Run(ILogger logger)
        {
            OnlineClient client = Bootstrap.Client(logger);

            List <IFilter> filterList = new List <IFilter>();

            filterList.Add((new Filter("CUSTOMERID")).SetLike("c%"));
            filterList.Add((new Filter("CUSTOMERID")).SetLike("1%"));
            OrOperator filter = new OrOperator(filterList);

            OrderBuilder orderBuilder = new OrderBuilder();

            IOrder[] orders = orderBuilder.Descending("CUSTOMERID").GetOrders();

            SelectBuilder selectBuilder = new SelectBuilder();

            ISelect[] fields = selectBuilder.
                               Fields(new[] { "CUSTOMERID", "CUSTOMERNAME" }).
                               Sum("TOTALDUE").
                               GetFields();

            QueryFunction query = new QueryFunction()
            {
                SelectFields    = fields,
                FromObject      = "ARINVOICE",
                Filter          = filter,
                CaseInsensitive = true,
                PageSize        = 100,
                OrderBy         = orders
            };

            logger.LogInformation("Executing query to Intacct API");

            Task <OnlineResponse> task = client.Execute(query);

            task.Wait();
            OnlineResponse response = task.Result;
            Result         result   = response.Results[0];

            dynamic json = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result.Data));

            if (json != null && json.First != null)
            {
                Console.WriteLine("Success! Number of ARINVOICE objects found: " + result.TotalCount);
                Console.WriteLine("First ARINVOICE result found");
                Console.WriteLine("CUSTOMERID: " + json.First["ARINVOICE"]["CUSTOMERID"].Value);
                Console.WriteLine("CUSTOMERNAME: " + json.First["ARINVOICE"]["CUSTOMERNAME"].Value);
                Console.WriteLine("SUM.TOTALDUE: " + json.First["ARINVOICE"]["SUM.TOTALDUE"].Value);

                Console.WriteLine("See the log file (logs/intacct.log) for the complete list of results.");
            }
            else
            {
                Console.WriteLine("The query executed, but no ARINVOICE objects met the query criteria.");
                Console.WriteLine("Either modify the filter or comment it out from the query.");
                Console.WriteLine("See the log file (logs/intacct.log) for the XML request.");
            }

            try
            {
                string jsonString = json.ToString();

                logger.LogDebug(
                    "Query successful [ Company ID={0}, User ID={1}, Request control ID={2}, Function control ID={3}, Total count={4}, Data={5} ]",
                    response.Authentication.CompanyId,
                    response.Authentication.UserId,
                    response.Control.ControlId,
                    result.ControlId,
                    result.TotalCount,
                    jsonString
                    );
            }
            catch (NullReferenceException e)
            {
                logger.LogDebug("No response in Data. {0}", e);
            }
            finally
            {
                LogManager.Flush();
            }
        }
Esempio n. 2
0
        public static void Run(ILogger logger)
        {
            OnlineClient client = Bootstrap.Client(logger);

            ReadByQuery query = new ReadByQuery()
            {
                ObjectName = "VENDOR",
                PageSize   = 2, // Keep the count to just 2 for the example
                Fields     =
                {
                    "RECORDNO",
                    "VENDORID",
                }
            };

            logger.LogInformation("Executing query to Intacct API");

            Task <OnlineResponse> task = client.Execute(query);

            task.Wait();
            OnlineResponse response = task.Result;
            Result         result   = response.Results[0];

            try
            {
                dynamic json = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(result.Data));

                string jsonString = json.ToString();

                logger.LogDebug(
                    "Query successful - page 1 [ Total count={0}, Data={1} ]",
                    result.TotalCount,
                    jsonString
                    );

                Console.WriteLine("Page 1 success! Number of vendor objects found: " + result.TotalCount + ". Number remaining: " + result.NumRemaining);
            } catch (NullReferenceException e)
            {
                logger.LogDebug("No response in Data. {0}", e);
            }

            LogManager.Flush();
            int i = 1;

            while (result.NumRemaining > 0 && i <= 3 && !string.IsNullOrEmpty(result.ResultId))
            {
                i++;
                ReadMore more = new ReadMore()
                {
                    ResultId = result.ResultId
                };

                Task <OnlineResponse> taskMore = client.Execute(more);
                taskMore.Wait();
                OnlineResponse responseMore = taskMore.Result;
                Result         resultMore   = responseMore.Results[0];

                try
                {
                    dynamic resultMoreJson =
                        JsonConvert.DeserializeObject(JsonConvert.SerializeObject(resultMore.Data));
                    string resultMoreJsonString = resultMoreJson.ToString();

                    logger.LogDebug(
                        "Read More successful - page " + i + " [ Total remaining={0}, Data={1} ]",
                        resultMore.NumRemaining,
                        resultMoreJsonString
                        );

                    Console.WriteLine("Page " + i + " success! Records remaining: " + resultMore.NumRemaining);
                }
                catch (NullReferenceException e)
                {
                    logger.LogDebug("No response in Data. {0}", e);
                }
                finally
                {
                    LogManager.Flush();
                }
            }

            Console.WriteLine("Successfully read " + i + " pages");
        }
Esempio n. 3
0
        public static void Run(ILogger logger)
        {
            OnlineClient client = Bootstrap.Client(logger);

            logger.LogInformation("Executing CRUD customer functions to API");

            CustomerCreate create = new CustomerCreate()
            {
                CustomerName = "Joshua Granley",
                Active       = false,
            };

            Task <OnlineResponse> createTask = client.Execute(create);

            createTask.Wait();
            OnlineResponse createResponse = createTask.Result;
            Result         createResult   = createResponse.Results[0];

            string customerId = createResult.Data[0].Element("CUSTOMERID").Value;
            int    recordNo   = int.Parse(createResult.Data[0].Element("RECORDNO").Value);

            Console.WriteLine("Created inactive customer ID " + customerId);

            CustomerUpdate update = new CustomerUpdate()
            {
                CustomerId = customerId,
                Active     = true,
            };

            Task <OnlineResponse> updateTask = client.Execute(update);

            updateTask.Wait();

            Console.WriteLine("Updated customer ID " + customerId + " to active");

            Read read = new Read()
            {
                ObjectName = "CUSTOMER",
                Fields     =
                {
                    "RECORDNO",
                    "CUSTOMERID",
                    "STATUS",
                },
                Keys =
                {
                    recordNo,
                }
            };

            Task <OnlineResponse> readTask = client.Execute(read);

            readTask.Wait();

            Console.WriteLine("Read customer ID " + customerId);

            CustomerDelete delete = new CustomerDelete()
            {
                CustomerId = customerId,
            };

            Task <OnlineResponse> deleteTask = client.Execute(delete);

            deleteTask.Wait();

            Console.WriteLine("Deleted customer ID " + customerId);

            LogManager.Flush();
        }