Exemplo n.º 1
0
        } // End of the CreateAnnytabDoxTravelExpenseClaim method

        /// <summary>
        /// Create a drive log according to the Annytab Dox Drive Log v1 standard
        /// </summary>
        public static byte[] CreateAnnytabDoxDriveLog()
        {
            // Create a drive log
            AnnytabDoxDriveLog post = new AnnytabDoxDriveLog();
            post.personnel_id = "001";
            post.name = "Nils Nilsson";
            post.cost_center = "Marketing";
            post.registration_number = "SXL 837";
            post.unit_code = "km";
            post.start_date = "2018-08-01T00:00:00";
            post.end_date = "2018-08-31T23:59:59";
            post.opening_odometer = 5000M;
            post.ending_odometer = 5125M;

            // Add log rows
            post.log_rows = new List<DriveLogRow>();
            post.log_rows.Add(new DriveLogRow
            {
                start_odometer = 5000M,
                start_time = "2018-08-05T09:30:11",
                from = "Halmstad",
                end_odometer = 5065M,
                end_time = "2018-08-05T12:30:11",
                to = "Stockholm",
                description = "Meeting with Olle.",
                business_trip = true
            });
            post.log_rows.Add(new DriveLogRow
            {
                start_odometer = 5065M,
                start_time = "2018-08-05T15:10:34",
                from = "Stockholm",
                end_odometer = 5125M,
                end_time = "2018-08-05T20:15:55",
                to = "Halmstad",
                description = "Driving home from meeting with Olle.",
                business_trip = true
            });

            // 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 CreateAnnytabDoxDriveLog method
Exemplo n.º 2
0
        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