示例#1
0
        public ProtoService(int session, IDeviceInfoService deviceInfoService, ISettingsService settings, IEventAggregator aggregator)
        {
            _session           = session;
            _deviceInfoService = deviceInfoService;
            _settings          = settings;
            _aggregator        = aggregator;

            _preferences = new AutoDownloadPreferences(ApplicationData.Current.LocalSettings.CreateContainer("autoDownload", ApplicationDataCreateDisposition.Always));

            Initialize();
        }
        public ProtoService(int session, IDeviceInfoService deviceInfoService, ISettingsService settings, IEventAggregator aggregator)
        {
            Log.SetVerbosityLevel(ApplicationSettings.Current.VerbosityLevel);
            Log.SetFilePath(Path.Combine(ApplicationData.Current.LocalFolder.Path, $"{session}", "log"));

            _session           = session;
            _deviceInfoService = deviceInfoService;
            _aggregator        = aggregator;

            _preferences = new AutoDownloadPreferences(ApplicationData.Current.LocalSettings.CreateContainer("autoDownload", ApplicationDataCreateDisposition.Always));

            Initialize();
        }
示例#3
0
        public ProtoService(IDeviceInfoService deviceInfoService, IEventAggregator aggregator)
        {
            Log.SetVerbosityLevel(ApplicationSettings.Current.VerbosityLevel);
            Log.SetFilePath(Path.Combine(ApplicationData.Current.LocalFolder.Path, "0", "log"));

            _client            = Client.Create(this);
            _deviceInfoService = deviceInfoService;
            _aggregator        = aggregator;

            _preferences = new AutoDownloadPreferences(ApplicationData.Current.LocalSettings.CreateContainer("autoDownload", ApplicationDataCreateDisposition.Always));

            var parameters = new TdlibParameters
            {
                DatabaseDirectory  = Path.Combine(ApplicationData.Current.LocalFolder.Path, "0"),
                UseSecretChats     = true,
                UseMessageDatabase = true,
                ApiId              = Telegram.Api.Constants.ApiId,
                ApiHash            = Telegram.Api.Constants.ApiHash,
                SystemLanguageCode = "en",
                DeviceModel        = _deviceInfoService.DeviceModel,
                SystemVersion      = _deviceInfoService.SystemVersion,
                ApplicationVersion = _deviceInfoService.AppVersion,
            };

#if MOCKUP
            ProfilePhoto ProfilePhoto(string name)
            {
                return(new ProfilePhoto(0, new TdWindows.File(0, 0, 0, new LocalFile(System.IO.Path.Combine(Package.Current.InstalledLocation.Path, "Assets\\Mockup\\", name), true, true, false, true, 0, 0), null), null));
            }

            ChatPhoto ChatPhoto(string name)
            {
                return(new ChatPhoto(new TdWindows.File(0, 0, 0, new LocalFile(System.IO.Path.Combine(Package.Current.InstalledLocation.Path, "Assets\\Mockup\\", name), true, true, false, true, 0, 0), null), null));
            }

            _users[0]  = new User(0, "Jane", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[1]  = new User(1, "Tyrion", "Lannister", string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[2]  = new User(2, "Alena", "Shy", string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[3]  = new User(3, "Heisenberg", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[4]  = new User(4, "Bender", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[5]  = new User(5, "EVE", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[16] = new User(16, "Nick", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[7]  = new User(7, "Eileen", "Lockhard \uD83D\uDC99", string.Empty, string.Empty, new UserStatusOnline(int.MaxValue), ProfilePhoto("a5.png"), null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[11] = new User(11, "Thomas", string.Empty, string.Empty, string.Empty, null, ProfilePhoto("a3.png"), null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[9]  = new User(9, "Daenerys", string.Empty, string.Empty, string.Empty, null, ProfilePhoto("a2.png"), null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[13] = new User(13, "Angela", "Merkel", string.Empty, string.Empty, null, ProfilePhoto("a1.png"), null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[10] = new User(10, "Julian", "Assange", string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[8]  = new User(8, "Pierre", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[17] = new User(17, "Alexmitter", string.Empty, string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);
            _users[18] = new User(18, "Jaina", "Moore", string.Empty, string.Empty, null, null, null, null, false, string.Empty, true, new UserTypeRegular(), string.Empty);

            _secretChats[1] = new SecretChat(1, 7, new SecretChatStateReady(), false, 15, new byte[0], 75);

            _supergroups[0] = new Supergroup(0, string.Empty, 0, new ChatMemberStatusMember(), 0, false, false, true, true, string.Empty);
            _supergroups[1] = new Supergroup(1, string.Empty, 0, new ChatMemberStatusMember(), 0, false, false, true, false, string.Empty);
            _supergroups[2] = new Supergroup(2, string.Empty, 0, new ChatMemberStatusMember(), 7, false, false, false, false, string.Empty);
            _supergroups[3] = new Supergroup(3, string.Empty, 0, new ChatMemberStatusMember(), 0, false, false, false, false, string.Empty);

            int TodayDate(int hour, int minute)
            {
                return((int)Utils.DateTimeToUnixTimestamp(DateTime.Now.Date.AddHours(hour).AddMinutes(minute)));
            }

            int TuesdayDate()
            {
                var last = DateTime.Now;

                do
                {
                    last = last.AddDays(-1);
                }while (last.DayOfWeek != DayOfWeek.Tuesday);

                return((int)Utils.DateTimeToUnixTimestamp(last));
            }

            var lastMessage0  = new Message(long.MaxValue, 0, 0, null, false, false, false, false, false, false, false, TodayDate(17, 07), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Great news everyone! Unigram X is now available in the Microsoft Store", new TextEntity[0]), null), null);
            var lastMessage1  = new Message(long.MaxValue, 1, 1, null, false, false, false, false, false, false, false, TodayDate(15, 34), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Well I do help animals. Maybe I'll have a few cats in my new luxury apartment. 😊", new TextEntity[0]), null), null);
            var lastMessage2  = new Message(long.MaxValue, 2, 2, null, false, false, false, false, false, false, false, TodayDate(18, 12), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Sometimes possession is an abstract concept. They took my purse, but the...", new TextEntity[0]), null), null);
            var lastMessage3  = new Message(long.MaxValue, 3, 3, null, false, false, false, false, false, false, false, TodayDate(18, 00), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageSticker(new Sticker(0, 0, 0, "😍", false, null, null, null)), null);
            var lastMessage4  = new Message(long.MaxValue, 4, 4, null, false, false, false, false, false, false, false, TodayDate(17, 23), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Thanks, Telegram helps me a lot. You have my financial support if you need more servers.", new TextEntity[0]), null), null);
            var lastMessage5  = new Message(long.MaxValue, 5, 5, null, false, false, false, false, false, false, false, TodayDate(15, 10), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("I looove new Surfaces! If fact, they invited me to a focus group.", new TextEntity[0]), null), null);
            var lastMessage6  = new Message(long.MaxValue, 6, 6, null, false, false, false, false, false, false, false, TodayDate(12, 53), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Telegram just updated their iOS app!", new TextEntity[0]), null), null);
            var lastMessage7  = new Message(long.MaxValue, 7, 7, null, false, false, false, false, false, false, false, TuesdayDate(), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageDocument(new Document("LaserBlastSafetyGuide.pdf", string.Empty, null, null), new FormattedText(string.Empty, new TextEntity[0])), null);
            var lastMessage8  = new Message(long.MaxValue, 8, 8, null, false, false, false, false, false, false, false, TuesdayDate(), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("It's impossible.", new TextEntity[0]), null), null);
            var lastMessage9  = new Message(long.MaxValue, 9, 9, null, false, false, false, false, false, false, false, TuesdayDate(), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Hola!", new TextEntity[0]), null), null);
            var lastMessage10 = new Message(long.MaxValue, 17, 12, null, false, false, false, false, false, false, false, TuesdayDate(), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("Let's design more robust memes", new TextEntity[0]), null), null);
            var lastMessage11 = new Message(long.MaxValue, 18, 13, null, false, false, false, false, false, false, false, TuesdayDate(), 0, null, 0, 0, 0, 0, string.Empty, 0, 0, new MessageText(new FormattedText("What?! 😱", new TextEntity[0]), null), null);

            _chats[0]  = new Chat(0, new ChatTypeSupergroup(0, true), "Unigram News", ChatPhoto("a0.png"), lastMessage0, long.MaxValue - 0, true, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[1]  = new Chat(1, new ChatTypePrivate(0), "Jane", ChatPhoto("a6.png"), lastMessage1, long.MaxValue - 1, true, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[2]  = new Chat(2, new ChatTypePrivate(1), "Tyrion Lannister", null, lastMessage2, long.MaxValue - 2, false, 1, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[3]  = new Chat(3, new ChatTypePrivate(2), "Alena Shy", ChatPhoto("a7.png"), lastMessage3, long.MaxValue - 3, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[4]  = new Chat(4, new ChatTypeSecret(0, 3), "Heisenberg", ChatPhoto("a8.png"), lastMessage4, long.MaxValue - 4, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[5]  = new Chat(5, new ChatTypePrivate(4), "Bender", ChatPhoto("a9.png"), lastMessage5, long.MaxValue - 5, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[6]  = new Chat(6, new ChatTypeSupergroup(1, true), "World News Today", ChatPhoto("a10.png"), lastMessage6, long.MaxValue - 6, false, 1, 0, 0, 0, new NotificationSettings(int.MaxValue, string.Empty, true), 0, null, string.Empty);
            _chats[7]  = new Chat(7, new ChatTypePrivate(5), "EVE", ChatPhoto("a11.png"), lastMessage7, long.MaxValue - 7, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[8]  = new Chat(8, new ChatTypePrivate(16), "Nick", null, lastMessage8, long.MaxValue - 8, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[11] = new Chat(11, new ChatTypePrivate(16), "Kate Rodriguez", ChatPhoto("a13.png"), lastMessage9, long.MaxValue - 9, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[12] = new Chat(12, new ChatTypeSupergroup(3, false), "Meme Factory", ChatPhoto("a14.png"), lastMessage10, long.MaxValue - 10, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[13] = new Chat(13, new ChatTypePrivate(18), "Jaina Moore", null, lastMessage11, long.MaxValue - 11, false, 0, 0, 0, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);

            _chats[9]  = new Chat(9, new ChatTypeSupergroup(2, false), "Weekend Plans", ChatPhoto("a4.png"), null, 0, false, 0, 0, long.MaxValue, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
            _chats[10] = new Chat(10, new ChatTypeSecret(1, 7), "Eileen Lockhard \uD83D\uDC99", ChatPhoto("a5.png"), null, 0, false, 0, 0, long.MaxValue, 0, new NotificationSettings(0, string.Empty, true), 0, null, string.Empty);
#endif

            Task.Run(() =>
            {
                _client.Send(new SetTdlibParameters(parameters));
                _client.Send(new CheckDatabaseEncryptionKey(new byte[0]));
                _client.Run();

                var ttl = ApplicationSettings.Current.FilesTtl;
                if (ttl > 0)
                {
                    _client.Send(new OptimizeStorage(long.MaxValue, ttl * 60 * 60 * 24, int.MaxValue, 0, new FileType[0], new long[0], new long[0], 0));
                }
            });
        }
示例#4
0
 public void SetPreferences(AutoDownloadPreferences preferences)
 {
     _preferences = preferences ?? AutoDownloadPreferences.Default;
     _preferences.Save(ApplicationData.Current.LocalSettings.CreateContainer("autoDownload", ApplicationDataCreateDisposition.Always));
 }