Example #1
0
        public MainViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUpdatesService updatesService, IPushService pushService, IVibrationService vibrationService, ILiveLocationService liveLocationService, IContactsService contactsService, IPasscodeService passcodeService, DialogsViewModel dialogs)
            : base(protoService, cacheService, aggregator)
        {
            _updatesService      = updatesService;
            _pushService         = pushService;
            _vibrationService    = vibrationService;
            _liveLocationService = liveLocationService;
            _passcodeService     = passcodeService;

            _typingManagers     = new ConcurrentDictionary <int, InputTypingManager>();
            _chatTypingManagers = new ConcurrentDictionary <int, InputTypingManager>();

            //Dialogs = new DialogCollection(protoService, cacheService);
            SearchDialogs = new ObservableCollection <TLDialog>();
            Dialogs       = dialogs;
            Contacts      = new ContactsViewModel(protoService, cacheService, aggregator, contactsService);
            Calls         = new CallsViewModel(protoService, cacheService, aggregator);

            _selfDestructTimer = new YoloTimer(CheckSelfDestructMessages, this);
            _selfDestructItems = new List <TLMessage>();

            aggregator.Subscribe(this);

            LiveLocationCommand     = new RelayCommand(LiveLocationExecute);
            StopLiveLocationCommand = new RelayCommand(StopLiveLocationExecute);
        }
Example #2
0
 public UsersController(IUserService service, ISessionService sessionService, IUpdatesService updatesService, IOnlinesService onlinesService)
 {
     _userService    = service;
     _sessionService = sessionService;
     _updatesService = updatesService;
     _onlinesService = onlinesService;
 }
 public ApiController(IUniversitiesService universitiesService,
                      IUpdatesService updatesService,
                      IExecutionService executionService)
 {
     this.universitiesService = universitiesService;
     this.updatesService      = updatesService;
     this.executionService    = executionService;
 }
Example #4
0
 public SettingsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUpdatesService updatesService, IPushService pushService, IContactsService contactsService, IUploadFileManager uploadFileManager, IStickersService stickersService)
     : base(protoService, cacheService, aggregator)
 {
     _updatesService    = updatesService;
     _pushService       = pushService;
     _contactsService   = contactsService;
     _uploadFileManager = uploadFileManager;
     _stickersService   = stickersService;
 }
Example #5
0
        public SnapshotsViewModel(ICacheService cacheService, IUpdatesService updateService, ITelegramEventAggregator eventAggregator)
        {
            Items = new ObservableCollection <SnapshotItem>();

            _cacheService    = cacheService;
            _updateService   = updateService;
            _eventAggregator = eventAggregator;

            Execute.BeginOnThreadPool(() =>
            {
                try
                {
                    var currentState = _updateService.GetState();
                    State            = currentState;
                    NotifyOfPropertyChange(() => State);

                    var tempDifference = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), Telegram.Api.Constants.DifferenceFileName);
                    Difference         = tempDifference;
                    NotifyOfPropertyChange(() => Difference);

                    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (store.DirectoryExists(Constants.SnapshotsDirectoryName))
                        {
                            foreach (var directory in store.GetDirectoryNames(Constants.SnapshotsDirectoryName + "/*"))
                            {
                                var item = new SnapshotItem {
                                    Name = directory
                                };

                                var stateFullFileName = Path.Combine(Path.Combine(Constants.SnapshotsDirectoryName, directory), Telegram.Api.Constants.StateFileName);
                                if (store.FileExists(stateFullFileName))
                                {
                                    var state  = TLUtils.OpenObjectFromMTProtoFile <TLState>(new object(), stateFullFileName);
                                    item.State = state;
                                }

                                var differenceFullFileName = Path.Combine(Path.Combine(Constants.SnapshotsDirectoryName, directory), Telegram.Api.Constants.DifferenceFileName);
                                if (store.FileExists(differenceFullFileName))
                                {
                                    long length;
                                    var difference        = TLUtils.OpenObjectFromMTProtoFile <TLVector <TLDifferenceBase> >(new object(), differenceFullFileName, out length);
                                    item.Difference       = difference;
                                    item.DifferenceLength = length;
                                }

                                Execute.BeginOnUIThread(() => Items.Add(item));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            });
        }
Example #6
0
        public SettingsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IUpdatesService updatesService, IPushService pushService, IContactsService contactsService, IUploadFileManager uploadFileManager, IStickersService stickersService)
            : base(protoService, cacheService, aggregator)
        {
            _updatesService    = updatesService;
            _pushService       = pushService;
            _contactsService   = contactsService;
            _uploadFileManager = uploadFileManager;
            _stickersService   = stickersService;

            AskCommand       = new RelayCommand(AskExecute);
            LogoutCommand    = new RelayCommand(LogoutExecute);
            EditPhotoCommand = new RelayCommand <StorageFile>(EditPhotoExecute);
        }
Example #7
0
 public AdsService(SellMeDbContext context, IAddressesService addressesService, IUsersService usersService,
                   ICategoriesService categoriesService, IUpdatesService updatesService,
                   ISubCategoriesService subCategoriesService, IMapper mapper, ICloudinaryService cloudinaryService)
 {
     this.context              = context;
     this.addressesService     = addressesService;
     this.usersService         = usersService;
     this.categoriesService    = categoriesService;
     this.updatesService       = updatesService;
     this.subCategoriesService = subCategoriesService;
     this.mapper            = mapper;
     this.cloudinaryService = cloudinaryService;
 }
Example #8
0
        public async Task CreateUpdateAdAsync_WithInvalidAdId_ShouldThrowAndInvalidArgumentException()
        {
            //Arrange
            var expectedErrorMessage = "Ad with the given id doesn't exist!";

            var context = InitializeContext.CreateContextForInMemory();

            updatesService = new UpdatesService(context);

            //Act and assert
            var ex = await Assert.ThrowsAsync <ArgumentException>(() => updatesService.CreateUpdateAdAsync(1));

            Assert.Equal(expectedErrorMessage, ex.Message);
        }
Example #9
0
        public async Task CreateUpdateAdAsync_WithValidData_ShouldCreateUpdateAd()
        {
            //Arrange
            var expectedUpdateAdCount = 1;

            var context = InitializeContext.CreateContextForInMemory();

            updatesService = new UpdatesService(context);

            var testingAd = new Ad
            {
                Id                = 1,
                Title             = "Iphone 6s",
                Description       = "PerfectCondition",
                ActiveFrom        = DateTime.UtcNow,
                ActiveTo          = DateTime.UtcNow.AddDays(30),
                AvailabilityCount = 1,
                Price             = 120,
                Condition         = new Condition {
                    Name = "Brand New"
                },
                Address = new Address
                {
                    Country      = "Bulgaria",
                    City         = "Sofia",
                    Street       = "Ivan Vazov",
                    District     = "Student city",
                    ZipCode      = 1000,
                    PhoneNumber  = "0895335532",
                    EmailAddress = "*****@*****.**"
                }
            };

            await context.Ads.AddAsync(testingAd);

            await context.SaveChangesAsync();

            //Act
            await updatesService.CreateUpdateAdAsync(1);

            //Assert
            Assert.Equal(expectedUpdateAdCount, context.UpdateAds.Count());
        }
        private BannerService()
        {
            try
            {
                this.serviceInstance = UpdatesServiceClientFactory.CreateNew();

                this.localBannersDirInfo = new DirectoryInfo(Path.Combine(Configuration.JustAssemblyAppDataFolder, "Banners"));

                if (!localBannersDirInfo.Exists)
                {
                    localBannersDirInfo.Create();
                }

                this.holderIdToDefaultBannerMap = GenerateDefaultBannersMap();

                this.currentBannerCampaignVersion = GetCurrentBannerCampaignVersion();

                if (this.currentBannerCampaignVersion != null)
                {
                    // Delete banners from old campaigns
                    this.DeleteBannerCampaignVersions(str => !str.Equals(currentBannerCampaignVersion.ToString(), StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    // Just to be sure that the Banners folder is empty
                    this.DeleteAllBannerCampaignVersions();
                }

                if (this.currentBannerCampaignVersion != null)
                {
                    this.currentBannerCampaignDirInfo = new DirectoryInfo(Path.Combine(localBannersDirInfo.FullName, this.currentBannerCampaignVersion.ToString()));

                    this.holderIdToBannerConfigMap = GenerateHolderIdToConfigMap(this.currentBannerCampaignDirInfo);
                }

                this.CheckLatestServerCampaignVersionsAsync(OnCheckLatestServerCampaignVersionsAsync);
            }
            catch (Exception ex)
            {
                Configuration.Analytics.TrackException(ex);
            }
        }
Example #11
0
        public static void LogOutCommon(ITelegramEventAggregator eventAggregator, IMTProtoService mtProtoService, IUpdatesService updateService, ICacheService cacheService, IStateService stateService, IPushService pushService, INavigationService navigationService)
        {
            eventAggregator.Publish(Commands.LogOutCommand);

            SettingsHelper.SetValue(Constants.IsAuthorizedKey, false);
            SettingsHelper.RemoveValue(Constants.CurrentUserKey);
            mtProtoService.ClearQueue();
            updateService.ClearState();
            cacheService.ClearAsync();
            stateService.ResetPasscode();
            stateService.GetAllStickersAsync(result =>
            {
                var allStickers29 = result as TLAllStickers29;
                if (allStickers29 != null)
                {
                    allStickers29.RecentlyUsed = new TLVector <TLRecentlyUsedSticker>();
                }

                stateService.SaveAllStickersAsync(allStickers29);
            });
            SearchViewModel.DeleteRecentAsync();

            if (navigationService.CurrentSource == navigationService.UriFor <StartupViewModel>().BuildUri() ||
                navigationService.CurrentSource == navigationService.UriFor <SignInViewModel>().BuildUri() ||
                navigationService.CurrentSource == navigationService.UriFor <ConfirmViewModel>().BuildUri() ||
                navigationService.CurrentSource == navigationService.UriFor <SignUpViewModel>().BuildUri())
            {
                return;
            }

            stateService.ClearNavigationStack = true;
            Telegram.Logs.Log.Write("StartupViewModel SettingsViewModel.LogOutCommon");
            navigationService.UriFor <StartupViewModel>().Navigate();
        }
Example #12
0
 public UserService(IUsersRepository repository, IUpdatesService updatesService)
 {
     _repository     = repository;
     _updatesService = updatesService;
 }
Example #13
0
        public MTProtoService(int account, IDeviceInfoService deviceInfo, IUpdatesService updatesService, ICacheService cacheService, IConnectionService connectionService, IStatsService statsService)
        {
            var isBackground = deviceInfo != null && deviceInfo.IsBackground;

            _connectionManager        = ConnectionManager.Instance;
            _connectionManager.Logger = new Logs.Log();
            _connectionManager.CurrentNetworkTypeChanged  += ConnectionManager_CurrentNetworkTypeChanged;
            _connectionManager.ConnectionStateChanged     += ConnectionManager_ConnectionStateChanged;
            _connectionManager.UnprocessedMessageReceived += ConnectionManager_UnprocessedMessageReceived;
            _connectionManager.AuthenticationRequired     += ConnectionManager_AuthenticationRequired;
            _connectionManager.UserConfigurationRequired  += ConnectionManager_UserConfigurationRequired;
            _connectionManager.SessionCreated             += ConnectionManager_SessionCreated;

            CurrentUserId = SettingsHelper.UserId;

            _statsService = statsService;

            _deviceInfo = deviceInfo;

            _deviceLockedTimer = new Timer(CheckDeviceLockedInternal, this, TimeSpan.FromSeconds(60.0), TimeSpan.FromSeconds(60.0));

            _connectionService = connectionService;
            _connectionService.Initialize(this);
            //_connectionService.ConnectionLost += OnConnectionLost;

            var sendStatusEvents = Observable.FromEventPattern <EventHandler <bool>, bool>(
                keh => { SendStatus += keh; },
                keh => { SendStatus -= keh; });

            _statusSubscription = sendStatusEvents
                                  .Throttle(TimeSpan.FromSeconds(Constants.UpdateStatusInterval))
                                  .Subscribe(e => UpdateStatusAsync(e.EventArgs, result => { }));

            _cacheService = cacheService;

            _updatesService = updatesService;

            if (_updatesService != null)
            {
                //_updatesService.DCOptionsUpdated += OnDCOptionsUpdated;

                _updatesService.GetDifferenceAsync = GetDifferenceAsync;
                _updatesService.GetStateAsync      = GetStateAsync;
                _updatesService.GetCurrentUserId   = GetCurrentUserId;
                _updatesService.GetDHConfigAsync   = GetDHConfigAsync;
                //_updatesService.AcceptEncryptionAsync = AcceptEncryptionAsync;
                _updatesService.SendEncryptedServiceAsync = SendEncryptedServiceAsync;
                _updatesService.SetMessageOnTimeAsync     = SetMessageOnTime;
                _updatesService.RemoveFromQueue           = RemoveFromQueue;
                _updatesService.UpdateChannelAsync        = UpdateChannelAsync;
                _updatesService.GetParticipantAsync       = GetParticipantAsync;
                _updatesService.GetFullChatAsync          = GetFullChatAsync;
                _updatesService.GetFullUserAsync          = GetFullUserAsync;
                _updatesService.GetChannelMessagesAsync   = GetMessagesAsync;
                _updatesService.GetMessagesAsync          = GetMessagesAsync;
            }

            if (!SettingsHelper.IsAuthorized)
            {
                SendInformativeMessage <TLNearestDC>("help.getNearestDc", new TLHelpGetNearestDC(), result =>
                {
                    RaiseGotUserCountry(result.Country);
                }, null, flags: RequestFlag.FailOnServerError | RequestFlag.WithoutLogin);
            }

            ToggleProxy();
            Current = this;
        }
Example #14
0
 public ChatService(IChatRepository repository, IFileService fileService, IUpdatesService updatesService)
 {
     _repository     = repository;
     _fileService    = fileService;
     _updatesService = updatesService;
 }
Example #15
0
 public OnlinesService(IUsersRepository usersRepository, IUpdatesService updatesService)
 {
     _usersRepository = usersRepository;
     _updatesService  = updatesService;
 }
 public HomeController(IUpdatesService service)
 {
     this._service = service;
 }
Example #17
0
        public static void LogOutCommon(ITelegramEventAggregator eventAggregator, IMTProtoService mtProtoService, IUpdatesService updateService, ICacheService cacheService, IStateService stateService, IPushService pushService, INavigationService navigationService)
        {
            eventAggregator.Publish(Commands.LogOutCommand);

            SettingsHelper.SetValue(Constants.IsAuthorizedKey, false);
            SettingsHelper.RemoveValue(Constants.CurrentUserKey);
            mtProtoService.ClearQueue();
            updateService.ClearState();
            cacheService.ClearAsync();
            stateService.ResetPasscode();

            stateService.ClearAllStickersAsync();
            stateService.ClearFeaturedStickersAsync();
            stateService.ClearArchivedStickersAsync();

            EmojiControl emojiControl;

            if (EmojiControl.TryGetInstance(out emojiControl))
            {
                emojiControl.ClearStickersOnLogOut();
            }

            cacheService.ClearConfigImportAsync();
            SearchViewModel.DeleteRecentAsync();

            Bootstrapper.UpdateMainTile();

            DialogDetailsViewModel.DeleteInlineBots();
            FileUtils.Delete(new object(), Constants.InlineBotsNotificationFileName);
            FileUtils.Delete(new object(), Constants.WebPagePreviewsFileName);

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

            liveLocationService.Clear();

            if (navigationService.CurrentSource == navigationService.UriFor <StartupViewModel>().BuildUri() ||
                navigationService.CurrentSource == navigationService.UriFor <SignInViewModel>().BuildUri() ||
                navigationService.CurrentSource == navigationService.UriFor <ConfirmViewModel>().BuildUri() ||
                navigationService.CurrentSource == navigationService.UriFor <SignUpViewModel>().BuildUri())
            {
                return;
            }

            stateService.ClearNavigationStack = true;
            Telegram.Logs.Log.Write("StartupViewModel SettingsViewModel.LogOutCommon");
            navigationService.UriFor <StartupViewModel>().Navigate();
        }