Ejemplo n.º 1
0
 public void CreateNewLicense(string licenseFile, MyLicense license)
 {
     license.Signature = _rsa.SignData(license.getData, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1);
     license.Key       = _rsa.ExportParameters(false);
     File.WriteAllText(licenseFile, LicenseExtensions.LicenseToXmlString(license));
 }
Ejemplo n.º 2
0
        public MyLicense GetLicense(String licenseFile)
        {
            string xmlString = File.ReadAllText(licenseFile);

            return(LicenseExtensions.XmlStringToLicense(xmlString));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAuthorizationPdf(string eventId)
        {
            MicrosoftDynamicsCRMadoxioEvent licenceEvent;
            LicenceEvent licenceEventVM;
            MicrosoftDynamicsCRMadoxioLicences licence;
            MicrosoftDynamicsCRMaccount        account;
            Dictionary <string, string>        serviceAreas;

            try
            {
                licenceEvent   = _dynamicsClient.Events.GetByKey(eventId);
                licenceEventVM = licenceEvent.ToViewModel(_dynamicsClient);
                licence        = _dynamicsClient.Licenceses.GetByKey(
                    licenceEventVM.LicenceId,
                    expand: new List <string> {
                    "adoxio_adoxio_licences_adoxio_applicationtermsconditionslimitation_Licence"
                });
                account = _dynamicsClient.Accounts.GetByKey(licence._adoxioLicenceeValue);
                var areas = LicenseExtensions.GetServiceAreas(licence.AdoxioLicencesid, _dynamicsClient);
                // Create lookup dictionary with service areas to speed up lookup times (vs an array)
                serviceAreas = areas.ToDictionary(x => x.Id, x => x.AreaLocation);
            }
            catch (HttpOperationException)
            {
                return(new NotFoundResult());
            }

            if (!CurrentUserHasAccessToEventOwnedBy(licence._adoxioLicenceeValue))
            {
                return(new NotFoundResult());
            }

            string       eventTimings = "";
            TimeZoneInfo hwZone;

            try
            {
                hwZone = TimeZoneInfo.FindSystemTimeZoneById("America/Vancouver");
            }
            catch (TimeZoneNotFoundException)
            {
                hwZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            }

            foreach (var schedule in licenceEventVM.Schedules)
            {
                // Event times are stored in UTC but we want the printed PDF to reflect times and dates in Pacific Standard Time (PST)
                DateTime?pstStart       = schedule.EventStartDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.EventStartDateTime.Value.DateTime, hwZone) : (DateTime?)null;
                DateTime?pstEnd         = schedule.EventEndDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.EventEndDateTime.Value.DateTime, hwZone) : (DateTime?)null;
                DateTime?pstLiquorStart = schedule.ServiceStartDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.ServiceStartDateTime.Value.DateTime, hwZone) : (DateTime?)null;
                DateTime?pstLiquorEnd   = schedule.ServiceEndDateTime.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(schedule.ServiceEndDateTime.Value.DateTime, hwZone) : (DateTime?)null;

                string eventDate       = pstStart.HasValue ? pstStart.Value.ToString("MMMM dd, yyyy") : "";
                string startTime       = pstStart.HasValue ? pstStart.Value.ToString("h:mm tt") : "";
                string endTime         = pstEnd.HasValue ? pstEnd.Value.ToString("h:mm tt") : "";
                string liquorStartTime = pstLiquorStart.HasValue ? pstLiquorStart.Value.ToString("h:mm tt") : "";
                string liquorEndTime   = pstLiquorEnd.HasValue ? pstLiquorEnd.Value.ToString("h:mm tt") : "";
                eventTimings += $@"<tr class='hide-border'>
                        <td style='width: 50%; text-align: left;'>{eventDate} - Event Hours: {startTime} to {endTime}</td>
                        <td style='width: 50%; text-align: left;'>Service Hours: {liquorStartTime} to {liquorEndTime}</td>
                    </tr>";
            }

            var eventLocations = "";

            if (licenceEventVM.EventLocations.Count > 0)
            {
                eventLocations += $@"<table style='width: 100%'>
                    <thead>
                        <tr>
                            <th>Location ID</th>
                            <th>Location Name</th>
                            <th>Attendance</th>
                        </tr>
                    </thead>";
                foreach (var location in licenceEventVM.EventLocations)
                {
                    string area = serviceAreas.GetValueOrDefault(location.ServiceAreaId, "");
                    eventLocations += $@"<tr class='hide-border'>
                        <td style='width: 30%; text-align: left;'>{area}</td>
                        <td style='width: 50%; text-align: left;'>{location.Name ?? ""}</td>
                        <td style='width: 20%; text-align: left;'>{location.Attendance ?? 0}</td>
                    </tr>";
                }
                eventLocations += "</table>";
            }

            var termsAndConditions = "";

            foreach (var item in licence.AdoxioAdoxioLicencesAdoxioApplicationtermsconditionslimitationLicence)
            {
                termsAndConditions += $"<li>{item.AdoxioTermsandconditions}</li>";
            }

            var parameters = new Dictionary <string, string>
            {
                { "licensee", account.Name },
                { "licenceNumber", licence.AdoxioLicencenumber },
                { "licenceExpiryDate", licence.AdoxioExpirydate?.ToString("MMMM dd, yyyy") },
                { "licenseePhone", account.Telephone1 },
                { "licenseeEmail", account.Emailaddress1 },
                { "contactName", licenceEventVM.ContactName },
                { "contactEmail", licenceEventVM.ContactEmail },
                { "contactPhone", licenceEventVM.ContactPhone },
                { "hostname", licenceEventVM.ClientHostname },
                { "startDate", licenceEventVM.StartDate?.ToString("MMMM dd, yyyy") },
                { "endDate", licenceEventVM.EndDate?.ToString("MMMM dd, yyyy") },
                { "eventTimings", eventTimings },
                { "eventNumber", licenceEventVM.EventNumber },
                { "eventType", licenceEventVM.EventType.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.EventType) : "" },
                { "eventDescription", licenceEventVM.EventTypeDescription },
                { "foodService", licenceEventVM.FoodService.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.FoodService) : "" },
                { "entertainment", licenceEventVM.Entertainment.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.Entertainment) : "" },
                { "attendance", licenceEventVM.MaxAttendance.ToString() },
                { "minors", licenceEventVM.MinorsAttending ?? false ? "Yes" : "No" },
                { "location", licenceEventVM.SpecificLocation.ToString() },
                { "addressLine1", licenceEventVM.Street1 },
                { "addressLine2", licenceEventVM.Street2 },
                { "addressLine3", $"{licenceEventVM.City}, BC {licenceEventVM.PostalCode}" },
                { "inspectorName", licenceEvent.AdoxioEventinspectorname },
                { "inspectorPhone", licenceEvent.AdoxioEventinspectorphone },
                { "inspectorEmail", licenceEvent.AdoxioEventinspectoremail },
                { "date", DateTime.Now.ToString("MMMM dd, yyyy") },
                { "marketName", licenceEventVM.MarketName },
                { "marketDuration", licenceEventVM.MarketDuration.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.MarketDuration) : "" },
                { "restrictionsText", termsAndConditions },
                // TUA-specific fields
                { "tuaEventType", licenceEventVM.TuaEventType.HasValue ? EnumExtensions.GetEnumMemberValue(licenceEventVM.TuaEventType) : "" },
                { "isClosedToPublic", licenceEventVM.IsClosedToPublic ?? false ? "Yes" : "No" },
                { "isWedding", licenceEventVM.IsWedding ?? false ? "1" : null },
                { "isNetworkingParty", licenceEventVM.IsNetworkingParty ?? false ? "1" : null },
                { "isConcert", licenceEventVM.IsConcert ?? false ? "1" : null },
                { "isNoneOfTheAbove", licenceEventVM.IsNoneOfTheAbove ?? false ? "1" : null },
                { "isBanquet", licenceEventVM.IsBanquet ?? false ? "1" : "" },
                { "isAmplifiedSound", licenceEventVM.IsAmplifiedSound ?? false ? "1" : null },
                { "isDancing", licenceEventVM.IsDancing ?? false ? "1" : null },
                { "isReception", licenceEventVM.IsReception ?? false ? "1" : null },
                { "isLiveEntertainment", licenceEventVM.IsLiveEntertainment ?? false ? "1" : null },
                { "isGambling", licenceEventVM.IsGambling ?? false ? "1" : null },
                { "eventLocations", eventLocations },
            };

            byte[] data;
            try
            {
                string pdfType = null;
                if (licenceEventVM.EventCategory == EventCategory.Market)
                {
                    pdfType = "market_event_authorization";
                }
                else if (licenceEventVM.EventCategory == EventCategory.Catering)
                {
                    pdfType = "catering_event_authorization";
                }
                else if (licenceEventVM.EventCategory == EventCategory.TemporaryUseArea)
                {
                    pdfType = "tua_event_authorization";
                }
                if (pdfType != null)
                {
                    data = await _pdfClient.GetPdf(parameters, pdfType).ConfigureAwait(true);

                    // Save copy of generated licence PDF for auditing/logging purposes
                    try
                    {
                        var hash = await _pdfClient.GetPdfHash(parameters, pdfType);

                        var entityName = "event";
                        var entityId   = eventId;
                        var folderName = await _dynamicsClient.GetFolderName(entityName, entityId).ConfigureAwait(true);

                        var documentType = "EventAuthorization";
                        _fileManagerClient.UploadPdfIfChanged(_logger, entityName, entityId, folderName, documentType, data, hash);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Error uploading PDF");
                    }

                    return(File(data, "application/pdf", "authorization.pdf"));
                }
                return(new NotFoundResult());
            }
            catch (Exception)
            {
                return(new NotFoundResult());
            }
        }