Example #1
0
        private static void UpdateSpeakerAvatars(Realm auditRealm, IEnumerable <UpdatedFile> speakerPhotos)
        {
            foreach (UpdatedFile updatedFile in speakerPhotos)
            {
                var speakerID = updatedFile.Filename.Split('/')[2];

                byte[] speakerAvatar = updatedFile.Content;

                var speaker = auditRealm.Find <Speaker>(speakerID);
                speaker.Avatar = speakerAvatar;

                DotNetRuLogger.TrackEvent("AuditUpdate. Updated speaker avatar: " + updatedFile.Filename);
            }
        }
Example #2
0
        public static async Task <List <Tweet> > Get()
        {
            try
            {
                var config = AppConfig.GetConfig();

                var tweets = await config.TweetFunctionUrl
                             .GetJsonAsync <List <Tweet> >();

                return(tweets);
            }
            catch (Exception e)
            {
                DotNetRuLogger.Report(e);
            }

            return(new List <Tweet>());
        }
Example #3
0
        public static async Task <List <ISocialPost> > GetBySubscriptionsAsync(List <string> communities)
        {
            try
            {
                var config = AppConfig.GetConfig();

                var tweets = await config.SubscriptionTweetFunctionUrl.PostJsonAsync(communities)
                             .ReceiveJson <List <Tweet> >();

                return(tweets.Cast <ISocialPost>().ToList());
            }
            catch (Exception e)
            {
                DotNetRuLogger.Report(e);
            }

            return(new List <ISocialPost>());
        }
Example #4
0
        public static async Task <List <ISocialPost> > GetAsync()
        {
            try
            {
                var config = AppConfig.GetConfig();

                var vkontaktePosts = await config.VkontakteFunctionUrl
                                     .GetJsonAsync <List <VkontaktePost> >();

                return(vkontaktePosts.Cast <ISocialPost>().ToList());
            }
            catch (Exception e)
            {
                DotNetRuLogger.Report(e);
            }

            return(new List <ISocialPost>());
        }
Example #5
0
        public static async Task <List <ISocialPost> > GetBySubscriptionsAsync(IDictionary <string, byte> communities)
        {
            try
            {
                var config = AppConfig.GetConfig();

                var vkontaktePosts =
                    await config.SubscriptionVkontakteFunctionUrl.PostJsonAsync(communities)
                    .ReceiveJson <List <VkontaktePost> >();

                return(vkontaktePosts.Cast <ISocialPost>().ToList());
            }
            catch (Exception e)
            {
                DotNetRuLogger.Report(e);
            }

            return(new List <ISocialPost>());
        }
Example #6
0
        private static void UpdateModels <T>(IMapper mapper, Realm auditRealm, IEnumerable <UpdatedFile> files)
        {
            foreach (UpdatedFile file in files)
            {
                using (var memoryStream = new MemoryStream(file.Content))
                {
                    var xmlEntity = new XmlSerializer(typeof(T)).Deserialize(memoryStream);

                    DotNetRuLogger.TrackEvent($"AuditUpdate: updating {file.Filename}");

                    var realmType = mapper.ConfigurationProvider.GetAllTypeMaps().Single(x => x.SourceType == typeof(T))
                                    .DestinationType;

                    var realmObject = mapper.Map(xmlEntity, typeof(T), realmType);

                    auditRealm.Add(realmObject as RealmObject, update: true);

                    DotNetRuLogger.TrackEvent($"AuditUpdate. Updated {file.Filename}");
                }
            }
        }
Example #7
0
        // Called whenever your app performs a background fetch
        public override void PerformFetch(UIApplication application, Action <UIBackgroundFetchResult> completionHandler)
        {
            // Do Background Fetch
            var downloadSuccessful = false;

            try
            {
                Forms.Init(); // need for dependency services
            }
            catch (Exception ex)
            {
                ex.Data["Method"] = "PerformFetch";
                DotNetRuLogger.Report(ex);
            }

            // If you don't call this, your application will be terminated by the OS.
            // Allows OS to collect stats like data cost and power consumption
            var resultFlag = downloadSuccessful ? UIBackgroundFetchResult.NewData : UIBackgroundFetchResult.Failed;

            completionHandler(resultFlag);
        }
Example #8
0
        private bool ExecuteLoadNotifications(bool force = false)
        {
            if (this.IsBusy)
            {
                return(false);
            }
            try
            {
                this.IsBusy = true;
            }
            catch (Exception ex)
            {
                DotNetRuLogger.Report(ex);
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                this.IsBusy = false;
            }

            return(true);
        }
Example #9
0
        private void ExecuteLoadSubscriptions()
        {
            if (this.IsBusy)
            {
                return;
            }

            try
            {
                this.IsBusy = true;

                UpdateSubscriptions();
            }
            catch (Exception ex)
            {
                DotNetRuLogger.Report(ex);
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                this.IsBusy = false;
            }
        }
Example #10
0
        public static async Task UpdateAudit()
        {
            try
            {
                DotNetRuLogger.TrackEvent("AuditUpdate. Started updating audit");

                string currentCommitSha;
                using (var auditRealm = Realm.GetInstance("Audit.realm"))
                {
                    var auditVersion = auditRealm.All <AuditVersion>().Single();
                    currentCommitSha = auditVersion.CommitHash;
                }

                DotNetRuLogger.TrackEvent("AuditUpdate. Current synchronization context: " + SynchronizationContext.Current);
                DotNetRuLogger.TrackEvent("AuditUpdate. Current version is: " + currentCommitSha);

                var client = new GitHubClient(new ProductHeaderValue("DotNetRu"));

                var reference = await client.Git.Reference.Get(DotNetRuAppRepositoryID, "heads/master");

                var latestMasterCommitSha = reference.Object.Sha;

                DotNetRuLogger.TrackEvent("AuditUpdate. Latest version (master) is: " + latestMasterCommitSha);

                var contentUpdate = await client.Repository.Commit.Compare(
                    DotNetRuAppRepositoryID,
                    currentCommitSha,
                    latestMasterCommitSha);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var httpClient = new HttpClient();

                var streamTasks = contentUpdate.Files.Select(
                    async file => new UpdatedFile
                {
                    Filename = file.Filename,
                    Content  = await httpClient.GetByteArrayAsync(file.RawUrl)
                               .ConfigureAwait(false)
                });
                var fileContents = await Task.WhenAll(streamTasks);

                DotNetRuLogger.TrackEvent("AuditUpdate. Downloading files time: " + stopwatch.Elapsed.ToString("g"));

                var xmlFiles = fileContents.Where(x => x.Filename.EndsWith(".xml")).ToList();

                using (var auditRealm = Realm.GetInstance("Audit.realm"))
                {
                    using (var trans = auditRealm.BeginWrite())
                    {
                        var mapper = GetAutoMapper(auditRealm);

                        UpdateModels <SpeakerEntity>(mapper, auditRealm, xmlFiles, "speakers");
                        UpdateModels <FriendEntity>(mapper, auditRealm, xmlFiles, "friends");
                        UpdateModels <VenueEntity>(mapper, auditRealm, xmlFiles, "venues");
                        UpdateModels <TalkEntity>(mapper, auditRealm, xmlFiles, "talks");
                        UpdateModels <MeetupEntity>(mapper, auditRealm, xmlFiles, "meetups");

                        var speakerPhotos = fileContents.Where(x => x.Filename.EndsWith("avatar.jpg"));
                        UpdateSpeakerAvatars(auditRealm, speakerPhotos);

                        var auditVersion = auditRealm.All <AuditVersion>().Single();

                        auditVersion.CommitHash = latestMasterCommitSha;
                        auditRealm.Add(auditVersion, update: true);

                        trans.Commit();
                    }
                }

                stopwatch.Stop();

                DotNetRuLogger.TrackEvent("AuditUpdate. Finished! Time: " + stopwatch.Elapsed.ToString("g"));
            }
            catch (Exception e)
            {
                DotNetRuLogger.Report(e, "AuditUpdate");

                throw;
            }
        }