示例#1
0
        private bool GetHistoricalPose(out Vector3 cameraPosition, out Quaternion cameraRotation)
        {
#if !UNITY_EDITOR && UNITY_WSA
            SpatialCoordinateSystem unityCoordinateSystem = Marshal.GetObjectForIUnknown(WorldManager.GetNativeISpatialCoordinateSystemPtr()) as SpatialCoordinateSystem;
            if (unityCoordinateSystem == null)
            {
                Debug.LogError("Failed to get the native SpatialCoordinateSystem");
                cameraPosition = default(Vector3);
                cameraRotation = default(Quaternion);
                return(false);
            }

            if (timeConversionCalendar == null)
            {
                timeConversionCalendar = new Calendar();
            }

            timeConversionCalendar.SetToNow();

            PerceptionTimestamp perceptionTimestamp = PerceptionTimestampHelper.FromHistoricalTargetTime(timeConversionCalendar.GetDateTime());

            if (perceptionTimestamp != null)
            {
                SpatialLocator locator = SpatialLocator.GetDefault();
                if (locator != null)
                {
                    SpatialLocation headPose = locator.TryLocateAtTimestamp(perceptionTimestamp, unityCoordinateSystem);
                    if (headPose != null)
                    {
                        var systemOrientation = headPose.Orientation;
                        var systemPostion     = headPose.Position;

                        // Convert the orientation and position from Windows to Unity coordinate spaces
                        cameraRotation.x = -systemOrientation.X;
                        cameraRotation.y = -systemOrientation.Y;
                        cameraRotation.z = systemOrientation.Z;
                        cameraRotation.w = systemOrientation.W;

                        cameraPosition.x = systemPostion.X;
                        cameraPosition.y = systemPostion.Y;
                        cameraPosition.z = -systemPostion.Z;
                        return(true);
                    }
                }
            }

            cameraPosition = default(Vector3);
            cameraRotation = default(Quaternion);
            return(false);
#else
            cameraPosition = Camera.main.transform.position;
            cameraRotation = Camera.main.transform.rotation;
            return(true);
#endif
        }
示例#2
0
        /// <summary>
        /// Gets user friendly text representing the time difference between the current time and the specified time
        /// </summary>
        /// <param name="dt"></param>
        /// <returns>User friendly strings representing the text and period and an icon glyph to display</returns>
        public static (string text, string range, string glyph, int index) GetFriendlyTimeSpan(this DateTimeOffset dt)
        {
            Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
            var t     = DateTimeOffset.Now;
            var t2    = dt.ToLocalTime();
            var today = DateTime.Today;

            var diff = t - dt;
            var y    = t.AddDays(-1);
            var w    = t.AddDays(diff.Days * -1);

            if (t.Month == t2.Month && t.Day == t2.Day && t.Year == t2.Year)
            {
                return("Today".GetLocalized(), today.ToUserDateString(), "\ue184", 0);
            }

            if (y.Month == t2.Month && y.Day == t2.Day && y.Year == t2.Year)
            {
                return("ItemTimeText_Yesterday".GetLocalized(), today.Subtract(TimeSpan.FromDays(1)).ToUserDateString(), "\ue161", 1);
            }

            if (diff.Days < 7 && w.GetWeekOfYear() == t2.GetWeekOfYear() && w.Year == t2.Year)
            {
                return("ItemTimeText_ThisWeek".GetLocalized(), t.Subtract(TimeSpan.FromDays((int)t.DayOfWeek)).ToUserDateString(), "\uE162", 2);
            }

            if (diff.Days < 14 && w.GetWeekOfYear() == t2.GetWeekOfYear() && w.Year == t2.Year)
            {
                return("ItemTimeText_LastWeek".GetLocalized(), t.Subtract(TimeSpan.FromDays((int)t.DayOfWeek + 7)).Date.ToShortDateString(), "\uE162", 3);
            }

            if (t.Year == t2.Year && t.Month == t2.Month)
            {
                return("ItemTimeText_ThisMonth".GetLocalized(), t.Subtract(TimeSpan.FromDays(t.Day - 1)).ToUserDateString(), "\ue163", 4);
            }

            if (t.AddMonths(-1).Year == t2.Year && t.AddMonths(-1).Month == t2.Month)
            {
                return("ItemTimeText_LastMonth".GetLocalized(), t.Subtract(TimeSpan.FromDays(t.Day - 1 + calendar.GetDaysInMonth(t.AddMonths(-1).Year, t.AddMonths(-1).Month))).ToUserDateString(), "\ue163", 5);
            }

            if (t.Year == t2.Year)
            {
                return("ItemTimeText_ThisYear".GetLocalized(), t.Subtract(TimeSpan.FromDays(t.DayOfYear - 1)).ToUserDateString(), "\ue163", 5);
            }

            return("ItemTimeText_Older".GetLocalized(), string.Format("ItemTimeText_Before".GetLocalized(), today.Subtract(TimeSpan.FromDays(today.DayOfYear - 1)).ToUserDateString()), "\uEC92", 6);
        }
示例#3
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var date    = (DateTime)value;
            var color   = string.Empty;
            var dateNow = new Windows.Globalization.Calendar();

            if (date < dateNow.GetDateTime())
            {
                color = "Red";
            }
            else
            {
                color = "White";
            }
            return(color);
        }
        void UpdateTileExpiring_Click(object sender, RoutedEventArgs e)
        {
            int seconds;

            if (!Int32.TryParse(Time.Text, out seconds))
            {
                seconds = 10;
            }

            Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
            cal.SetToNow();
            cal.AddSeconds(seconds);

            var            longTime         = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime");
            DateTimeOffset expiryTime       = cal.GetDateTime();
            string         expiryTimeString = longTime.Format(expiryTime);

            // Create a notification for the Square310x310 tile using one of the available templates for the size.
            ITileSquare310x310Text09 tileSquare310x310Content = TileContentFactory.CreateTileSquare310x310Text09();

            tileSquare310x310Content.TextHeadingWrap.Text = "This notification will expire at " + expiryTimeString;

            // Create a notification for the Wide310x150 tile using one of the available templates for the size.
            ITileWide310x150Text04 wide310x150TileContent = TileContentFactory.CreateTileWide310x150Text04();

            wide310x150TileContent.TextBodyWrap.Text = "This notification will expire at " + expiryTimeString;

            // Create a notification for the Square150x150 tile using one of the available templates for the size.
            ITileSquare150x150Text04 square150x150TileContent = TileContentFactory.CreateTileSquare150x150Text04();

            square150x150TileContent.TextBodyWrap.Text = "This notification will expire at " + expiryTimeString;

            // Attach the Square150x150 template to the Wide310x150 template.
            wide310x150TileContent.Square150x150Content = square150x150TileContent;

            // Attach the Wide310x150 template to the Square310x310 template.
            tileSquare310x310Content.Wide310x150Content = wide310x150TileContent;

            TileNotification tileNotification = tileSquare310x310Content.CreateNotification();

            // Set the expiration time and update the tile.
            tileNotification.ExpirationTime = expiryTime;
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

            rootPage.NotifyUser("Tile notification sent. It will expire at " + expiryTime, NotifyType.StatusMessage);
        }
示例#5
0
        protected internal override void Open()
        {
            var date = Date;

            // If we're setting the date to the null sentinel value,
            // we'll instead set it to the current date for the purposes
            // of where to place the user's position in the looping selectors.
            if (date.Ticks == DatePicker.DEFAULT_DATE_TICKS)
            {
                var temp     = new Windows.Globalization.Calendar();
                var calendar = new Windows.Globalization.Calendar(
                    temp.Languages,
                    CalendarIdentifier,
                    temp.GetClock());
                calendar.SetToNow();
                date = calendar.GetDateTime();
            }

            // Note: Month needs to be -1 since on Android months go from 0-11
            // http://developer.android.com/reference/android/app/DatePickerDialog.OnDateSetListener.html#onDateSet(android.widget.DatePicker, int, int, int)
            _dialog = new DatePickerDialog(
                ContextHelper.Current,
                OnDateSet,
                date.Year,
                date.Month - 1,
                date.Day
                );

            //Removes title that is unnecessary as it is a duplicate -> http://stackoverflow.com/questions/33486643/remove-title-from-datepickerdialog
            _dialog.SetTitle("");

            var minYearCalendar = Calendar.Instance;

            minYearCalendar.Set(MinYear.Year, MinYear.Month - 1, MinYear.Day, MinYear.Hour, MinYear.Minute, MinYear.Second);
            _dialog.DatePicker.MinDate = minYearCalendar.TimeInMillis;

            var maxYearCalendar = Calendar.Instance;

            maxYearCalendar.Set(MaxYear.Year, MaxYear.Month - 1, MaxYear.Day, MaxYear.Hour, MaxYear.Minute, MaxYear.Second);
            _dialog.DatePicker.MaxDate = maxYearCalendar.TimeInMillis;

            _dialog.DismissEvent += OnDismiss;
            _dialog.Show();
        }
示例#6
0
        private void HandleCalendarChanged(Windows.Globalization.Calendar oldCalendar, Windows.Globalization.Calendar newCalendar)
        {
            DateTime oldMaxValue = DateTime.MaxValue;
            DateTime oldMinValue = DateTime.MinValue;

            if (oldCalendar != null)
            {
                oldMaxValue = this.maxCalendar.GetUtcDateTime();
                oldMinValue = this.minCalendar.GetUtcDateTime();
            }

            if (newCalendar == null)
            {
                throw new ArgumentException();
            }

            newCalendar.ChangeTimeZone("UTC");
            this.UpdateCalendars(newCalendar, oldMaxValue, oldMinValue);
        }
        void UpdateTileExpiring_Click(object sender, RoutedEventArgs e)
        {
            int seconds;
            if (!Int32.TryParse(Time.Text, out seconds))
            {
                seconds = 10;
            }

            Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
            cal.SetToNow();
            cal.AddSeconds(seconds);

            var longTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime");
            DateTimeOffset expiryTime = cal.GetDateTime();
            string expiryTimeString = longTime.Format(expiryTime);

            // Create a notification for the Square310x310 tile using one of the available templates for the size.
            ITileSquare310x310Text09 tileSquare310x310Content = TileContentFactory.CreateTileSquare310x310Text09();
            tileSquare310x310Content.TextHeadingWrap.Text = "This notification will expire at " + expiryTimeString;

            // Create a notification for the Wide310x150 tile using one of the available templates for the size.
            ITileWide310x150Text04 wide310x150TileContent = TileContentFactory.CreateTileWide310x150Text04();
            wide310x150TileContent.TextBodyWrap.Text = "This notification will expire at " + expiryTimeString;

            // Create a notification for the Square150x150 tile using one of the available templates for the size.
            ITileSquare150x150Text04 square150x150TileContent = TileContentFactory.CreateTileSquare150x150Text04();
            square150x150TileContent.TextBodyWrap.Text = "This notification will expire at " + expiryTimeString;

            // Attach the Square150x150 template to the Wide310x150 template.
            wide310x150TileContent.Square150x150Content = square150x150TileContent;

            // Attach the Wide310x150 template to the Square310x310 template.
            tileSquare310x310Content.Wide310x150Content = wide310x150TileContent;

            TileNotification tileNotification = tileSquare310x310Content.CreateNotification();

            // Set the expiration time and update the tile.
            tileNotification.ExpirationTime = expiryTime;
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

            rootPage.NotifyUser("Tile notification sent. It will expire at " + expiryTime, NotifyType.StatusMessage);
        }
示例#8
0
        private bool FindValidMinute(Windows.Globalization.Calendar calendar, int minuteStep, bool isMinDate, bool isMaxDate)
        {
            var minMinute = isMinDate && calendar.Period == this.minCalendarWithStep.Period && calendar.Hour == this.minCalendarWithStep.Hour ? this.minCalendarWithStep.Minute : calendar.FirstMinuteInThisHour;
            var maxMinute = isMaxDate && calendar.Period == this.maxCalendarWithStep.Period && calendar.Hour == this.maxCalendarWithStep.Hour ? this.maxCalendarWithStep.Minute : calendar.LastMinuteInThisHour;

            var minuteRemainder = this.GetStepRemainderForComponent(calendar.Minute, calendar.FirstMinuteInThisHour, StepBehavior.StartFromBase, minuteStep);

            var currentMinute = calendar.Minute - minuteRemainder;

            if (currentMinute < minMinute)
            {
                currentMinute += minuteStep;
                if (currentMinute > maxMinute)
                {
                    return(false);
                }
            }

            calendar.Minute = currentMinute;
            return(true);
        }
示例#9
0
        private bool FindValidDay(Windows.Globalization.Calendar calendar, int dayStep)
        {
            var minDay = calendar.Year == this.minCalendarWithStep.Year && calendar.Month == this.minCalendarWithStep.Month ? this.minCalendarWithStep.Day : calendar.FirstDayInThisMonth;
            var maxDay = calendar.Year == this.maxCalendarWithStep.Year && calendar.Month == this.maxCalendarWithStep.Month ? this.maxCalendarWithStep.Day : calendar.LastDayInThisMonth;

            var dayRemainder = this.GetStepRemainderForComponent(calendar.Day, calendar.FirstDayInThisMonth, this.DayStepBehavior, dayStep);

            var currentDay = calendar.Day - dayRemainder;

            if (currentDay < minDay)
            {
                currentDay += dayStep;
                if (currentDay > maxDay)
                {
                    return(false);
                }
            }

            calendar.Day = currentDay;
            return(true);
        }
示例#10
0
        private Geofence GenerateGeofence(string key, double latitude, double longitude, double altitude, double radius)
        {
            var calendar = new Windows.Globalization.Calendar();

            calendar.SetToNow();

            BasicGeoposition position;

            position.Latitude  = latitude;
            position.Longitude = longitude;
            position.Altitude  = altitude;

            Geocircle geocircle = new Geocircle(position, radius);

            // want to listen for enter geofence, exit geofence and remove geofence events
            // you can select a subset of these event states
            MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed;

            var dwellTime = TimeSpan.FromSeconds(5);

            return(new Geofence(key, geocircle, mask, false, dwellTime));
        }
示例#11
0
        private void ApplyDateStepToMinCalendar()
        {
            var oldMinCalendar = this.minCalendarWithStep.Clone();

            var yearStep  = this.GetStepForComponentType(DateTimeComponentType.Year);
            var monthStep = this.GetStepForComponentType(DateTimeComponentType.Month);
            var dayStep   = this.GetStepForComponentType(DateTimeComponentType.Day);

            var maxYear = this.maxCalendarWithStep.Year;

            var currentYear   = this.minCalendarWithStep.Year;
            var yearRemainder = this.GetStepRemainderForComponent(this.minCalendarWithStep.Year, this.minCalendarWithStep.FirstYearInThisEra, this.YearStepBehavior, yearStep);

            currentYear += (yearStep - yearRemainder) % yearStep;

            while (currentYear <= maxYear)
            {
                var yearsUpdate = currentYear - this.minCalendarWithStep.Year;
                this.minCalendarWithStep.AddYears(yearsUpdate);

                if (yearsUpdate > 0)
                {
                    // go to next year => reset month & day to min
                    this.minCalendarWithStep.Month = this.minCalendarWithStep.FirstMonthInThisYear;
                    this.minCalendarWithStep.Day   = this.minCalendarWithStep.FirstDayInThisMonth;
                }

                if (this.FindValidMinMonth(monthStep, dayStep))
                {
                    return;
                }

                currentYear++;
            }

            // TO DO: what to do here?
            this.minCalendarWithStep = oldMinCalendar.Clone();
            throw new InvalidOperationException();
        }
示例#12
0
        private void ApplyTimeStepToMaxCalendar()
        {
            var oldMaxCalendar = this.minCalendarWithStep.Clone();

            var areMinMaxDatesEqual = this.minCalendarWithStep.Year == this.maxCalendarWithStep.Year &&
                                      this.minCalendarWithStep.Month == this.maxCalendarWithStep.Month &&
                                      this.minCalendarWithStep.Day == this.maxCalendarWithStep.Day;

            var hourStep   = this.GetStepForComponentType(DateTimeComponentType.Hour);
            var minuteStep = this.GetStepForComponentType(DateTimeComponentType.Minute);

            var minPeriod     = areMinMaxDatesEqual ? this.minCalendarWithStep.Period : this.maxCalendarWithStep.FirstPeriodInThisDay;
            var currentPeriod = this.maxCalendarWithStep.Period;

            while (currentPeriod >= minPeriod)
            {
                var periodUpdate = currentPeriod - this.maxCalendarWithStep.Period;
                this.maxCalendarWithStep.AddPeriods(periodUpdate);

                if (periodUpdate < 0)
                {
                    // go to previous period => reset hours & minutes to max
                    this.maxCalendarWithStep.Hour   = this.maxCalendarWithStep.LastHourInThisPeriod;
                    this.maxCalendarWithStep.Minute = this.maxCalendarWithStep.LastMinuteInThisHour;
                }

                if (this.FindValidMaxHour(hourStep, minuteStep, areMinMaxDatesEqual))
                {
                    return;
                }

                currentPeriod--;
            }

            // TO DO: what to do here?
            this.maxCalendarWithStep = oldMaxCalendar.Clone();
            throw new InvalidOperationException();
        }
示例#13
0
 protected override DateTime? GetRelativeTo(DateTime relativeDate, int delta)
 {
     Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
     int daysInMonth = cal.NumberOfDaysInThisMonth;
     int nextDay = ((daysInMonth + relativeDate.Day - 1 + delta) % daysInMonth) + 1;
     return new DateTime(relativeDate.Year, relativeDate.Month, nextDay, relativeDate.Hour, relativeDate.Minute, relativeDate.Second);
 }
        private async void ButtonSendNotification_Click(object sender, RoutedEventArgs e)
        {
            base.IsEnabled = false;

            try
            {
                if (_tileId == null)
                {
                    await new MessageDialog("No secondary tile was pinned. In the previous step, you had to pin the tile.", "Error").ShowAsync();
                    return;
                }

                SecondaryTile tile = (await SecondaryTile.FindAllAsync()).FirstOrDefault(i => i.TileId.Equals(_tileId));
                if (tile == null)
                {
                    await new MessageDialog("The secondary tile that was previously pinned could not be found. Has it been removed from Start?", "Error").ShowAsync();
                    return;
                }

                // Decide expiration time
                Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
                cal.SetToNow();
                cal.AddSeconds(20);

                // Get expiration time and date
                var longTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime");
                DateTimeOffset expiryTime = cal.GetDateTime();
                string expiryTimeString = longTime.Format(expiryTime);

                // Create the custom tile that will expire
                string tileXmlString = 
                "<tile>"
                + "<visual>"
                + "<binding template='TileMedium'>"
                + "<text hint-wrap='true'>This notification will expire at " + expiryTimeString + "</text>"
                + "</binding>"
                + "<binding template='TileWide'>"
                + "<text hint-wrap='true'>This notification will expire at " + expiryTimeString + "</text>"
                + "</binding>"
                + "<binding template='TileLarge'>"
                + "<text hint-wrap='true'>This notification will expire at " + expiryTimeString + "</text>"
                + "</binding>"
                + "</visual>"
                + "</tile>";

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(tileXmlString);

                // Create the notification
                TileNotification notifyTile = new TileNotification(xmlDoc);

                // Set expiration time for the notification
                notifyTile.ExpirationTime = expiryTime;

                // And send the notification to the tile
                TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notifyTile);
            }

            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error updating tile").ShowAsync();
            }

            finally
            {
                base.IsEnabled = true;
            }
        }
示例#15
0
        public Scenario4()
        {
            this.InitializeComponent();

            try
            {
                formatterShortDateLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{month.integer}/{day.integer}/{year.full} {hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);
                formatterLongTime          = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);
                calendar         = new Windows.Globalization.Calendar();
                decimalFormatter = new Windows.Globalization.NumberFormatting.DecimalFormatter();

                geofenceCollection = new GeofenceItemCollection();
                eventCollection    = new EventDescriptorCollection();

                // Get a geolocator object
                geolocator = new Geolocator();

                geofences = GeofenceMonitor.Current.Geofences;

                // using data binding to the root page collection of GeofenceItems
                RegisteredGeofenceListBox.DataContext = geofenceCollection;

                // using data binding to the root page collection of GeofenceItems associated with events
                GeofenceEventsListBox.DataContext = eventCollection;

                FillRegisteredGeofenceListBoxWithExistingGeofences();
                FillEventListBoxWithExistingEvents();

                accessInfo = DeviceAccessInformation.CreateFromDeviceClass(DeviceClass.Location);
                accessInfo.AccessChanged += OnAccessChanged;

                coreWindow = CoreWindow.GetForCurrentThread(); // this needs to be set before InitializeComponent sets up event registration for app visibility
                coreWindow.VisibilityChanged += OnVisibilityChanged;

                // register for state change events
                GeofenceMonitor.Current.GeofenceStateChanged += OnGeofenceStateChanged;
                GeofenceMonitor.Current.StatusChanged        += OnGeofenceStatusChanged;
            }
            catch (UnauthorizedAccessException)
            {
                if (DeviceAccessStatus.DeniedByUser == accessInfo.CurrentStatus)
                {
                    rootPage.NotifyUser("Location has been disabled by the user. Enable access through the settings charm.", NotifyType.StatusMessage);
                }
                else if (DeviceAccessStatus.DeniedBySystem == accessInfo.CurrentStatus)
                {
                    rootPage.NotifyUser("Location has been disabled by the system. The administrator of the device must enable location access through the location control panel.", NotifyType.StatusMessage);
                }
                else if (DeviceAccessStatus.Unspecified == accessInfo.CurrentStatus)
                {
                    rootPage.NotifyUser("Location has been disabled by unspecified source. The administrator of the device may need to enable location access through the location control panel, then enable access through the settings charm.", NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                // GeofenceMonitor failed in adding a geofence
                // exceptions could be from out of memory, lat/long out of range,
                // too long a name, not a unique name, specifying an activation
                // time + duration that is still in the past

                // If ex.HResult is RPC_E_DISCONNECTED (0x80010108):
                // The Location Framework service event state is out of synchronization
                // with the Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.
                // To recover remove all event handlers on the GeofenceMonitor or restart the application.
                // Once all event handlers are removed you may add back any event handlers and retry the operation.

                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        private async void ButtonSendNotification_Click(object sender, RoutedEventArgs e)
        {
            base.IsEnabled = false;

            try
            {
                if (_tileId == null)
                {
                    await new MessageDialog("No secondary tile was pinned. In the previous step, you had to pin the tile.", "Error").ShowAsync();
                    return;
                }

                SecondaryTile tile = (await SecondaryTile.FindAllAsync()).FirstOrDefault(i => i.TileId.Equals(_tileId));
                if (tile == null)
                {
                    await new MessageDialog("The secondary tile that was previously pinned could not be found. Has it been removed from Start?", "Error").ShowAsync();
                    return;
                }

                // Decide expiration time
                Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
                cal.SetToNow();
                cal.AddSeconds(20);

                // Get expiration time and date
                var            longTime         = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime");
                DateTimeOffset expiryTime       = cal.GetDateTime();
                string         expiryTimeString = longTime.Format(expiryTime);

                // Create the custom tile that will expire
                string tileXmlString =
                    "<tile>"
                    + "<visual>"
                    + "<binding template='TileMedium'>"
                    + "<text hint-wrap='true'>This notification will expire at " + expiryTimeString + "</text>"
                    + "</binding>"
                    + "<binding template='TileWide'>"
                    + "<text hint-wrap='true'>This notification will expire at " + expiryTimeString + "</text>"
                    + "</binding>"
                    + "<binding template='TileLarge'>"
                    + "<text hint-wrap='true'>This notification will expire at " + expiryTimeString + "</text>"
                    + "</binding>"
                    + "</visual>"
                    + "</tile>";

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(tileXmlString);

                // Create the notification
                TileNotification notifyTile = new TileNotification(xmlDoc);

                // Set expiration time for the notification
                notifyTile.ExpirationTime = expiryTime;

                // And send the notification to the tile
                TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notifyTile);
            }

            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error updating tile").ShowAsync();
            }

            finally
            {
                base.IsEnabled = true;
            }
        }
示例#17
0
        public async void fillCalendar()
        {
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);

            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();

            List<NameValueItem2> dList = new List<NameValueItem2>();
            try
            {
                if ((!SelectedMonth.Equals(calendar.MonthAsSoloString()) || !SelectedYear.Equals(calendar.Year.ToString())) && flip == 0)
                    stay = true;
            }
            catch
            {

            }

            int noOfDaysInTheSelectedMonth = 0;
            int shift = 0;
            string firstDay = String.Empty;

            if (flip == 0)
            {
                if (!stay)
                {
                    SelectedMonth = calendar.MonthAsSoloString();

                    SelectedYear = calendar.Year.ToString();
                }
                // firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd");
            }

            if (flip == -1)
            {
                int temp = DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month;
                if (temp == 1)
                {
                    temp = 12;
                }
                else
                {
                    temp--;
                }
                SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(temp);
                if (temp != 12)
                {
                    //SelectedYear = calendar.Year.ToString();
                }
                else
                {
                    int tempYear = Convert.ToInt32(SelectedYear);
                    tempYear--;
                    SelectedYear = tempYear.ToString();

                }


            }

            if (flip == 1)
            {
                {
                    int temp = DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month;
                    if (temp == 12)
                    {
                        temp = 1;
                    }
                    else
                    {
                        temp++;
                    }
                    SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(temp);
                    if (temp != 1)
                    {
                    }
                    else
                    {
                        int tempYear = Convert.ToInt32(SelectedYear);
                        tempYear++;
                        SelectedYear = tempYear.ToString();

                    }


                }
            }


            noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
            firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd");

            switch (firstDay)
            {
                case "Sunday": shift = 0;
                    break;
                case "Monday": shift = 1;
                    break;
                case "Tuesday": shift = 2;
                    break;
                case "Wednesday": shift = 3;
                    break;
                case "Thursday": shift = 4;
                    break;
                case "Friday": shift = 5;
                    break;
                case "Saturday": shift = 6;
                    break;
            }

            while (shift > 0)
            {
                dList.Add(new NameValueItem2());
                shift--;
            }
            appList = await Appointment.ReadAppointmentsList();
            appList = appList.Where(ap => ap.PatientID == SelectedPatient.PatientID).ToList();
            try
            {
                peList = (await PatientEncounter.ReadPatientEncountersList()).Where(pe => (getAppointment(pe.AppointmentId)).PatientID == SelectedPatient.PatientID).ToList();
            }
            catch
            {

            }
            List<PatientHistory> pList = await patientViewModel.patientsInfoTable.Where(
            ph => (ph.PatientId == SelectedPatient.PatientID
            &&
            ph.InfoDate > (new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1))
            &&
            ph.InfoDate < (new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, noOfDaysInTheSelectedMonth))
            )).ToListAsync();
            //Where(p => p.FName == ComboPatient).Select(patient => patient.PatientID).ToListAsync()).First();
            for (int i = 1; i <= noOfDaysInTheSelectedMonth; i++)
            {
                DateTime loopDate = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, i);

                PatientHistory temp;
                try
                {
                    temp = pList.Where(ph => ph.InfoDate.ToString("MMMM dd, yyyy") == loopDate.ToString("MMMM dd, yyyy")).ToList().First();
                }
                catch
                {
                    temp = new PatientHistory();
                }
                Appointment app;

                try
                {
                    app = appList.Where(ap => ap.Date.Date.Equals(loopDate.Date.Date)).ToList().First();
                }
                catch
                {
                    app = new Appointment();
                }
                PatientEncounter pee;

                try
                {
                    pee = peList.Where(pe => (getAppointment(pe.AppointmentId)).Date.Date.Equals(loopDate.Date.Date)).ToList().First();
                }
                catch
                {
                    pee = new PatientEncounter();
                }


                dList.Add(new NameValueItem2 { Value = i.ToString(), date = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, i), pHistory = temp, Color = ((!String.IsNullOrEmpty(temp.PatientId)) ? "Pink" : (pee.AppointmentId != null) ? "LightBlue" : (!String.IsNullOrEmpty(app.PatientID) ? "#BFB5DF" : "White")), appointment = app, patientEncounter = pee, Width1 = ((!String.IsNullOrEmpty(temp.PatientId)) || (String.IsNullOrEmpty(temp.PatientId) && String.IsNullOrEmpty(app.PatientID)) ? 98 : 0), Width2 = (!String.IsNullOrEmpty((app.PatientID)) && String.IsNullOrEmpty(temp.PatientId) && pee.AppointmentId == null ? 98 : 0), Width3 = (pee.AppointmentId != null ? 98 : 0) });


            }

            MonthGridView.ItemsSource = dList;
            flip = 0;

            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);

        }
示例#18
0
        private void GetGeofenceStateChangedReports(Geoposition pos)
        {
            geofenceBackgroundEvents.Clear();

            FillEventCollectionWithExistingEvents();

            GeofenceMonitor monitor = GeofenceMonitor.Current;

            Geoposition posLastKnown = monitor.LastKnownGeoposition;

            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();
            Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatterLongTime;
            formatterLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);

            bool eventOfInterest = true;

            // NOTE TO DEVELOPER:
            // These events can be filtered out if the
            // geofence event time is stale.
            DateTimeOffset eventDateTime = pos.Coordinate.Timestamp;

            calendar.SetToNow();
            DateTimeOffset nowDateTime = calendar.GetDateTime();

            TimeSpan diffTimeSpan = nowDateTime - eventDateTime;

            long deltaInSeconds = diffTimeSpan.Ticks / oneHundredNanosecondsPerSecond;

            // NOTE TO DEVELOPER:
            // If the time difference between the geofence event and now is too large
            // the eventOfInterest should be set to false.

            if (eventOfInterest)
            {
                // NOTE TO DEVELOPER:
                // This event can be filtered out if the
                // geofence event location is too far away.
                if ((posLastKnown.Coordinate.Point.Position.Latitude != pos.Coordinate.Point.Position.Latitude) ||
                    (posLastKnown.Coordinate.Point.Position.Longitude != pos.Coordinate.Point.Position.Longitude))
                {
                    // NOTE TO DEVELOPER:
                    // Use an algorithm like the Haversine formula or Vincenty's formulae to determine
                    // the distance between the current location (pos.Coordinate)
                    // and the location of the geofence event (latitudeEvent/longitudeEvent).
                    // If too far apart set eventOfInterest to false to
                    // filter the event out.
                }

                if (eventOfInterest)
                {
                    string geofenceItemEvent = null;

                    int numEventsOfInterest = 0;

                    // Retrieve a vector of state change reports
                    var reports = GeofenceMonitor.Current.ReadReports();

                    foreach (GeofenceStateChangeReport report in reports)
                    {
                        GeofenceState state = report.NewState;

                        geofenceItemEvent = report.Geofence.Id + " " + formatterLongTime.Format(eventDateTime);

                        if (state == GeofenceState.Removed)
                        {
                            GeofenceRemovalReason reason = report.RemovalReason;

                            if (reason == GeofenceRemovalReason.Expired)
                            {
                                geofenceItemEvent += " (Removed/Expired)";
                            }
                            else if (reason == GeofenceRemovalReason.Used)
                            {
                                geofenceItemEvent += " (Removed/Used)";
                            }
                        }
                        else if (state == GeofenceState.Entered)
                        {
                            geofenceItemEvent += " (Entered)";
                        }
                        else if (state == GeofenceState.Exited)
                        {
                            geofenceItemEvent += " (Exited)";
                        }

                        AddGeofenceEvent(geofenceItemEvent);

                        ++numEventsOfInterest;
                    }

                    if (eventOfInterest && (0 != numEventsOfInterest))
                    {
                        SaveExistingEvents();

                        // NOTE: Other notification mechanisms can be used here, such as Badge and/or Tile updates.
                        DoToast(numEventsOfInterest, geofenceItemEvent);
                    }
                }
            }
        }
示例#19
0
        private bool FindValidMonth(Windows.Globalization.Calendar calendar, int monthStep, int dayStep)
        {
            var minMonth = calendar.Year == this.minCalendarWithStep.Year ? this.minCalendarWithStep.Month : calendar.FirstMonthInThisYear;
            var maxMonth = calendar.Year == this.maxCalendarWithStep.Year ? this.maxCalendarWithStep.Month : calendar.LastMonthInThisYear;

            var monthRemainder = this.GetStepRemainderForComponent(calendar.Month, calendar.FirstMonthInThisYear, this.MonthStepBehavior, monthStep);

            var currentMonth = calendar.Month - monthRemainder;

            while (currentMonth < minMonth)
            {
                currentMonth += monthStep;
                if (currentMonth > maxMonth)
                {
                    return(false);
                }
            }

            // keep the start calendar
            var startCalendar = calendar.Clone();

            startCalendar.AddMonths(currentMonth - startCalendar.Month);

            while (currentMonth >= minMonth)
            {
                var monthsUpdate = currentMonth - calendar.Month;
                calendar.AddMonths(monthsUpdate);

                if (monthsUpdate < 0)
                {
                    calendar.Day = calendar.LastDayInThisMonth;
                }

                if (this.FindValidDay(calendar, dayStep))
                {
                    return(true);
                }

                currentMonth -= monthStep;
            }

            calendar     = startCalendar.Clone();
            currentMonth = calendar.Month;

            while (currentMonth <= maxMonth)
            {
                var monthsUpdate = currentMonth - calendar.Month;
                calendar.AddMonths(monthsUpdate);

                if (monthsUpdate > 0)
                {
                    calendar.Day = calendar.FirstDayInThisMonth;
                }

                if (this.FindValidDay(calendar, dayStep))
                {
                    return(true);
                }

                currentMonth += monthStep;
            }

            return(false);
        }
示例#20
0
        private async Task GetGeofenceStateChangedReports(Geoposition pos)
        {
            _geofenceBackgroundEvents.Clear();
            FillEventCollectionWithExistingEvents();

            GeofenceMonitor monitor      = GeofenceMonitor.Current;
            Geoposition     posLastKnown = monitor.LastKnownGeoposition;

            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();
            Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatterLongTime;
            formatterLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "hr-HR" }, "HR", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);

            bool eventOfInterest = true;

            // NOTE TO DEVELOPER:
            // Registered geofence events can be filtered out if the
            // geofence event time is stale.
            var eventDateTime = pos.Coordinate.Timestamp;

            calendar.SetToNow();
            var nowDateTime  = calendar.GetDateTime();
            var diffTimeSpan = nowDateTime - eventDateTime;

            var deltaInSeconds = diffTimeSpan.TotalSeconds;

            if (deltaInSeconds > 120)
            {
                eventOfInterest = false;
            }

            if (eventOfInterest)
            {
                // NOTE TO DEVELOPER:
                // This event can be filtered out if the
                // geofence event location is too far away.
                var distance = 0.0d;

                if ((posLastKnown.Coordinate.Point.Position.Latitude != pos.Coordinate.Point.Position.Latitude) ||
                    (posLastKnown.Coordinate.Point.Position.Longitude != pos.Coordinate.Point.Position.Longitude))
                {
                    distance = new HaversineFormula().Distance(posLastKnown.Coordinate.Point.Position, pos.Coordinate.Point.Position, HaversineFormula.DistanceType.Kilometers);

                    // NOTE TO DEVELOPER:
                    // Use an algorithm like the Haversine formula or Vincenty's formulae to determine
                    // the distance between the current location (pos.Coordinate)
                    // and the location of the geofence event (latitudeEvent/longitudeEvent).
                    // If too far apart set eventOfInterest to false to
                    // filter the event out.
                }

                if (eventOfInterest)
                {
                    string geofenceItemEvent   = null;
                    int    numEventsOfInterest = 0;

                    // Retrieve a vector of state change reports
                    var reports = GeofenceMonitor.Current.ReadReports();

                    foreach (var report in reports)
                    {
                        GeofenceState state = report.NewState;
                        geofenceItemEvent = report.Geofence.Id + " " + formatterLongTime.Format(eventDateTime);

                        if (state == GeofenceState.Removed)
                        {
                            GeofenceRemovalReason reason = report.RemovalReason;
                            if (reason == GeofenceRemovalReason.Expired)
                            {
                                geofenceItemEvent += " (Removed/Expired)";
                            }
                            else if (reason == GeofenceRemovalReason.Used)
                            {
                                geofenceItemEvent += " (Removed/Used)";
                            }
                        }
                        else if (state == GeofenceState.Entered)
                        {
                            geofenceItemEvent += " (Entered)";
                        }
                        else if (state == GeofenceState.Exited)
                        {
                            geofenceItemEvent += " (Exited)";
                        }

                        geofenceItemEvent += $" - {deltaInSeconds}";
                        geofenceItemEvent += $"\nDistance - {distance}";

                        AddGeofenceEvent(geofenceItemEvent);
                        ++numEventsOfInterest;

                        var userLocation = new UserLocation()
                        {
                            Latitude   = report.Geoposition.Coordinate.Point.Position.Latitude,
                            Longitude  = report.Geoposition.Coordinate.Point.Position.Longitude,
                            Name       = report.Geofence.Id,
                            UpdatedUtc = eventDateTime.UtcDateTime,
                            Status     = (LocationStatus)(int)state
                        };

                        await UploadDataToCloud(userLocation);
                    }

                    if (eventOfInterest == true && numEventsOfInterest != 0)
                    {
                        SaveExistingEvents();
                        // NOTE: Other notification mechanisms can be used here, such as Badge and/or Tile updates.
                        //DoToast(numEventsOfInterest, geofenceItemEvent);
                    }
                }
            }
        }
示例#21
0
        private bool FindValidHour(Windows.Globalization.Calendar calendar, int hourStep, int minuteStep, bool isMinDate, bool isMaxDate)
        {
            var clock = calendar.GetClock();

            var minHour = isMinDate && calendar.Period == this.minCalendarWithStep.Period ? this.minCalendarWithStep.ZeroBasedHour() : DateTimeHelper.GetZeroBasedHour(clock, calendar.FirstHourInThisPeriod);
            var maxHour = isMaxDate && calendar.Period == this.maxCalendarWithStep.Period ? this.maxCalendarWithStep.ZeroBasedHour() : DateTimeHelper.GetZeroBasedHour(clock, calendar.LastHourInThisPeriod);

            var firstHour   = DateTimeHelper.GetZeroBasedHour(clock, calendar.FirstHourInThisPeriod);
            var currentHour = calendar.ZeroBasedHour();

            var hourRemainder = this.GetStepRemainderForComponent(currentHour, firstHour, StepBehavior.StartFromBase, hourStep);

            currentHour -= hourRemainder;

            if (currentHour < minHour)
            {
                currentHour += hourStep;
                if (currentHour > maxHour)
                {
                    return(false);
                }
            }

            // keep the start calendar
            var startCalendar = calendar.Clone();

            startCalendar.SetZeroBasedHour(currentHour);

            while (currentHour >= minHour)
            {
                var hoursUpdate = currentHour - calendar.ZeroBasedHour();
                calendar.AddHours(hoursUpdate);
                if (hoursUpdate < 0)
                {
                    calendar.Minute = calendar.LastMinuteInThisHour;
                }

                if (this.FindValidMinute(calendar, minuteStep, isMinDate, isMaxDate))
                {
                    return(true);
                }

                currentHour -= hourStep;
            }

            calendar    = startCalendar.Clone();
            currentHour = calendar.Hour;

            while (currentHour <= maxHour)
            {
                var hoursUpdate = currentHour - calendar.ZeroBasedHour();
                calendar.AddHours(hoursUpdate);
                if (hoursUpdate > 0)
                {
                    calendar.Minute = calendar.FirstMinuteInThisHour;
                }

                if (this.FindValidMinute(calendar, minuteStep, isMinDate, isMaxDate))
                {
                    return(true);
                }

                currentHour += hourStep;
            }

            return(false);
        }
示例#22
0
        public async void fillWeeklyCalendar()
        {
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
            myGrid.Opacity = 0.5;
            appIncrease++;

            //if (flip2 == 0)
            //{
                whList = (await WorkHours.ReadListAsync()).Where(w => w.EmployeeId == SelectedDoctor.UserId).ToList();
                appList = (await Appointment.ReadAppointmentsList()).Where(a => a.UserID == SelectedDoctor.UserId).ToList();
                invList = (await Invitation.ReadInvitationsList()).Where(i => i.ToUserId == SelectedDoctor.UserId).ToList();
            //}
            if (SelectedWeek != 0 && flip2 == 0)
            {
                stay = true;

            }
            if (!stay)
            {
                LeftMonth = String.Empty;
                LeftYear = String.Empty;
                RightMonth = String.Empty;
                RightYear = String.Empty;
            }
            //   whList = (await WorkHours.ReadListAsync()).Where(w => w.EmployeeId == Connection.User.UserId).ToList();

           calendar = new Windows.Globalization.Calendar();

            //ObservableCollection
            List<NameValueItem3> dList = new List<NameValueItem3>();
            //dList.Clear();
            // List<WeekDay> weekList = new List<WeekDay>(7);

            if (flip2 == 0)
            {
                if (String.IsNullOrEmpty(SelectedMonth))
                    SelectedMonth = calendar.MonthAsSoloString();
                if (String.IsNullOrEmpty(SelectedYear))
                    SelectedYear = calendar.Year.ToString();



                if (!stay)
                    SelectedWeek = 1;

            }
            if (flip2 == -1)
            {


                if (SelectedWeek == 1)
                {
                    SelectedWeek = 4;

                    if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 1)
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);
                        SelectedYear = ((Convert.ToInt32(SelectedYear)) - 1).ToString();
                    }
                    else
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);
                    }

                }
                else
                {
                    SelectedWeek--;
                }




            }

            if (flip2 == 1)
            {



                if (SelectedWeek == 4)
                {
                    SelectedWeek = 1;

                    if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 12)
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
                        SelectedYear = ((Convert.ToInt32(SelectedYear)) + 1).ToString();
                    }
                    else
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month + 1);
                    }

                }
                else
                {
                    SelectedWeek++;
                }
            }
            int noOfDaysInTheSelectedMonth = 0;
            int shift = 0;
            string firstDay = String.Empty;


            if (!stay)
                weekList.Clear();

            if (SelectedWeek == 1)
            {
                //int noOfDaysInTheSelectedMonth = 0;
                //int shift = 0;
                //string firstDay = String.Empty;

                if (!stay)
                {
                    noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
                    firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd");

                    switch (firstDay)
                    {
                        case "Sunday": shift = 0;
                            break;
                        case "Monday": shift = 1;
                            break;
                        case "Tuesday": shift = 2;
                            break;
                        case "Wednesday": shift = 3;
                            break;
                        case "Thursday": shift = 4;
                            break;
                        case "Friday": shift = 5;
                            break;
                        case "Saturday": shift = 6;
                            break;
                    }

                    int NumberOfPreviousMonthDays;
                    string previuosMonth;
                    string previousMonthYear;

                    if (shift != 0)
                    {

                        if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1)
                        {
                            NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);
                            previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            previousMonthYear = SelectedYear;
                        }
                        else
                        {
                            NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12);
                            previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            previousMonthYear = (Convert.ToInt32(SelectedYear) - 1).ToString();

                        }

                        for (int i = shift - 1; i >= 0; i--)
                        {
                            weekList.Add(new WeekDay { Year = previousMonthYear, Month = previuosMonth, Day = NumberOfPreviousMonthDays - i });
                        }

                        for (int i = 1; i <= 7 - shift; i++)
                        {
                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == 7 - shift)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();

                            }
                        }

                        LeftMonth = previuosMonth;
                        LeftYear = previousMonthYear;

                        RightMonth = SelectedMonth;
                        //  MonthNameTextBlock3.Text =SelectedMonth  ;
                        RightYear = selectedYear;
                    }
                    if (shift == 0)
                    {
                        for (int i = 1; i <= 7; i++)
                        {

                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == 7)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                            }
                        }

                        LeftMonth = SelectedMonth;
                        LeftYear = SelectedYear;

                        RightMonth = String.Empty;
                        RightYear = String.Empty;
                    }



                }
            }
            else if (SelectedWeek == 2 || SelectedWeek == 3 || SelectedWeek == 4)
            {
                if (!stay)
                {
                    if (!backward)
                    {
                        for (int i = ReachedDayInWeeklyCalendar.Day + 1; i <= (ReachedDayInWeeklyCalendar.Day + 7); i++)
                        {
                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == ReachedDayInWeeklyCalendar.Day + 7)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                                break;
                            }
                        }



                    }

                    else //backward true
                    {

                        if (StartDayInWeeklyCalendar.Day - 1 != 0)
                        {
                            for (int i = StartDayInWeeklyCalendar.Day - 7; i <= (StartDayInWeeklyCalendar.Day - 1); i++)
                            {

                                weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                                if (i == StartDayInWeeklyCalendar.Day - 1)
                                {
                                    ReachedDayInWeeklyCalendar = weekList.Last();
                                    StartDayInWeeklyCalendar = weekList.First();
                                    break;
                                }


                            }
                        }
                        else
                        {
                            if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1)
                            {
                                noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
                                //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                                //SelectedYear = SelectedYear;
                            }
                            else
                            {
                                noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12);
                                //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                                //SelectedYear = (Convert.ToInt32(SelectedYear) - 1).ToString();

                            }

                            for (int i = noOfDaysInTheSelectedMonth - 6; i <= (noOfDaysInTheSelectedMonth - 0); i++)
                            {

                                weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                                if (i == (noOfDaysInTheSelectedMonth - 0))
                                {
                                    ReachedDayInWeeklyCalendar = weekList.Last();
                                    StartDayInWeeklyCalendar = weekList.First();
                                    break;
                                }


                            }



                        }



                    }


                    LeftMonth = SelectedMonth;
                    LeftYear = SelectedYear;
                    RightMonth = String.Empty;
                    RightYear = String.Empty;

                }

            }




            for (int i = 0; i < 192; i++)
            {
                OutLookEvent[] myOEvent2 = null;
                OutLookEvent myOEvent = null;
                WorkHours wh = null;

                Appointment app1 = null;
                Appointment app2 = null;
                Appointment app3 = null;
                Appointment app4 = null;
                Invitation inv1 = null;
                Invitation inv2 = null;
                Invitation inv3 = null;
                Invitation inv4 = null;

                if (i % 8 == 0)
                {
                    dList.Add(new NameValueItem3() { timeItem = true, time = new TimeSpan(i / 8, 0, 0), Width = 1, timeStr = (new TimeSpan(i / 8, 0, 0)).ToString().Substring(0, (new TimeSpan(i / 8, 0, 0)).ToString().LastIndexOf(":")) + "_", Color1 = "#BFB5DF", Width1 = 45 }); //( new TimeSpan(i / 8, 0, 0)).ToString()
                }

                else
                {

                    DateTime loopDate = new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                           DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                           weekList.ElementAt((i % 8) - 1).Day);

                    //try
                    //{
                    //    //  myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy"))).ToArray().First();
                    //    //   myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (e.start_time.TimeOfDay.Equals(new TimeSpan(i / 8, 0, 0)) || e.end_time.TimeOfDay >= (new TimeSpan(i / 8, 0, 0)))).ToArray().First();
                    //    //   myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (new TimeSpan(e.end_time.TimeOfDay.Hours,0,0) >= (new TimeSpan(i / 8, 0, 0)) || e.isAllDay == true)).ToArray().First();
                    //    // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))&&(TimeSpan)(e.end_time - e.start_time) <= new TimeSpan(1, 0, 0)))).ToArray().First();
                    //    myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray().First();
                    //    myOEvent2 = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray();
                    //}
                    //catch
                    //{

                    //}

                    try
                    {
                        wh = whList.Where(w => ((w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours <= (i / 8) && w.To.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.To.TimeOfDay.Hours >= (i / 8)) || (w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours <= i / 8 && w.To.Date.Equals(loopDate.AddDays(1))) || (w.From.Date.Equals(loopDate.AddDays(-1).Date) && w.To.Date.Equals(loopDate.Date) && w.To.TimeOfDay.Hours >= (i / 8)) || (w.TimeOffFrom.Date.Equals(loopDate.Date) && w.TimeOffFrom.TimeOfDay.Hours <= (i / 8) && w.TimeOffTo.TimeOfDay.Hours >= (i / 8)))).ToArray().First();
                        if (!String.IsNullOrEmpty(wh.TimeOffReason))
                            wh = null;
                    }
                    catch
                    {

                    }

                    try
                    {
                        app1 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 0) && (a.TimeTo.Minutes == 15))).ToList().First();
                    }
                    catch
                    {
                        app1 = new Appointment();
                        // app1.Complaint = "hiii2";

                    }

                    try
                    {
                        app2 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 15) && (a.TimeTo.Minutes == 30))).ToList().First();
                    }
                    catch
                    {
                        app2 = new Appointment();

                    }

                    try
                    {
                        app3 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 30) && (a.TimeTo.Minutes == 45))).ToList().First();
                    }
                    catch
                    {
                        app3 = new Appointment();

                    }

                    try
                    {
                        app4 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 45) && (a.TimeTo.Minutes == 0))).ToList().First();
                    }
                    catch
                    {
                        app4 = new Appointment();


                    }

                    try
                    {
                        inv1 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 0) && (a.TimeTo.Minutes == 15))).ToList().First();
                    }
                    catch
                    {

                        inv1 = new Invitation();

                    }

                    try
                    {
                        inv2 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 15) && (a.TimeTo.Minutes == 30))).ToList().First();
                    }
                    catch
                    {

                        inv2 = new Invitation();

                    }

                    try
                    {
                        inv3 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 30) && (a.TimeTo.Minutes == 45))).ToList().First();
                    }
                    catch
                    {

                        inv3 = new Invitation();

                    }

                    try
                    {
                        inv4 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 45) && (a.TimeTo.Minutes == 0))).ToList().First();
                    }
                    catch
                    {

                        inv4 = new Invitation();

                    }


                    dList.Add(new NameValueItem3()
                    {
                        timeItem = false,
                        time = new TimeSpan(i / 8, 0, 0),
                        timeStr = null,
                        Width = 3,
                        weekDay = weekList.ElementAt((i % 8) - 1),
                        Color1 = (myOEvent != null ? "Wheat" : "#BFB5DF"),
                        myOutLookEvent = myOEvent,
                        myOutLookEvent2 = myOEvent2,
                        workHours = wh,
                        Border = (myOEvent != null || wh != null ? new Thickness(1) : new Thickness(0)),
                        //Color2 = (wh == null ? "AliceBlue" : (wh.From.TimeOfDay.Hours == 7 ? "#99FF99" : (wh.From.TimeOfDay.Hours == 15 ? "#99CCFF" : (wh.From.TimeOfDay.Hours == 23 ? "Wheat" : "AliceBlue")))),
                        Color2 = (wh == null ? "#BFB5DF" : (wh.From.TimeOfDay.Hours == 7 ? "#A3F1A7" : (wh.From.TimeOfDay.Hours == 15 ? "#A3F1A7" : (wh.From.TimeOfDay.Hours == 23 ? "#A3F1A7" : "#BFB5DF")))),

                        Width1 = (myOEvent == null && wh != null ? 0 : (myOEvent != null && wh != null) ? 67 : 135),
                        Width2 = (wh != null && myOEvent == null ? 135 : (wh != null && myOEvent != null) ? 67 : 0),
                        Appointment1 = app1,
                        Appointment2 = app2,
                        Appointment3 = app3,
                        Appointment4 = app4,
                        Invitation1 = inv1,
                        Invitation2 = inv2,
                        Invitation3 = inv3,
                        Invitation4 = inv4,

                        EnableTextBlockes = Visibility.Visible,
                        EnableTextBlockes2 = Visibility.Visible,
                        EnableTextBlockes3 = Visibility.Visible,
                        EnableTextBlockes4 = Visibility.Visible,



                        EnableTextBoxes = Visibility.Collapsed,
                        EnableTextBoxes2 = Visibility.Collapsed,
                        EnableTextBoxes3 = Visibility.Collapsed,
                        EnableTextBoxes4 = Visibility.Collapsed,



                        EnableButton = Visibility.Collapsed,
                        EnableButton2 = Visibility.Collapsed,
                        EnableButton3 = Visibility.Collapsed,
                        EnableButton4 = Visibility.Collapsed,


                        EnableDelButton = Visibility.Collapsed,
                        EnableDelButton2 = Visibility.Collapsed,
                        EnableDelButton3 = Visibility.Collapsed,
                        EnableDelButton4 = Visibility.Collapsed,


                    });
                    if (i > 0 || i < 8)
                    {
                        //  if(myOEvent.isAllDay)
                        switch (i)
                        {
                            case 1: Sunday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Sunday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Sunday2.Text = String.Empty;
                                //}
                                break;
                            case 2: Monday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                 DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                 weekList.ElementAt((i % 8) - 1).Day)
                                 ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Monday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Monday2.Text = String.Empty;
                                //}
                                break;
                            case 3: Tuesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Tuesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Tuesday2.Text = String.Empty;
                                //}
                                break;
                            case 4: Wednesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Wednesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Wednesday2.Text = String.Empty;
                                //}
                                break;
                            case 5: Thursday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Thursday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Thursday2.Text = String.Empty;
                                //}
                                break;
                            case 6: Friday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Friday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Friday2.Text = String.Empty;
                                //}
                                break;
                            case 7:


                                Saturday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                //try
                                //{
                                //    Saturday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                //}
                                //catch
                                //{
                                //    Saturday2.Text = String.Empty;
                                //}
                                break;


                        }
                        // weekList.ElementAt((i-1)%8)
                    }
                }
            }

            flip2 = 0;
            backward = false;
            WeekGridView.ItemsSource = dList;
            //weekList.Clear();
            stay = false;
            //Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            //{
            //    WeekGridView.ScrollIntoView(dList.ElementAt(147));
            //});


            myGrid.Opacity = 1;
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);


        }
        public Scenario4()
        {
            this.InitializeComponent();

            try
            {
                formatterShortDateLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{month.integer}/{day.integer}/{year.full} {hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);
                formatterLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);
                calendar = new Windows.Globalization.Calendar();
                decimalFormatter = new Windows.Globalization.NumberFormatting.DecimalFormatter();

                geofenceCollection = new GeofenceItemCollection();
                eventCollection = new EventDescriptorCollection();

                // Get a geolocator object
                geolocator = new Geolocator();

                geofences = GeofenceMonitor.Current.Geofences;

                // using data binding to the root page collection of GeofenceItems
                RegisteredGeofenceListBox.DataContext = geofenceCollection;

                // using data binding to the root page collection of GeofenceItems associated with events
                GeofenceEventsListBox.DataContext = eventCollection;

                FillRegisteredGeofenceListBoxWithExistingGeofences();
                FillEventListBoxWithExistingEvents();

#if WINDOWS_APP
                accessInfo = DeviceAccessInformation.CreateFromDeviceClass(DeviceClass.Location);
                accessInfo.AccessChanged += OnAccessChanged;
#endif

                coreWindow = CoreWindow.GetForCurrentThread(); // this needs to be set before InitializeComponent sets up event registration for app visibility
                coreWindow.VisibilityChanged += OnVisibilityChanged;

                // register for state change events
                GeofenceMonitor.Current.GeofenceStateChanged += OnGeofenceStateChanged;
                GeofenceMonitor.Current.StatusChanged += OnGeofenceStatusChanged;
            }
#if WINDOWS_APP
            catch (UnauthorizedAccessException)
            {
                if (DeviceAccessStatus.DeniedByUser == accessInfo.CurrentStatus)
                {
                    rootPage.NotifyUser("Location has been disabled by the user. Enable access through the settings charm.", NotifyType.StatusMessage);
                }
                else if (DeviceAccessStatus.DeniedBySystem == accessInfo.CurrentStatus)
                {
                    rootPage.NotifyUser("Location has been disabled by the system. The administrator of the device must enable location access through the location control panel.", NotifyType.StatusMessage);
                }
                else if (DeviceAccessStatus.Unspecified == accessInfo.CurrentStatus)
                {
                    rootPage.NotifyUser("Location has been disabled by unspecified source. The administrator of the device may need to enable location access through the location control panel, then enable access through the settings charm.", NotifyType.StatusMessage);
                }
            }
#endif
            catch (Exception ex)
            {
                // GeofenceMonitor failed in adding a geofence
                // exceptions could be from out of memory, lat/long out of range,
                // too long a name, not a unique name, specifying an activation
                // time + duration that is still in the past

                // If ex.HResult is RPC_E_DISCONNECTED (0x80010108):
                // The Location Framework service event state is out of synchronization
                // with the Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.
                // To recover remove all event handlers on the GeofenceMonitor or restart the application.
                // Once all event handlers are removed you may add back any event handlers and retry the operation.

                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
示例#24
0
        public async void fillWeeklyCalendar()
        {
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
            myGrid.Opacity = 0.5;

            if(SelectedWeek!=0 && flip2==0){
                    stay = true;
	            }
             if (!stay)
             {
                 LeftMonth = String.Empty;
                 LeftYear = String.Empty;
                 RightMonth = String.Empty;
                 RightYear = String.Empty;
             }
            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();


            dList = new List<StaffItem>();

           

            if (flip2 == 0)
            {
                if (String.IsNullOrEmpty(SelectedMonth))
                    SelectedMonth = calendar.MonthAsSoloString();
                if (String.IsNullOrEmpty(SelectedYear))
                    SelectedYear = calendar.Year.ToString();

                if (!stay)
                    SelectedWeek = 1;
                //else
                //   stay = true;

              

            }
            if (flip2 == -1)
            {


                if (SelectedWeek == 1)
                {
                    SelectedWeek = 4;

                    if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 1)
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);
                        SelectedYear = ((Convert.ToInt32(SelectedYear)) - 1).ToString();
                    }
                    else
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);
                    }

                }
                else
                {
                    SelectedWeek--;
                }




            }

            if (flip2 == 1)
            {



                if (SelectedWeek == 4)
                {
                    SelectedWeek = 1;

                    if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 12)
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
                        SelectedYear = ((Convert.ToInt32(SelectedYear)) + 1).ToString();
                    }
                    else
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month + 1);
                    }

                }
                else
                {
                    SelectedWeek++;
                }
            }
            int noOfDaysInTheSelectedMonth = 0;
            int shift = 0;
            string firstDay = String.Empty;

            if(!stay)
               weekList.Clear();


            if (SelectedWeek == 1)
            {
                //int noOfDaysInTheSelectedMonth = 0;
                //int shift = 0;
                //string firstDay = String.Empty;
                if (!stay)
                {
                    noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
                    firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd");

                    switch (firstDay)
                    {
                        case "Sunday": shift = 0;
                            break;
                        case "Monday": shift = 1;
                            break;
                        case "Tuesday": shift = 2;
                            break;
                        case "Wednesday": shift = 3;
                            break;
                        case "Thursday": shift = 4;
                            break;
                        case "Friday": shift = 5;
                            break;
                        case "Saturday": shift = 6;
                            break;
                    }

                    int NumberOfPreviousMonthDays;
                    string previuosMonth;
                    string previousMonthYear;

                    if (shift != 0)
                    {

                        if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1)
                        {
                            NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);
                            previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            previousMonthYear = SelectedYear;
                        }
                        else
                        {
                            NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12);
                            previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            previousMonthYear = (Convert.ToInt32(SelectedYear) - 1).ToString();

                        }

                        for (int i = shift - 1; i >= 0; i--)
                        {
                            weekList.Add(new WeekDay { Year = previousMonthYear, Month = previuosMonth, Day = NumberOfPreviousMonthDays - i });
                        }

                        for (int i = 1; i <= 7 - shift; i++)
                        {
                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == 7 - shift)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();

                            }
                        }

                        LeftMonth = previuosMonth;
                        LeftYear = previousMonthYear;

                        RightMonth = SelectedMonth;
                        //  MonthNameTextBlock3.Text =SelectedMonth  ;
                        RightYear = selectedYear;
                    }
                    if (shift == 0)
                    {
                        for (int i = 1; i <= 7; i++)
                        {

                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == 7)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                            }
                        }

                        LeftMonth = SelectedMonth;
                        LeftYear = SelectedYear;

                        RightMonth = String.Empty;
                        RightYear = String.Empty;
                    }

                    //fill dList


                }
            }
            else if (SelectedWeek == 2 || SelectedWeek == 3 || SelectedWeek == 4)
            {
                if (!stay) { 
                if (!backward)
                {
                    for (int i = ReachedDayInWeeklyCalendar.Day + 1; i <= (ReachedDayInWeeklyCalendar.Day + 7); i++)
                    {
                        weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                        if (i == ReachedDayInWeeklyCalendar.Day + 7)
                        {
                            ReachedDayInWeeklyCalendar = weekList.Last();
                            StartDayInWeeklyCalendar = weekList.First();
                            break;
                        }
                    }



                }

                else //backward true
                {

                    if (StartDayInWeeklyCalendar.Day - 1 != 0)
                    {
                        for (int i = StartDayInWeeklyCalendar.Day - 7; i <= (StartDayInWeeklyCalendar.Day - 1); i++)
                        {

                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == StartDayInWeeklyCalendar.Day - 1)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                                break;
                            }


                        }
                    }
                    else
                    {
                        if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1)
                        {
                            noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
                            //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            //SelectedYear = SelectedYear;
                        }
                        else
                        {
                            noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12);
                            //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            //SelectedYear = (Convert.ToInt32(SelectedYear) - 1).ToString();

                        }

                        for (int i = noOfDaysInTheSelectedMonth - 6; i <= (noOfDaysInTheSelectedMonth - 0); i++)
                        {

                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == (noOfDaysInTheSelectedMonth - 0))
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                                break;
                            }
                        }
                    }

                }
                LeftMonth = SelectedMonth;
                LeftYear = SelectedYear;
                RightMonth = String.Empty;
                RightYear = String.Empty;

            }
            }

            empList = await User.ReadUsersList();
            List<WorkHours> whList = await WorkHours.ReadListAsync();

            int total = 0;
            for (int i = 0; i < empList.Count * 9; i++)
            {

                OutLookEvent myOEvent = null;
                if (i % 9 == 0)
                {
                    //dList.Add(new NameValueItem3() { timeItem = true, time = new TimeSpan(i / 9, 0, 0), Width = 4, timeStr = "Employee Name", Color = "AliceBlue" }); //( new TimeSpan(i / 9, 0, 0)).ToString()
                    dList.Add(new StaffItem() { Employee = empList.ElementAt(i / 9), Color = "#BFB5DF", Width = 4, i = i });
                    //fill employee names
                }

                else if ((i % 9) - 1 == 7)
                {
                    //calculate work hours
                    //dList.Add(new NameValueItem3() { timeItem = true, time = new TimeSpan(i / 9, 0, 0), Width = 1, timeStr = "Total", Color = "AliceBlue" }); //( new TimeSpan(i / 9, 0, 0)).ToString()
                    dList.Add(new StaffItem() { Total = total, Width = 1, Color = "#BFB5DF", i = i });
                    total = 0;
                }

                else
                {

                    DateTime loopDate = new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                           DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                           weekList.ElementAt((i % 9) - 1).Day);

                    WorkHours temp;
                    try
                    {
                        temp = whList.Where(w => w.EmployeeId == empList.ElementAt(i / 9).UserId && (w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) || w.TimeOffFrom.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")))).First(); ;
                        total = (String.IsNullOrEmpty(temp.TimeOffReason) ? (total + 8) : total);


                    }
                    catch
                    {
                        temp = null;
                    }
                    //  dList.Add(new NameValueItem3() { timeItem = false, time = new TimeSpan(i / 9, 0, 0), Width = 3, weekDay = weekList.ElementAt((i % 9) - 1), Color = (myOEvent != null ? "Wheat" : "AliceBlue"), myOutLookEvent = myOEvent });

                    dList.Add(new StaffItem() { workHours = temp, Color = (temp == null ? "#BFB5DF" : (temp.From.TimeOfDay.Hours == 7 ? "#99FF99" : (temp.From.TimeOfDay.Hours == 15 ? "#99CCFF" : (temp.From.TimeOfDay.Hours == 23 ? "Wheat" : "#BFB5DF")))), Width = 3, i = i, date = loopDate, border = (temp != null ? new Thickness(1) : new Thickness(0)) });

                    //increment total

                    if (i > 0 || i < 8)
                    {
                        //  if(myOEvent.isAllDay)
                        switch (i)
                        {
                            case 1: Sunday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 9) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;
                            case 2: Monday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                 DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                 weekList.ElementAt((i % 9) - 1).Day)
                                 ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;
                            case 3: Tuesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 9) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;
                            case 4: Wednesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 9) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;
                            case 5: Thursday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 9) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;
                            case 6: Friday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 9) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;
                            case 7:


                                Saturday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 9) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 9) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 9) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 9) - 1).Day;

                                break;


                        }

                    }
                }


            }

            flip2 = 0;
            backward = false;
            WeekGridView.ItemsSource = dList;
            stay  = false;
          //  weekList.Clear();

            //Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            //{
            //    WeekGridView.ScrollIntoView(dList.ElementAt(147));
            //});
            myGrid.Opacity = 1;
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);


        }
示例#25
0
        private void GetGeofenceStateChangedReports(Geoposition pos)
        {
            _geofenceBackgroundEvents.Clear();

            FillEventCollectionWithExistingEvents();

            GeofenceMonitor monitor = GeofenceMonitor.Current;

            Geoposition posLastKnown = monitor.LastKnownGeoposition;

            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();
            Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatterLongTime;
            formatterLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);

            bool eventOfInterest = true;

            // NOTE TO DEVELOPER:
            // Registered geofence events can be filtered out if the
            // geofence event time is stale.
            DateTimeOffset eventDateTime = pos.Coordinate.Timestamp;

            calendar.SetToNow();
            DateTimeOffset nowDateTime  = calendar.GetDateTime();
            TimeSpan       diffTimeSpan = nowDateTime - eventDateTime;

            long deltaInSeconds = diffTimeSpan.Ticks / oneHundredNanosecondsPerSecond;

            if (true == eventOfInterest)
            {
                if ((posLastKnown.Coordinate.Point.Position.Latitude != pos.Coordinate.Point.Position.Latitude) ||
                    (posLastKnown.Coordinate.Point.Position.Longitude != pos.Coordinate.Point.Position.Longitude))
                {
                    UpdateInforamtion.WipeGeolocDataFromAppData();
                }

                if (true == eventOfInterest)
                {
                    string geofenceItemEvent   = null;
                    int    numEventsOfInterest = 0;

                    // Retrieve a vector of state change reports
                    var reports = GeofenceMonitor.Current.ReadReports();

                    foreach (var report in reports)
                    {
                        GeofenceState state = report.NewState;
                        geofenceItemEvent = report.Geofence.Id + " " + formatterLongTime.Format(eventDateTime);

                        if (state == GeofenceState.Removed)
                        {
                            GeofenceRemovalReason reason = report.RemovalReason;
                            if (reason == GeofenceRemovalReason.Expired)
                            {
                                geofenceItemEvent += " (Removed/Expired)";
                            }
                            else if (reason == GeofenceRemovalReason.Used)
                            {
                                geofenceItemEvent += " (Removed/Used)";
                            }
                        }
                        else if (state == GeofenceState.Entered)
                        {
                            geofenceItemEvent += " (Entered)";
                        }
                        else if (state == GeofenceState.Exited)
                        {
                            geofenceItemEvent += " (Exited)";
                        }

                        AddGeofenceEvent(geofenceItemEvent);

                        ++numEventsOfInterest;
                    }

                    if (true == eventOfInterest && 0 != numEventsOfInterest)
                    {
                        SaveExistingEvents();

                        // NOTE: Other notification mechanisms can be used here, such as Badge and/or Tile updates.
                        DoToast(numEventsOfInterest, geofenceItemEvent);
                    }
                }
            }
        }
示例#26
0
      //  List<WorkHours> whList = new List<WorkHours>();
        public  void fillWeeklyCalendar()
        {


            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2);
            myGrid.Opacity = 0.5;

            LeftMonth = String.Empty;
            LeftYear = String.Empty;
            RightMonth = String.Empty;
            RightYear = String.Empty;
         //   whList = (await WorkHours.ReadListAsync()).Where(w => w.EmployeeId == Connection.User.UserId).ToList();

            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();


            List<NameValueItem3> dList = new List<NameValueItem3>();

            List<WeekDay> weekList = new List<WeekDay>(7);

            if (flip2 == 0)
            {
                if (String.IsNullOrEmpty(SelectedMonth))
                    SelectedMonth = calendar.MonthAsSoloString();
                if (String.IsNullOrEmpty(SelectedYear))
                    SelectedYear = calendar.Year.ToString();



                SelectedWeek = 1;

            }
            if (flip2 == -1)
            {


                if (SelectedWeek == 1)
                {
                    SelectedWeek = 4;

                    if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 1)
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);
                        SelectedYear = ((Convert.ToInt32(SelectedYear)) - 1).ToString();
                    }
                    else
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);
                    }

                }
                else
                {
                    SelectedWeek--;
                }




            }

            if (flip2 == 1)
            {



                if (SelectedWeek == 4)
                {
                    SelectedWeek = 1;

                    if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 12)
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1);
                        SelectedYear = ((Convert.ToInt32(SelectedYear)) + 1).ToString();
                    }
                    else
                    {
                        SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month + 1);
                    }

                }
                else
                {
                    SelectedWeek++;
                }
            }
            int noOfDaysInTheSelectedMonth = 0;
            int shift = 0;
            string firstDay = String.Empty;


           

            if (SelectedWeek == 1)
            {
                //int noOfDaysInTheSelectedMonth = 0;
                //int shift = 0;
                //string firstDay = String.Empty;

                noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
                firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd");

                switch (firstDay)
                {
                    case "Sunday": shift = 0;
                        break;
                    case "Monday": shift = 1;
                        break;
                    case "Tuesday": shift = 2;
                        break;
                    case "Wednesday": shift = 3;
                        break;
                    case "Thursday": shift = 4;
                        break;
                    case "Friday": shift = 5;
                        break;
                    case "Saturday": shift = 6;
                        break;
                }

                int NumberOfPreviousMonthDays;
                string previuosMonth;
                string previousMonthYear;

                if (shift != 0)
                {

                    if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1)
                    {
                        NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);
                        previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                        previousMonthYear = SelectedYear;
                    }
                    else
                    {
                        NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12);
                        previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                        previousMonthYear = (Convert.ToInt32(SelectedYear) - 1).ToString();

                    }

                    for (int i = shift - 1; i >= 0; i--)
                    {
                        weekList.Add(new WeekDay { Year = previousMonthYear, Month = previuosMonth, Day = NumberOfPreviousMonthDays - i });
                    }

                    for (int i = 1; i <= 7 - shift; i++)
                    {
                        weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                        if (i == 7 - shift)
                        {
                            ReachedDayInWeeklyCalendar = weekList.Last();
                            StartDayInWeeklyCalendar = weekList.First();

                        }
                    }

                    LeftMonth = previuosMonth;
                    LeftYear = previousMonthYear;

                    RightMonth = SelectedMonth;
                    //  MonthNameTextBlock3.Text =SelectedMonth  ;
                    RightYear = selectedYear;
                }
                if (shift == 0)
                {
                    for (int i = 1; i <= 7; i++)
                    {

                        weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                        if (i == 7)
                        {
                            ReachedDayInWeeklyCalendar = weekList.Last();
                            StartDayInWeeklyCalendar = weekList.First();
                        }
                    }

                    LeftMonth = SelectedMonth;
                    LeftYear = SelectedYear;

                    RightMonth = String.Empty;
                    RightYear = String.Empty;
                }

                //fill dList

             
              //  weekList.Clear();


            }
            else if (SelectedWeek == 2 || SelectedWeek == 3 || SelectedWeek == 4)
            {
                if (!backward)
                {
                    for (int i = ReachedDayInWeeklyCalendar.Day + 1; i <= (ReachedDayInWeeklyCalendar.Day + 7); i++)
                    {
                        weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                        if (i == ReachedDayInWeeklyCalendar.Day + 7)
                        {
                            ReachedDayInWeeklyCalendar = weekList.Last();
                            StartDayInWeeklyCalendar = weekList.First();
                            break;
                        }
                    }



                }

                else //backward true
                {

                    if (StartDayInWeeklyCalendar.Day - 1 != 0)
                    {
                        for (int i = StartDayInWeeklyCalendar.Day - 7; i <= (StartDayInWeeklyCalendar.Day - 1); i++)
                        {

                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == StartDayInWeeklyCalendar.Day - 1)
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                                break;
                            }


                        }
                    }
                    else
                    {
                        if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1)
                        {
                            noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month);
                            //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            //SelectedYear = SelectedYear;
                        }
                        else
                        {
                            noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12);
                            //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);//
                            //SelectedYear = (Convert.ToInt32(SelectedYear) - 1).ToString();

                        }

                        for (int i = noOfDaysInTheSelectedMonth - 6; i <= (noOfDaysInTheSelectedMonth - 0); i++)
                        {

                            weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i });
                            if (i == (noOfDaysInTheSelectedMonth - 0))
                            {
                                ReachedDayInWeeklyCalendar = weekList.Last();
                                StartDayInWeeklyCalendar = weekList.First();
                                break;
                            }


                        }



                    }



                }


                LeftMonth = SelectedMonth;
                LeftYear = SelectedYear;
                RightMonth = String.Empty;
                RightYear = String.Empty;

               

            }




            for (int i = 0; i < 192; i++)
            {
                OutLookEvent[] myOEvent2 = null;
                OutLookEvent myOEvent = null;
                WorkHours wh = null;
                if (i % 8 == 0)
                {
                    dList.Add(new NameValueItem3() { timeItem = true, time = new TimeSpan(i / 8, 0, 0), Width = 1, timeStr = (new TimeSpan(i / 8, 0, 0)).ToString(), Color1 = "#BFB5DF", Width1 = 120 }); //( new TimeSpan(i / 8, 0, 0)).ToString()
                }

                else
                {

                    DateTime loopDate = new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                           DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                           weekList.ElementAt((i % 8) - 1).Day);

                    try
                    {
                        //  myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy"))).ToArray().First();
                        //   myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (e.start_time.TimeOfDay.Equals(new TimeSpan(i / 8, 0, 0)) || e.end_time.TimeOfDay >= (new TimeSpan(i / 8, 0, 0)))).ToArray().First();
                        //   myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (new TimeSpan(e.end_time.TimeOfDay.Hours,0,0) >= (new TimeSpan(i / 8, 0, 0)) || e.isAllDay == true)).ToArray().First();
                       // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))&&(TimeSpan)(e.end_time - e.start_time) <= new TimeSpan(1, 0, 0)))).ToArray().First();
                        myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray().First();
                        myOEvent2 = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray();
                    }
                    catch
                    {

                    }

                    try
                    {
                        wh  = whList.Where(w =>(( w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours<=(i / 8) && w.To.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.To.TimeOfDay.Hours>=(i / 8)) || ( w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours<=i / 8 && w.To.Date.Equals(loopDate.AddDays(1))) || (w.From.Date.Equals(loopDate.AddDays(-1).Date) && w.To.Date.Equals(loopDate.Date) && w.To.TimeOfDay.Hours >= (i/8)) || (w.TimeOffFrom.Date.Equals(loopDate.Date) && w.TimeOffFrom.TimeOfDay.Hours<=(i/8) && w.TimeOffTo.TimeOfDay.Hours>=(i/8) ) ) ).ToArray().First();
                    }
                    catch
                    {

                    }

                    dList.Add(new NameValueItem3()
                    {
                        timeItem = false,
                        time = new TimeSpan(i / 8, 0, 0),
                        Width = 3,
                        weekDay = weekList.ElementAt((i % 8) - 1),
                        Color1 = (myOEvent != null ? "Wheat" : "#BFB5DF"),
                        myOutLookEvent = myOEvent,
                        myOutLookEvent2 = myOEvent2,
                        workHours = wh,
                        Border = (myOEvent != null || wh != null ? new Thickness(1) : new Thickness(0)),
                        Color2 = (wh == null ? "#BFB5DF" : (wh.From.TimeOfDay.Hours == 7 ? "#99FF99" : (wh.From.TimeOfDay.Hours == 15 ? "#99CCFF" : (wh.From.TimeOfDay.Hours == 23 ? "Wheat" : "#BFB5DF")))),
                        Width1 = (myOEvent == null && wh != null ? 0 : (myOEvent != null && wh != null) ? 60 : 120),
                        Width2 = (wh != null && myOEvent == null ? 120 : (wh != null && myOEvent != null) ? 60 : 0),
                    });
                    if (i > 0 || i < 8)
                    {
                      //  if(myOEvent.isAllDay)
                        switch (i)
                        {
                            case 1: Sunday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Sunday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Sunday2.Text = String.Empty;
                                }
                                break;
                            case 2: Monday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                 DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                 weekList.ElementAt((i % 8) - 1).Day)
                                 ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Monday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Monday2.Text = String.Empty;
                                }
                                break;
                            case 3: Tuesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Tuesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Tuesday2.Text = String.Empty;
                                }
                                break;
                            case 4: Wednesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Wednesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Wednesday2.Text = String.Empty;
                                }
                                break;
                            case 5: Thursday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Thursday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Thursday2.Text = String.Empty;
                                }
                                break;
                            case 6: Friday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Friday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Friday2.Text = String.Empty;
                                }
                                break;
                            case 7:


                                Saturday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year),
                                DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month,
                                weekList.ElementAt((i % 8) - 1).Day)
                                ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day;
                                try
                                {
                                    Saturday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null);
                                }
                                catch
                                {
                                    Saturday2.Text = String.Empty;
                                }
                                break;


                        }
                        // weekList.ElementAt((i-1)%8)
                    }
                }
            }

            flip2 = 0;
            backward = false;
            WeekGridView.ItemsSource = dList;
            weekList.Clear();
            Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                WeekGridView.ScrollIntoView(dList.ElementAt(147));
            });


            myGrid.Opacity = 1;
            Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2);
            

        }
示例#27
0
 private void UpdateMinCalendarWithStep()
 {
     this.minCalendarWithStep = this.minCalendar.Clone();
     this.ApplyDateStepToMinCalendar();
     this.ApplyTimeStepToMinCalendar();
 }
        private void GetGeofenceStateChangedReports(Geoposition pos)
        {
            _geofenceBackgroundEvents.Clear();

            FillEventCollectionWithExistingEvents();

            GeofenceMonitor monitor = GeofenceMonitor.Current;

            Geoposition posLastKnown = monitor.LastKnownGeoposition;

            Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar();
            Windows.Globalization.DateTimeFormatting.DateTimeFormatter formatterLongTime;
            formatterLongTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("{hour.integer}:{minute.integer(2)}:{second.integer(2)}", new[] { "en-US" }, "US", Windows.Globalization.CalendarIdentifiers.Gregorian, Windows.Globalization.ClockIdentifiers.TwentyFourHour);

            bool eventOfInterest = true;

            // NOTE TO DEVELOPER:
            // Registered geofence events can be filtered out if the
            // geofence event time is stale.
            DateTimeOffset eventDateTime = pos.Coordinate.Timestamp;

            calendar.SetToNow();
            DateTimeOffset nowDateTime = calendar.GetDateTime();
            TimeSpan diffTimeSpan = nowDateTime - eventDateTime;

            long deltaInSeconds = diffTimeSpan.Ticks / oneHundredNanosecondsPerSecond;

            // NOTE TO DEVELOPER:
            // If the time difference between the geofence event and now is too large
            // the eventOfInterest should be set to false.

            if (true == eventOfInterest)
            {
                // NOTE TO DEVELOPER:
                // This event can be filtered out if the
                // geofence event location is too far away.
                if ((posLastKnown.Coordinate.Point.Position.Latitude != pos.Coordinate.Point.Position.Latitude) ||
                    (posLastKnown.Coordinate.Point.Position.Longitude != pos.Coordinate.Point.Position.Longitude))
                {
                    // NOTE TO DEVELOPER:
                    // Use an algorithm like the Haversine formula or Vincenty's formulae to determine
                    // the distance between the current location (pos.Coordinate)
                    // and the location of the geofence event (latitudeEvent/longitudeEvent).
                    // If too far apart set eventOfInterest to false to
                    // filter the event out.
                }

                if (true == eventOfInterest)
                {
                    string geofenceItemEvent = null;
                    int numEventsOfInterest = 0;

                    // Retrieve a vector of state change reports
                    var reports = GeofenceMonitor.Current.ReadReports();

                    foreach (var report in reports)
                    {
                        GeofenceState state = report.NewState;
                        geofenceItemEvent = report.Geofence.Id + " " + formatterLongTime.Format(eventDateTime);

                        if (state == GeofenceState.Removed)
                        {
                            GeofenceRemovalReason reason = report.RemovalReason;
                            if (reason == GeofenceRemovalReason.Expired)
                            {
                                geofenceItemEvent += " (Removed/Expired)";
                            }
                            else if (reason == GeofenceRemovalReason.Used)
                            {
                                geofenceItemEvent += " (Removed/Used)";
                            }
                        }
                        else if (state == GeofenceState.Entered)
                        {
                            geofenceItemEvent += " (Entered)";
                        }
                        else if (state == GeofenceState.Exited)
                        {
                            geofenceItemEvent += " (Exited)";
                        }

                        AddGeofenceEvent(geofenceItemEvent);

                        ++numEventsOfInterest;
                    }

                    if (true == eventOfInterest && 0 != numEventsOfInterest)
                    {
                        SaveExistingEvents();

                        // NOTE: Other notification mechanisms can be used here, such as Badge and/or Tile updates.
                        DoToast(numEventsOfInterest, geofenceItemEvent);
                    }
                }
            }
        }