예제 #1
0
 public void AddClock(ClockInfo info)
 {
     if (!Clocks.Contains(info))
     {
         Clocks.Add(info);
     }
 }
예제 #2
0
        private async void InitializeLocation()
        {
            try
            {
                IsLoading = true;
                var pos = await _geolocator.GetGeopositionAsync();

                var cities = await _citiesRepository.Get();

                var city = cities.FirstOrDefault(c => Math.Abs(c.Latitude - pos.Coordinate.Latitude) < 0.03 && Math.Abs(c.Longitude - pos.Coordinate.Longitude) < 0.03);
                CurrentCity = city;
                var clockInfo = new ClockInfo
                {
                    CityName    = city.Name,
                    CountryCode = city.CountryCode,
                    CountryName = city.CountryName,
                    TimeZoneId  = city.TimeZoneId
                };
                CurrentTime = DependencyResolver.Resolve <ClockViewModel>(new Tuple <string, object>("info", clockInfo));
                Status      = _geolocator.LocationStatus;
            }
            catch
            {
                Status = PositionStatus.NotAvailable;
            }
            finally
            {
                IsLoading = false;
            }
        }
예제 #3
0
            public static ClockInfo FromHashEntries(HashEntry[] hashEntries)
            {
                var clock = new ClockInfo();

                foreach (var entry in hashEntries)
                {
                    switch ((string)entry.Name)
                    {
                    case "DeviceId":
                        clock.DeviceId = entry.Value;
                        break;

                    case "SerialNumber":
                        clock.SerialNumber = entry.Value;
                        break;

                    case "ClientId":
                        clock.ClientId = (int)entry.Value;
                        break;

                    case "ClockGroupId":
                        clock.ClockGroupId = Guid.Parse(entry.Value);
                        break;
                    }
                }

                return(clock);
            }
예제 #4
0
        /// <summary>
        ///     Using Extensions
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        private static async Task GenerateClocks(IRedisDatabase db)
        {
            var sw = Stopwatch.StartNew();

            var allClocks = new Dictionary <string, ClockInfo>();
            var random    = new Random();

            for (var i = 0; i < Total; i++)
            {
                var partition = $"GT-{i}";
                var clock     = new ClockInfo
                {
                    DeviceId     = partition,
                    SerialNumber = partition.ToLower(),
                    ClientId     = random.Next(10000, 99999),
                    ClockGroupId = Guid.NewGuid()
                };
                allClocks.Add(partition, clock);
            }

            await db.HashSetAsync("clocksPartition1", allClocks);

            await db.UpdateExpiryAsync("clocksPartition1", DateTimeOffset.Now.AddMinutes(5));

            Console.WriteLine($"Storing {Total} (v2): {Math.Round(sw.Elapsed.TotalMilliseconds)}ms");
        }
예제 #5
0
 public ClockViewModel(ClockInfo info, TimeShiftProvider timeShiftProvider)
 {
     _info = info;
     _timeShiftProvider = timeShiftProvider;
     _timeZoneService   = TimeZoneService.FindSystemTimeZoneById(_info.TimeZoneId);
     _timer.Tick       += OnTimerTick;
     Delete             = new RelayCommand(() => ViewModelStorage.Main.DeleteClock(_info)); //Clean-up
     CalculateTime();
     _timeShiftProvider.PropertyChanged += (s, e) => CalculateTime();
 }
예제 #6
0
        public void DeleteClock(ClockInfo clock)
        {
            if (!Clocks.Contains(clock))
            {
                return;
            }

            Clocks.Remove(clock);

            //NOTE: Need a way to cleanup
        }
예제 #7
0
 public ClockInfo GetClock(int id)
 {
     for (int i = 0; i < clocks.Count; i++)
     {
         ClockInfo clock = clocks[i];
         if (clock.id == id)
         {
             return(clock);
         }
     }
     return(null);
 }
예제 #8
0
 public void RemoveClock(int id)
 {
     for (int i = 0; i < clocks.Count; i++)
     {
         ClockInfo clock = clocks[i];
         if (clock.id == id)
         {
             clocks.Remove(clock);
             return;
         }
     }
 }
예제 #9
0
 public void SetClock(ClockInfo clockInfo)
 {
     for (int i = 0; i < clocks.Count; i++)
     {
         ClockInfo clock = clocks[i];
         if (clock.id == clockInfo.id)
         {
             clocks [i] = clockInfo;
             return;
         }
     }
     clocks.Add(clockInfo);
 }
예제 #10
0
        private void OnSearchPaneResultSuggestionChosen(SearchPane sender, SearchPaneResultSuggestionChosenEventArgs args)
        {
            var id     = int.Parse(args.Tag);
            var result = _cities.Single(x => x.Id == id);
            var info   = new ClockInfo
            {
                CityName    = result.Name,
                TimeZoneId  = result.TimeZoneId,
                CountryCode = result.CountryCode,
                CountryName = result.CountryName
            };

            AddClock(info);
        }
예제 #11
0
    private void Tick()
    {
        int currentSecond = ConvertDateTimeInt(DateTime.Now);

        for (int i = 0; i < clocks.Count; i++)
        {
            ClockInfo clock = clocks[i];
            clock.Correct(currentSecond);
        }

        if (clockEvent != null && clocks.Count > 0)
        {
            clockEvent(clocks);
        }

        LeanTween.delayedCall(1, Tick);
    }
예제 #12
0
    private void OnClockEvent(List <ClockInfo> clocks)
    {
        if (energyInfo.count >= energyInfo.limit)
        {
            coutDownText.text = "";
        }
        else
        {
            ClockInfo energyClock = ClockModel.Instance.GetClock((int)WealthTypeEnum.Energy);

            if (energyClock != null)
            {
                coutDownText.text = "" + ((int)GameModel.Instance.GetGameConfig(1004) - energyClock.value) + "s +1";
            }
            else
            {
                coutDownText.text = "";
            }
        }
    }
        private void OnResultSelected(object sender, ItemClickEventArgs e)
        {
            var id     = (e.ClickedItem as SearchResult).Id;
            var result = _cities.Single(x => x.Id == id);
            var info   = new ClockInfo
            {
                CityName    = result.Name,
                TimeZoneId  = result.TimeZoneId,
                CountryCode = result.CountryCode,
                CountryName = result.CountryName
            };

            ViewModelStorage.Main.AddClock(info);

            var previousContent = Window.Current.Content;
            var frame           = previousContent as Frame;

            frame.Navigate(typeof(MainPage));
            Window.Current.Content = frame;

            Window.Current.Activate();
        }
예제 #14
0
        private static async Task LookupSingleItem2(IDatabaseAsync db)
        {
            var sw = Stopwatch.StartNew();

            var random = new Random();

            for (var i = 0; i < 100; i++)
            {
                var id = $"GT-{random.Next(0, Total)}";

                var entries = await db.HashGetAllAsync($"clock:{id}");

                var clock = ClockInfo.FromHashEntries(entries);

                if (clock == null)
                {
                    Console.WriteLine("not found");
                }
            }

            Console.WriteLine($"Looking up single item a 100 times (v1): {Math.Round(sw.Elapsed.TotalMilliseconds)}ms");
        }
예제 #15
0
        /// <summary>
        ///     Using HashSetAsync
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        private static async Task GenerateClocks(IDatabaseAsync db)
        {
            var sw     = Stopwatch.StartNew();
            var random = new Random();

            for (var i = 0; i < Total; i++)
            {
                var id    = $"GT-{i}";
                var clock = new ClockInfo
                {
                    DeviceId     = id,
                    SerialNumber = id.ToLower(),
                    ClientId     = random.Next(10000, 99999),
                    ClockGroupId = Guid.NewGuid()
                };
                await db.HashSetAsync($"clock:{id}", clock.ToHashEntries());

                await db.KeyExpireAsync($"clock:{id}", DateTime.Now.AddMinutes(5));
            }

            Console.WriteLine(
                $"Storing {Total} Using original HashSetAsync (v1): {Math.Round(sw.Elapsed.TotalMilliseconds, 3)}ms");
        }
예제 #16
0
    private void OnClockEvent(List <ClockInfo> clocks)
    {
        for (int i = 0; i < clocks.Count; i++)
        {
            ClockInfo clock = clocks[i];
            if (clock.id == (int)WealthTypeEnum.Energy)
            {
                WealthInfo energyInfo = GetWealth((int)WealthTypeEnum.Energy);
                if (energyInfo.count < energyInfo.limit)
                {
                    float ENERGY_RECOVER = GameModel.Instance.GetGameConfig(1004);
                    if (clock.value >= ENERGY_RECOVER)
                    {
                        int recoverCount = (int)Math.Floor(clock.value / ENERGY_RECOVER);
                        if ((energyInfo.limit - energyInfo.count) > recoverCount)
                        {
                            energyInfo.count = energyInfo.count + (int)recoverCount;
                        }
                        else
                        {
                            energyInfo.count = energyInfo.limit;
                        }
                        PlayerModel.Instance.SaveWealths();
                        PlayerPrefsUtil.SetInt(PlayerPrefsUtil.ENERGY_OUT_TIME, ClockModel.ConvertDateTimeInt(System.DateTime.Now));

                        int leftTime = (int)(clock.value % ENERGY_RECOVER);
                        ClockModel.Instance.SetClock(new ClockInfo((int)WealthTypeEnum.Energy, leftTime));
                    }
                }
                else
                {
                    ClockModel.Instance.RemoveClock(clock.id);
                }
                return;
            }
        }
    }
예제 #17
0
 public MainClockViewModel(IClockService clockService)
 {
     MainClockInfo = clockService.MainClockInfo;
 }