コード例 #1
0
        private static String FormatTime(TimeZones whichTimeZone, TimeFormatting typeOfFormatting)
        {
            String formattedTime = "";

            DateTimeOffset localDateTime = GetLocalDateTime(whichTimeZone);
            int            hour          = localDateTime.Hour;
            int            minute        = localDateTime.Minute;
            int            second        = localDateTime.Second;

            switch (typeOfFormatting)
            {
            case TimeFormatting.NUMERIC:
                formattedTime = FormatTimeNumeric(hour, minute, second);
                if (whichTimeZone == TimeZones.UTC)
                {
                    formattedTime += "Z";
                }
                break;

            case TimeFormatting.APPROXIMATE_WORDING:
                formattedTime = FormatTimeApproximateWording(hour, minute, second);
                if (whichTimeZone == TimeZones.UTC)
                {
                    formattedTime += " Zulu";
                }
                break;
            }

            return(formattedTime);
        }
コード例 #2
0
        public static String GetFormattedTime(TimeZones whichTimeZone, TimeFormatting typeOfFormatting, Boolean eMailTimeFlag)
        {
            String formattedTime = FormatTime(whichTimeZone, typeOfFormatting);

            if (eMailTimeFlag)
            {
                SendEmail(formattedTime);
            }

            return(formattedTime);
        }
コード例 #3
0
        public string GetFlightLogsAsCsv(List <int> flightLogIds)
        {
            var flightLogs    = GetFlightLogsForFileExporting(flightLogIds).Result;
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(
                "ID,CountryCode,OrganizationName,DepartmentName," +
                "UserPilotedNameFormal,UserLoggedNameFormal," +
                "TypeOfOperations,EntityName,DateTakeOff," +
                "AddressTakeOff,CoordinatesTakeOff,SecondsFlown," +
                "AddressLanding,CoordinatesLanding,Remarks");
            foreach (var flightLog in flightLogs)
            {
                flightLog.Remarks ??= "";
                var stringArray = new[]
                {
                    flightLog.FlightLogId.ToString(),

                    flightLog.CountryCode,
                    flightLog.OrganizationName,
                    flightLog.DepartmentName,

                    flightLog.UserPiloted.GetNameFormal(),
                    flightLog.UserLogged.GetNameFormal(),
                    flightLog.TypeOfOperationsCommaSeparated(),
                    flightLog.EntityName,
                    flightLog.DateTakeOff.ToString("yyyy/MM/dd HH:mm"),
                    flightLog.AddressTakeOff,
                    flightLog.coordinatesTakeOffToString(),
                    TimeFormatting.SecondsToHHMM(flightLog.SecondsFlown),
                    flightLog.AddressLanding,
                    flightLog.coordinatesLandingToString(),
                    flightLog.Remarks
                };
                stringBuilder.AppendLine(string.Join(", ", stringArray.Select(x => $"\"{x.ToString()}\"").ToArray()));
            }
            return(stringBuilder.ToString());
        }
コード例 #4
0
        public static String GetResult(TimeZones whichTimeZone, TimeFormatting typeOfFormatting, Boolean special)
        {
            String formattedTime = "";
            int    hour          = 0;
            int    minute        = 0;
            int    second        = 0;

            switch (whichTimeZone)
            {
            case TimeZones.LOCAL:
                hour   = DateTime.Now.Hour;
                minute = DateTime.Now.Minute;
                second = DateTime.Now.Second;
                break;

            case TimeZones.UTC:
                hour   = DateTime.UtcNow.Hour;
                minute = DateTime.UtcNow.Minute;
                second = DateTime.UtcNow.Second;
                break;
            }

            switch (typeOfFormatting)
            {
            case TimeFormatting.NUMERIC:
                formattedTime = hour.ToString("00") + ":" + minute.ToString("00") + ":" + second.ToString("00");
                if (whichTimeZone == TimeZones.UTC)
                {
                    formattedTime += "Z";
                }
                break;

            case TimeFormatting.APPROXIMATE_WORDING:
                String[] namesOfTheHours  = { "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" };
                String[] fuzzyTimeWords   = { "about", "a little after", "about ten after", "about a quarter after", "about twenty after", "almost half past", "about half past", "almost twenty before", "about twenty before", "about a quarter of", "about ten of", "almost", "about" };
                String[] quadrantOfTheDay = { "at night", "in the morning", "in the afternoon", "in the evening" };

                if (second >= SECONDS_IN_A_HALF_MINUTE)
                {
                    minute++;
                }

                formattedTime += fuzzyTimeWords[(minute + 2) / 5] + " ";

                if (minute < MINUTE_TO_START_FUZZING_INTO_NEXT_HOUR)
                {
                    formattedTime += namesOfTheHours[hour % namesOfTheHours.Length];
                }
                else
                {
                    formattedTime += namesOfTheHours[(hour + 1) % namesOfTheHours.Length];
                }

                formattedTime += " " + quadrantOfTheDay[hour / HOURS_IN_A_QUARTER_OF_A_DAY];

                if (whichTimeZone == TimeZones.UTC)
                {
                    formattedTime += " Zulu";
                }

                break;
            }

            if (special)
            {
                try
                {
                    NetworkCredential networkCredential = new NetworkCredential(
                        GetConfigProperty("smtpUserId"),
                        GetConfigProperty("smtpUserPassword")
                        );

                    MailMessage mailMessage = new MailMessage()
                    {
                        From    = new MailAddress(GetConfigProperty("emailFromAddress")),
                        Subject = GetConfigProperty("emailSubject"),
                        Body    = GetConfigProperty("eMailMessage") + " " + formattedTime
                    };

                    mailMessage.To.Add(new MailAddress(GetConfigProperty("emailToAddress")));

                    SmtpClient smtpClient = new SmtpClient()
                    {
                        Port                  = Convert.ToInt32(GetConfigProperty("smtpPort")),
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = Convert.ToBoolean(GetConfigProperty("smtpUseDefaultCredentials")),
                        Host                  = GetConfigProperty("smtpHost"),
                        EnableSsl             = Convert.ToBoolean(GetConfigProperty("smtpEnableSsl")),
                        Credentials           = networkCredential
                    };

                    smtpClient.Send(mailMessage);
                }
                catch (Exception ex)
                {
                    return(formattedTime);
                }
            }

            return(formattedTime);
        }
コード例 #5
0
        // https://localhost:44345/api/ExportDataAPI/FlightLogs/Pdf?flightLogIds=WzEsMyw0LDUsNiw3LDgsOSwxMCwxMSwxMiwxMywxNCwxNSwxNiwyXQ%3d%3d&applicationUserIdExtracted=IjEwZTA1YTJiLTFlYjMtNDdjOS04OWQwLWIzMTk3N2JiNTdlNCI%3d
        public byte[] GetFlightLogsAsPdf(List <int> flightLogIds, string applicationUserIdExtracted, int departmentId)
        {
            var flightLogs      = GetFlightLogsForFileExporting(flightLogIds).Result;
            var applicationUser = db.ApplicationUsers.FindAsync(applicationUserIdExtracted).Result;
            var department      = db.Departments.FindAsync(departmentId).Result;
            var organization    = db.Organizations.FindAsync(department.OrganizationId).Result;



            /* Creat a new Document */
            using var ms = new MemoryStream();
            var document  = new Document(PageSize.A4.Rotate(), 25, 25, 30, 30);
            var pdfWriter = PdfWriter.GetInstance(document, ms);

            /* Define fonts */
            var baseFont  = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            var titleFont = new Font(baseFont, 22, Font.NORMAL);
            var font      = new Font(baseFont, 10, Font.NORMAL);


            /* START */
            document.Open();
            /* Add some metadata */
            document.AddCreator("StaCake.Server");
            document.AddAuthor($"{applicationUser.FirstName} {applicationUser.LastName}");
            document.AddHeader("FlightLogs", "FlightLogs");
            document.AddTitle("Flight-logs");
            document.AddSubject("Flight-logs");
            document.AddKeywords("FlightLogs Flight Logs Log");
            document.AddCreationDate();

            /* Add centred title */
            var title = new Paragraph("Flight-logs\n\n", titleFont)
            {
                Alignment = 1
            };

            document.Add(title);

            /* Create a table */
            const int numAttribsInModel = 15;
            var       table             = new PdfPTable(numAttribsInModel)
            {
                WidthPercentage = 100
            };

            table.SetWidths(new[] { 1f, 1f, 2f, 2f, 1f, 2f, 3f, 2f, 2f, 2f, 2f, 1f, 2f, 3f, 3f });
            /* Add table-header */
            table.AddCell(new Phrase(new Chunk("ID", font)));
            table.AddCell(new Phrase(new Chunk("CountryCode", font)));
            table.AddCell(new Phrase(new Chunk("OrganizationName", font)));
            table.AddCell(new Phrase(new Chunk("DepartmentName", font)));
            table.AddCell(new Phrase(new Chunk("UserPilotedNameForma", font)));
            table.AddCell(new Phrase(new Chunk("UserLoggedNameFormal", font)));
            table.AddCell(new Phrase(new Chunk("TypeOfOperations", font)));
            table.AddCell(new Phrase(new Chunk("EntityName", font)));
            table.AddCell(new Phrase(new Chunk("DateTakeOff (yyyy.MM.dd HH:mm)", font)));
            table.AddCell(new Phrase(new Chunk("AddressTakeOff", font)));
            table.AddCell(new Phrase(new Chunk("CoordinatesTakeOff", font)));
            table.AddCell(new Phrase(new Chunk("SecondsFlown", font)));
            table.AddCell(new Phrase(new Chunk("AddressLanding", font)));
            table.AddCell(new Phrase(new Chunk("CoordinatesLanding", font)));
            table.AddCell(new Phrase(new Chunk("Remarks", font)));

            /* Add table-data */
            foreach (var flightLog in flightLogs)
            {
                table.AddCell(new Phrase(new Chunk(flightLog.FlightLogId.ToString(), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.CountryCode, font)));
                table.AddCell(new Phrase(new Chunk(flightLog.OrganizationName, font)));
                table.AddCell(new Phrase(new Chunk(flightLog.DepartmentName, font)));
                table.AddCell(new Phrase(new Chunk(flightLog.UserPiloted.GetNameFormal(), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.UserLogged.GetNameFormal(), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.TypeOfOperationsCommaSeparated(), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.EntityName, font)));
                table.AddCell(new Phrase(new Chunk(flightLog.DateTakeOff.ToString("yyyy/MM/dd HH:mm"), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.AddressTakeOff, font)));
                table.AddCell(new Phrase(new Chunk(flightLog.coordinatesTakeOffToString(), font)));
                table.AddCell(new Phrase(new Chunk(TimeFormatting.SecondsToHHMM(flightLog.SecondsFlown), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.AddressLanding, font)));
                table.AddCell(new Phrase(new Chunk(flightLog.coordinatesLandingToString(), font)));
                table.AddCell(new Phrase(new Chunk(flightLog.Remarks, font)));
            }
            document.Add(table);

            /* Add some info about the document */
            document.Add(new Paragraph(
                             "\n\nInfo:" +
                             $"File extraction date: {DateTime.Now:yyyy/MM/dd HH:mm}\n" +
                             $"File extracted by user: {applicationUser.FirstName} {applicationUser.LastName}\n" +
                             $"Number of flight-logs extracted: {flightLogs.Count}\n"
                             ));

            /* FIN */
            document.Close();
            return(ms.ToArray());
        }
コード例 #6
0
        public ExcelPackage GetFlightLogsAsExcelPackage(List <int> flightLogIds, string applicationUserIdExtracted)
        {
            var flightLogs = GetFlightLogsForFileExporting(flightLogIds).Result;

            // Make a new Excel Package
            var package = new ExcelPackage();

            package.Workbook.Properties.Title    = $"FlightLog-Report generated at {DateTime.Now:yyyy-M-d dddd}";
            package.Workbook.Properties.Author   = "StarCake server";
            package.Workbook.Properties.Subject  = "FlightLog";
            package.Workbook.Properties.Keywords = "FlightLogs";

            var worksheetFlightLogs = package.Workbook.Worksheets.Add("FlightLogs");

            // Add the headers
            worksheetFlightLogs.Cells[1, 1].Value  = "ID";
            worksheetFlightLogs.Cells[1, 2].Value  = "CountryCode";
            worksheetFlightLogs.Cells[1, 3].Value  = "OrganizationName";
            worksheetFlightLogs.Cells[1, 4].Value  = "DepartmentName";
            worksheetFlightLogs.Cells[1, 5].Value  = "UserPilotedNameForma";
            worksheetFlightLogs.Cells[1, 6].Value  = "UserLoggedNameFormal";
            worksheetFlightLogs.Cells[1, 7].Value  = "TypeOfOperations";
            worksheetFlightLogs.Cells[1, 8].Value  = "EntityName";
            worksheetFlightLogs.Cells[1, 9].Value  = "DateTakeOff (yyyy.MM.dd HH:mm)";
            worksheetFlightLogs.Cells[1, 10].Value = "AddressTakeOff";
            worksheetFlightLogs.Cells[1, 11].Value = "CoordinatesTakeOff";
            worksheetFlightLogs.Cells[1, 12].Value = "SecondsFlown";
            worksheetFlightLogs.Cells[1, 13].Value = "AddressLanding";
            worksheetFlightLogs.Cells[1, 14].Value = "CoordinatesLanding";
            worksheetFlightLogs.Cells[1, 15].Value = "Remarks";

            // Add some formats
            var numberformat      = "#,##0";
            var dataCellStyleName = "TableNumber";
            var numStyle          = package.Workbook.Styles.CreateNamedStyle(dataCellStyleName);

            numStyle.Style.Numberformat.Format = numberformat;

            // Populate headers with data
            var count = 1;

            foreach (var flightLog in flightLogs)
            {
                count++;
                //worksheetFlightLogs.Cells[count, 1].Value = (count - 1).ToString();
                worksheetFlightLogs.Cells[count, 1].Value  = flightLog.FlightLogId.ToString();
                worksheetFlightLogs.Cells[count, 2].Value  = flightLog.CountryCode;
                worksheetFlightLogs.Cells[count, 3].Value  = flightLog.OrganizationName;
                worksheetFlightLogs.Cells[count, 4].Value  = flightLog.DepartmentName;
                worksheetFlightLogs.Cells[count, 5].Value  = flightLog.UserPiloted.GetNameFormal();
                worksheetFlightLogs.Cells[count, 6].Value  = flightLog.UserLogged.GetNameFormal();
                worksheetFlightLogs.Cells[count, 7].Value  = flightLog.TypeOfOperationsCommaSeparated();
                worksheetFlightLogs.Cells[count, 8].Value  = flightLog.EntityName;
                worksheetFlightLogs.Cells[count, 9].Value  = flightLog.DateTakeOff.ToString("yyyy/MM/dd HH:mm");
                worksheetFlightLogs.Cells[count, 10].Value = flightLog.AddressTakeOff;
                worksheetFlightLogs.Cells[count, 11].Value = flightLog.coordinatesTakeOffToString();
                worksheetFlightLogs.Cells[count, 12].Value = TimeFormatting.SecondsToHHMM(flightLog.SecondsFlown);
                worksheetFlightLogs.Cells[count, 13].Value = flightLog.AddressLanding;
                worksheetFlightLogs.Cells[count, 14].Value = flightLog.coordinatesLandingToString();
                worksheetFlightLogs.Cells[count, 15].Value = flightLog.Remarks;
            }

            var nAttributesInFlightLog = 15;

            // Add to table / Add summary row
            var tbl = worksheetFlightLogs.Tables.Add(new ExcelAddressBase(fromRow: 1, fromCol: 1, toRow: flightLogs.Count() + 1, toColumn: nAttributesInFlightLog), "Data");

            tbl.ShowHeader = true;
            tbl.TableStyle = TableStyles.Dark9;

            // AutoFitColumns
            worksheetFlightLogs.Cells[1, 1, flightLogs.Count() + 1, nAttributesInFlightLog].AutoFitColumns();

            // Add extra info worksheet
            var worksheetInfo = package.Workbook.Worksheets.Add("info");

            worksheetInfo.Cells[1, 1].Value = "File extraction date: ";
            worksheetInfo.Cells[1, 2].Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
            worksheetInfo.Cells[2, 1].Value = "File extracted by user: "******"{x.LastName}, {x.FirstName} ({x.Email})")).FirstOrDefault();
            worksheetInfo.Cells[3, 1].Value = "Number of FlightLogs extracted: ";
            worksheetInfo.Cells[3, 2].Value = flightLogs.Count().ToString();
            worksheetInfo.Cells[1, 1, 3, 2].AutoFitColumns();

            // Return as ExcelPackage
            return(package);
        }