コード例 #1
0
        //Upload a symbolicLocation in the background (update or create)
	    //Form: AsyncTask<[Input Parameter Type], [Progress Report Type], [Result Type]>
	    private void UploadSymbolicLocationTask(SymbolicLocation tmpSymLoc)
        {
            isUploading = true;
            mContext = LocationService.radiomapContext;

		    Vertex currentVertex = Map2DOffline.SelectedOfflineVertex;
			SymbolicLocation currentSymLoc = currentVertex.SymbolicLocations.FirstOrDefault();
			//1) upload NEW symbolic location 
			if (currentSymLoc == null)
            {
                mContext.AddRelatedObject(currentVertex, "SymbolicLocations", tmpSymLoc);
                currentVertex.SymbolicLocations.Add(tmpSymLoc);
			}
			//2) or UPDATE existing
			else
			{
                //copy updated values 
                currentSymLoc.title = tmpSymLoc.title;
                currentSymLoc.description = tmpSymLoc.description;
                currentSymLoc.url = tmpSymLoc.url;
                currentSymLoc.is_entrance = tmpSymLoc.is_entrance;    
                
                mContext.UpdateObject(currentSymLoc);				
			}
            try
            {
                mContext.BeginSaveChanges(OnChangesSaved, mContext);
                
                //uploadProgressBar.Visibility = System.Windows.Visibility.Visible;
                uploadProgressIndicator.IsVisible = isUploading;             
                
            }
            catch (Exception ex)
            {
                isUploading = false;
                uploadProgressIndicator.IsVisible = isUploading;
                                
                MessageBox.Show(string.Format("The changes could not be saved.\n"
                    + "The following error occurred: {0}", ex.Message));
            }
		}
コード例 #2
0
        private void OnChangesSaved(IAsyncResult result)
        {
            bool errorOccured = false;

            // Use the Dispatcher to ensure that the 
            // asynchronous call returns in the correct thread.
            Dispatcher.BeginInvoke(() =>
            {
                isUploading = false;
                uploadProgressIndicator.IsVisible = isUploading;

                mContext = result.AsyncState as radiomapEntities;
                try
                {
                    // Complete the save changes operation and display the response.
                    DataServiceResponse response = mContext.EndSaveChanges(result);

                    foreach (ChangeOperationResponse changeResponse in response)
                    {
                        if (changeResponse.Error != null) errorOccured = true;
                    }
                    if (!errorOccured)
                    {
                        Globals.ShowDialog(this, Globals.CHANGES_SAVED, Globals.DURATION_SHORT);

                        //Finalize edge, i.e., add it to the endpoint's edges and to the building
                        /*
                        Building b = LocationService.CurrentBuilding;
                        b.Edges.Add(mCurrentEdge);
                        foreach (Vertex v in mCurrentEdge.Vertices)
                        {
                            if (!v.Edges.Contains(mCurrentEdge))
                                v.Edges.Add(mCurrentEdge);
                        }
                        */
                        NavigationService.GoBack();
                        //Tell everyone the good news!
                        if (OnEdgeAdded != null)
                        {
                            OnEdgeAdded(this, EventArgs.Empty);
                        } 
                    }
                    else
                    {
                        MessageBox.Show("An error occured. One or more changes could not be saved.");
                    }
                }
                catch (Exception ex)
                {
                    // Display the error from the response.
                    string errorMsg = ex.InnerException != null ?
                        ex.InnerException.Message :
                        ex.Message;
                    MessageBox.Show(string.Format("The following error occured: {0}", errorMsg));
                }
            }
            );
        }
コード例 #3
0
        //Upload a symbolicLocation in the background (update or create)
        //Form: AsyncTask<[Input Parameter Type], [Progress Report Type], [Result Type]>
        private void AddEdgeTask()
        {
            isUploading = true;
            mContext = LocationService.radiomapContext;
            
            /*
            Uri radiomapUri = new Uri("http://smartcampusaau.cs.aau.dk/RadioMapService3/RadioMapService.svc/");
            mContext = new radiomapEntities(radiomapUri);
            Building b = (mContext.Buildings.Where(b1 => b1.ID == LocationService.CurrentBuilding.ID)).First();
            Vertex v0 = (mContext.Vertices.Where(v => v.ID == mCurrentEdge.Vertices[0].ID)).First();
            Vertex v1 = (mContext.Vertices.Where(v => v.ID == mCurrentEdge.Vertices[1].ID)).Single();
            mContext.AddToEdges(mCurrentEdge);
            mContext.AddLink(b, "Edges", mCurrentEdge);
            mContext.AddLink(v0, "Edges", mCurrentEdge);
            mContext.AddLink(v1, "Edges", mCurrentEdge);
            */

            //Link to/from the building and endpoints
            mContext.AddToEdges(mCurrentEdge);
            Building b = LocationService.CurrentBuilding;
            b.Edges.Add(mCurrentEdge);
            /*
            foreach (Vertex v in mCurrentEdge.Vertices)
            {
                if (!v.Edges.Contains(mCurrentEdge))
                    v.Edges.Add(mCurrentEdge);
            }
            */
            try
            {
                mContext.BeginSaveChanges(OnChangesSaved, mContext);

                uploadProgressIndicator.IsVisible = isUploading;

            }
            catch (Exception ex)
            {
                isUploading = false;
                uploadProgressIndicator.IsVisible = isUploading;

                MessageBox.Show(string.Format("The changes could not be saved.\n"
                    + "The following error occurred: {0}", ex.Message));
            }
        }
コード例 #4
0
 private static void UploadTrackingDataAndFlushBuffer()
 {
     if (bufferedTrackedPositions == null)
         return;
     if (bufferedTrackedPositions.Count == 0)
         return;
                 
     //copy tracking data and clear buffer
     TrackedPosition[] tmp;
     lock (bufferedTrackedPositionsLock)
     {
         int numPositions = bufferedTrackedPositions.Count;
         tmp = new TrackedPosition[numPositions];
         bufferedTrackedPositions.CopyTo(tmp);
         bufferedTrackedPositions.Clear();
     }
     
     radiomapEntities context = new radiomapEntities(radiomapUri);
     foreach (TrackedPosition pos in tmp)
     {
         context.AddToTrackedPositions(pos);
     }
     context.BeginSaveChanges(SaveChangesOptions.Batch, OnPositionEstimatesSaved, context);
     
 }
コード例 #5
0
		/// <summary>
		/// Downloads a radio map for the building with the specified id. 
		/// </summary>
		/// <param name="buildingId"></param>
		public static void DownloadRadioMap(int buildingId)
		{
			radiomapContext = new radiomapEntities(radiomapUri);
			buildings = new DataServiceCollection<Building>(radiomapContext);
            
            String expandOptions = "Building_Floors,Vertices,Vertices/AbsoluteLocations,Vertices/SymbolicLocations,Vertices/Edges,Edges,Edges/Vertices,Edges/Vertices/AbsoluteLocations";
			var query = from b in radiomapContext.Buildings.Expand(expandOptions)
						where b.ID == buildingId 
						select b;

			// Register for the LoadCompleted event.
			buildings.LoadCompleted
				+= new EventHandler<LoadCompletedEventArgs>(buildings_LoadCompleted);
			buildings.LoadAsync(query);
		}
コード例 #6
0
        private void RemoveEdgeTask()
        {
            if (CurrentEdge == null)
                throw new InvalidOperationException("No link to remove");

            isUploading = true;
            mContext = LocationService.radiomapContext;

            //Add the edge
            mContext.DeleteObject(CurrentEdge);
            
            try
            {
                mContext.BeginSaveChanges(OnChangesSaved, mContext);

                uploadProgressIndicator.IsVisible = isUploading;
            }
            catch (Exception ex)
            {
                isUploading = false;
                uploadProgressIndicator.IsVisible = isUploading;

                // Display the error from the response.
                string errorMsg = ex.InnerException != null ?
                    ex.InnerException.Message :
                    ex.Message;
                MessageBox.Show(string.Format("The following error occured: {0}", errorMsg));
            }
        }
コード例 #7
0
        private void OnChangesSaved(IAsyncResult result)
        {
            bool errorOccured = false;
            
            // Use the Dispatcher to ensure that the 
            // asynchronous call returns in the correct thread.
            Dispatcher.BeginInvoke(() =>
            {
                isUploading = false;
                uploadProgressIndicator.IsVisible = isUploading;
                
                mContext = result.AsyncState as radiomapEntities;
                try
                {
                    // Complete the save changes operation and display the response.
                    DataServiceResponse response = mContext.EndSaveChanges(result);

                    foreach (ChangeOperationResponse changeResponse in response)
                    {
                        if (changeResponse.Error != null) errorOccured = true;
                    }
                    if (!errorOccured)
                    {
                        Globals.ShowDialog(this, Globals.CHANGES_SAVED, Globals.DURATION_SHORT);
                        NavigationService.GoBack();
                        if (OnSymbolicLocationChange != null)
                        {
                            OnSymbolicLocationChange(this, null);
                        }
                    }
                    else
                    {
                        MessageBox.Show("An error occured. One or more changes could not be saved.");
                    }
                }
                catch (Exception ex)
                {
                    // Display the error from the response.
                    MessageBox.Show(string.Format("The following error occured: {0}", ex.Message));
                }
            }
            );
        }