Ejemplo n.º 1
0
        public static void SendData(IEnumerable <SOOrder> data, string name = "orders.csv")
        {
            //Create needed graphs
            var graph = PXGraph.CreateInstance <AFSetupMaint>();

            AFSetup setup = graph.AFSetupView.Current ?? graph.AFSetupView.Select();

            //-----------------------------------------------------------------------------
            //Change for Setup daya
            string bucketName      = setup.AFBucketName;    //"acumatica-forecast";
            string s3DirectoryName = setup.AFDirectoryName; //"dynamics/facturas";
            string accessKey       = setup.AFAccessKey;
            string secretKey       = setup.AFSecretKey;

            //-----------------------------------------------------------------------------

            PXTrace.WriteInformation($"AFAccessKey: {accessKey} AFSecretKey: {secretKey} AFBucketName: {bucketName} AFDirectoryName: {s3DirectoryName}");

            //if (data?.Count == 0) return;

            using (var stream = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(stream))
                {
                    try
                    {
                        // Convert to csv and upload
                        foreach (var i in data)
                        {
                            try
                            {
                                //var row = data[i];
                                //Check current item
                                //PXProcessing.SetCurrentItem(row);

                                //sw.WriteLine(i);
                            }
                            catch (Exception e)
                            {
                                PXProcessing <SOOrder> .SetError(e.Message);
                            }
                        }

                        var line = $"TEST,2020-01-25T00:10:10,1.00";
                        sw.WriteLine(line);

                        //Si existe el CFDI permite la subida del XML y PDF
                        //Se crea la instancia a S3
                        AFAmazonTools myUploader = new AFAmazonTools();
                        var           result     = myUploader.UploadToS3(accessKey, secretKey, stream.ToArray(), bucketName, s3DirectoryName, name);
                    }
                    catch (Exception e)
                    {
                        PXProcessing <SOOrder> .SetError(e.Message);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public virtual IEnumerable importForecast(PXAdapter adapter)
        {
            PXLongOperation.StartOperation(this, delegate()
            {
                //Create needed graphs
                var graph = PXGraph.CreateInstance <AFResultMaint>();

                AFSetup setup = graph.Setup.Current ?? graph.Setup.Select();

                //-----------------------------------------------------------------------------
                //Change for Setup daya
                string bucketName      = setup.AFBucketName;
                string s3DirectoryName = setup.AFOutDirectoryName;
                string accessKey       = setup.AFAccessKey;
                string secretKey       = setup.AFSecretKey;
                //-----------------------------------------------------------------------------

                PXTrace.WriteInformation($"AFAccessKey: {accessKey} AFSecretKey: {secretKey} AFBucketName: {bucketName} AFDirectoryName: {s3DirectoryName}");

                //if (data?.Count == 0) return;


                try
                {
                    AFAmazonTools myUploader = new AFAmazonTools();
                    var result = myUploader.DownloadFromS3(accessKey, secretKey, bucketName, s3DirectoryName);

                    foreach (var line in result)
                    {
                        try
                        {
                            var item          = new AFResult();
                            item.ResultID     = line[0];
                            item.ResultTstamp = DateTime.Parse(line[1], null, System.Globalization.DateTimeStyles.RoundtripKind);
                            item.ResultP10    = Convert.ToDecimal(line[2]);
                            item.ResultE50    = Convert.ToDecimal(line[3]);
                            item.ResultP90    = Convert.ToDecimal(line[4]);

                            graph.AFResultView.Update(item);
                        }
                        catch (Exception e)
                        {
                            PXTrace.WriteError($"Error parsing data ({String.Join(",", line)}): {e.Message}");
                        }
                    }
                    graph.Save.Press();
                }
                catch (Exception e)
                {
                    throw new PXException(e.Message, e);
                }
            });

            return(adapter.Get());
        }