public void ProcessContent(IContentPersister persister) { using (var db = new GameDatabaseContext()) { var repo = new QuestRepository(db); var items = repo.GetAll(); foreach (var item in items) { // Save out properties we want to a new object and then persist dynamic persistable = new ExpandoObject(); Console.WriteLine("Processing quest with ID {0}", item.Id); persistable.id = item.Id; persistable.name = item.Name; persistable.description = item.Description; persister.Persist(persistable, "\\quests\\{0}.json".FormatWith(item.Id)); } } }
/// <summary> /// Loads the content. /// </summary> public void LoadContent() { string questRepositoryPath = Path.Combine(ApplicationPaths.EntitiesDirectory, "quests.xml"); QuestRepository questRepository = new QuestRepository(questRepositoryPath); quests = questRepository.GetAll().ToDomainModels().ToList(); }
public void ImportFromQuestListXML() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); //LazySessionContext.Bind(new Lazy<ISession>(() => session), fac); try { IRepository <QuestDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <QuestDefinition> >(); IQuestRepository repository = new QuestRepository(rep); IList <QuestDefinition> items = repository.GetAll(); string filename = "Data\\questlist.xml"; if (!File.Exists(filename)) { throw new Exception("File missing"); } list data = new list(); data = list.LoadFromFile(filename); XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNodeList quests = doc.SelectNodes("//romquest"); foreach (XmlNode romquest in quests) { int id = Convert.ToInt32(romquest.Attributes["id"].Value); string name = romquest.Attributes["name"].Value; QuestDefinition quest = items.FirstOrDefault(definition => definition.RomId == id); if (quest == null) { quest = new QuestDefinition() { RomId = id, Name = name }; repository.Add(quest); } else { quest.RomId = id; quest.Name = name; repository.Update(quest); } } tx.Commit(); } finally { session.Close(); } }
static void Main(string[] args) { /* ISce * for (int i = 0; i < 10; ++i) * { * string scenario = $"Super uber scenario {i}"; * for (int j = 0; j < 50 ; ++j) * { * string quest = $"Rescure world {j}"; * * } * } * */ SessionBornEntities context = new SessionBornEntities(); MotorollaService motorolla = new MotorollaService(); Common.Transactions.StandardTransactionScopeProvider scopeProvider = new Common.Transactions.StandardTransactionScopeProvider(); ScenarioRepository scenarioRepo = new ScenarioRepository(context); QuestRepository questRepo = new QuestRepository(context); QuestService questService = new QuestService(questRepo, motorolla, scopeProvider); IEnumerable <Quest> ciastko = questRepo.GetAll(); IEnumerable <Scenario> ciacho = scenarioRepo.GetAll(); Console.WriteLine("Scenarios:"); foreach (Scenario s in ciacho) { Console.WriteLine($"{s.ID} : {s.Name}"); } foreach (Quest q in ciastko) { if (q.ScenarioID != 1) { Console.WriteLine($"{q.ID} : {q.Name} : {q.Description} + {q.ScenarioID}"); } } //Tuple<decimal, decimal> latlong = getPoints(); //questService.CreateQuest("Kolokwium 1", "1sze Kolokwium z Unixów", 1, 2, new DateTime(2018, 01, 11), 300, latlong.Item1, latlong.Item2); //questService.CreateQuest("Kolokwium 2", "2gie Kolokwium z Unixów", 1, 2, new DateTime(2018, 03, 14), 300, latlong.Item1, latlong.Item2); //latlong = getPoints(); //questService.CreateQuest("Wykład", "Wykład z Unixów", 3, 2, new DateTime(2018, 02, 14), 20, latlong.Item1, latlong.Item2); //questService.CreateQuest("Pytania", "Pytania z próbnego egzaminu z zeszłego roku", 1, 2, new DateTime(2018, 05, 14), 200); //latlong = getPoints(); //questService.CreateQuest("Kolokwium 1", "Kolokwium z Liczb Zespolonych", 1, 3, new DateTime(2018, 2, 5), 300, latlong.Item1, latlong.Item2); //questService.CreateQuest("Kolokwium 2", "Kolokwium z Dekompozycji Jordana", 1, 3, new DateTime(2018, 3, 7), 300, latlong.Item1, latlong.Item2); //latlong = getPoints(); //questService.CreateQuest("Wykład", "Wykład z Algebry", 3, 3, new DateTime(2018, 3, 14), 20, latlong.Item1, latlong.Item2); //questService.CreateQuest("Pytania", "Pytania zdobyte od starszej grupy", 1, 3, new DateTime(2018, 6, 14), 200); //latlong = getPoints(); //questService.CreateQuest("Egzamin", "Ekstremalnie trudny egzamin z algebry", 2, 3, new DateTime(2018, 6, 15), 600); //latlong = getPoints(); //questService.CreateQuest("Kolokwium 1", "Kolokwium z Szybkiej Transformaty Fouriera", 1, 5, new DateTime(2018, 4, 5), 300, latlong.Item1, latlong.Item2); //questService.CreateQuest("Kolokwium 2", "Kolokwium z Przestrzeni Hilberta", 1, 5, new DateTime(2018, 05, 7), 300, latlong.Item1, latlong.Item2); //latlong = getPoints(); //questService.CreateQuest("Wykład", "Wykład z obowiązkową obecnością z Matematyki", 3, 3, new DateTime(2018, 05, 14), 100, latlong.Item1, latlong.Item2); //questService.CreateQuest("Pytania", "Pytania zdobyte od starszej grupy", 1, 5, new DateTime(2018, 05, 14), 200); //latlong = getPoints(); //questService.CreateQuest("Egzamin", "Prosty egzamin z matematyki", 2, 5, new DateTime(2018, 05, 14), 600); Console.ReadKey(); Tuple <decimal, decimal> getPoints() { decimal latmin = new decimal(50.030331); decimal latmax = new decimal(50.08103); decimal longimin = new decimal(19.831237); decimal longimax = new decimal(19.881936); Random rnd = new Random(); decimal lati = NextDecimal(rnd, latmin, latmax); decimal longi = NextDecimal(rnd, longimin, longimax); return(new Tuple <decimal, decimal>(lati, longi)); } }