Пример #1
0
        public void AddCoordinates(List <coordinate> coords)
        {
            // Reset Coords
            Coords.Clear();

            // Add each Site
            foreach (var coord in coords)
            {
                _coord c = new _coord();
                c.id      = coord.ID;
                c.placeId = coord.idPlaceInMap;
                double.TryParse(coord.longitude, out c._x);
                double.TryParse(coord.latitude, out c._y);
                c.x = coord.longitude.ToString();
                c.y = coord.latitude.ToString();
                // add to Coords
                Coords.Add(c);

                // Adjust Site's Coord List
                _site site = getSite(coord.idPlaceInMap);
                // assert site is valid
                //Debug.Assert(site != null);
                site.coords.Add(c);
            }

            // prepare Json String for Coordinations
            prepare_Coord_JsonString();
        }
Пример #2
0
        public void UpdateSite(List <rvsite_status_view> status)
        {
            // update site poly_color
            foreach (var s in status)
            {
                _site site = getSite(s.id);     // to optimize search, you can use sort and search algo
                // assert site is valid
                //Debug.Assert(site != null);

                if (s.isAvaialable == 0)
                {
                    site.isAvailable = false;
                    if (s.ReservedFrom != null)
                    {
                        site.poly_color = _reservedColor;
                    }
                    else
                    {
                        site.poly_color = _selectedColor;
                    }
                }

                // if you want to expand information coverage of _site, you can add here.
                //   e.g., reservation info, out of service, etc..
            }
        }
Пример #3
0
        private void doFetchUpdate2()
        {
            while (stopFromParent == false)
            {
                // fetch from database
                Random rnd = new Random();
                int    id  = rnd.Next(firstSiteId, lastSiteId);
                int    id2 = rnd.Next(firstSiteId, lastSiteId);

                _site s  = getSite(id);
                _site s2 = getSite(id2);
                if (s != null && s2 != null)
                {
                    s.poly_color  = _dimGrayRGB;
                    s2.poly_color = _dimGrayRGB;


                    DateTime now = DateTime.Now;
                    //now = DateTime.Now;

                    // update Updates List with lock & monitor
                    lock (Updates)
                    {
                        while (locked == true)     // Block this thread Until other thread call pulse
                        {
                            Monitor.Wait(Updates); // Stay as WaitSleepJoin State
                        }
                        locked = true;

                        // pop updates after UpdateKeepSpan from tail
                        for (int i = 0; i < Updates.Count;)
                        {
                            if (now - Updates[0].lastUpdateTime > UpdateKeepSpan)
                            {
                                Updates.RemoveAt(0);
                            }
                            else
                            {
                                break;
                            }
                        }

                        // push new updates to head
                        Updates.Add(new _siteUpdate {
                            id = id, fillColor = s.poly_color, lastUpdate = DateTime.Now.ToString(), lastUpdateTime = DateTime.Now
                        });
                        Updates.Add(new _siteUpdate {
                            id = id2, fillColor = s2.poly_color, lastUpdate = DateTime.Now.ToString(), lastUpdateTime = DateTime.Now
                        });

                        // Wake other thread
                        locked = false;
                        Monitor.Pulse(Updates);
                    }
                }

                Thread.Sleep(updateInterval);
            }
        }
Пример #4
0
        public void SetPlaceIdInCoords()
        {
            foreach (var c in Coords)
            {
                _site site = getSite(c.siteTag);
                // assert site is valid
                Debug.Assert(site != null);

                // update site id
                c.placeId = site.id;
            }
        }
Пример #5
0
        public void AddSite(List <placeinmap> places)
        {
            // reset site id;
            firstSiteId = int.MaxValue;
            lastSiteId  = 0;

            // Reset Sites
            Sites.Clear();

            // Add each Site
            foreach (var place in places)
            {
                _site s = new _site();
                s.id      = place.ID;
                s.eventId = (int)place.idIPMEvent;
                s.name    = place.site;
                s.tag     = place.tag;
                s.typeId  = place.idSiteType;

                // Adjust Site's style and type
                // check this later
                // type is more than style ????
                // get type
                s.type = getType(s.typeId);
                // assert site is valid
                Debug.Assert(s.type != null);
                // get style
                s.style = getStyle(s.type.styleId);
                // assert site's style is valid
                Debug.Assert(s.style != null);

                s.poly_color = s.style.poly_color;
                s.size       = getSize(s.type.sizeId);
                s.service    = getService(s.type.serviceId);

                // increase styleurl's sites count
                s.style.siteCount++;

                // add to Sites
                Sites.Add(s);
                // for test
                lastSiteId  = lastSiteId < (int)s.id ? (int)s.id : lastSiteId;
                firstSiteId = firstSiteId > (int)s.id ? (int)s.id : firstSiteId;
            }
        }
Пример #6
0
        private void resetUpdate()
        {
            // fetch from database
            Random rnd = new Random();
            int    id  = rnd.Next(firstSiteId, lastSiteId);
            int    id2 = rnd.Next(firstSiteId, lastSiteId);

            _site s = getSite(id);

            if (s != null)
            {
                s.poly_color = "ffff0000";
                _site s2 = getSite(id2);
                s2.poly_color = "ffff0000";

                DateTime now = DateTime.UtcNow;

                // pop updates after UpdateKeepSpan from tail
                for (int i = 0; i < Updates.Count;)
                {
                    if (now - Updates[0].lastUpdateTime > UpdateKeepSpan)
                    {
                        Updates.RemoveAt(0);
                    }
                    else
                    {
                        break;
                    }
                }

                // push new updates to head
                Updates.Add(new _siteUpdate {
                    id = id, fillColor = s.poly_color, lastUpdate = DateTime.UtcNow.ToString(), lastUpdateTime = now
                });
                Updates.Add(new _siteUpdate {
                    id = id2, fillColor = s2.poly_color, lastUpdate = DateTime.UtcNow.ToString(), lastUpdateTime = now
                });
            }
        }
Пример #7
0
        public void AddSite(List<placeinmap> places)
        {
            // reset site id;
            firstSiteId = int.MaxValue;
            lastSiteId = 0;

            // Reset Sites
            Sites.Clear();

            // Add each Site
            foreach (var place in places)
            {
                _site s = new _site();
                s.id = place.ID;
                s.eventId = (int)place.idIPMEvent;
                s.name = place.site;
                s.tag = place.tag;
                s.typeId = place.idSiteType;

                // Adjust Site's style and type
                // check this later 
                // type is more than style ????
                // get type
                s.type = getType(s.typeId);
                // assert site is valid
                Debug.Assert(s.type != null);
                // get style
                s.style = getStyle(s.type.styleId);
                // assert site's style is valid
                Debug.Assert(s.style != null);

                s.poly_color = s.style.poly_color;
                s.size = getSize(s.type.sizeId);
                s.service = getService(s.type.serviceId);

                // increase styleurl's sites count
                s.style.siteCount++;

                // add to Sites
                Sites.Add(s);
                // for test
                lastSiteId = lastSiteId < (int)s.id ? (int)s.id : lastSiteId;
                firstSiteId = firstSiteId > (int)s.id ? (int)s.id : firstSiteId;
            }
        }
Пример #8
0
        public void Parse(XDocument xDoc, long eventId)
        {
            // reset data lists
            polys.Reset();

            // get Root Namespace
            string xNs = "{" + xDoc.Root.Name.Namespace.ToString() + "}";

            // style parsing
            var styleList = from s in xDoc.Descendants(xNs + "Style")
                            select s;

            foreach (var i in styleList)
            {
                _style newStyle = new _style();
                newStyle.styleUrl = "#" + i.Attribute("id").Value;
                newStyle.eventId = eventId;
                newStyle.label_color = i.Element(xNs + "LabelStyle").Element(xNs + "color").Value;
                newStyle.line_color = i.Element(xNs + "LineStyle").Element(xNs + "color").Value;
                newStyle.poly_color = i.Element(xNs + "PolyStyle").Element(xNs + "color").Value;

                polys.Styles.Add(newStyle);
            }

            // _site parsing
            var coordsStr = from f in xDoc.Descendants(xNs + "Placemark")
                                // where elementToFind.Contains(f.Parent.Element(xNs + "name").Value + f.Element(xNs + "name").Value)
                                //select f.Element(xNs + "LineString").Element(xNs + "coordinates");
                            select f;
            int siteID = 1;
            foreach (var i in coordsStr)
            {
                var y = i.Element(xNs + "MultiGeometry").Descendants(xNs + "Polygon").Descendants(xNs + "outerBoundaryIs").Descendants(xNs + "LinearRing").Descendants(xNs + "coordinates");
                char[] delemeters = { ',', ' ' };
                // create new site
                _site newSite = new _site();
                newSite.style = polys.GetStyle(i.Element(xNs + "styleUrl").Value);
                newSite.styleUrl = newSite.style.styleUrl;
                newSite.eventId = eventId;
                newSite.id = siteID++;
                newSite.name = i.Element(xNs + "name").Value;
                newSite.tag = i.Attribute("id").Value;
                var tmpCoords = y.ElementAt(0).Value.ToString().TrimStart().Split(delemeters).ToList();
                while (tmpCoords.Remove("0"))
                    ;

                // assert even count 
                Debug.Assert((tmpCoords.Count % 2) == 0);

                for (int j = 0; j < tmpCoords.Count; j += 2)
                {
                    _coord c = new _coord();
                    c._x = double.Parse(tmpCoords[j]);
                    c._y = double.Parse(tmpCoords[j + 1]);
                    c.x = tmpCoords[j];
                    c.y = tmpCoords[j + 1];
                    c.placeId = newSite.id;
                    c.eventId = eventId;
                    c.seqCoordinate = (j / 2) + 1;
                    c.siteTag = newSite.tag;
                    newSite.coords.Add(c);
                    polys.Coords.Add(c);
                }

                polys.Sites.Add(newSite);
                // style site count add
                newSite.style.siteCount++;
            }
            Console.WriteLine(coordsStr.Count());

        }
Пример #9
0
        private void doFetchUpdate()
        {
            while (stopFromParent == false)
            {
                // get list of _reserve_selection from database
                List <_reserve_selection> updates;
                MySqlReader.GetSiteUpdate(lastUpdateTime, out updates);

                // prepare to remove old _siteUpdate object
                DateTime now = DateTime.UtcNow;

                // update Updates List with lock & monitor
                lock (Updates)
                {
                    while (locked == true)     // Block this thread Until other thread call pulse
                    {
                        Monitor.Wait(Updates); // Stay as WaitSleepJoin State
                    }
                    locked = true;

                    // pop updates after UpdateKeepSpan from tail
                    for (int i = 0; i < Updates.Count;)
                    {
                        if (now - Updates[0].lastUpdateTime > UpdateKeepSpan)
                        {
                            Updates.RemoveAt(0);
                        }
                        else
                        {
                            break;
                        }
                    }

                    // insert new update
                    foreach (var u in updates)
                    {
                        _site  s          = getSite(u.id);
                        string site_color = "";
                        if (s != null)
                        {
                            if (u.removed)
                            {
                                site_color = s.style.poly_color;
                            }
                            else if (u.type == _reserve_selection._type.reservation)
                            {
                                site_color = _reservedColor;
                            }
                            else
                            {
                                site_color = _selectedColor;
                            }
                            // insert new _siteUpdate
                            Updates.Add(new _siteUpdate {
                                id = u.id, fillColor = site_color, lastUpdate = u.lastUpdateString, lastUpdateTime = u.lastUpdate
                            });
                            // update site poly_color
                            s.poly_color = site_color;
                        }
                        // update last check time
                        lastUpdateTime = u.lastUpdate;
                    }

                    // Wake other thread
                    locked = false;
                    Monitor.Pulse(Updates);
                }

                Thread.Sleep(updateInterval);
            }
        }
Пример #10
0
        public void Parse(XDocument xDoc, long eventId)
        {
            // reset data lists
            polys.Reset();

            // get Root Namespace
            string xNs = "{" + xDoc.Root.Name.Namespace.ToString() + "}";

            // style parsing
            var styleList = from s in xDoc.Descendants(xNs + "Style")
                            select s;

            foreach (var i in styleList)
            {
                _style newStyle = new _style();
                newStyle.styleUrl    = "#" + i.Attribute("id").Value;
                newStyle.eventId     = eventId;
                newStyle.label_color = i.Element(xNs + "LabelStyle").Element(xNs + "color").Value;
                newStyle.line_color  = i.Element(xNs + "LineStyle").Element(xNs + "color").Value;
                newStyle.poly_color  = i.Element(xNs + "PolyStyle").Element(xNs + "color").Value;

                polys.Styles.Add(newStyle);
            }

            // _site parsing
            var coordsStr = from f in xDoc.Descendants(xNs + "Placemark")
                            // where elementToFind.Contains(f.Parent.Element(xNs + "name").Value + f.Element(xNs + "name").Value)
                            //select f.Element(xNs + "LineString").Element(xNs + "coordinates");
                            select f;
            int siteID = 1;

            foreach (var i in coordsStr)
            {
                var    y          = i.Element(xNs + "MultiGeometry").Descendants(xNs + "Polygon").Descendants(xNs + "outerBoundaryIs").Descendants(xNs + "LinearRing").Descendants(xNs + "coordinates");
                char[] delemeters = { ',', ' ' };
                // create new site
                _site newSite = new _site();
                newSite.style    = polys.GetStyle(i.Element(xNs + "styleUrl").Value);
                newSite.styleUrl = newSite.style.styleUrl;
                newSite.eventId  = eventId;
                newSite.id       = siteID++;
                newSite.name     = i.Element(xNs + "name").Value;
                newSite.tag      = i.Attribute("id").Value;
                var tmpCoords = y.ElementAt(0).Value.ToString().TrimStart().Split(delemeters).ToList();
                while (tmpCoords.Remove("0"))
                {
                    ;
                }

                // assert even count
                Debug.Assert((tmpCoords.Count % 2) == 0);

                for (int j = 0; j < tmpCoords.Count; j += 2)
                {
                    _coord c = new _coord();
                    c._x            = double.Parse(tmpCoords[j]);
                    c._y            = double.Parse(tmpCoords[j + 1]);
                    c.x             = tmpCoords[j];
                    c.y             = tmpCoords[j + 1];
                    c.placeId       = newSite.id;
                    c.eventId       = eventId;
                    c.seqCoordinate = (j / 2) + 1;
                    c.siteTag       = newSite.tag;
                    newSite.coords.Add(c);
                    polys.Coords.Add(c);
                }

                polys.Sites.Add(newSite);
                // style site count add
                newSite.style.siteCount++;
            }
            Console.WriteLine(coordsStr.Count());
        }