コード例 #1
0
 public static void Start()
 {
     var _context = new Context();
      foreach (Employee e in _context.Employees.ToList())
      {
          _context.Employees.Remove(e);
      }
      Employee e1 = new Employee();
      e1.Name = "James";
      e1.Password = "******";
      e1.Organization = "work";
      _context.Employees.Add(e1);
      Employee e2 = new Employee();
      e2.Name = "Phil";
      e2.Password = "******";
      e2.Organization = "work";
      _context.Employees.Add(e2);
      Employee e3 = new Employee();
      e3.Name = "Michelle ";
      e3.Password = "******";
      e3.Organization = "work";
      _context.Employees.Add(e3);
      Employee e4 = new Employee();
      e4.Name = "Keith";
      e4.Password = "******";
      e4.Organization = "work";
      _context.Employees.Add(e4);
      _context.SaveChanges();
      foreach (Employee e in _context.Employees.ToList())
      {
          Trace.WriteLine(e.Name);
      }
 }
コード例 #2
0
        public String SetIgnore(string ignorelist)
        {
            Trace.WriteLine("STARTING IGNORE PROCEEDURE");
            Trace.WriteLine(ignorelist + " coming in from client");
            var _context = new Context();
            //List<SMJob> num = _context.SMJobs.ToList();
            // Trace.WriteLine("1 from ignore there are "+ num.Count+" jobs in the db");
            String[] a = ignorelist.Split(';');
            Trace.WriteLine(a.Count());
            foreach (string s in a)
            {
                String[] b = s.Split(':');
                SMJob job = _context.getSMJobByName(b[0]);

                if (job != null && b[0] != "")
                {
                    if (b[1].Equals("1"))
                    {
                        Trace.WriteLine("IGNORESERVICE: turning on ignore for " + job.Name);
                        job.alertsAllowed = false;
                    }
                    else
                    {
                        Trace.WriteLine("IGNORESERVICE: turning off ignore for " + job.Name);
                        job.alertsAllowed = true;
                    }
                    //_context.SMJobs.Add(job);
                    _context.SaveChanges();
                }
            }
            Trace.WriteLine("ENDING IGNORE PROCEEDURE");

            return "OK";
        }
コード例 #3
0
        public static void addToDataBase(ArrayList<GPSReadingXMLParser.tempGPSReading> list2)
        {
            var _context = new Context();
            //remove all old readings
            foreach (GPSReading gpsri in _context.GPSReadings.ToList())
            {
                _context.GPSReadings.Remove(gpsri);
            }
            _context.SaveChanges();

            foreach (GPSReadingXMLParser.tempGPSReading reading in list2)
            {
                //add the updated job
                var gpsreading = new GPSReading
                                     {
                                         Vin = reading.Vin,
                                         Address = reading.Address,
                                         Lat = reading.Lat,
                                         Lng = reading.Lng,
                                         Speed = reading.Speed,
                                         RouteNumber = reading.RouteNumber,
                                         Time = reading.Time
                                     };
                //Trace.WriteLine("gps saving to address " + reading.Address);
                _context.GPSReadings.Add(gpsreading);
            }
            _context.SaveChanges();
        }
コード例 #4
0
        public ActionResult TrackPoints(int routeId)
        {
            var context = new Context();

            var route = context.Routes.FirstOrDefault(x => x.Id == routeId);
            if (route == null)
                return new HttpStatusCodeResult(404);

            var data = new
            {
                Id = routeId,
                Name = route.Name,
                MaxLong = route.TrackPoints.Max(x => x.Longitude),
                MinLong = route.TrackPoints.Min(x => x.Longitude),
                MaxLat = route.TrackPoints.Max(x => x.Latitude),
                MinLat = route.TrackPoints.Min(x => x.Latitude),
                Distance = route.TrackPoints.Max(x => x.Distance),
                Points = route.TrackPoints.Select(x => new
                {
                    Id = x.Id,
                    Lat = x.Latitude,
                    Long = x.Longitude,
                    Ele = x.Elevation,
                    Dist = x.Distance
                }).OrderBy(x => x.Dist).ToArray()
            };

            return Json(data, JsonRequestBehavior.AllowGet);
        }
コード例 #5
0
ファイル: Smjob.cs プロジェクト: adowning/codefirstmigrations
 public void updateCurrentLoc()
 {
     var _context = new Context();
     var readings = new List<GPSReading>();
     try
     {
          readings = _context.GPSReadings.ToList();
     }
     catch (Exception e)
     {
         Trace.WriteLine("exception thrown when reading gps readings from context! ");
     }
     var lulist = new List<locupdate>();
     foreach (GPSReading reading in readings)
     {
         var lu = new locupdate
                      {
                          RouteNumber = reading.RouteNumber,
                          Address = reading.Address
                      };
         lulist.Add(lu);
     }
     string json = JsonConvert.SerializeObject(lulist);
     Clients.updatelocs(json);
 }
コード例 #6
0
ファイル: Smjob.cs プロジェクト: adowning/codefirstmigrations
        public void InitialUpdate()
        {
            var _context = new Context();

            List<SMJob> smjobs = _context.SMJobs.ToList();
            string json2 = JsonConvert.SerializeObject(smjobs);
            Clients.update(json2);
            updateCurrentLoc();
        }
コード例 #7
0
        public void InitialUpdate()
        {
            var _context = new Context();

            List<ClockLog> logs = _context.ClockLogs.ToList();
            string json2 = JsonConvert.SerializeObject(logs);
            Clients.update(json2);
            //updateCurrentLoc();
        }
コード例 #8
0
 public List<Customer> GetData(string value)
 {
     Context context = new Context();
     List<Customer> customersList = new List<Customer>();
     foreach (Customer c in context.Customers)
     {
         customersList.Add(c);
     }
     return customersList;
 }
コード例 #9
0
 private void RemoveDistricts()
 {
     using (var context = new Context())
     {
         foreach (var district in context.Features)
         {
             context.Features.Remove(district);
         }
         context.SaveChanges();
     }
 }
コード例 #10
0
ファイル: Smjob.cs プロジェクト: adowning/codefirstmigrations
        public void Ignore(string jobname, bool ignore)
        {
            var _context = new Context();

            SMJob job = _context.getSMJobByName(jobname);
            job.alertsAllowed = !ignore;
            _context.SaveChanges();
            List<SMJob> smjobs = _context.SMJobs.ToList();
            string json2 = JsonConvert.SerializeObject(smjobs);
            Clients.update(json2);
        }
コード例 #11
0
 public void Add()
 {
     Context context = new Context();
     for (int i = 0; i < 5; i++)
     {
         Customer c = new Customer();
         c.Id = i;
         c.Name = "Rehan # " + i;
         context.Customers.Add(c);
     }
     context.SaveChanges();
 }
コード例 #12
0
 private List<ArticleViewModel> GetArticlesFromDb()
 {
     using (var context = new Context())
     {
         var list = from x in context.Articles
                     select new ArticleViewModel
                     {
                         id = x.Id,
                         name = x.Name
                     };
         return list.ToList();
     }
 }
コード例 #13
0
        public void InsertMunicipailitiesFromShapeFile()
        {
            RemoveDistricts();

            var shapes = new DagiShapeFileReader().Read("..\\..\\..\\data\\KOMMUNE", "KOMNAVN");
            using (var context = new Context())
            {
                foreach (var shape in shapes)
                {
                    context.Features.Add(new Feature { Name = shape.Key, Geography = shape.Value });
                }
                context.SaveChanges();
            }
        }
コード例 #14
0
 public static void sendMessage(SMJob job)
 {
     var objIntelliSMS = new IntelliSMS();
     var _context = new Context();
     objIntelliSMS.Username = "******";
     objIntelliSMS.Password = "******";
     Trace.WriteLine(job.Company);
     Company c = _context.getCompany(job.Company);
     String message = job.Techs + " will be late to " + job.Name + " scheduled for " + job.Time;
     Trace.WriteLine("phone " + c.Phone + " message = " + message);
     // String messageId = objIntelliSMS.SendMsg
     //     (c.Phone, message, "SENDER_ID");
     // Trace.WriteLine("sent msg with id "+messageId);
 }
コード例 #15
0
        public ActionResult Edit(int routeId)
        {
            var model = new Models.EditRouteViewModel();

            var context = new Context();

            var route = context.Routes.FirstOrDefault(x => x.Id == routeId);
            if (route == null)
                return new HttpStatusCodeResult(404);

            model.RouteId = route.Id;
            model.RouteName = route.Name;

            return View(model);
        }
コード例 #16
0
 public JsonResult DeleteArticle(ArticleViewModel article)
 {
     Thread.Sleep(300);
     string r = string.Format("removed '{0}' from article", article.name);
     using (var context = new Context())
     {
         foreach (var at in context.ArticleTags.Where(x => x.Article.Id == article.id ))
         {
             context.ArticleTags.Remove(at);
         }
         context.SaveChanges();
         context.Articles.Where(x => x.Id == article.id).ToList().ForEach(y => context.Articles.Remove(y));
         context.SaveChanges();
     }
     return Json(this.GetArticlesFromDb(), JsonRequestBehavior.AllowGet); //Content(r);
 }
コード例 #17
0
        //private readonly Context _context = new Context();
        public void execute()
        {
            Trace.WriteLine("STARTING XML PARSING RUN ");

            var _context = new Context();
            List<Company> clist = _context.Companies.ToList();

            foreach (Company c in clist)
            {
                ArrayList<SMJobXMLParser.tempJob> l = SMJobXMLParser.readJobs(c.Name);
                ArrayList<GPSReadingXMLParser.tempGPSReading> l2 = GPSReadingXMLParser.readGPS(c.Name);
                SaveJobs.addToDataBase(l);
                SaveReadings.addToDataBase(l2);
            }

            Trace.WriteLine("FINISHED XML PARSING RUN ");
        }
コード例 #18
0
        public ActionResult Download(string model)
        {
            var ser = new JavaScriptSerializer();
            var newModel = ser.Deserialize<JsonViewModel>(model);

            var context = new Context();

            var route = context.Routes.FirstOrDefault(x => x.Id == newModel.routeId);
            if (route == null)
                return new HttpStatusCodeResult(404);

            route.Name = newModel.name;

            var doc = route.GetBdx(newModel.markers);

            return File(Encoding.UTF8.GetBytes(doc.ToString()), "text/xml", "route.bdx");
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: friism/VLGroups
        static void Main(string[] args)
        {
            while (true)
            {
                using (var context = new Context())
                {
                    var now = DateTime.UtcNow;
                    if (context.Batches.Any(x =>
                        x.FetchedAt.Year == now.Year && x.FetchedAt.Month == now.Month))
                    {
                        Thread.Sleep(24 * 60 * 60 * 1000);
                        continue;
                    }
                }

                try
                {
                    var batch = new Batch
                    {
                        FetchedAt = DateTime.UtcNow,
                    };

                    var members = VLGroupScraper.GetMembers();

                    batch.Members = members.ToList();

                    using (var context = new Context())
                    {
                        context.Batches.Add(batch);
                        context.SaveChanges();
                    }
                }
                catch (Exception exception)
                {
                    using (var smtpClient = new SmtpClient())
                    {
                        var emailAddress = ConfigurationManager.AppSettings.Get("logemailaddress");
                        smtpClient.Send(new MailMessage(
                            emailAddress, emailAddress, "Problem scraping", exception.ToString()));
                    }
                }
            }
        }
コード例 #20
0
ファイル: Smjob.cs プロジェクト: adowning/codefirstmigrations
 public void updateDrivers()
 {
     var _context = new Context();
     Trace.WriteLine("updateDrivers hit");
     List<SMEventLog> logs = _context.SMEventLogs.ToList();
     var lulist = new List<locupdate>();
     //foreach (SMEventLog log in logs)
     //{
     //    var lu = new locupdate
     //    {
     //        RouteNumber = reading.RouteNumber,
     //        Address = reading.Address
     //    };
     //    lulist.Add(lu);
     //}
     Trace.WriteLine(logs.Count);
     string json = JsonConvert.SerializeObject(logs);
     Clients.updatedrivers(json);
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: friism/Patents
        private static void ExtractInventors()
        {
            Console.WriteLine("extracting inventors...");
            using (var context = new Context())
            {
                foreach (var patent in context.Patents)
                {
                    var inventorStrings = Regex.Split(patent.InventorField, "[A-Z]{2},")
                        .Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim());

                    foreach (var inventorString in inventorStrings)
                    {
                        var name = inventorString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).First();
                        var firstname = name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).First();

                        Console.WriteLine(firstname);
                    }
                }
            }
        }
コード例 #22
0
        public static String getRouteNumberFromVin(String vin)
        {
            var _context = new Context();
            List<Route> routelist = _context.Routes.ToList();
            foreach (Route r in routelist)

            {
                string gpsid = Regex.Replace(r.GPSID, "[^0-9]+", string.Empty);
                //Trace.WriteLine("gpsid = "+gpsid);
                //Trace.WriteLine("vinid = " + vin);
                //return r.Number;
                if (gpsid.Equals(vin))
                {
                    //Trace.WriteLine("returning = " + r.Number);
                    return r.Number;
                }
            }

            return null;
        }
コード例 #23
0
        public ActionResult Index()
        {
            if (SimpleSessionPersister.Username == null)
            {
                Trace.WriteLine("admin 1");
                return RedirectToAction("Index", "Home");
            }
            var _context = new Context();
            User thisuser = _context.getUser(SimpleSessionPersister.Username);
            if (thisuser == null)
            {
                Trace.WriteLine("admin 2");
                return RedirectToAction("Index", "Home");
            }

            if (thisuser.Role.Equals("admin"))
            {
                Trace.WriteLine("admin 3");
                return RedirectToAction("Index", "Home");
            }
            Trace.WriteLine("admin 4");
            Trace.WriteLine(User.Identity.Name);

            int i = 2;
            ViewBag.inty = i;
            // TODO this whole controller needs work, low priority
            var userlistl = _context.Users.ToList();
            var routesl = _context.Routes.ToList();
            var companiesl = _context.Companies.ToList();
            var aivm = new AdminIndexViewModel
                           {
                               routes = routesl,
                               users = userlistl,
                               companies = companiesl

                           };
            //ViewBag.ipvm = ipvm;
            return View(aivm);
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: friism/Patents
        private static void GetPatentFromPage(IE browser, int year)
        {
            var inventor = browser.TableCell(x =>
                x.PreviousSibling != null && x.PreviousSibling.Text == "Opfinder").Text;

            var patentIdAndDate = browser.TableCell(x =>
                x.PreviousSibling != null && x.PreviousSibling.Text == "Patent/reg.nr. og dato").Text;

            var patentId = patentIdAndDate.Split(',').First();

            using (var context = new Context())
            {
                var patent = new Patent
                {
                    Html = browser.Html,
                    InventorField = inventor,
                    PatentId = patentId,
                    Year = year,
                };
                context.Patents.Add(patent);
                context.SaveChanges();
            }
        }
コード例 #25
0
 public JsonResult RemoveTag(TagViewModel tag)
 {
     Thread.Sleep(300);
     string r = string.Format("removed '{0}' from article", tag.name);
     using (var context = new Context())
     {
         foreach (var at in context.ArticleTags.Where(x => x.Article.Id == articleId && x.Tag.Name == tag.name))
         {
             context.ArticleTags.Remove(at);
         }
         context.SaveChanges();
         if (context.ArticleTags.Where(x => x.Tag.Name == tag.name).Count() == 0)
         {
             context.Tags.Where(x => x.Name == tag.name).ToList().ForEach(y => context.Tags.Remove(y));
             r = string.Format("removed tag '{0}' from article and tag '{0}'", tag.name);
         }
         context.SaveChanges();
     }
     return Json(this.GetTagsFromDb(), JsonRequestBehavior.AllowGet); //Content(r);
 }
コード例 #26
0
 public JsonResult SaveTag(TagViewModel tag)
 {
     Thread.Sleep(300);
     using (var context = new Context())
     {
         var article = context.Articles.Find(articleId);
         var dbTag = context.Tags.Where(x => x.Name == tag.name).FirstOrDefault();
         if (dbTag == null)
         {
             dbTag = context.Tags.Add(new Tag { Name = tag.name });
         }
         if (!context.ArticleTags.Any(x => x.Article.Id == articleId && x.Tag.Name == tag.name))
         {
             context.ArticleTags.Add(new ArticleTag { Article = article, Tag = dbTag });
         }
         context.SaveChanges();
     }
     return Json(this.GetTagsFromDb(), JsonRequestBehavior.AllowGet); //Content(r);
 }
コード例 #27
0
 private IQueryable<TagViewModel> GetTagsFromDb()
 {
     using (var context = new Context())
     {
         var list = (from t in _context.Tags
                     group t by new { t.Id, t.Name }
                         into grp
                         select new TagViewModel
                         {
                             tagId = grp.Key.Id,
                             name = grp.Key.Name,
                             isInArticle = grp.Sum(t => _context.ArticleTags.Where(x => x.Article.Id == articleId).Where(x => x.Tag.Id == t.Id).Count()) > 0
                         });
         return list;
     }
 }
コード例 #28
0
        public static void Execute()
        {
            var _context = new Context();

            var xp = new XMLParser();
            xp.execute();

            var readinglist = _context.GPSReadings.ToList();
            var smjoblist = _context.SMJobs.ToList();
            var now = string.Format("{0:HH:mm:ss tt}", DateTime.Now);
            var trucklocation = readinglist.First();
            var mh = new MapHelper();
            var n = string.Format("{0:HH:mm:ss tt}", DateTime.Now);
            var t = n.Split(':');
            var nowtime = (Convert.ToInt32(t[0]) * 60) + Convert.ToInt32(t[1]);
            foreach (SMJob job in smjoblist)
            {
                var jobminutes = (Convert.ToInt32(job.Hour) * 60) + Convert.ToInt32(job.Minute);
                var drivetime = mh.getDriveTimeinMinutes(job.Lat, job.Lng, trucklocation.Lat, trucklocation.Lng);
                if (drivetime < 2)
                {
                    var status = "";
                    job.isAtLocation = true;
                    job.hasArrived = true;

                    status = job.willBeLate ? "late" : "ontime";
                    var el = new SMEventLog
                    {
                        Type = status,
                        Address = job.Address,
                        RouteNumber = job.RouteNumber,
                        Time = now,
                        Techs = job.Techs,
                        Company = job.Company,
                        TimeDifference = jobminutes - nowtime
                    };
                    _context.SaveChanges();
                }
                else
                {
                    if (job.isAtLocation)
                    {
                        job.isAtLocation = false;
                        job.completed = true;
                    }
                }
                if (!job.completed && !job.isAtLocation)
                {
                    if (drivetime > (jobminutes - nowtime))
                    {
                        job.willBeLate = true;
                        // send sms here
                        if (!job.alertSent)
                        {
                            //SMSHelper.sendMessage(job);
                            job.alertSent = true;
                            job.alertSentTime = now;
                        }
                    }
                }
                // _context.SMJobs.Add(job);
                _context.SaveChanges();
            }
            Trace.WriteLine("UPDATING CLIENT");
            Notifier.Update();
        }
コード例 #29
0
            public static void Update()
            {
                var _context = new Context();

                List<SMJob> smjobs = _context.SMJobs.ToList();
                //Trace.WriteLine("smjobs count = "+ smjobs.Count);
                IHubContext hub2 = GlobalHost.ConnectionManager.GetHubContext<Smjob>();
                string json2 = JsonConvert.SerializeObject(smjobs);
                hub2.Clients.update(json2);

                List<GPSReading> readings = _context.GPSReadings.ToList();
                var lulist = new List<locupdate>();
                foreach (GPSReading reading in readings)
                {
                    var lu = new locupdate
                                 {
                                     RouteNumber = reading.RouteNumber,
                                     Address = reading.Address
                                 };
                    //Trace.WriteLine("rn =" + lu.RouteNumber);
                    lulist.Add(lu);
                }
                string json = JsonConvert.SerializeObject(lulist);
                hub2.Clients.updatelocs(json);
            }
コード例 #30
0
        public static String getRouteNumberFromDriver(String s)
        {
            string driver = "";
            string[] arr = s.Split(',');

            var _context = new Context();
            List<Driver> driverlist = _context.Drivers.ToList();

            foreach(Driver d in driverlist)
            {
                if (d.Name.Replace(" ", "").Equals(arr[0].Replace(" ", "")) && d.Company.Equals(cn))
                {
                    driver = d.Name.Replace(" ", "");
                }
            }

            List<Route> routelist = _context.Routes.ToList();

            Route r = null;
            string rtnum = "";
            foreach (Route route in routelist.Where(route => route.Company.Equals(cn) && route.Driver.Replace(" ", "").Equals(driver)))
            {
                //Trace.WriteLine("route number set");
                rtnum = route.Number;
            }
            return rtnum;
        }