Exemple #1
0
 public Travel CreateTravelViewTest()
 {
     string partitionKey = "Lanxing"; // TODO: Initialize to an appropriate value
     Guid rowKey = Guid.NewGuid(); // TODO: Initialize to an appropriate value
     string place = "Shanghai"; // TODO: Initialize to an appropriate value
     DateTime time = DateTime.Now; // TODO: Initialize to an appropriate value
     SqlGeography sqlGeography = SqlGeography.Point(31, 121, 4326);
     Travel travelView = new Travel() { PartitionKey = partitionKey, RowKey = rowKey, Place = place, Time = time, GeoLocationText = sqlGeography.ToString() };
     return travelView;
 }
Exemple #2
0
 public void GeoLocationTest()
 {
     Travel target = new Travel(); // TODO: Initialize to an appropriate value
     byte[] expected = null; // TODO: Initialize to an appropriate value
     byte[] actual;
     target.GeoLocation = expected;
     actual = target.GeoLocation;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Exemple #3
0
 public void RemoveFromTravel(Travel travel)
 {
     this._travelItems.Remove(travel);
     this._dataServiceContext.DeleteObject(travel);
 }
Exemple #4
0
 public void AddToTravel(Travel travel)
 {
     this._travelItems.Add(travel);
     this._dataServiceContext.AddObject("Travels", travel);
 }
Exemple #5
0
 public void UpdateTravel(Travel travel)
 {
     this._dataServiceContext.UpdateObject(travel);
 }
        public override int SaveChanges(SaveOptions options)
        {
            int returnValue = 0;
            // 因为我们不调用base.SaveChanges, 我们必须手动关闭链接.
            // 否则我们将留下许多打开的链接, 最终导致链接瓶颈.
            // Entity Framework提供了base.SaveChanges内部使用的EnsureConnection和ReleaseConnection.
            // 这些是内部方法, 所以我们必须使用反射调用它们.
            var EnsureConnectionMethod = typeof(ObjectContext).GetMethod(
                "EnsureConnection", BindingFlags.Instance | BindingFlags.NonPublic);

            EnsureConnectionMethod.Invoke(this, null);
            // 使用ObjectStateManager.GetObjectStateEntries完成增加,修改,和删除集合.
            foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Added))
            {
                Travel travel = ose.Entity as Travel;
                if (travel != null)
                {
                    RetryPolicy retryPolicy = new RetryPolicy();
                    retryPolicy.Task = new Action(() =>
                    {
                        this.InsertIntoTravel(travel.PartitionKey,
                                              travel.Place, travel.GeoLocationText, travel.Time);
                    });
                    retryPolicy.Execute();
                    returnValue++;
                }
            }
            foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Modified))
            {
                Travel travel = ose.Entity as Travel;
                if (travel != null)
                {
                    RetryPolicy retryPolicy = new RetryPolicy();
                    retryPolicy.Task = new Action(() =>
                    {
                        this.UpdateTravel(travel.PartitionKey,
                                          travel.RowKey, travel.Place, travel.GeoLocationText, travel.Time);
                    });
                    retryPolicy.Execute();
                    returnValue++;
                }
            }
            foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
            {
                Travel travel = ose.Entity as Travel;
                if (travel != null)
                {
                    RetryPolicy retryPolicy = new RetryPolicy();
                    retryPolicy.Task = new Action(() =>
                    {
                        this.DeleteFromTravel(travel.PartitionKey, travel.RowKey);
                    });
                    retryPolicy.Execute();
                    returnValue++;
                }
            }
            var ReleaseConnectionMethod = typeof(ObjectContext).
                                          GetMethod("ReleaseConnection", BindingFlags.Instance | BindingFlags.NonPublic);

            ReleaseConnectionMethod.Invoke(this, null);
            return(returnValue);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Travels EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTravels(Travel travel)
 {
     base.AddObject("Travels", travel);
 }
 /// <summary>
 /// Create a new Travel object.
 /// </summary>
 /// <param name="partitionKey">Initial value of the PartitionKey property.</param>
 /// <param name="rowKey">Initial value of the RowKey property.</param>
 /// <param name="place">Initial value of the Place property.</param>
 /// <param name="time">Initial value of the Time property.</param>
 public static Travel CreateTravel(global::System.String partitionKey, global::System.Guid rowKey, global::System.String place, global::System.DateTime time)
 {
     Travel travel = new Travel();
     travel.PartitionKey = partitionKey;
     travel.RowKey = rowKey;
     travel.Place = place;
     travel.Time = time;
     return travel;
 }
Exemple #9
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Travels EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTravels(Travel travel)
 {
     base.AddObject("Travels", travel);
 }
        public override int SaveChanges(SaveOptions options)
        {
            int returnValue = 0;
            // Since we do not call base.SaveChanges, we have to take care of connections manually.
            // Otherwise we may leave a lot of connections open, which results in connection throttle.
            // Entity Framework provides EnsureConnection and ReleaseConnection which base.SaveChanges uses internally.
            // They're internal methods, so we have to use reflection to invoke them.
            var EnsureConnectionMethod = typeof(ObjectContext).GetMethod(
                "EnsureConnection", BindingFlags.Instance | BindingFlags.NonPublic);

            EnsureConnectionMethod.Invoke(this, null);
            // Use ObjectStateManager.GetObjectStateEntries to obtain added, modified, and deleted entities.
            foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Added))
            {
                Travel travel = ose.Entity as Travel;
                if (travel != null)
                {
                    RetryPolicy retryPolicy = new RetryPolicy();
                    retryPolicy.Task = new Action(() =>
                    {
                        this.InsertIntoTravel(travel.PartitionKey,
                                              travel.Place, travel.GeoLocationText, travel.Time);
                    });
                    retryPolicy.Execute();
                    returnValue++;
                }
            }
            foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Modified))
            {
                Travel travel = ose.Entity as Travel;
                if (travel != null)
                {
                    RetryPolicy retryPolicy = new RetryPolicy();
                    retryPolicy.Task = new Action(() =>
                    {
                        this.UpdateTravel(travel.PartitionKey,
                                          travel.RowKey, travel.Place, travel.GeoLocationText, travel.Time);
                    });
                    retryPolicy.Execute();
                    returnValue++;
                }
            }
            foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
            {
                Travel travel = ose.Entity as Travel;
                if (travel != null)
                {
                    RetryPolicy retryPolicy = new RetryPolicy();
                    retryPolicy.Task = new Action(() =>
                    {
                        this.DeleteFromTravel(travel.PartitionKey, travel.RowKey);
                    });
                    retryPolicy.Execute();
                    returnValue++;
                }
            }
            var ReleaseConnectionMethod = typeof(ObjectContext).
                                          GetMethod("ReleaseConnection", BindingFlags.Instance | BindingFlags.NonPublic);

            ReleaseConnectionMethod.Invoke(this, null);
            return(returnValue);
        }
Exemple #11
0
 public void TravelViewConstructorTest()
 {
     Travel target = new Travel();
     //Assert.Inconclusive("TODO: Implement code to verify target");
 }
Exemple #12
0
 public void TimeTest()
 {
     Travel target = new Travel(); // TODO: Initialize to an appropriate value
     DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value
     DateTime actual;
     target.Time = expected;
     actual = target.Time;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Exemple #13
0
 public void RowKeyTest()
 {
     Travel target = new Travel(); // TODO: Initialize to an appropriate value
     Guid expected = new Guid(); // TODO: Initialize to an appropriate value
     Guid actual;
     target.RowKey = expected;
     actual = target.RowKey;
     Assert.AreEqual(expected, actual);
 }
Exemple #14
0
 public void PlaceTest()
 {
     Travel target = new Travel(); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.Place = expected;
     actual = target.Place;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Exemple #15
0
 /// <summary>
 /// Bing Maps Geocode服务的回调方法.
 /// </summary>
 private void GeocodeClient_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         MessageBox.Show(e.Error.Message);
     }
     else if (e.Result.Results.Count > 0)
     {
         // 我们只关心第一个结果.
         var result = e.Result.Results[0];
         Travel travel = new Travel()
         {
             // PartitionKey代表用户.
             // 然而, 客户端可以如下演示般发送一个假身份.
             // 为了防止客户端使用假身份,
             // 我们的服务一直在服务器端查询真实的身份.
             PartitionKey = "*****@*****.**",
             RowKey = Guid.NewGuid(),
             Place = result.DisplayName,
             Time = DateTime.Now,
             // Latitude/Longitude通过服务获得地址,
             // 因此可能不是正巧为所点击的地址.
             Latitude = result.Locations[0].Latitude,
             Longitude = result.Locations[0].Longitude
         };
         // 添加到ObservableCollection.
         App.DataSource.AddToTravel(travel);
     }
 }