/// <summary>
        /// Load dummy pushpins at design-time
        /// </summary>
        /// <param name="layer">The layer to which the downloaded pushpins will be associated.</param>
        /// <param name="pushpins">The PushpinModel collection to be populated.</param>
        public static void LoadPushpinsAsync(LayerModel layer, Collection<PushpinModel> pushpins)
        {
            PushpinModel pushpin1 = new PushpinModel
            {
                Guid = Guid.NewGuid().ToString(),
                Description = "Design-Time Description",
                Layer = layer,
                Location = new GeoCoordinate(48.8925, 2.3449)
            };

            PushpinModel pushpin2 = new PushpinModel
            {
                Guid = Guid.NewGuid().ToString(),
                Description = "Design-Time Description",
                Layer = layer,
                Location = new GeoCoordinate(48.8875, 2.3882)
            };

            PushpinModel pushpin3 = new PushpinModel
            {
                Guid = Guid.NewGuid().ToString(),
                Description = "Design-Time Description",
                Layer = layer,
                Location = new GeoCoordinate(48.8766, 2.3555)
            };

            PushpinModel pushpin4 = new PushpinModel
            {
                Guid = Guid.NewGuid().ToString(),
                Description = "Design-Time Description",
                Layer = layer,
                Location = new GeoCoordinate(48.8641, 2.3977)
            };

            PushpinModel pushpin5 = new PushpinModel
            {
                Guid = Guid.NewGuid().ToString(),
                Description = "Design-Time Description",
                Layer = layer,
                Location = new GeoCoordinate(48.8327, 2.3261)
            };

            PushpinModel pushpin6 = new PushpinModel
            {
                Guid = Guid.NewGuid().ToString(),
                Description = "Design-Time Description",
                Layer = layer,
                Location = new GeoCoordinate(48.8166, 2.3605)
            };

            pushpins.Add(pushpin1);
            pushpins.Add(pushpin2);
            pushpins.Add(pushpin3);
            pushpins.Add(pushpin4);
            pushpins.Add(pushpin5);
            pushpins.Add(pushpin6);
        }
        public TwitterViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                try
                {
                    AccessToken = IsolatedStorageSettings.ApplicationSettings["AccessToken"] as OAuthAccessToken;
                    TwitterUsername = IsolatedStorageSettings.ApplicationSettings["TwitterUsername"] as string;
                    TwitterPassword = IsolatedStorageSettings.ApplicationSettings["TwitterPassword"] as string;

                    SelectedPushpin = IsolatedStorageSettings.ApplicationSettings["SelectedPushpin"] as PushpinModel;
                    //We create the summary if it doesn't exist only when when authentication against ODAF website has been established
                    CommentService.Authenticated += (sender, e) =>
                        {
                            CommentService.CreateSummaryAsync(SelectedPushpin);
                        };
                    CommentService.SummaryCreated += (sender, e) =>
                        {
                            SummaryHasBeenCreated = true;
                        };
                    CommentService.AuthenticateAsync(AccessToken.Token, AccessToken.TokenSecret);

                    if (AccessToken == null || TwitterUsername == null || TwitterPassword == null)
                    {
                        throw new KeyNotFoundException();
                    }
                    Twitter.AuthenticateWith(AccessToken.Token, AccessToken.TokenSecret);
                    HasUserAlreadyAuthorizedApp = true;
                }
                catch (KeyNotFoundException)
                {
                    HasUserAlreadyAuthorizedApp = false;
                    GetRequestToken();
                }
            }

            _AuthenticateUserCommand = new DelegateCommand(AuthenticateUser, (obj) => true);
            _SendTweetCommand = new DelegateCommand(SendTweet, CanSendTweet);
            _ResetTwitterCredentialsCommand = new DelegateCommand(ResetTwitterCredentials, (obj) => true);
            _TakePhotoCommand = new DelegateCommand(TakePhoto, (obj) => HasUserAlreadyAuthorizedApp);
        }
Beispiel #3
0
        private static void LoadPushpinsAsync_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            LayerAndPushpin layerAndPushpin = e.UserState as LayerAndPushpin;
            if (layerAndPushpin.LayerModel == null)
            {
                throw new ArgumentNullException("layer", "The layer parameter provided to the LoadPushpinsAsync method is null.");
            }
            if (layerAndPushpin.PushpinModels == null)
            {
                throw new ArgumentNullException("pushpins", "The pushpins parameter provided to the LoadPushpinsAsync method is null.");
            }
            if (e.Error != null)
            {
                throw e.Error;
            }

            XElement root = XElement.Parse(e.Result);
            XNamespace kml = "http://www.opengis.net/kml/2.2";

            var placemarks = from placemark in root.Descendants(kml + "Placemark")
                             select new
                             {
                                 Guid = placemark.Element(kml + "name").Value,
                                 Description = placemark.Element(kml + "description").Value,
                                 Latitude = double.Parse(placemark.Element(kml + "Point").Element(kml + "coordinates").Value.Split(',')[1], CultureInfo.InvariantCulture),
                                 Longitude = double.Parse(placemark.Element(kml + "Point").Element(kml + "coordinates").Value.Split(',')[0], CultureInfo.InvariantCulture)
                             };

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (send, evt) =>
            {
                foreach (var placemark in placemarks)
                {
                    PushpinModel pushpin = new PushpinModel
                    {
                        Guid = placemark.Guid,
                        Description = placemark.Description,
                        Location = new GeoCoordinate(placemark.Latitude, placemark.Longitude),
                        Layer = layerAndPushpin.LayerModel
                    };

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        layerAndPushpin.PushpinModels.Add(pushpin);
                    });
                }
            };
            worker.RunWorkerAsync();
        }
        /// <summary>
        /// Create a PointDataSummary in the ODAF database asynchronously.
        /// The PointDataSummary properties will be mapped to the PushpinModel properties passed as a parameter.
        /// </summary>
        /// <param name="pushpinModel">the PushpinModel which serves as a base to create the PointDataSummary.</param>
        public void CreateSummaryAsync(PushpinModel pushpinModel)
        {
            Uri uri = new Uri(App.OdafWebsiteUrl
                + _summariesAddControllerRelativeUrl);

            HttpWebRequest request = WebRequest.CreateHttp(uri);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.CookieContainer = container;

            CreateSummaryUserState userState = new CreateSummaryUserState
            {
                Request = request,
                PushpinModel = pushpinModel
            };

            request.BeginGetRequestStream(CreateSummaryPostRequest, userState);
        }