Ejemplo n.º 1
0
        private static string FindSituationItem(Situation item, string key)
        {
            SituationItem situationItem = item.SituationItems.FirstOrDefault(si => si.Key.ToLower() == key.ToLower());

            if (situationItem != null)
            {
                return(situationItem.Value);
            }

            return(string.Empty);
        }
Ejemplo n.º 2
0
 public static void RemoveSituation()
 {
     try
     {
         Globals dbHelp = new Globals();
         dbHelp.OpenDatabase();
         var sqlDatabase = dbHelp.GetSQLiteDatabase();
         if (sqlDatabase != null)
         {
             Log.Info(TAG, "Situation with ID " + SituationItem.SituationId.ToString() + " about to be removed...");
             if (SituationItem.SituationId != 0)
             {
                 SituationItem.Remove(sqlDatabase);
             }
         }
         dbHelp.CloseDatabase();
     }
     catch (System.Exception e)
     {
         Log.Error(TAG, "RemoveSituation: Error occurred removing Situation - " + e.Message);
     }
 }
Ejemplo n.º 3
0
        private static void ParseFile(string filename)
        {
            SaveFile fileItem;

            fileItem = new SaveFile()
            {
                FileName  = filename,
                FileTime  = long.TryParse(filename.Split("_")[0], out long timeInTick) ? new DateTime(timeInTick) : DateTime.Now,
                Processed = (int)SaveFileProcessedEnum.NotProcessed
            };

            string jsonex = File.ReadAllText(filename).Replace(" NULL", " \"NULL\"");

            dynamic jsonFile = JObject.Parse(jsonex);

            var elementStacks = jsonFile["elementStacks"];

            foreach (JProperty property in elementStacks.Properties())
            {
                ElementStack element = new ElementStack
                {
                    ElementStackIdentification = property.Name,
                    SaveFile = fileItem
                };

                fileItem.ElementStacks.Add(element);

                //var elementStackItems = JObject.Parse(property.Values);
                foreach (JProperty subprop in property.Values())
                {
                    ElementStackItem item = new ElementStackItem
                    {
                        Value        = subprop.Value.ToString(),
                        Key          = subprop.Name,
                        ElementStack = element
                    };

                    element.ElementStackItems.Add(item);
                }
            }

            var decks = jsonFile["decks"];

            foreach (JProperty property in decks.Properties())
            {
                Deck deck = new Deck()
                {
                    Name     = property.Name,
                    SaveFile = fileItem
                };

                fileItem.Decks.Add(deck);
                //How to identify eliminated cards?

                foreach (JProperty subprop in property.Values())
                {
                    if (subprop.Name == "eliminatedCards")
                    {
                        //Aqui eu tenho uma sub parte
                        foreach (JToken subsubprop in subprop.Values())
                        {
                            DeckItem decksubItem = new DeckItem()
                            {
                                Eliminated = true,
                                Value      = subsubprop.Value <string>(),
                                Key        = "0",
                                Deck       = deck
                            };
                            deck.DeckItems.Add(decksubItem);
                        }
                        continue;
                    }

                    DeckItem deckItem = new DeckItem()
                    {
                        Eliminated = false,
                        Key        = subprop.Name,
                        Value      = subprop.Value.ToString(),
                        Deck       = deck
                    };
                    deck.DeckItems.Add(deckItem);
                }
            }

            var metainfo = jsonFile["metainfo"];

            MetaInfo meta = new MetaInfo();

            foreach (JProperty property in metainfo.Properties())
            {
                if (property.Name.ToUpper() == "BirdWormSlider".ToUpper())
                {
                    meta.BirdWormSlider = int.Parse(property.Value.ToString());
                }
                if (property.Name.ToUpper() == "VERSIONNUMBER".ToUpper())
                {
                    meta.Version = property.Value.ToString();
                }
                if (property.Name.ToUpper() == "WeAwaitSTE".ToUpper())
                {
                    meta.WeAwaitSTE = property.Value.ToString();
                }
            }

            fileItem.MetaInfo = meta;

            var             characterDetails = jsonFile["characterDetails"];
            CharacterDetail characterDetail  = new CharacterDetail()
            {
                SaveFile = fileItem,
                Levers   = new List <Lever>()
            };

            fileItem.CharacterDetail = characterDetail;

            foreach (JProperty property in characterDetails.Properties())
            {
                if (property.Name.ToUpper() == "activeLegacy".ToUpper())
                {
                    characterDetail.ActiveLegacy = property.Value.HasValues ? property.Value.ToString() : string.Empty;
                    continue;
                }
                if (property.Name.ToUpper() == "name".ToUpper())
                {
                    characterDetail.Name = property.Value.ToString();
                    continue;
                }
                if (property.Name.ToUpper() == "profession".ToUpper())
                {
                    characterDetail.Profession = property.Value.ToString();
                    continue;
                }
                LeverPartEnum leverPart = LeverPartEnum.Error;

                if (property.Name.ToUpper() == "pastLevers".ToUpper())
                {
                    leverPart = LeverPartEnum.PastLevers;
                }

                if (property.Name.ToUpper() == "futureLevers".ToUpper())
                {
                    leverPart = LeverPartEnum.FutureLevers;
                }

                if (property.Name.ToUpper() == "executions".ToUpper())
                {
                    leverPart = LeverPartEnum.Executions;
                }

                foreach (JProperty subprop in property.Values())
                {
                    Lever lever = new Lever()
                    {
                        CharacterDetail = characterDetail,
                        Part            = (int)leverPart,
                        Key             = subprop.Name,
                        Value           = subprop.Value.ToString()
                    };
                    characterDetail.Levers.Add(lever);
                }
            }

            var situations = jsonFile["situations"];

            foreach (JProperty property in situations.Properties())
            {
                Situation situation = new Situation()
                {
                    SaveFile = fileItem,
                    SituationIdentification = property.Name
                };

                fileItem.Situations.Add(situation);

                foreach (JProperty sitItem in property.Values())
                {
                    //ongoingSlotElements
                    if (sitItem.Name.ToUpper() == "ongoingSlotElements".ToUpper())
                    {
                        foreach (JProperty subprop in sitItem.Values())
                        {
                            OngoingSlotElement ongoingSlotElement = new OngoingSlotElement()
                            {
                                Situation = situation,
                                OngoingSlotElementIdentification = subprop.Name
                            };

                            situation.OngoingSlotElements.Add(ongoingSlotElement);

                            foreach (JProperty subpropitem in subprop.Values())
                            {
                                OngoingSlotElementItem ongoingSlotElementItem = new OngoingSlotElementItem()
                                {
                                    OngoingSlotElement = ongoingSlotElement,
                                    Key   = subpropitem.Name,
                                    Value = subpropitem.Value.ToString(),
                                };

                                ongoingSlotElement.OngoingSlotElementItems.Add(ongoingSlotElementItem);
                            }
                        }
                        continue;
                    }

                    //situationOutputNotes
                    if (sitItem.Name.ToUpper() == "situationOutputNotes".ToUpper())
                    {
                        foreach (JProperty subprop in sitItem.Values())
                        {
                            string indexValue = subprop.Name;
                            foreach (JProperty subpropitem in subprop.Values())
                            {
                                SituationOutputNote situationOutputNote = new SituationOutputNote()
                                {
                                    Situation = situation,
                                    Index     = indexValue,
                                    Key       = subpropitem.Name,
                                    Value     = subpropitem.Value.ToString(),
                                };

                                situation.SituationOutputNotes.Add(situationOutputNote);
                            }
                        }
                        continue;
                    }

                    //situationStoredElements
                    if (sitItem.Name.ToUpper() == "situationStoredElements".ToUpper())
                    {
                        foreach (JProperty subprop in sitItem.Values())
                        {
                            SituationStoredElement situationStoredElement = new SituationStoredElement()
                            {
                                Situation = situation,
                                SituationStoredElementIdentification = subprop.Name
                            };
                            situation.SituationStoredElements.Add(situationStoredElement);

                            foreach (JProperty subpropitem in subprop.Values())
                            {
                                SituationStoredElementItem situationStoredElementItem = new SituationStoredElementItem()
                                {
                                    SituationStoredElement = situationStoredElement,
                                    Key   = subpropitem.Name,
                                    Value = subpropitem.Value.ToString(),
                                };

                                situationStoredElement.SituationStoredElementItems.Add(situationStoredElementItem);
                            }
                        }
                        continue;
                    }

                    SituationItem situationItem = new SituationItem()
                    {
                        Key       = sitItem.Name,
                        Value     = sitItem.Value.ToString(),
                        Situation = situation
                    };

                    situation.SituationItems.Add(situationItem);
                }
            }

            //Verify some properties:
            VerifyFile(fileItem);
        }