Exemplo n.º 1
0
    public ActionResult Create(Station station)
    {
        if (ModelState.IsValid)
        {
            db.Stations.AddObject(station);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(station);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Stations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStations(Station station)
 {
     base.AddObject("Stations", station);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new Station object.
 /// </summary>
 /// <param name="stationID">Initial value of the StationID property.</param>
 /// <param name="approved">Initial value of the Approved property.</param>
 public static Station CreateStation(global::System.Int64 stationID, global::System.Boolean approved)
 {
     Station station = new Station();
     station.StationID = stationID;
     station.Approved = approved;
     return station;
 }
Exemplo n.º 4
0
        public FilesModel RequiredFiles(string serverKey, string hardwareKey, string version)
        {
            lock (RequiredFilesLock)
            {


                // Get Mosaic For station
                var container = new eAdDataContainer();

                var thisStation = (from s in container.Stations
                                   where s.HardwareKey == hardwareKey
                                   select s).FirstOrDefault<Station>();

                if (thisStation == null)
                {
                    thisStation = new Station();
                    thisStation.HardwareKey = hardwareKey;
                    thisStation.Name = hardwareKey;
                    thisStation.LastCheckIn = DateTime.Now;
                    thisStation.Status = "Registered";
                    container.Stations.AddObject(thisStation);
                    container.SaveChanges();
                }
                else
                {
                    thisStation.LastCheckIn = DateTime.Now;
                    thisStation.Status = "Online";
                    container.SaveChanges();
                }

                Mosaic mosaic = null;
                Mosaic profilemosaic = null;
                if (thisStation != null)
                {
                    var grouping = (from m in container.Groupings
                                    where m.Mosaic != null
                                    select m).FirstOrDefault<Grouping>();

                    if (grouping != null)
                    {
                        mosaic = grouping.Mosaic;
                        profilemosaic = container.Mosaics.Where(mo => mo.MosaicID == grouping.ProfileMosaicID).FirstOrDefault();
                    }
                }

                if (mosaic == null)
                {
                    mosaic = (from m in container.Mosaics
                              where m.Name.Contains("as")
                              select m).FirstOrDefault();
                }

                if (profilemosaic == null)
                {
                    profilemosaic = container.Mosaics.Where(m => m.Type == "Profile").FirstOrDefault();
                }

                var mosaicCache = AppPath + "Layouts\\" + mosaic.MosaicID + ".mosaic";
                var profilemosaicCache = AppPath + "Layouts\\" + profilemosaic.MosaicID + ".mosaic";

                if (File.Exists(mosaicCache))
                {
                    if (new FileInfo(mosaicCache).CreationTime < mosaic.Updated)
                    {
                        UpdateMosaicCache(mosaic, mosaicCache);

                    }


                }
                else
                {
                    UpdateMosaicCache(mosaic, mosaicCache);

                }

                if (File.Exists(profilemosaicCache))
                {
                    if (new FileInfo(profilemosaicCache).CreationTime < mosaic.Updated)
                    {
                        UpdateMosaicCache(profilemosaic, profilemosaicCache);

                    }


                }
                else
                {
                    UpdateMosaicCache(profilemosaic, profilemosaicCache);

                }


                container.SaveChanges();
                var files = CreateFileModel(new List<Mosaic> { mosaic, profilemosaic });
                return files;
            }
        }
Exemplo n.º 5
0
    public void DownloadInfo(HttpContextBase httpContext,string xmlUrl, string stationID, bool start=true)
    {
        try
        {

            Station station;
            Customer customer;
            Car car;

            StreamReader reader = new StreamReader(WebRequest.Create(xmlUrl).GetResponse().GetResponseStream());
            XmlSerializer xSerializer = new XmlSerializer(typeof(proton));
            proton greenlotsInfo = (proton)xSerializer.Deserialize(reader);

            if(db.Stations.Where(s=>s.UniqueID==stationID).Count() <=0)
            {
                station = new Station {UniqueID = stationID};
                db.Stations.AddObject(station);
                db.SaveChanges();
            }
            else
            {
                station = db.Stations.Where(s => s.UniqueID.Trim() == stationID.Trim()).FirstOrDefault();

            }



            string path = httpContext.Server.MapPath("~/Logs/GreenLots/" + "log.txt");



            if (station != null)
            {
                station.Name = greenlotsInfo.Location.information[0].name;
                station.Address = greenlotsInfo.Location.information[0].address + "\n" + greenlotsInfo.Location.information[0].address1 + "\n" + greenlotsInfo.Location.information[0].address2;
                station.PostalCode = greenlotsInfo.Location.information[0].postal;
                try
                {
                    station.Rate = Convert.ToDouble( greenlotsInfo.Location.information[0].rate);
                }
                catch(Exception ex)
                {

                }
            }

            var customerInfo = greenlotsInfo.User.information[0];
            if (db.Customers.Where(s => s.Email == customerInfo.email).Count() <= 0)
            {
                customer = new Customer();
                customer.Email = greenlotsInfo.User.information[0].email;
                db.Customers.AddObject(customer);
                db.SaveChanges();
            }
            else
            {
                customer = db.Customers.Where(s => s.Email == customerInfo.email).FirstOrDefault();
            }

            if (customer != null)
            {
                customer.Picture = customerInfo.image;
                customer.Name = customerInfo.firstname + " " + customerInfo.lastname;
                customer.Address = customerInfo.address + " " + customerInfo.address1 + " " + customerInfo.address2;
                customer.Language = customerInfo.language;
                customer.SMSAlert =customerInfo.sms_alert=="1";
                customer.EmailAlert =customerInfo.email_alert=="1";
                customer.Phone = customerInfo.contact;
                customer.Balance = customerInfo.credit_balance;
            }


            var carInfo = greenlotsInfo.Vehicle.information[0];
            var history = greenlotsInfo.History.session[0];
            if (db.Cars.Where(s => s.RFID == carInfo.rfid).Count() <= 0)
            {
                car = new Car();
                car.RFID = carInfo.rfid;
                if (customer != null)
                    car.CustomerID = customer.CustomerID;
                db.Cars.AddObject(car);
                db.SaveChanges();
            }
            else
            {
                car = db.Cars.Where(s => s.RFID == carInfo.rfid).FirstOrDefault();
            }

            if (car != null)
            {
                car.License = carInfo.license_plate;
                car.Make = carInfo.make;
                car.Model = carInfo.model;
                try
                {
                    car.TotalUsage = Convert.ToDouble(carInfo.total_usage);
                    car.BatteryCycle = Convert.ToDouble(carInfo.battery_cycle);
                }
                catch(Exception ex)
                {

                }
                //Fix up date
                var datetxt = history.end;
                try
                {
                    datetxt = datetxt.Replace("Today", DateTime.Now.Date.ToShortDateString());
                    datetxt = datetxt.Replace("Yesterday", DateTime.Now.Date.ToShortDateString());
                    car.LastRechargeDate = DateTime.Parse(datetxt);
                }
                catch (Exception ex)
                {
                    try
                    {
                        DateTime.ParseExact(datetxt, "dd/MM/yyyy HH:mm", null);
                    }
                    catch(Exception ex1)
                    {

                        Logger.WriteLine(path, "\nInvalid Date Format Detected");
                    }

                }


            }



            Logger.WriteLine(path, "\n--------------- Data Received  ---------------");
            Logger.WriteLine(path, (string) greenlotsInfo.User.information[0].address);
            //   Logger.WriteLine(path, greenlotsInfo.email);
            Logger.WriteLine(path, "\n--------------- Data Received End---------------");

            db.SaveChanges();

            if (start)
            {
                if (station != null && car!=null)
                    Service.MakeStationUnAvailable(station.StationID, car.RFID);
            }
            else
            {
                if (station != null)
                    Service.MakeStationAvailable(station.StationID);
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
Exemplo n.º 6
0
 public ActionResult Edit(Station station)
 {
     if (ModelState.IsValid)
     {
         db.Stations.Attach(station);
         db.ObjectStateManager.ChangeObjectState(station, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(station);
 }