Example #1
0
        public CrmCalendar(WebItemSecurity webItemSecurity,
                           DaoFactory daoFactory,
                           AuthContext authContext,
                           TimeZoneConverter timeZoneConverter,
                           TenantManager tenantManager,
                           TenantUtil tenantUtil
                           ) : base(authContext, timeZoneConverter)
        {
            _tenantUtil      = tenantUtil;
            _tenantManager   = tenantManager;
            _webItemSecurity = webItemSecurity;
            _daoFactory      = daoFactory;

            Context.HtmlBackgroundColor = "";
            Context.HtmlTextColor       = "";
            Context.CanChangeAlertType  = false;
            Context.CanChangeTimeZone   = false;
            Context.GetGroupMethod      = () => CRMCommonResource.ProductName;
            Id             = "crm_calendar";
            EventAlertType = EventAlertType.Never;
            Name           = CRMCommonResource.ProductName;
            Description    = "";
            SharingOptions = new SharingOptions();
            //            SharingOptions.PublicItems.Add(new SharingOptions.PublicItem { Id = userId, IsGroup = false });
        }
Example #2
0
 public PortalController(
     IConfiguration configuration,
     Core.SecurityContext securityContext,
     TenantManager tenantManager,
     SettingsManager settingsManager,
     ApiSystemHelper apiSystemHelper,
     CommonMethods commonMethods,
     HostedSolution hostedSolution,
     CoreSettings coreSettings,
     TenantDomainValidator tenantDomainValidator,
     UserFormatter userFormatter,
     UserManagerWrapper userManagerWrapper,
     CommonConstants commonConstants,
     IOptionsMonitor <ILog> option,
     TimeZonesProvider timeZonesProvider,
     TimeZoneConverter timeZoneConverter)
 {
     Configuration         = configuration;
     SecurityContext       = securityContext;
     TenantManager         = tenantManager;
     SettingsManager       = settingsManager;
     ApiSystemHelper       = apiSystemHelper;
     CommonMethods         = commonMethods;
     HostedSolution        = hostedSolution;
     CoreSettings          = coreSettings;
     TenantDomainValidator = tenantDomainValidator;
     UserFormatter         = userFormatter;
     UserManagerWrapper    = userManagerWrapper;
     CommonConstants       = commonConstants;
     TimeZonesProvider     = timeZonesProvider;
     TimeZoneConverter     = timeZoneConverter;
     Log = option.Get("ASC.ApiSystem");
 }
Example #3
0
        public async Task <IActionResult> GetRegistrationAudit(string id)
        {
            if (!long.TryParse(id, out var essFileNumber))
            {
                return(BadRequest($"'{id}' not a valid ESS file number"));
            }
            var registration = await mediator.Send(new RegistrationSummaryQueryRequest(id));

            if (registration == null)
            {
                return(NotFound());
            }
            var results = await mediator.Send(new RegistrationAuditQueryRequest(essFileNumber));

            Response.Headers.Add("Content-Disposition", $"inline; filename=\"{id}.csv\"");
            return(Content(results
                           .Select(e => new
            {
                e.EssFileNumber,
                e.UserName,
                //The time zone being recorded in the audit is UTC and the OpenShift pods local time is UTC, the below ensures that PST is always returned
                Date = TimeZoneConverter.GetFormatedLocalDateTime(e.DateViewed),      //eg: Tue 11 Jun 2019 11:36:22 PDT
                e.Reason
            })
                           .ToCSV(), "text/csv"));
        }
        private TimeZoneInfo GetTimeZone(string zoneId)
        {
            if (defaultTimeZone == null)
            {
                try
                {
                    var tz = TimeZoneInfo.Local;
                    if (Path.DirectorySeparatorChar == '/')
                    {
                        if (tz.StandardName == "UTC" || tz.StandardName == "UCT")
                        {
                            tz = TimeZoneInfo.Utc;
                        }
                        else
                        {
                            var file = File.Exists("/etc/timezone") ? "/etc/timezone" : "/etc/localtime";
                            var id   = File.ReadAllText(file).Trim();
                            tz = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(z => z.Id == id) ?? tz;
                        }
                    }
                    defaultTimeZone = tz;
                }
                catch (Exception)
                {
                    // ignore
                    defaultTimeZone = TimeZoneInfo.Utc;
                }
            }

            return(string.IsNullOrEmpty(zoneId) ? defaultTimeZone : TimeZoneConverter.GetTimeZone(zoneId));
        }
        public void fromOlsonTz_itReturnsPacificTimeWithUnknownTimeZones()
        {
            var tz = TimeZoneConverter.fromOlsonTz("SomeInvalid/TimeZone");

            Assert.True(tz is TimeZoneInfo);
            Assert.AreEqual("Pacific Standard Time", tz.Id);
        }
Example #6
0
        /// <summary>
        /// Initialize the Group
        /// </summary>
        /// <returns></returns>
        public Group New(Saml.Response samlResponse)
        {
            if (samlResponse != null)
            {
                NameValueCollection att = samlResponse.GetAttributes();

                // General info
                Uid           = att["group_uid"];
                Name          = att["group_name"];
                Email         = att["group_email"];
                CompanyName   = att["company_name"];
                HasCreditCard = att["group_has_credit_card"].Equals("true");

                // Set Free trial in the past on failure
                try
                {
                    FreeTrialEndAt = DateTime.Parse(att["group_end_free_trial"]);
                }
                catch
                {
                    FreeTrialEndAt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                }

                // Geo info
                Currency = att["group_currency"];
                Timezone = TimeZoneConverter.fromOlsonTz(att["group_timezone"]);
                Country  = att["group_country"];
                City     = att["group_city"];
            }

            return(this);
        }
Example #7
0
        public CommonMethods(
            IHttpContextAccessor httpContextAccessor,
            IConfiguration configuration,
            IOptionsMonitor <ILog> option,
            CoreSettings coreSettings,
            CommonLinkUtility commonLinkUtility,
            EmailValidationKeyProvider emailValidationKeyProvider,
            TimeZoneConverter timeZoneConverter, CommonConstants commonConstants,
            IMemoryCache memoryCache,
            IOptionsSnapshot <HostedSolution> hostedSolutionOptions,
            CoreBaseSettings coreBaseSettings,
            TenantManager tenantManager)
        {
            HttpContextAccessor = httpContextAccessor;

            Configuration = configuration;

            Log = option.Get("ASC.ApiSystem");

            CoreSettings = coreSettings;

            CommonLinkUtility = commonLinkUtility;

            EmailValidationKeyProvider = emailValidationKeyProvider;

            TimeZoneConverter = timeZoneConverter;

            CommonConstants = commonConstants;

            MemoryCache      = memoryCache;
            CoreBaseSettings = coreBaseSettings;
            TenantManager    = tenantManager;
            HostedSolution   = hostedSolutionOptions.Get(CommonConstants.BaseDbConnKeyString);
        }
Example #8
0
        public void MapEntityToFormFields()
        {
            if (Match.RealStart.HasValue && Match.RealEnd.HasValue)
            {
                var startDate = TimeZoneConverter.ToZonedTime(Match.RealStart);
                var endDate   = TimeZoneConverter.ToZonedTime(Match.RealEnd);
                MatchDate     = startDate.DateTimeOffset.Date;
                MatchTimeFrom = startDate.DateTimeOffset.TimeOfDay;
                MatchTimeTo   = endDate.DateTimeOffset.TimeOfDay;
                Remarks       = Match.Remarks;
            }
            else
            {
                MatchDate = TimeZoneConverter.ToZonedTime(Match.PlannedStart)?.DateTimeOffset.Date;
            }

            Match.Sets.Sort((int)SetFieldIndex.SequenceNo, ListSortDirection.Ascending);
            foreach (var set in Match.Sets)
            {
                Sets.Add(new PointResultNullable(set.HomeBallPoints, set.GuestBallPoints));
            }

            while (Sets.Count < _maxNumberOfSets)
            {
                Sets.Add(new PointResultNullable(null, null));
            }

            Id = Match.Id;

            Remarks = Match.Remarks;
        }
        public static BaseCalendar ConvertCalendar(DDay.iCal.IICalendar calandarObj)
        {
            if (calandarObj == null)
            {
                return(null);
            }

            var result = new BusinessObjects.Calendar();

            result.Name = string.IsNullOrEmpty(calandarObj.Name)
                           ? calandarObj.Properties.ContainsKey("X-WR-CALNAME")
                                 ? calandarObj.Properties["X-WR-CALNAME"].Value.ToString()
                                 : string.Empty
                           : calandarObj.Name;

            result.Description = calandarObj.Properties.ContainsKey("X-WR-CALDESC")
                                     ? calandarObj.Properties["X-WR-CALDESC"].Value.ToString()
                                     : string.Empty;

            var tzids = calandarObj.TimeZones.Select(x => x.TZID).Where(x => !string.IsNullOrEmpty(x)).ToList();

            result.TimeZone = tzids.Any()
                                  ? TimeZoneConverter.GetTimeZone(tzids.First())
                                  : (calandarObj.Properties.ContainsKey("X-WR-TIMEZONE")
                                         ? TimeZoneConverter.GetTimeZone(
                                         calandarObj.Properties["X-WR-TIMEZONE"].Value.ToString())
                                         : CoreContext.TenantManager.GetCurrentTenant().TimeZone);

            return(result);
        }
Example #10
0
 public iCalendarCache(
     AuthContext authContext,
     TimeZoneConverter timeZoneConverter,
     TenantManager tenantManager
     ) : this(authContext, timeZoneConverter, tenantManager, iCalendarCacheParams.Default)
 {
 }
Example #11
0
 public BaseCalendar(AuthContext authContext, TimeZoneConverter timeZoneConverter)
 {
     this.Context        = new CalendarContext();
     this.SharingOptions = new SharingOptions();
     AuthContext         = authContext;
     TimeZoneConverter   = timeZoneConverter;
 }
Example #12
0
        public void MapFormFieldsToEntity()
        {
            // Save match date/time to entity
            if (MatchDate.HasValue && MatchTimeFrom.HasValue && MatchTimeTo.HasValue)
            {
                var period = new DateTimePeriod(MatchDate?.Add(MatchTimeFrom.Value), MatchDate?.Add(MatchTimeTo.Value));
                Match.SetRealStart(TimeZoneConverter.ToUtc(period.Start), period.Duration());
            }
            else
            {
                Match.SetRealStart(null, TimeSpan.Zero);
            }

            // Add sets to entity
            Match.Sets.Clear(true);
            for (var i = 0; i < Sets.Count; i++)
            {
                // sets where home and guest ball points are NULL, will be ignored
                if (Sets[i].Home.HasValue || Sets[i].Guest.HasValue)
                {
                    // home or guest NULL values are invalidated with -1
                    Match.Sets.Add(new SetEntity {
                        MatchId = Match.Id, SequenceNo = i + 1, HomeBallPoints = Sets[i].Home ?? -1, GuestBallPoints = Sets[i].Guest ?? -1
                    });
                }
            }

            // point calculation must run before validation because of tie-break handling
            Match.Sets.CalculateSetPoints(Round.SetRule, Round.MatchRule);
            Match.Remarks = Remarks;
            Match.ChangeSerial++;
            Match.IsComplete = true;
        }
Example #13
0
        public static TimeZoneInfo ConvertTimeZoneFormat(string timezone)
        {
            string convertedTimeZoneStr;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                convertedTimeZoneStr = TimeZoneConverter.IanaToWindows(timezone);
            }
            else
            {
                convertedTimeZoneStr = TimeZoneConverter.WindowsToIana(timezone);
            }

            TimeZoneInfo convertedTimeZone;

            try
            {
                convertedTimeZone = TimeZoneInfo.FindSystemTimeZoneById(convertedTimeZoneStr);
            }
            catch
            {
                throw new Exception($"{timezone} is an illegal timezone");
            }

            return(convertedTimeZone);
        }
Example #14
0
        public CalendarWrapper UpdateCalendarView(string calendarId, string name, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents)
        {
            TimeZoneInfo timeZoneInfo = TimeZoneConverter.GetTimeZone(timeZone);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);
            }

            var settings = new UserViewSettings()
            {
                BackgroundColor = backgroundColor,
                CalendarId      = calendarId,
                IsHideEvents    = hideEvents,
                TextColor       = textColor,
                EventAlertType  = alertType,
                IsAccepted      = true,
                UserId          = SecurityContext.CurrentAccount.ID,
                Name            = name,
                TimeZone        = timeZoneInfo
            };

            _dataProvider.UpdateCalendarUserView(settings);
            return(GetCalendarById(calendarId));
        }
Example #15
0
        public void CanConvertDateToPST()
        {
            var utc9hourAhead = new DateTime(2019, 5, 30, 1, 0, 0);
            var result        = TimeZoneConverter.GetLocalDate(utc9hourAhead);

            Assert.Equal("May-29-2019", result);
        }
Example #16
0
        public void CanGetLocalTime12h24h()
        {
            var utcTime = new DateTime(2019, 6, 1, 0, 30, 0);

            Assert.Equal("5:30 PM", TimeZoneConverter.GetLocalTime(utcTime));
            Assert.Equal("17:30", TimeZoneConverter.GetLocalTime24h(utcTime));
        }
Example #17
0
        public string ToiCalFormat()
        {
            var sb = new StringBuilder();

            sb.AppendLine("BEGIN:VCALENDAR");
            sb.AppendLine("PRODID:TeamLab Calendar");
            sb.AppendLine("VERSION:2.0");

            sb.AppendLine("METHOD:PUBLISH");
            sb.AppendLine("CALSCALE:GREGORIAN");
            sb.AppendLine(String.Format("X-WR-CALNAME:{0}", Name));
            sb.AppendLine(String.Format("X-WR-TIMEZONE:{0}", TimeZoneConverter.WindowsTzId2OlsonTzId(TimeZone.Id)));
            //tz
            sb.AppendLine("BEGIN:VTIMEZONE");
            sb.AppendLine(String.Format("TZID:{0}", TimeZoneConverter.WindowsTzId2OlsonTzId(TimeZone.Id)));
            sb.AppendLine("END:VTIMEZONE");

            //events
            foreach (var e in LoadEvents(SecurityContext.CurrentAccount.ID, DateTime.MinValue, DateTime.MaxValue))
            {
                if (e is BaseEvent && e.GetType().GetCustomAttributes(typeof(AllDayLongUTCAttribute), true).Length == 0)
                {
                    (e as BaseEvent).TimeZone = TimeZone;
                }

                sb.AppendLine(e.ToiCalFormat());
            }

            sb.Append("END:VCALENDAR");

            return(sb.ToString());
        }
Example #18
0
        public void CanGetLocalTime12h24h()
        {
            var dt = new DateTime(2019, 6, 1, 17, 30, 0);

            Assert.Equal(TimeZoneConverter.GetLocalTime(dt), "5:30 PM");
            Assert.Equal(TimeZoneConverter.GetLocalTime24h(dt), "17:30");
        }
Example #19
0
 public FirstTimeTenantSettings(
     IOptionsMonitor <ILog> options,
     IConfiguration configuration,
     TenantManager tenantManager,
     CoreSettings coreSettings,
     TenantExtra tenantExtra,
     SettingsManager settingsManager,
     UserManager userManager,
     SetupInfo setupInfo,
     SecurityContext securityContext,
     PaymentManager paymentManager,
     MessageService messageService,
     LicenseReader licenseReader,
     StudioNotifyService studioNotifyService,
     TimeZoneConverter timeZoneConverter,
     CoreBaseSettings coreBaseSettings)
 {
     Log                 = options.CurrentValue;
     Configuration       = configuration;
     TenantManager       = tenantManager;
     CoreSettings        = coreSettings;
     TenantExtra         = tenantExtra;
     SettingsManager     = settingsManager;
     UserManager         = userManager;
     SetupInfo           = setupInfo;
     SecurityContext     = securityContext;
     PaymentManager      = paymentManager;
     MessageService      = messageService;
     LicenseReader       = licenseReader;
     StudioNotifyService = studioNotifyService;
     TimeZoneConverter   = timeZoneConverter;
     CoreBaseSettings    = coreBaseSettings;
 }
        public void fromOlsonTz_itReturnsANativeTimeZone()
        {
            var tz = TimeZoneConverter.fromOlsonTz("Europe/Rome");

            Assert.True(tz is TimeZoneInfo);
            Assert.AreEqual("W. Europe Standard Time", tz.Id);
        }
 public RegistrationController(
     CommonMethods commonMethods,
     CommonConstants commonConstants,
     IOptionsSnapshot <HostedSolution> hostedSolution,
     TimeZonesProvider timeZonesProvider,
     TimeZoneConverter timeZoneConverter,
     ApiSystemHelper apiSystemHelper,
     SecurityContext securityContext,
     TenantManager tenantManager,
     SettingsManager settingsManager,
     CoreSettings coreSettings,
     TenantDomainValidator tenantDomainValidator,
     UserFormatter userFormatter,
     UserManagerWrapper userManagerWrapper,
     IConfiguration configuration,
     IOptionsMonitor <ILog> option,
     PasswordHasher passwordHasher)
 {
     CommonMethods         = commonMethods;
     CommonConstants       = commonConstants;
     HostedSolution        = hostedSolution.Value;
     TimeZonesProvider     = timeZonesProvider;
     TimeZoneConverter     = timeZoneConverter;
     ApiSystemHelper       = apiSystemHelper;
     SecurityContext       = securityContext;
     TenantManager         = tenantManager;
     SettingsManager       = settingsManager;
     CoreSettings          = coreSettings;
     TenantDomainValidator = tenantDomainValidator;
     UserFormatter         = userFormatter;
     UserManagerWrapper    = userManagerWrapper;
     Configuration         = configuration;
     PasswordHasher        = passwordHasher;
     Log = option.Get("ASC.ApiSystem");
 }
Example #22
0
 private TimeZoneInfo GetTimeZone(string zoneId)
 {
     if (!string.IsNullOrEmpty(zoneId))
     {
         return(TimeZoneConverter.GetTimeZone(zoneId));
     }
     return(TimeZoneInfo.Utc);
 }
Example #23
0
        public void CanConvertDateToPST()
        {
            var utc9hourAhead = new DateTime(2019, 5, 30, 1, 0, 0);
            var result        = TimeZoneConverter.GetLocalDate(utc9hourAhead);
            var expected      = new DateTime(2019, 5, 29, 16, 0, 0).ToString("MMM-dd-yyyy");

            Assert.Equal(expected, result);
        }
Example #24
0
 public ConfigureTenantUtil(
     IOptionsSnapshot <TenantManager> tenantManager,
     TimeZoneConverter timeZoneConverter
     )
 {
     TenantManager     = tenantManager;
     TimeZoneConverter = timeZoneConverter;
 }
Example #25
0
        public void WindowsToIanaTest()
        {
            var    input  = "China Standard Time";
            string result = TimeZoneConverter.WindowsToIana(input);
            var    expect = "Asia/Shanghai";

            Assert.AreEqual(result, expect);
        }
Example #26
0
        public void IanaToWindowsTest()
        {
            string input  = "Asia/Shanghai";
            string result = TimeZoneConverter.IanaToWindows(input);
            string expect = "China Standard Time";

            Assert.AreEqual(result, expect);
        }
Example #27
0
 public static ApiDateTime FromDate(TenantManager tenantManager, TimeZoneConverter timeZoneConverter, DateTime?d)
 {
     if (d.HasValue)
     {
         var date = new ApiDateTime(tenantManager, timeZoneConverter, d);
         return(date);
     }
     return(null);
 }
Example #28
0
 public iCalendarEmitter(
     AuthContext authContext,
     TimeZoneConverter timeZoneConverter,
     TenantManager tenantManager)
 {
     AuthContext       = authContext;
     TimeZoneConverter = timeZoneConverter;
     TenantManager     = tenantManager;
 }
Example #29
0
        private TimeZoneInfo GetTimeZone(string zoneId)
        {
            if (defaultTimeZone == null)
            {
                try
                {
                    var tz = TimeZoneInfo.Local;
                    if (Path.DirectorySeparatorChar == '/')
                    {
                        if (tz.StandardName == "UTC" || tz.StandardName == "UCT")
                        {
                            tz = TimeZoneInfo.Utc;
                        }
                        else
                        {
                            var id = string.Empty;
                            if (File.Exists("/etc/timezone"))
                            {
                                id = File.ReadAllText("/etc/timezone").Trim();
                            }

                            if (string.IsNullOrEmpty(id))
                            {
                                var psi = new ProcessStartInfo
                                {
                                    FileName  = "/bin/bash",
                                    Arguments = "date +%Z",
                                    RedirectStandardOutput = true,
                                    UseShellExecute        = false,
                                };
                                using (var p = Process.Start(psi))
                                {
                                    if (p.WaitForExit(1000))
                                    {
                                        id = p.StandardOutput.ReadToEnd();
                                    }
                                    p.Close();
                                }
                            }
                            if (!string.IsNullOrEmpty(id))
                            {
                                tz = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(z => z.Id == id) ?? tz;
                            }
                        }
                    }
                    defaultTimeZone = tz;
                }
                catch (Exception)
                {
                    // ignore
                    defaultTimeZone = TimeZoneInfo.Utc;
                }
            }

            return(string.IsNullOrEmpty(zoneId) ? defaultTimeZone : TimeZoneConverter.GetTimeZone(zoneId));
        }
Example #30
0
 public Event(AuthContext context,
              TimeZoneConverter timeZoneConverter,
              iCalendar iCalendar,
              DataProvider dataProvider)
 {
     AuthContext       = context;
     ICalendar         = iCalendar;
     TimeZoneConverter = timeZoneConverter;
     DataProvider      = dataProvider;
 }