Ejemplo n.º 1
0
        public ListeningEditViewModel(IUnityContainer container, IEventAggregator eventAggregator, IDataService dataService)
            : base(container, eventAggregator)
        {
            this.dataService = dataService;

            SubscribeEvents();

            SearchAlbumCommand = new DelegateCommand <object>(OnSearchAlbumCommand);
            CreatePlaceCommand = new DelegateCommand <object>(OnCreatePlaceCommand);
            CreateMoodCommand  = new DelegateCommand <object>(OnCreateMoodCommand);

            LoadDictionaries(() =>
            {
                if (Listening.IsNew)
                {
                    bool originalValue = Listening.NeedValidate;

                    Listening.NeedValidate = false; // force reset to avoid initial validation errors

                    Listening.Mood  = Moods.FirstOrDefault();
                    Listening.Place = Places.FirstOrDefault(); // restore to original value

                    Listening.NeedValidate = originalValue;
                }
            });
        }
Ejemplo n.º 2
0
        public bool NewToken(int number)
        {
            var tk = new Token(number.ToString(), Places.FirstOrDefault(p => p.Name.Contains("0")));

            Tokens.Add(tk);

            return(DbConn.Pn_InsertNewToken(tk));
        }
Ejemplo n.º 3
0
        public DynamicContentPlace GetContentPlaceById(string id)
        {
            var retVal = Places.FirstOrDefault(x => x.Id == id);

            if (retVal != null)
            {
                retVal.Folder = GetContentFolderById(retVal.FolderId);
            }
            return(retVal);
        }
Ejemplo n.º 4
0
        //An item has moved to the wp in question
        public bool NewEvent(Workplace wp, int ItemNumber)
        {
            var tk     = Tokens.FirstOrDefault(t => t.Name.Split('_')[1] == ItemNumber.ToString());
            var pl     = Places.FirstOrDefault(p => p.Name.Contains(wp.Number.ToString()));
            var prevPl = tk.Location;

            //Update Place
            prevPl.Capacity--;
            if (!DbConn.Pn_UpdateLocation(prevPl))
            {
                return(false);
            }
            pl.Capacity++;
            if (DbConn.Pn_UpdateLocation(pl))
            {
                return(false);
            }

            //Update Token
            tk.Location = pl;
            if (!DbConn.Pn_UpdateToken(tk))
            {
                return(false);
            }

            //Finding the transition and connectors between the places
            Connector first = null, second = null;

            foreach (var tr in Transitions)
            {
                var conns = Connectors.Where(c => c.Trans.IsEqual(tr));

                if (conns.Any(c => c.Pla.IsEqual(prevPl)) && conns.Any(c => c.Pla.IsEqual(pl)))
                {
                    first  = conns.Single(c => c.Pla.IsEqual(prevPl));
                    second = conns.Single(c => c.Pla.IsEqual(pl));
                }
            }

            if (first == null || second == null)
            {
                return(false);
            }

            //Create the event
            var ev = new Event(first, second, tk, DateTime.Now);

            if (!DbConn.Pn_InsertEvent(ev))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public void UpdateExistingEntries(List <DbTables.Place> entries)
        {
            foreach (var entry in entries)
            {
                //check existing entry, see if it requires being updated
                var existingData = Places.FirstOrDefault(md => md.SourceItemID == entry.SourceItemID && md.SourceItemType == entry.SourceItemType);
                if (existingData != null)
                {
                    if (existingData.AreaSize != entry.AreaSize)
                    {
                        existingData.AreaSize = entry.AreaSize;
                    }
                    if (existingData.GameElementName != entry.GameElementName)
                    {
                        existingData.GameElementName = entry.GameElementName;
                    }

                    bool expireTiles = false;
                    if (!existingData.ElementGeometry.EqualsTopologically(entry.ElementGeometry)) //TODO: this might need to be EqualsExact?
                    {
                        //update the geometry for this object.
                        existingData.ElementGeometry = entry.ElementGeometry;
                        expireTiles = true;
                    }
                    if (!existingData.Tags.OrderBy(t => t.Key).SequenceEqual(entry.Tags.OrderBy(t => t.Key)))
                    {
                        existingData.Tags = entry.Tags;
                        var styleA = TagParser.GetStyleForOsmWay(existingData.Tags);
                        var styleB = TagParser.GetStyleForOsmWay(entry.Tags);
                        if (styleA != styleB)
                        {
                            expireTiles = true; //don't force a redraw on tags unless we change our drawing rules.
                        }
                    }

                    if (expireTiles)   //geometry or style has to change, otherwise we can skip expiring values.
                    {
                        SaveChanges(); //save before expiring, so the next redraw absolutely has the latest data. Can't catch it mid-command if we do this first.
                        ExpireMapTiles(entry.ElementGeometry, "mapTiles");
                        ExpireSlippyMapTiles(entry.ElementGeometry, "mapTiles");
                    }
                }
                else
                {
                    //We don't have this item, add it.
                    Places.Add(entry);
                    SaveChanges(); //again, necessary here to get tiles to draw correctly after expiring.
                    ExpireMapTiles(entry.ElementGeometry, "mapTiles");
                    ExpireSlippyMapTiles(entry.ElementGeometry, "mapTiles");
                }
            }
            SaveChanges(); //final one for anything not yet persisted.
        }
Ejemplo n.º 6
0
        public void GenerateEventsIntoDb(int count)
        {
            //Creating an amount of items on the entry
            int indexOfFirstPlace = Places.IndexOf(Places.FirstOrDefault(p => p.Name == "p0"));

            for (var i = 0; i < count; i++)
            {
                var tk = new Token("Token_" + i.ToString(), Places.ElementAt(indexOfFirstPlace));
                Tokens.Add(tk);
                Places.ElementAt(indexOfFirstPlace).Capacity++;

                DbConn.Pn_InsertNewToken(tk);

                Event ev = GenerateNextEvent(Tokens.Last());
                //DbConn.Pn_InsertEvent(ev);

                while (ev != null)
                {
                    DbConn.Pn_InsertEvent(ev);
                    ev = GenerateNextEvent(Tokens.Last());
                }
            }
        }
Ejemplo n.º 7
0
        private Event GenerateNextEvent(Token tk)
        {
            Event retVal;
            var   rnd = new Random();

            //To continue, or not to continue
            if (rnd.Next(1, 3) < 1 || tk.Location.Name == "p6")
            {
                return(null);
            }

            //The place were at
            var pl = Places.FirstOrDefault(p => p.IsEqual(tk.Location));

            Places.FirstOrDefault(p => p.IsEqual(tk.Location)).Capacity--;

            //Getting the connectors out of the place
            var conns = Connectors.Where(c => c.Pla.IsEqual(pl) && c.Direction == ConnectorDirection.PlTr);
            //Drafting the connector to select
            var firstConn = conns.ElementAt(rnd.Next(0, conns.Count() - 1));
            var tr        = Transitions.Single(t => t.IsEqual(firstConn.Trans));
            //Getting the connector leaving from the transition (should be single)
            var secoConn = Connectors.Single(c => c.Trans.IsEqual(tr) && c.Direction == ConnectorDirection.TrPl);

            //Increasing the capacity of the target place, and updating the location of the token
            tk.Location = Places.Single(p => p.IsEqual(secoConn.Pla));
            Places.Single(p => p.IsEqual(secoConn.Pla)).Capacity++;

            //Sending the updated data to the DB
            DbConn.Pn_UpdateToken(tk);
            DbConn.Pn_UpdateLocation(Places.Single(p => p.IsEqual(secoConn.Pla)));

            retVal = new Event(firstConn, secoConn, tk);

            return(retVal);
        }
Ejemplo n.º 8
0
 public PlaceDef GetPlace(string id)
 {
     return(Places.FirstOrDefault(x => x.Id == id));
 }
Ejemplo n.º 9
0
        private Place FindPlace(ObjectId placeId)
        {
            var findPlace = Places.FirstOrDefault(p => p.PlaceId == placeId);

            return(findPlace);
        }