Beispiel #1
0
        public World(string path)
        {
            path_ = path;

            using (var s = File.OpenRead(Path.Combine(path, "level.dat")))
            {
                s.Seek(8, SeekOrigin.Begin);
                var nbtStream = new NbtStream(s);
                if (!nbtStream.MoveNext())
                {
                    throw new InvalidDataException("Unable to read level.dat.");
                }
                levelDat_ = nbtStream.CurrentValue.AsDictionary();
            }

            spawnX_     = levelDat_[LevelDatConstants.SPAWN_X_KEY].As <int>().Value;
            spawnZ_     = levelDat_[LevelDatConstants.SPAWN_Z_KEY].As <int>().Value;
            difficulty_ = (Difficulty)levelDat_[LevelDatConstants.DIFFICULTY_KEY].As <int>().Value;
            var versionTag = levelDat_[LevelDatConstants.VERSION_KEY].AsArray <int>();

            lastLoadVersion_ = new Version(
                versionTag[0],
                versionTag[1],
                versionTag[2],
                versionTag[3]
                );
            commandBlocksEnabled_    = levelDat_.Contains(LevelDatConstants.COMMAND_BLOCKS_ENABLED_KEY) ? levelDat_[LevelDatConstants.COMMAND_BLOCKS_ENABLED_KEY].As <byte>().Value == 1 : false;
            commandsEnabled_         = levelDat_.Contains(LevelDatConstants.COMMANDS_ENABLED_KEY) ? levelDat_[LevelDatConstants.COMMANDS_ENABLED_KEY].As <byte>().Value == 1 : false;
            hasBeenLoadedInCreative_ = levelDat_[LevelDatConstants.LOADED_IN_CREATIVE_KEY].As <byte>().Value == 1;
            chunkTickRange_          = levelDat_.Contains(LevelDatConstants.TICK_RANGE_KEY) ? levelDat_[LevelDatConstants.TICK_RANGE_KEY].As <int>().Value : 4;
            name_ = levelDat_[LevelDatConstants.NAME_KEY].As <string>().Value;
            seed_ = levelDat_[LevelDatConstants.SEED_KEY].As <long>().Value;
            mode_ = (GameType)levelDat_[LevelDatConstants.GAME_MODE_KEY].As <int>().Value;
            db_   = new DbBroker(Path.Combine(path_, "db"));
        }
Beispiel #2
0
 private void Dispose(bool disposing)
 {
     if (db_ != null)
     {
         db_.Dispose();
         db_ = null;
     }
 }
Beispiel #3
0
 private void NapuniGrid()
 {
     try {
         dataGridView1.DataSource = DbBroker.VratiSveKnjige();
     } catch (Exception ex) {
         MessageBox.Show(string.Format("Greška prilikom vraćanja podataka iz baze: {0}", ex.Message), "Greška");
         throw;
     }
 }
Beispiel #4
0
        public ActionResult UpdateHoliday()
        {
            string holidayId = Request["holidayid"];

            DbBroker broker      = new DbBroker();
            Holiday  selectedOne = broker.SelectOne(Int32.Parse(holidayId));

            Debug.WriteLine(selectedOne.Name);
            ViewBag.Holiday = selectedOne;

            return(View("UpdateHoliday"));
        }
Beispiel #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (textBoxId.Text == "" || textBoxId.Text == null)
            {
                MessageBox.Show("morate uneti id polja koje se brise!");
            }
            Knjiga knjiga = new Knjiga();

            try { knjiga.id = Int32.Parse(textBoxId.Text); } catch { MessageBox.Show("Nije u dobrom formatu ID"); };
            DbBroker.DeleteKnjiga(knjiga);

            NapuniGrid();
        }
Beispiel #6
0
        public string DeleteHoliday()
        {
            string toDelete = Request["deleteHolidays"];

            string[] arrayDelete = toDelete.Split(',');
            for (int i = 0; i < arrayDelete.Length; i++)
            {
                DbBroker deletenew   = new DbBroker();
                int      deletedOnes = deletenew.Delete(Int32.Parse(arrayDelete[i]));
                Debug.WriteLine(toDelete);
            }

            return("OK");
        }
Beispiel #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Knjiga knjiga = new Knjiga();


            knjiga.autor = textBoxAutor.Text;
            knjiga.naziv = textBoxNaziv.Text;
            try { knjiga.cena = Int32.Parse(textBoxCena.Text); } catch { MessageBox.Show("Nije u dobrom formatu cena"); };
            knjiga.slika      = textBoxSlika.Text;
            knjiga.kategorija = textBoxKategorija.Text;

            DbBroker.InsertKnjiga(knjiga);

            NapuniGrid();
        }
Beispiel #8
0
        public void TestConnection()
        {
            try
            {
                var connectionString = CapiConfig.GetConfig().AgentDbConnectionString;

                var broker = new DbBroker(connectionString);
                broker.Database.EnsureCreated();

                //Assert.IsTrue(dbExists);

                Attempt @case = new Attempt();
                Job     @job  = new Job()
                {
                    Attempt = @case
                };

                job.Status = "Test";
                broker.Jobs.Add(job);
                broker.SaveChanges();

                broker.Attempts.Add(@case);
                broker.SaveChanges();

                var jobFromDb = broker.GetJobByStatus("Test").FirstOrDefault();
                Assert.IsFalse(jobFromDb.Attempt == null);

                broker.Attempts.Remove(@case);
                broker.SaveChanges();
                broker.Jobs.Remove(@job);
                broker.SaveChanges();

                var @case2 = new Attempt
                {
                    CurrentAccession = "TestAcc",
                    Status           = "Pending",
                    Method           = Attempt.AdditionMethod.Hl7
                };;
                broker.Attempts.Add(@case2);
                broker.SaveChanges();
                broker.Attempts.Remove(@case2);
                broker.SaveChanges();
            }
            catch (Exception e)
            {
                Assert.Inconclusive("Something went wrong with DB connection : " + e);
            }
        }
Beispiel #9
0
        public void SourceLoggingTest()
        {
            string connectionString = @"Data Source=X:\code\Private\RssPublisher\RssPublisherTest\rss_AddSourceLog.db;";
            string dbFile           = connectionString.Replace("Data Source=", "").Replace(";", "");

            if (File.Exists(dbFile))
            {
                File.Delete(dbFile);
            }

            DbBroker db = new DbBroker(connectionString);

            Source r      = new Source("CNN", "https://www.cnbc.com/id/100003114/device/rss/rss.html", 1, 1, db);
            var    result = r.Log("This is a log entry from the unit tests...");

            Assert.IsTrue(result == 1);
        }
Beispiel #10
0
        public void TestTtlUpdate()
        {
            var ff = @"X:\code\Private\RssPublisher\RssPublisherTest\rss_RetrieveTest3.db";

            if (File.Exists(ff))
            {
                File.Delete(ff);
            }

            string connectionString = @"Data Source=X:\code\Private\RssPublisher\RssPublisherTest\rss_RetrieveTest3.db;";
            string dbFile           = connectionString.Replace("Data Source=", "").Replace(";", "");

            DbBroker db = new DbBroker(connectionString);

            Source r = new Source("CNBC", "https://www.cnbc.com/id/100003114/device/rss/rss.html", 1, 1, db);

            r.Id = 10;
            // Get default ttl

            var origTtl = r.Ttl;
            var origLf  = r.LastFetched;

            var f = r.Retrieve();

            //Check ttl from feed

            var newTtl = r.Ttl;
            var newLf  = r.LastFetched;

            //Get from DB
            Source dbTtl = db.GetActiveSources().Where(x => x.Id == 10).FirstOrDefault();

            if (dbTtl != null)
            {
                Assert.AreEqual(newTtl, dbTtl.Ttl);
                Assert.AreEqual(newLf, dbTtl.LastFetched);
            }
            else
            {
                Assert.Fail("Source not found in test db.");
            }

            Assert.IsTrue(f.Count > 0);
            Assert.AreNotEqual(origTtl, newTtl);
            Assert.AreNotEqual(origLf, newLf);
        }
Beispiel #11
0
        private void btn_kreiraj_Click(object sender, EventArgs e)
        {
            List <string> porudzbine = new List <string>();

            foreach (var item in order_list.Items)
            {
                porudzbine.Add(item.ToString());
            }

            int id_porudzbine = DbBroker.kreirajPorudzbinu(DateTime.Now, racun);

            MessageBox.Show("Porudzbina je sacuvana.");

            order_list.Items.Clear();
            racun       = 0;
            label2.Text = "0";
        }
Beispiel #12
0
        public void AddStoryTest()
        {
            string connectionString = @"Data Source=X:\code\Private\RssPublisher\RssPublisherTest\rss_AddStoryTest.db;";
            string dbFile           = connectionString.Replace("Data Source=", "").Replace(";", "");

            if (File.Exists(dbFile))
            {
                File.Delete(dbFile);
            }

            DbBroker db = new DbBroker(connectionString);

            Source s = new Source("CNN", "https://www.cnbc.com/id/100003114/device/rss/rss.html", 1, 1, db);

            var f = s.Retrieve();

            Assert.IsTrue(f.Count > 0);
        }
Beispiel #13
0
        public void TestRetrieval()
        {
            string connectionString = @"Data Source=X:\code\Private\RssPublisher\RssPublisherTest\rss_RetrieveTest.db;";
            string dbFile           = connectionString.Replace("Data Source=", "").Replace(";", "");

            DbBroker db = new DbBroker(connectionString);


            Source r = new Source("CNBC", "https://www.cnbc.com/id/100003114/device/rss/rss.html", 1, 1, db);
            var    f = r.Retrieve();

            Assert.IsTrue(f.Count > 0);
            Assert.IsTrue(f[0].Title.Length > 0);
            Assert.IsTrue(f[0].Url.Length > 0);
            Assert.IsTrue(f[0].Description.Length > 0);

            File.Delete(dbFile);
        }
Beispiel #14
0
        // GET: Holidays
        public ActionResult Index()
        {
            //return "This is my default action...";
            //List<Holiday> listOfHolidays = new List<Holiday> ();
            DbBroker       showSelected = new DbBroker();
            List <Holiday> allSelected  = showSelected.SelectAll();

            //Debug.WriteLine("vdvdsvf");

            //for (int i = 0; i < allSelected.Count(); i++)
            //{
            //    Debug.WriteLine(allSelected[i].Name);
            //}

            ViewBag.Holidays = allSelected;

            return(View());
        }
Beispiel #15
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBoxId.Text == "" || textBoxId.Text == null)
            {
                MessageBox.Show("morate uneti id polja koje se updateuje!");
            }
            Knjiga knjiga = new Knjiga();

            try { knjiga.id = Int32.Parse(textBoxId.Text); } catch { MessageBox.Show("Nije u dobrom formatu ID"); };
            knjiga.autor = textBoxAutor.Text;
            knjiga.naziv = textBoxNaziv.Text;
            try { knjiga.cena = Int32.Parse(textBoxCena.Text); } catch { MessageBox.Show("Nije u dobrom formatu cena"); };
            knjiga.slika      = textBoxSlika.Text;
            knjiga.kategorija = textBoxKategorija.Text;

            DbBroker.UpdateKnjigu(knjiga);

            NapuniGrid();
        }
Beispiel #16
0
        private void SetupDefaultRecipeInDb(Recipe recipe)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
            {
                DataSource     = txtDBServer.Text,
                UserID         = txtDBUser.Text,
                Password       = txtDBPassword.Text,
                InitialCatalog = txtDBName.Text,
            };

            try
            {
                DbBroker broker = new DbBroker(builder.ConnectionString);
                broker.Database.EnsureCreated();
                broker.Database.ExecuteSqlRaw("IF OBJECTPROPERTY(OBJECT_ID('dbo.StoredRecipes'), 'TableHasIdentity') = 1  SET IDENTITY_INSERT [dbo].[StoredRecipes] ON");
                broker.SaveChanges();
                broker.StoredRecipes.Add(new StoredRecipe()
                {
                    Id           = -1,
                    UserEditable = false,
                    Name         = "Manual Recipe",
                    RecipeString = "{}"
                });
                broker.StoredRecipes.Add(new StoredRecipe()
                {
                    Id           = 1,
                    UserEditable = false,
                    Name         = "MS Lesion Compare",
                    RecipeString = JsonConvert.SerializeObject(recipe)
                });
                broker.SaveChanges();
            }
            catch (Exception ex)
            {
                do
                {
                    log(ex.Message);
                    ex = ex.InnerException;
                } while (ex != null);
            }
        }
Beispiel #17
0
        public void AddSourceTest()
        {
            string connectionString = @"Data Source=X:\code\Private\RssPublisher\RssPublisherTest\rss_AddSourceTest.db;";
            string dbFile           = connectionString.Replace("Data Source=", "").Replace(";", "");

            if (File.Exists(dbFile))
            {
                File.Delete(dbFile);
            }

            DbBroker db = new DbBroker(connectionString);

            var    sources = db.GetActiveSources();
            Source s       = new Source("Test", "https://example.org", 1, 99, db);

            s.SaveNew();

            var sources2 = db.GetActiveSources();

            Assert.IsTrue(sources.Count < sources2.Count);
            Assert.AreEqual(1, sources2.Count - sources.Count);
        }
Beispiel #18
0
        public void TestRetrievalAndPublish()
        {
            var f = @"X:\code\Private\RssPublisher\RssPublisherTest\rss_RetrieveTest2.db";

            if (File.Exists(f))
            {
                File.Delete(f);
            }

            string connectionString = @"Data Source=X:\code\Private\RssPublisher\RssPublisherTest\rss_RetrieveTest2.db;";
            string dbFile           = connectionString.Replace("Data Source=", "").Replace(";", "");

            DbBroker db = new DbBroker(connectionString);

            Source r       = new Source("CNBC", "https://www.cnbc.com/id/100003114/device/rss/rss.html", 1, 1, db);
            var    stories = r.RetrieveAndPublish();

            Assert.IsTrue(stories.Count > 0);
            Assert.IsTrue(stories[0].Title.Length > 0);
            Assert.IsTrue(stories[0].Url.Length > 0);
            Assert.IsTrue(stories[0].Description.Length > 0);
        }
Beispiel #19
0
        public ActionResult SaveHoliday()
        {
            string holidayId    = Request["holidayID"];
            string holidayName  = Request["Name"];
            string holidayStart = Request["StartsAt"];
            string holidayEnd   = Request["EndsAt"];
            // string holidayAnual = Request["OccursAnually"];
            bool   holidayAnual = false;
            string holidayCheck = Request.Form["OccursAnnually"];

            Debug.WriteLine("Holiday check " + holidayCheck);
            //holidayCheck = "ftruedd";
            if (!string.IsNullOrEmpty(holidayCheck) && holidayCheck.Contains("on"))
            {
                holidayAnual = true;
            }
            string holidayDays = Request["DaysOff"];

            if (!String.IsNullOrEmpty(holidayId))
            {
                Debug.WriteLine("Update is on");

                DbBroker broker  = new DbBroker();
                int      updated = broker.Update(holidayName, DateTime.Parse(holidayStart), DateTime.Parse(holidayEnd), holidayAnual, Int32.Parse(holidayId));
            }
            else
            {
                DbBroker insertNew = new DbBroker();
                Debug.WriteLine(holidayAnual);
                int rowsAffected = insertNew.Insert(holidayName, DateTime.Parse(holidayStart), DateTime.Parse(holidayEnd), holidayAnual);
            }
            DbBroker       showSelected = new DbBroker();
            List <Holiday> allSelected  = showSelected.SelectAll();

            ViewBag.Holidays = allSelected;

            return(View("Index"));
        }
Beispiel #20
0
 private void btn_uloni_Click(object sender, EventArgs e)
 {
     racun -= DbBroker.getKnjigaPriceByName(order_list.Text);
     order_list.Items.Remove(order_list.Text);
     label2.Text = racun.ToString();
 }
Beispiel #21
0
 private void button1_Click(object sender, EventArgs e)
 {
     order_list.Items.Add(listBox1.Text);
     racun      += DbBroker.getKnjigaPriceByName(listBox1.Text);
     label2.Text = racun.ToString();
 }