コード例 #1
0
        } // End of the CreateAnnytabDoxContract method

        /// <summary>
        /// Create a travel expense claim according to the Annytab Dox Travel Expense Claim v1 standard
        /// </summary>
        public static byte[] CreateAnnytabDoxTravelExpenseClaim()
        {
            // Create a travel expense claim
            AnnytabDoxTravelExpenseClaim post = new AnnytabDoxTravelExpenseClaim();
            post.personnel_id = "001";
            post.name = "Nils Nilsson";
            post.cost_center = "Marketing";
            post.currency_code = "SEK";
            post.trip_purpose = "Meeting with our largest customer";
            post.destination = "Stockholm";
            post.departure_date = "2018-08-01T08:00:00";
            post.return_date = "2018-08-02T16:00:00";

            // Add expense rows
            post.expense_rows = new List<TravelExpenseRow>();
            post.expense_rows.Add(new TravelExpenseRow
            {
                code = "ADT1016",
                description = "Private car fuel, tax free",
                quantity = 200,
                unit_code = "km",
                unit_price = 1.85M
            });
            post.expense_rows.Add(new TravelExpenseRow
            {
                code = "ADT1015",
                description = "Accomodation",
                quantity = 1,
                unit_code = "day",
                unit_price = 1495M
            });

            // Convert the object to a byte array and return it
            string json = JsonConvert.SerializeObject(post, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
            return Encoding.UTF8.GetBytes(json);

        } // End of the CreateAnnytabDoxTravelExpenseClaim method
コード例 #2
0
ファイル: FilesTest.cs プロジェクト: annytab/a-dox-standards
        public void ReadFromDisk()
        {
            // Create a file path
            string directory = "C:\\DATA\\home\\AnnytabDoxStandards";

            // Variables
            AnnytabDoxMeta meta = null;
            byte[] file_array = null;

            // Get all files
            string[] files = System.IO.Directory.GetFiles(directory + "\\Open");

            // Loop files
            foreach (string path in files)
            {
                // Create and use an archive
                using (ZipArchive archive = ZipFile.OpenRead(path))
                {
                    // Loop files in zip
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        // Check if a file is meta or file
                        if (entry.FullName.StartsWith("meta", StringComparison.OrdinalIgnoreCase))
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                entry.Open().CopyTo(stream);
                                byte[] array = stream.ToArray();
                                meta = JsonConvert.DeserializeObject<AnnytabDoxMeta>(Encoding.UTF8.GetString(array, 0, array.Length));
                            }
                        }
                        else
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                entry.Open().CopyTo(stream);
                                file_array = stream.ToArray();
                            }
                        }
                    }

                    // Log standard name
                    this.logger.LogInformation($"Fetching: {meta.standard_name} from open folder.", null);

                    // Get file contents depending on standard name
                    if (meta.standard_name.Equals("Annytab Dox Trade v1", StringComparison.OrdinalIgnoreCase))
                    {
                        AnnytabDoxTrade doc = JsonConvert.DeserializeObject<AnnytabDoxTrade>(Encoding.UTF8.GetString(file_array, 0, file_array.Length));
                    }
                    else if (meta.standard_name.Equals("Annytab Dox Contract v1", StringComparison.OrdinalIgnoreCase))
                    {
                        AnnytabDoxContract doc = JsonConvert.DeserializeObject<AnnytabDoxContract>(Encoding.UTF8.GetString(file_array, 0, file_array.Length));
                    }
                    else if (meta.standard_name.Equals("Annytab Dox Drive Log v1", StringComparison.OrdinalIgnoreCase))
                    {
                        AnnytabDoxDriveLog doc = JsonConvert.DeserializeObject<AnnytabDoxDriveLog>(Encoding.UTF8.GetString(file_array, 0, file_array.Length));
                    }
                    else if (meta.standard_name.Equals("Annytab Dox Travel Expense Claim v1", StringComparison.OrdinalIgnoreCase))
                    {
                        AnnytabDoxTravelExpenseClaim doc = JsonConvert.DeserializeObject<AnnytabDoxTravelExpenseClaim>(Encoding.UTF8.GetString(file_array, 0, file_array.Length));
                    }
                }

                // Move file from open to closed
                System.IO.Directory.Move(path, directory + "\\Closed\\" + Path.GetFileName(path));
            }

        } // End of the ReadFromDisk method