Exemple #1
0
        /// <summary>
        /// Load data from the database
        /// </summary>
        public void LoadData()
        {
            Dto = new Dto2Object()
            {
                Zones = new List <PolyZone>()
            };

            int count = 0;

            if (MaxZones > 0)
            {
                count = MaxZones;
            }
            else
            {
                count = Sql.Instance.GetZoneCount();
            }

            var current = 0;

            Sql.Instance.LoadZones((zone) => {
                Dto.Zones.Add(zone);
                current++;

                ConsoleKit.Message(ConsoleKit.MessageType.INFO, "Loading {0}/{1} zones\t\r", current, count);
                return(true);
            }, count);
            Console.Write("\n");
        }
Exemple #2
0
        /// <summary>
        /// Constructs Polygon objects that GMap.NET will use
        /// to display and draw the map control
        /// </summary>
        /// <param name="dto">Data transfer object</param>
        public void ConstructGui(Dto2Object dto = null)
        {
            if (dto != null)
            {
                _dtoObject = dto;
            }
            else if (_dtoObject == null)
            {
                return;
            }


            UnloadSession();
            foreach (var zone in _dtoObject.Zones)
            {
                var polygonPoints = zone.Geometry.Select(m => new GMap.NET.PointLatLng(m.Lat, m.Lng)).ToList();
                var polygonColor  = ColorTranslator.FromHtml(zone.Color);

                _polygons.Polygons.Add(new Polygon(polygonPoints, zone.Description)
                {
                    Tag = zone,
                    IsHitTestVisible = true,
                    Fill             = new SolidBrush(Color.FromArgb(ZoneOpacity, polygonColor)),
                    Stroke           = new Pen(polygonColor)
                    {
                        Width = 2
                    }
                });
            }
            UpdateVerticlesCount();
        }
Exemple #3
0
        /// <summary>
        /// Save polygon data to a file
        /// </summary>
        /// <param name="file"></param>
        public void SavePolygons(string file)
        {
            var data = new Dto2Object()
            {
                Type  = "ZoneCollection",
                Zones = new List <PolyZone>()
            };

            data.Zones.AddRange(_polygons.Polygons.Select(x => (PolyZone)x.Tag));
            File.WriteAllText(file, JsonConvert.SerializeObject(data));
        }
        /// <summary>
        /// Sets default values for each important attribute
        /// and shows the login form
        /// </summary>
        private void OnFormLoad()
        {
            Text = "ParkPlaces Editor";

            Map.UnloadSession(true);

            var loginForm = new LoginForm();

            if (loginForm.ShowDialog(this) != DialogResult.OK)
            {
                Application.Exit();
                return;
            }

            Text         += $" / Logged in as {loginForm.User.UserName}, with {loginForm.User.GroupRole} rights /";
            _loggedInUser = loginForm.User;

            var offlineMode = Client.Instance.GetOfflineMode();

            Map.SetReadOnly(loginForm.User.GroupRole < GroupRole.Editor);
            Map.SetPositionByKeywords("Szeged");

            if (!offlineMode)
            {
                var loadingForm = new LoadingForm();
                loadingForm.OnReadyEventHandler += (s, dto) =>
                {
                    Map.ConstructGui(dto);
                    Show();
                };

                loadingForm.LoadDataAsync();
                loadingForm.ShowDialog();
            }
            else
            {
                var dto = new Dto2Object
                {
                    Zones = new List <PolyZone>(),
                    Type  = "ZoneCollection"
                };

                Map.ConstructGui(dto);
                Show();
            }
        }
Exemple #5
0
        public async void LoadDataAsync()
        {
            // Get zones count
            await Task.Run(() => {
                Client.Instance.Send(new ZoneCountReq());
                _manualResetEvent.WaitOne();
            });

            _manualResetEvent.Reset();

            // Get zones
            _dto = new Dto2Object
            {
                Type  = "ZoneCollection",
                Zones = new List <PolyZone>()
            };

            if (_zoneCount > 0)
            {
                Client.Instance.Send(new ZoneListReq());

                // Wait for all the data to arrive
                _manualResetEvent = new ManualResetEvent(false);
                await Task.Run(() => {
                    _manualResetEvent.WaitOne();
                });

                _manualResetEvent.Reset();
            }

            OnReadyEventHandler?.Invoke(this, _dto);

            Client.Instance.OnZoneCountAck -= OnZoneCountAck;
            Client.Instance.OnZoneListAck  -= OnZoneListAck;

            Close();
        }
Exemple #6
0
 public static string ToJson(this Dto2Object self) => JsonConvert.SerializeObject(self, Converter.Settings);