Exemple #1
0
        internal override void Link()
        {
            if (ParentCiv?.Entity != null)
            {
                if (ParentCiv.Entity.Children == null)
                {
                    ParentCiv.Entity.Children = new ConcurrentBag <Entity>();
                }
                if (!ParentCiv.Entity.Children.Contains(this))
                {
                    ParentCiv.Entity.Children.Add(this);
                }
                if (ChildrenIDs != null)
                {
                    foreach (var child in ChildrenIDs)
                    {
                        if (Children == null)
                        {
                            Children = new ConcurrentBag <Entity>();
                        }
                        if (World.Entities.ContainsKey(child))
                        {
                            Children.Add(World.Entities[child]);
                        }
                    }
                }
            }

            if (EntityLinks != null && EntityLinks.ContainsKey(EntityEntityLink.LinkTypes.IndexOf("PARENT")))
            {
                if (EntityLinks[EntityEntityLink.LinkTypes.IndexOf("PARENT")].Count == 1)
                {
                    var parentEnt = EntityLinks[EntityEntityLink.LinkTypes.IndexOf("PARENT")][0].Target;
                    if (parentEnt.Civilization != null)
                    {
                        ParentCiv = parentEnt.Civilization;
                    }
                    else if (parentEnt.ParentCiv != null)
                    {
                        ParentCiv = parentEnt.ParentCiv;
                    }
                }
            }

            if (WorshipHfid.HasValue && World.HistoricalFigures.ContainsKey(WorshipHfid.Value))
            {
                WorshipHf = World.HistoricalFigures[WorshipHfid.Value];
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="entityName"></param>
        /// <param name="dataMsg"></param>
        /// <returns></returns>
        public Message SaveLookup(WebOperationContext ctx, string entityName, Message dataMsg)
        {
            Message responseMsg = null;
            string  jsonData    = JSON.GetPayload(dataMsg);

            try
            {
                switch (entityName)
                {
                case "EntityLinks":
                    EntityLinks entityLinks = this.SaveLookup <EntityLinks>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <EntityLinks>(ctx, entityLinks, this.timer);
                    break;

                case "EventLogging":
                    EventLogger eventLogger = this.SaveLookup <EventLogger>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <EventLogger>(ctx, eventLogger, this.timer);
                    break;

                case "KPAdmins":
                    Admin kpAdmin = this.SaveLookup <Admin>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <Admin>(ctx, kpAdmin, this.timer);
                    break;

                case "KPCategoryL1":
                    CategoryL1 kpCatL1 = this.SaveLookup <CategoryL1>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <CategoryL1>(ctx, kpCatL1, this.timer);
                    break;

                case "KPCategoryL2":
                    CategoryL2 kpCatL2 = this.SaveLookup <CategoryL2>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <CategoryL2>(ctx, kpCatL2, this.timer);
                    break;

                case "KPConfigList":
                    ConfigList kpConfigList = this.SaveLookup <ConfigList>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <ConfigList>(ctx, kpConfigList, this.timer);
                    break;

                //case "KPCountry":
                //    Country kpCountry = this.SaveLookup<Country>(entityName, jsonData);
                //    responseMsg = ctx.CreateJsonResponse<Country>(kpCountry);
                //    break;
                case "KPCustomers":
                    Customer kpCustomers = this.SaveLookup <Customer>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <Customer>(ctx, kpCustomers, this.timer);
                    break;

                //case "KPEffortInstances":
                //    EffortInstance kpEffortInstances = this.SaveLookup<EffortInstance>(entityName, jsonData);
                //    responseMsg = ctx.CreateJsonResponse<EffortInstance>(kpEffortInstances);
                //    break;
                //case "KPEfforts":
                //    Effort kpEfforts = this.SaveLookup<Effort>(entityName, jsonData);
                //    responseMsg = ctx.CreateJsonResponse<Effort>(kpEfforts);
                //    break;
                case "KPGoalSetLocks":
                    GoalSetLock kpGoalSetLock = this.SaveLookup <GoalSetLock>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <GoalSetLock>(ctx, kpGoalSetLock, this.timer);
                    break;

                case "KPGoalSets":
                    GoalSet kpGoalSet = this.SaveLookup <GoalSet>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <GoalSet>(ctx, kpGoalSet, this.timer);
                    break;

                //case "KPPerspectives":
                //    Perspective kpPerspective = this.SaveLookup<Perspective>(entityName, jsonData);
                //    responseMsg = ctx.CreateJsonResponse<Perspective>(kpPerspective);
                //    break;
                case "KPPerspectiveInstances":
                    PerspectiveInstance kpPerspectiveInstance = this.SaveLookup <PerspectiveInstance>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <PerspectiveInstance>(ctx, kpPerspectiveInstance, this.timer);
                    break;

                case "KingpinLockdown":
                    KingpinLockdown lockdown = this.SaveLookup <KingpinLockdown>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <KingpinLockdown>(ctx, lockdown, this.timer);
                    break;

                case "Announcements":
                    Announcement announcement = this.SaveLookup <Announcement>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <Announcement>(ctx, announcement, this.timer);
                    break;

                case "KPTeams":
                    Team kpTeam = this.SaveLookup <Team>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <Team>(ctx, kpTeam, this.timer);
                    break;

                case "KPVPs":
                    VP kpVP = this.SaveLookup <VP>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <VP>(ctx, kpVP, this.timer);
                    break;

                case "OneOffConfigurations":
                    OneOffConfiguration oneOffConfiguration = this.SaveLookup <OneOffConfiguration>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <OneOffConfiguration>(ctx, oneOffConfiguration, this.timer);
                    break;

                case "UserEventLogging":
                    UserLogging userEvent = this.SaveLookup <UserLogging>(entityName, jsonData);
                    responseMsg = HttpUtilities.GenerateResponse <UserLogging>(ctx, userEvent, this.timer);
                    break;

                default:
                    string errMsg = string.Format("Error: No lookup list found with the name: {0}", entityName);
                    responseMsg = HttpUtilities.GenerateExceptionResponse(ctx, new Exception(errMsg), "POST/PUT", HttpStatusCode.BadRequest);
                    break;
                }
            }
            catch (Exception ex)
            {
                responseMsg = HttpUtilities.GenerateExceptionResponse(ctx, ex, "POST/PUT", HttpStatusCode.InternalServerError);
            }

            this.timer.Stop();
            return(responseMsg);
        }
Exemple #3
0
        internal override void Plus(XDocument xdoc)
        {
            foreach (var element in xdoc.Root.Elements())
            {
                var val = element.Value;
                int valI;
                int.TryParse(val, out valI);

                switch (element.Name.LocalName)
                {
                case "id":
                    break;

                case "race_id":
                    if (valI != -1 && World.Races.ContainsKey(valI))
                    {
                        Race = World.Races[valI];
                    }
                    break;

                case "type":
                    if (!Types.Contains(val))
                    {
                        Types.Add(val);
                    }
                    _entityType = (short)Types.IndexOf(val);
                    break;

                case "site_link":
                    var newSl = new EntitySiteLink(element, this);
                    if (SiteLinks == null)
                    {
                        SiteLinks = new Dictionary <int, List <EntitySiteLink> >();
                    }
                    if (!SiteLinks.ContainsKey(newSl.LinkType))
                    {
                        SiteLinks.Add(newSl.LinkType, new List <EntitySiteLink>());
                    }
                    SiteLinks[newSl.LinkType].Add(newSl);
                    break;

                case "entity_link":
                    var newEl = new EntityEntityLink(element, this);
                    if (EntityLinks == null)
                    {
                        EntityLinks = new Dictionary <int, List <EntityEntityLink> >();
                    }
                    if (!EntityLinks.ContainsKey(newEl.LinkType))
                    {
                        EntityLinks.Add(newEl.LinkType, new List <EntityEntityLink>());
                    }
                    EntityLinks[newEl.LinkType].Add(newEl);
                    break;

                case "children":
                    ChildrenIDs = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToList();
                    break;

                case "worship_id":
                    WorshipHfid = valI;
                    break;

                case "coords":
                    if (Coords == null)
                    {
                        Coords = new List <Point>();
                    }
                    foreach (var coordSplit in val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(coord => coord.Split(',')).Where(coordSplit => coordSplit.Length == 2))
                    {
                        Coords.Add(new Point(Convert.ToInt32(coordSplit[0]), Convert.ToInt32(coordSplit[1])));
                    }
                    break;

                case "claims":
                    Claims = val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(coord => coord.Split(','))
                             .Where(coordSplit => coordSplit.Length == 2)
                             .Select(split => new Point(Convert.ToInt32(split[0]), Convert.ToInt32(split[1])))
                             .ToList();
                    break;

                case "entity_position":
                    var newPosition = new EntityPosition(element, this);
                    if (Positions == null)
                    {
                        Positions = new List <EntityPosition>();
                    }
                    Positions.Add(newPosition);
                    break;

                case "entity_position_assignment":
                    var newPositionAssignment = new EntityPositionAssignment(element, this);
                    if (PositionAssignments == null)
                    {
                        PositionAssignments = new List <EntityPositionAssignment>();
                    }
                    PositionAssignments.Add(newPositionAssignment);
                    break;

                case "histfig_id":
                    if (MemberHfids == null)
                    {
                        MemberHfids = new List <int>();
                    }
                    MemberHfids.Add(valI);
                    break;

                case "histfig_ids":
                    MemberHfids = val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToList();
                    break;

                case "occasion":
                    var newOccasion = new EntityOccasion(element, this);
                    if (Occasions == null)
                    {
                        Occasions = new List <EntityOccasion>();
                    }
                    Occasions.Add(newOccasion);
                    break;

                default:
                    DFXMLParser.UnexpectedXmlElement(xdoc.Root.Name.LocalName + "\t", element, xdoc.Root.ToString());
                    break;
                }
            }
        }