コード例 #1
0
 private static void AddReportToDb(INinjaFactoryData db, JobReport rep)
 {
     Job finishedJob = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();
     finishedJob.IsSuccessfull = rep.Success;
     finishedJob.EndDate = rep.EndDate;
     finishedJob.Ninja.KillCount += rep.KillCount;
     db.SaveChanges();
 }
コード例 #2
0
        private static void AddReportToDb(INinjaFactoryData db, JobReport rep)
        {
            Job finishedJob = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();

            finishedJob.IsSuccessfull    = rep.Success;
            finishedJob.EndDate          = rep.EndDate;
            finishedJob.Ninja.KillCount += rep.KillCount;
            db.SaveChanges();
        }
コード例 #3
0
        private static bool CheckIfReportIsValid(INinjaFactoryData db, JobReport rep)
        {
            var job = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();

            if (job == null)
            {
                throw new ArgumentOutOfRangeException("There is no job with Id '" + rep.Id + "'");
            }

            if (job.IsSuccessfull.HasValue == true)
            {
                throw new ArgumentException("The job with Id '" + rep.Id + "' is already compleated");
            }

            return(true);
        }
コード例 #4
0
        private static ICollection <JobReport> GetAllRecordsInCollection(MongoCollection <BsonDocument> collection)
        {
            var jobs = collection.FindAll();
            List <JobReport> reports = new List <JobReport>();

            foreach (var job in jobs)
            {
                if (!job.Contains("_id") || !job.Contains("Success"))
                {
                    throw new ArgumentException("There is an invalid row in the Mongo Database");
                }

                int jobId = job["_id"].AsInt32;

                bool isSuccessful = job["Success"].AsBoolean;

                JobReport report = new JobReport()
                {
                    Id      = jobId,
                    Success = isSuccessful
                };

                if (job.Contains("EndDate") && job["EndDate"].IsValidDateTime)
                {
                    report.EndDate = job["EndDate"].ToUniversalTime();
                }
                else
                {
                    report.EndDate = DateTime.Now;
                }

                if (job.Contains("KillCount"))
                {
                    report.KillCount = job["KillCount"].AsInt32;
                }

                reports.Add(report);
            }

            return(reports);
        }
コード例 #5
0
 private static void AddNewEntityToCollection(MongoCollection<BsonDocument> collection, JobReport newEntity)
 {
     collection.Insert(newEntity);
 }
コード例 #6
0
        private static ICollection<JobReport> GetAllRecordsInCollection(MongoCollection<BsonDocument> collection)
        {
            var jobs = collection.FindAll();
            List<JobReport> reports = new List<JobReport>();
            foreach (var job in jobs)
            {
                if (!job.Contains("_id") || !job.Contains("Success"))
                {
                    throw new ArgumentException("There is an invalid row in the Mongo Database");
                }

                int jobId = job["_id"].AsInt32;

                bool isSuccessful = job["Success"].AsBoolean;

                JobReport report = new JobReport()
                {
                    Id = jobId,
                    Success = isSuccessful
                };

                if (job.Contains("EndDate") && job["EndDate"].IsValidDateTime)
                {
                    report.EndDate = job["EndDate"].ToUniversalTime();
                }
                else
                {
                    report.EndDate = DateTime.Now;
                }

                if (job.Contains("KillCount"))
                {
                    report.KillCount = job["KillCount"].AsInt32;
                }

                reports.Add(report);
            }

            return reports;
        }
コード例 #7
0
        private static bool CheckIfReportIsValid(INinjaFactoryData db, JobReport rep)
        {
            var job = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();

            if (job == null)
            {
                throw new ArgumentOutOfRangeException("There is no job with Id '" + rep.Id + "'");
            }

            if (job.IsSuccessfull.HasValue == true)
            {
                throw new ArgumentException("The job with Id '" + rep.Id + "' is already compleated");
            }

            return true;
        }
コード例 #8
0
 private static void AddNewEntityToCollection(MongoCollection <BsonDocument> collection, JobReport newEntity)
 {
     collection.Insert(newEntity);
 }