Beispiel #1
0
    public async Task <byte[]> GetAsync(SIEType type, long?finYearID = null, SIEExportOptions exportOptions = null)
    {
        var request = new FileDownloadRequest()
        {
            Endpoint = Endpoint,
            Indices  = new List <string> {
                type.GetStringValue()
            }
        };

        if (finYearID != null)
        {
            request.Parameters.Add("financialyear", finYearID.ToString());
        }

        if (exportOptions != null)
        {
            foreach (var parameter in GetExportParameters(exportOptions))
            {
                request.Parameters.Add(parameter.Key, parameter.Value);
            }
        }

        return(await SendAsync(request).ConfigureAwait(false));
    }
Beispiel #2
0
        private byte[] Export(SIEType sieType, string localPath = "")
        {
            Resource = "sie/" + (int)sieType;
            var requestString = GetUrl();

            Parameters = new Dictionary <string, string>();
            AddExportOptions();

            requestString = AddParameters(requestString);

            var wr = SetupRequest(requestString, "GET");

            var data = Array.Empty <byte>();

            try
            {
                using var response       = wr.GetResponse();
                using var responseStream = response.GetResponseStream();

                if (localPath != "")
                {
                    responseStream.ToFile(localPath);
                }
                else
                {
                    data = responseStream.ToBytes();
                }
            }
            catch (WebException we)
            {
                Error = HandleException(we);
            }

            return(data);
        }
Beispiel #3
0
        private SieFile Export(SIEType sieType, string localPath = "")
        {
            base.Resource = "sie/" + (int)sieType;
            string requestString = base.GetUrl();

            this.Parameters = new Dictionary <string, string>();

            AddCustomParameters();

            AddExportOptions();

            requestString = base.AddParameters(requestString);

            HttpWebRequest wr = base.SetupRequest(requestString, "GET");

            List <byte> data = new List <byte>();

            SieFile sieFile = new SieFile();

            try
            {
                using (WebResponse response = wr.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        int b;

                        if (localPath != "")
                        {
                            using (var writer = new FileStream(localPath, FileMode.Create))
                            {
                                while ((b = responseStream.ReadByte()) != -1)
                                {
                                    writer.WriteByte((byte)b);
                                }
                            }
                        }
                        else
                        {
                            while ((b = responseStream.ReadByte()) != -1)
                            {
                                data.Add((byte)b);
                            }
                        }
                    }

                    sieFile.ContentDisposition = response.Headers.Get("Content-Disposition");
                    sieFile.Content            = data.ToArray();
                }
            }
            catch (WebException we)
            {
                Error = base.HandleException(we);
            }

            return(sieFile);
        }
        public async Task <byte[]> GetAsync(SIEType type)
        {
            RequestInfo = new RequestInfo()
            {
                BaseUrl  = BaseUrl,
                Resource = Resource,
                Indices  = new[] { type.GetStringValue() }
            };

            return(await DownloadFile().ConfigureAwait(false));
        }
Beispiel #5
0
        public async Task <byte[]> GetAsync(SIEType type, long?finYearID = null)
        {
            var request = new FileDownloadRequest()
            {
                Resource = Resource,
                Indices  = new List <string> {
                    type.GetStringValue()
                }
            };

            if (finYearID != null)
            {
                request.Parameters.Add("financialyear", finYearID.ToString());
            }

            return(await SendAsync(request).ConfigureAwait(false));
        }
Beispiel #6
0
        private string Export(SIEType sieType, string localPath = "")
        {
            base.Resource = "sie/" + (int)sieType;
            string requestString = base.GetUrl();

            this.Parameters = new Dictionary <string, string>();

            AddCustomParameters();

            AddExportOptions();

            requestString = base.AddParameters(requestString);

            HttpWebRequest wr = base.SetupRequest(requestString, "GET");

            string sie = "";

            try
            {
                WebResponse response       = wr.GetResponse();
                Stream      responseStream = response.GetResponseStream();

                StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("CP437"));

                if (localPath != "")
                {
                    using (StreamWriter writer = new StreamWriter(localPath))
                    {
                        writer.Write(reader.ReadToEnd());
                    }
                }
                else
                {
                    sie = reader.ReadToEnd();
                }
            }
            catch (WebException we)
            {
                Error = base.HandleException(we);
            }

            return(sie);
        }
Beispiel #7
0
 /// <summary>
 /// Export SIE to a file
 /// </summary>
 /// <param name="sieType">The type of SIE to export</param>
 /// <param name="localPath">Path to sie-file</param>
 public void ExportSIE(SIEType sieType, string localPath)
 {
     Export(sieType, localPath);
 }
Beispiel #8
0
 /// <summary>
 /// Export SIE to a string
 /// </summary>
 /// <param name="sieType">The type of SIE to export</param>
 /// <returns>SIE</returns>
 public SieFile ExportSIE(SIEType sieType)
 {
     return(Export(sieType));
 }
Beispiel #9
0
 public byte[] Get(SIEType type, long?finYearID = null)
 {
     return(GetAsync(type, finYearID).GetResult());
 }
 public byte[] Get(SIEType type)
 {
     return(GetAsync(type).Result);
 }
Beispiel #11
0
 public byte[] Get(SIEType type, long?finYearID = null, SIEExportOptions exportOptions = null)
 {
     return(GetAsync(type, finYearID, exportOptions).GetResult());
 }
Beispiel #12
0
 /// <summary>
 /// Export SIE to a string
 /// </summary>
 /// <param name="sieType">The type of SIE to export</param>
 /// <returns>SIE</returns>
 public byte[] ExportSIE(SIEType sieType)
 {
     return(Export(sieType));
 }
Beispiel #13
0
 /// <summary>
 /// Export SIE to a string
 /// </summary>
 /// <param name="sieType">The type of SIE to export</param>
 /// <returns>SIE</returns>
 public string ExportSIE(SIEType sieType)
 {
     return(Export(sieType));
 }