Esempio n. 1
0
        private IAsyncOperation <bool> LaunchGeoPointAsync(string title, TLGeoPoint point)
        {
            if (point != null)
            {
                return(Launcher.LaunchUriAsync(new Uri(string.Format(CultureInfo.InvariantCulture, "bingmaps:?collection=point.{0}_{1}_{2}", point.Lat, point.Long, WebUtility.UrlEncode(title)))));
            }

            return(Task.FromResult(true).AsAsyncOperation());
        }
Esempio n. 2
0
        private void GeoLive_OnTick(object sender, System.EventArgs e)
        {
            if (_timerMessage == null)
            {
                _timer.Stop();
                return;
            }

            var peer = With as IInputPeer;

            if (peer == null)
            {
                return;
            }

            var message = _timerMessage as TLMessage70;

            if (message == null)
            {
                return;
            }

            var mediaGeoLive = message.Media as TLMessageMediaGeoLive;

            if (mediaGeoLive == null)
            {
                return;
            }

            var geoPoint = mediaGeoLive.Geo as TLGeoPoint;

            if (geoPoint == null)
            {
                return;
            }

            var newGeoPoint = new TLGeoPoint {
                Lat = new TLDouble(geoPoint.Lat.Value - 0.001 / 6.0), Long = new TLDouble(geoPoint.Long.Value - 0.001538762512 / 6.0)
            };

            var liveLocationsService = IoC.Get <ILiveLocationService>();

            liveLocationsService.UpdateAsync(message, newGeoPoint, result =>
                                             Execute.BeginOnUIThread(() =>
            {
                mediaGeoLive.EditDate = message.EditDate;
                mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Geo);
                mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.EditDate);
                mediaGeoLive.NotifyOfPropertyChange(() => mediaGeoLive.Active);

                StopEditMessage();
            }),
                                             error => Execute.BeginOnUIThread(() =>
            {
                _timer.Stop();
            }));
        }
        private void SendGeoPoint(TLGeoPoint geoPoint)
        {
            var chat = Chat as TLEncryptedChat;

            if (chat == null)
            {
                return;
            }

            var decryptedTuple = GetDecryptedMessageAndObject(TLString.Empty, new TLDecryptedMessageMediaGeoPoint {
                Lat = geoPoint.Lat, Long = geoPoint.Long
            }, chat);

            Items.Insert(0, decryptedTuple.Item1);
            RaiseScrollToBottom();
            NotifyOfPropertyChange(() => DescriptionVisibility);

            SendEncrypted(chat, decryptedTuple.Item2, MTProtoService, CacheService);
        }
        private void SendGeoPoint(TLGeoPoint geoPoint)
        {
            var media = new TLMessageMediaGeo {
                Geo = geoPoint
            };

            var message = GetMessage(TLString.Empty, media);

            BeginOnUIThread(() =>
            {
                var previousMessage = InsertSendingMessage(message);
                IsEmptyDialog       = Items.Count == 0 && LazyItems.Count == 0;

                BeginOnThreadPool(() =>
                                  CacheService.SyncSendingMessage(
                                      message, previousMessage,
                                      TLUtils.InputPeerToPeer(Peer, StateService.CurrentUserId),
                                      SendGeoPointInternal));
            });
        }
Esempio n. 5
0
        public static BitmapSource ReturnOrEnqueueGeoPointImage(TLGeoPoint geoPoint, int width, int height, TLObject owner)
        {
            var destFileName = geoPoint.GetFileName();

            BitmapSource  imageSource;
            WeakReference weakImageSource;

            if (_cachedSources.TryGetValue(destFileName, out weakImageSource))
            {
                if (weakImageSource.IsAlive)
                {
                    imageSource = weakImageSource.Target as BitmapSource;

                    return(imageSource);
                }
            }

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.FileExists(destFileName))
                {
                    var sourceUri = string.Format(Constants.StaticGoogleMap, geoPoint.Lat.Value.ToString(new CultureInfo("en-US")), geoPoint.Long.Value.ToString(new CultureInfo("en-US")), width, height);

                    var fileManager = IoC.Get <IHttpDocumentFileManager>();

                    fileManager.DownloadFileAsync(sourceUri, destFileName, owner, item =>
                    {
                        var messageMediaGeoPoint = owner as IMessageMediaGeoPoint;
                        if (messageMediaGeoPoint != null)
                        {
                            var newGeoPoint = messageMediaGeoPoint.Geo as TLGeoPoint;
                            if (newGeoPoint != null)
                            {
                                var newFileName = newGeoPoint.GetFileName();
                                var oldFileName = destFileName;

                                using (var store2 = IsolatedStorageFile.GetUserStoreForApplication())
                                {
                                    if (store2.FileExists(oldFileName))
                                    {
                                        if (!string.IsNullOrEmpty(oldFileName) && !string.Equals(oldFileName, newFileName, StringComparison.OrdinalIgnoreCase))
                                        {
                                            store2.CopyFile(oldFileName, newFileName, true);
                                            store2.DeleteFile(oldFileName);
                                        }
                                    }
                                }
                            }

                            Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
                            {
                                var messageMediaBase = owner as TLMessageMediaBase;
                                if (messageMediaBase != null)
                                {
                                    messageMediaBase.NotifyOfPropertyChange(() => messageMediaBase.Self);
                                }
                                var decryptedMessageMediaBase = owner as TLDecryptedMessageMediaBase;
                                if (decryptedMessageMediaBase != null)
                                {
                                    decryptedMessageMediaBase.NotifyOfPropertyChange(() => decryptedMessageMediaBase.Self);
                                }
                            });
                        }
                    });
                }
                else
                {
                    try
                    {
                        using (var stream = store.OpenFile(destFileName, FileMode.Open, FileAccess.Read))
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            var image = new BitmapImage();
                            image.SetSource(stream);
                            imageSource = image;
                        }

                        _cachedSources[destFileName] = new WeakReference(imageSource);
                    }
                    catch (Exception)
                    {
                        return(null);
                    }

                    return(imageSource);
                }
            }

            return(null);
        }
Esempio n. 6
0
        public static BitmapSource ReturnOrEnqueueGeoPointImage(TLGeoPoint geoPoint, int width, int height, TLObject owner)
        {
            var destFileName = geoPoint.GetFileName();

            BitmapSource  imageSource;
            WeakReference weakImageSource;

            if (_cachedSources.TryGetValue(destFileName, out weakImageSource))
            {
                if (weakImageSource.IsAlive)
                {
                    imageSource = weakImageSource.Target as BitmapSource;

                    return(imageSource);
                }
            }

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.FileExists(destFileName))
                {
                    var config = IoC.Get <ICacheService>().GetConfig() as TLConfig82;
                    if (config == null)
                    {
                        return(null);
                    }

                    var fileManager = IoC.Get <IWebFileManager>();

                    var geoPoint82 = geoPoint as TLGeoPoint82;
                    var accessHash = geoPoint82 != null ? geoPoint82.AccessHash : new TLLong(0);

                    var inputLocation = new TLInputWebFileGeoPointLocation
                    {
                        GeoPoint = new TLInputGeoPoint {
                            Long = geoPoint.Long, Lat = geoPoint.Lat
                        },
                        AccessHash = accessHash,
                        W          = new TLInt(width),
                        H          = new TLInt(height),
                        Zoom       = new TLInt(15),
                        Scale      = new TLInt(2)
                    };

                    fileManager.DownloadFile(config.WebfileDCId, inputLocation, destFileName, owner, item =>
                    {
                        var messageMediaGeoPoint = owner as IMessageMediaGeoPoint;
                        if (messageMediaGeoPoint != null)
                        {
                            var newGeoPoint = messageMediaGeoPoint.Geo as TLGeoPoint;
                            if (newGeoPoint != null)
                            {
                                var newFileName = newGeoPoint.GetFileName();
                                var oldFileName = destFileName;

                                using (var store2 = IsolatedStorageFile.GetUserStoreForApplication())
                                {
                                    if (store2.FileExists(oldFileName))
                                    {
                                        if (!string.IsNullOrEmpty(oldFileName) && !string.Equals(oldFileName, newFileName, StringComparison.OrdinalIgnoreCase))
                                        {
                                            store2.CopyFile(oldFileName, newFileName, true);
                                            store2.DeleteFile(oldFileName);
                                        }
                                    }
                                }
                            }

                            Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
                            {
                                var messageMediaBase = owner as TLMessageMediaBase;
                                if (messageMediaBase != null)
                                {
                                    messageMediaBase.NotifyOfPropertyChange(() => messageMediaBase.Self);
                                }
                                var decryptedMessageMediaBase = owner as TLDecryptedMessageMediaBase;
                                if (decryptedMessageMediaBase != null)
                                {
                                    decryptedMessageMediaBase.NotifyOfPropertyChange(() => decryptedMessageMediaBase.Self);
                                }
                            });
                        }
                    });
                }
                else
                {
                    try
                    {
                        using (var stream = store.OpenFile(destFileName, FileMode.Open, FileAccess.Read))
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            var image = new BitmapImage();
                            image.SetSource(stream);
                            imageSource = image;
                        }

                        _cachedSources[destFileName] = new WeakReference(imageSource);
                    }
                    catch (Exception)
                    {
                        return(null);
                    }

                    return(imageSource);
                }
            }

            return(null);
        }