Ejemplo n.º 1
0
 public override void Delete(Geoname geoname)
 {
     if (geoname.EntityState == EntityState.Deleted)
     {
         this._entities.Geonames.Attach(geoname);
     }
     this._entities.Geonames.DeleteObject(geoname);
 }
Ejemplo n.º 2
0
        public override void Delete(Geoname geoname)
        {

          
            if (geoname.EntityState == EntityState.Deleted)
            {
                this._entities.Geonames.Attach(geoname);
            }
          this._entities.Geonames.DeleteObject(geoname);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new Geoname object.
        /// </summary>
        /// <param name="locationID">Initial value of the LocationID property.</param>
        /// <param name="country">Initial value of the Country property.</param>
        /// <param name="county">Initial value of the County property.</param>
        /// <param name="name">Initial value of the Name property.</param>
        public static Geoname CreateGeoname(global::System.Int32 locationID, global::System.String country, global::System.String county, global::System.String name)
        {
            Geoname geoname = new Geoname();

            geoname.LocationID = locationID;
            geoname.Country    = country;
            geoname.County     = county;
            geoname.Name       = name;
            return(geoname);
        }
Ejemplo n.º 4
0
        public List <Weather> FindWeathers(Geoname geoname, string screenName)
        {
            var requestUrlstring = String.Format("http://www.yr.no/place/{0}/{1}/{2}/forecast.xml", geoname.Country, geoname.County, geoname.Name);

            var document = LoadDocument(requestUrlstring);

            return((from time in document.Descendants("time")                              // Väljer ut alla time noder.
                    where Int32.Parse(time.Attribute("period").Value) >= 2                 // Där periodens värde är större eller lika med 2.
                    group time by DateTime.Parse(time.Attribute("from").Value).Date into g // Gruppera perioderna per dag. Välj sedan ut den första i varje par.
                    select(from t in g select t).First()).Take(5).Select(forecast => YrFactory.Create(forecast, geoname.LocationID)).ToList());
        }
Ejemplo n.º 5
0
        public List<Weather> FindWeathers(Geoname geoname, string screenName)
        {
           

            var requestUrlstring = String.Format("http://www.yr.no/place/{0}/{1}/{2}/forecast.xml", geoname.Country, geoname.County, geoname.Name);

            var document = LoadDocument(requestUrlstring);

           return (from time in document.Descendants("time") // Väljer ut alla time noder.
                    where Int32.Parse(time.Attribute("period").Value) >= 2 // Där periodens värde är större eller lika med 2.
                    group time by DateTime.Parse(time.Attribute("from").Value).Date into g // Gruppera perioderna per dag. Välj sedan ut den första i varje par.
                    select (from t in g select t).First()).Take(5).Select(forecast => YrFactory.Create(forecast, geoname.LocationID)).ToList();
        }
Ejemplo n.º 6
0
        public override void Update(Geoname geoname)
        {
            ObjectStateEntry entry;
            if (!this._entities.ObjectStateManager.TryGetObjectStateEntry(geoname, out entry) ||
                entry.State == EntityState.Detached)
            {
                this._entities.Geonames.Attach(geoname);
            }

            if (geoname.EntityState != EntityState.Modified)
            {
                this._entities.ObjectStateManager.ChangeObjectState(geoname, EntityState.Modified);
            }
        }
Ejemplo n.º 7
0
        public override void Update(Geoname geoname)
        {
            ObjectStateEntry entry;

            if (!this._entities.ObjectStateManager.TryGetObjectStateEntry(geoname, out entry) ||
                entry.State == EntityState.Detached)
            {
                this._entities.Geonames.Attach(geoname);
            }

            if (geoname.EntityState != EntityState.Modified)
            {
                this._entities.ObjectStateManager.ChangeObjectState(geoname, EntityState.Modified);
            }
        }
Ejemplo n.º 8
0
        public List<Weather> FindWeathers(Geoname geoname, string screenName, int locationID)
        {

            
           // Gets weather forecasts
             var weathers = this._repository.QueryWeather().Where(t => t.LocationID == locationID).OrderBy(w => w.Time).ToList();

            // Checks if there are any weather forecasts saved in db and if datetime hasn't occured
            if (!weathers.Any())
            {
               
                  // ...aktivates web service if no post with city exists
                var webservice = new GeonameWebservice();
                weathers = webservice.FindWeathers(geoname, screenName);

                // for every object sets FK from parameter int.
                weathers.ForEach(t => t.LocationID = locationID);

                // ...update the location and save the weather in the database.
                geoname.NextUpdate = DateTime.Now.AddMinutes(10);
                weathers.ForEach(t => this._repository.Add(t));
                //weathers.ForEach(t => this._repository.Update(t));
                this._repository.Save();
            }
               else
            {
                    // ...delete the old(?) weathers (if there are any),...
                    weathers.ForEach(t => this._repository.Delete(t));

                    var webservice = new GeonameWebservice();
                    weathers = webservice.FindWeathers(geoname, screenName);

                    weathers.ForEach(t => t.LocationID = locationID);
                    // ...update the user and save the weathers in the database.
                    geoname.NextUpdate = DateTime.Now.AddMinutes(10);
                    weathers.ForEach(t => this._repository.Add(t));
                    
                    this._repository.Save();
            }
            
                return weathers;
        }
Ejemplo n.º 9
0
        public List <Weather> FindWeathers(Geoname geoname, string screenName, int locationID)
        {
            // Gets weather forecasts
            var weathers = this._repository.QueryWeather().Where(t => t.LocationID == locationID).OrderBy(w => w.Time).ToList();

            // Checks if there are any weather forecasts saved in db and if datetime hasn't occured
            if (!weathers.Any())
            {
                // ...aktivates web service if no post with city exists
                var webservice = new GeonameWebservice();
                weathers = webservice.FindWeathers(geoname, screenName);

                // for every object sets FK from parameter int.
                weathers.ForEach(t => t.LocationID = locationID);

                // ...update the location and save the weather in the database.
                geoname.NextUpdate = DateTime.Now.AddMinutes(10);
                weathers.ForEach(t => this._repository.Add(t));
                //weathers.ForEach(t => this._repository.Update(t));
                this._repository.Save();
            }
            else
            {
                // ...delete the old(?) weathers (if there are any),...
                weathers.ForEach(t => this._repository.Delete(t));

                var webservice = new GeonameWebservice();
                weathers = webservice.FindWeathers(geoname, screenName);

                weathers.ForEach(t => t.LocationID = locationID);
                // ...update the user and save the weathers in the database.
                geoname.NextUpdate = DateTime.Now.AddMinutes(10);
                weathers.ForEach(t => this._repository.Add(t));

                this._repository.Save();
            }

            return(weathers);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Create a new Geoname object.
 /// </summary>
 /// <param name="locationID">Initial value of the LocationID property.</param>
 /// <param name="country">Initial value of the Country property.</param>
 /// <param name="county">Initial value of the County property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Geoname CreateGeoname(global::System.Int32 locationID, global::System.String country, global::System.String county, global::System.String name)
 {
     Geoname geoname = new Geoname();
     geoname.LocationID = locationID;
     geoname.Country = country;
     geoname.County = county;
     geoname.Name = name;
     return geoname;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Geonames EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGeonames(Geoname geoname)
 {
     base.AddObject("Geonames", geoname);
 }
Ejemplo n.º 12
0
 public override void Add(Geoname geoname)
 {
     this._entities.Geonames.AddObject(geoname);
 }
Ejemplo n.º 13
0
 public override void Add(Geoname geoname)
 {
     this._entities.Geonames.AddObject(geoname);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Geonames EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGeonames(Geoname geoname)
 {
     base.AddObject("Geonames", geoname);
 }