Exemplo n.º 1
0
 public UserTimelineViewModel(UserInfoViewModel parent, UserTimelineModel model)
     : base(model)
 {
     _parent = parent;
     _model  = model;
     this.CompositeDisposable.Add(
         new EventListener <Action>(
             h => _model.FocusRequired += h,
             h => _model.FocusRequired -= h,
             this.SetFocus));
 }
Exemplo n.º 2
0
        public UserInfoViewModel(SearchFlipViewModel parent, string screenName)
        {
            this._parent     = parent;
            this._screenName = screenName;
            var cd = new CompositeDisposable();

            this.CompositeDisposable.Add(cd);
            cd.Add(
                StoreHelper.GetUser(screenName)
                .Finally(() => Communicating = false)
                .ObserveOnDispatcher()
                .Subscribe(
                    user =>
            {
                User           = new UserViewModel(user);
                var ps         = this._statuses;
                var usm        = new UserTimelineModel(user.Id, TimelineType.User);
                this._statuses = new UserTimelineViewModel(this, usm);
                this.RaisePropertyChanged(() => Statuses);
                cd.Add(_statuses);
                if (ps != null)
                {
                    ps.Dispose();
                }
                var pf          = this._favorites;
                var ufm         = new UserTimelineModel(user.Id, TimelineType.Favorites);
                this._favorites = new UserTimelineViewModel(this, ufm);
                this.RaisePropertyChanged(() => Favorites);
                cd.Add(_favorites);
                if (pf != null)
                {
                    pf.Dispose();
                }
                var pfw         = this._following;
                this._following = new UserFollowingViewModel(this);
                this.RaisePropertyChanged(() => Following);
                cd.Add(_following);
                if (pfw != null)
                {
                    pfw.Dispose();
                }
                var pfr         = this._followers;
                this._followers = new UserFollowersViewModel(this);
                this.RaisePropertyChanged(() => Followers);
                cd.Add(_followers);
                if (pfr != null)
                {
                    pfr.Dispose();
                }
                Setting.Accounts.Collection
                .Where(a => a.Id != user.Id)
                .Select(a => new RelationControlViewModel(this, a, user))
                .ForEach(RelationControls.Add);
            },
                    ex =>
            {
                parent.Messenger.Raise(new TaskDialogMessage(new TaskDialogOptions
                {
                    Title           = "ユーザー表示エラー",
                    MainIcon        = VistaTaskDialogIcon.Error,
                    MainInstruction = "ユーザーを表示できません。",
                    Content         = ex.Message,
                    CommonButtons   = TaskDialogCommonButtons.Close
                }));
                User = null;
                parent.CloseResults();
            }));
        }
Exemplo n.º 3
0
        public static async Task <UserTimelineModel> GetTimeLine(ApplicationDbContext context, string userId, List <Guid> listIds = null, bool showDummy = false)
        {
            var userDetail = await context.Users.FirstOrDefaultAsync(x => x.Id == userId);

            if (userDetail == null)
            {
                return(null);
            }

            var userTimeline = new UserTimelineModel();
            IQueryable <FileStorage> files = context.Files;

            if (listIds != null && listIds.Any())
            {
                files = context.Files.Where(x => listIds.Contains(x.Id));
            }

            userTimeline.Name           = userDetail.Name;
            userTimeline.Surname        = userDetail.Surname;
            userTimeline.UserId         = userDetail.Id;
            userTimeline.DateOfAccident = userDetail.DateOfAccident.GetValueOrDefault(DateTime.UtcNow);
            userTimeline.PhotoURL       = AmazonS3Helper.GenerateUrl(userDetail.ProfilePictureKey, "attorney-journal-dev");

            userTimeline.Items = await files.Where(x => x.Owner.Id == userId && x.Parent == null).Select(
                x => new TimelineItemModel {
                CreatedAt = x.CreatedAt,
                File      = new ItemModel {
                    Id            = x.Id,
                    Title         = x.Title,
                    Content       = x.Content,
                    FileExtension = x.FileExtension,
                    MimeType      = x.MimeType,
                    ObjectKey     = x.AmazonObjectKey,
                    ObjectUrl     = AmazonS3Helper.GenerateUrl(x.AmazonObjectKey, "attorney-journal-dev"),
                    Type          = x.Type,
                    Viewed        = x.Viewed,
                    DateTaken     = x.DateTaken
                },
                Thumb = context.Files.Where(y => y.Parent == x).Select(y => new ItemModel {
                    FileExtension = y.FileExtension,
                    MimeType      = y.MimeType,
                    ObjectKey     = y.AmazonObjectKey,
                    ObjectUrl     = GetImageAsBase64Url(AmazonS3Helper.GenerateUrl(y.AmazonObjectKey, "attorney-journal-dev")),
                    DateTaken     = x.DateTaken
                }).FirstOrDefault()
            }).OrderByDescending(x => x.CreatedAt).ToListAsync(CancellationToken.None);

            if (showDummy)
            {
                userTimeline.Items.Add(new TimelineItemModel
                {
                    CreatedAt = DateTime.Now,
                    File      = new ItemModel
                    {
                        Id            = Guid.NewGuid(),
                        Title         = "test image",
                        Content       = "this is test image",
                        Type          = FileStorageType.Image,
                        FileExtension = "jpg",
                        MimeType      = "img/jpg",
                        ObjectUrl     = "https://appwrk.com/wp-content/themes/appwrk_theme/images/testi_1.jpg",
                        Viewed        = true,
                        DateTaken     = DateTime.Now
                    },
                    Thumb = new ItemModel
                    {
                        FileExtension = "jpg",
                        MimeType      = "img/jpg",
                        ObjectUrl     = GetImageAsBase64Url("https://appwrk.com/wp-content/themes/appwrk_theme/images/testi_1.jpg"),
                        DateTaken     = DateTime.Now
                    }
                });

                userTimeline.Items.Add(new TimelineItemModel
                {
                    CreatedAt = DateTime.Now,
                    File      = new ItemModel
                    {
                        Id        = Guid.NewGuid(),
                        Title     = "test video",
                        Content   = "this is test video",
                        Type      = FileStorageType.Video,
                        ObjectUrl = "https://www.youtube.com/watch?v=e_04ZrNroTo",
                        Viewed    = true,
                        DateTaken = DateTime.Now
                    },
                    Thumb = new ItemModel
                    {
                        ObjectUrl = GetImageAsBase64Url("http://i3.ytimg.com/vi/e_04ZrNroTo/hqdefault.jpg"),
                        DateTaken = DateTime.Now
                    }
                });
            }

            return(userTimeline);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timelineModel"></param>
        /// <returns></returns>
        public async Task <string> PrepareZip(UserTimelineModel timelineModel)
        {
            List <string> objectKeys = new List <string> ();

            timelineModel.Items = timelineModel.Items.OrderBy(x => x.CreatedAt).ToList();

            #region Path
            const string exportBucketName = "ver-exports";
            var          fileZipName      = $"{timelineModel.Name.ToLowerInvariant()}_{timelineModel.Surname.ToLowerInvariant()}_export_{DateTime.UtcNow:yyyyMMddHHmmss}.zip";
            var          tempPath         = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var          fileZipPath      = Path.Combine(Path.GetTempPath(), fileZipName);
            #endregion

            try {
                var files = new Dictionary <string, string> (objectKeys.Count);
                if (!Directory.Exists(tempPath))
                {
                    Directory.CreateDirectory(tempPath);
                }
                if (!Directory.Exists(Path.Combine(tempPath, "files")))
                {
                    Directory.CreateDirectory(Path.Combine(tempPath, "files"));
                }

                #region Config

                Directory.CreateDirectory(Path.Combine(tempPath, "config"));
                File.Copy("wwwroot/template/export_template/config/bootstrap.css", Path.Combine(tempPath, "config", "bootstrap.css"));
                File.Copy("wwwroot/template/export_template/config/bootstrap.js", Path.Combine(tempPath, "config", "bootstrap.js"));
                File.Copy("wwwroot/template/export_template/config/jquery.js", Path.Combine(tempPath, "config", "jquery.js"));
                File.Copy("wwwroot/template/export_template/config/site.css", Path.Combine(tempPath, "config", "site.css"));
                File.Copy("wwwroot/template/export_template/config/site.js", Path.Combine(tempPath, "config", "site.js"));

                Directory.CreateDirectory(Path.Combine(tempPath, "config/fonts"));
                File.Copy("wwwroot/template/export_template/config/fonts/glyphicons-halflings-regular.eot", Path.Combine(tempPath, "config/fonts", "glyphicons-halflings-regular.eot"));
                File.Copy("wwwroot/template/export_template/config/fonts/glyphicons-halflings-regular.svg", Path.Combine(tempPath, "config/fonts", "glyphicons-halflings-regular.svg"));
                File.Copy("wwwroot/template/export_template/config/fonts/glyphicons-halflings-regular.ttf", Path.Combine(tempPath, "config/fonts", "glyphicons-halflings-regular.ttf"));
                File.Copy("wwwroot/template/export_template/config/fonts/glyphicons-halflings-regular.woff", Path.Combine(tempPath, "config/fonts", "glyphicons-halflings-regular.woff"));
                File.Copy("wwwroot/template/export_template/config/fonts/glyphicons-halflings-regular.woff2", Path.Combine(tempPath, "config/fonts", "glyphicons-halflings-regular.woff2"));

                #endregion

                string templateToFill = File.ReadAllText("wwwroot/template/export_template/openME.html");
                templateToFill = templateToFill.Replace("*|PHOTO-FILENAME|*", timelineModel.PhotoURL);
                templateToFill = templateToFill.Replace("*|NAME|*", timelineModel.Name);
                templateToFill = templateToFill.Replace("*|SURNAME|*", timelineModel.Surname);
                templateToFill = templateToFill.Replace("*|DATEACCIDENT|*", timelineModel.DateOfAccident.ToLocalTime().ToString(CultureInfo.InvariantCulture));

                if (timelineModel.PhotoURL != null)
                {
                    objectKeys.Add(timelineModel.PhotoURL);
                }

                string templateContents = string.Empty;

                foreach (var item in timelineModel.Items)
                {
                    switch (item.File.Type)
                    {
                    case FileStorageType.Image:
                        var imageTemplate = File.ReadAllText("wwwroot/template/export_template/image.html");
                        if (item.File.DateTaken.HasValue)
                        {
                            imageTemplate = imageTemplate.Replace("*|DATE|*", "Created: " + item.File.DateTaken.Value.ToLocalTime().ToString(CultureInfo.InvariantCulture) + " Uploaded: " + item.CreatedAt.ToLocalTime().ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            imageTemplate = imageTemplate.Replace("*|DATE|*", "Uploaded: " + item.CreatedAt.ToLocalTime().ToString(CultureInfo.InvariantCulture));
                        }
                        imageTemplate     = imageTemplate.Replace("*|FILENAME|*", item.File.ObjectKey);
                        imageTemplate     = imageTemplate.Replace("*|TITLE|*", string.IsNullOrWhiteSpace(item.File.Title) ? item.File.Title : "A photo has been uploaded");
                        templateContents += imageTemplate;

                        objectKeys.Add(item.File.ObjectKey);

                        break;

                    case FileStorageType.Video:
                        var videoTemplate = File.ReadAllText("wwwroot/template/export_template/video.html");
                        if (item.File.DateTaken.HasValue)
                        {
                            videoTemplate = videoTemplate.Replace("*|DATE|*", "Created: " + item.File.DateTaken.Value.ToLocalTime().ToString(CultureInfo.InvariantCulture) + " Uploaded: " + item.CreatedAt.ToLocalTime().ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            videoTemplate = videoTemplate.Replace("*|DATE|*", "Uploaded: " + item.CreatedAt.ToLocalTime().ToString(CultureInfo.InvariantCulture));
                        }
                        videoTemplate     = videoTemplate.Replace("*|FILENAME|*", item.File.ObjectKey);
                        videoTemplate     = videoTemplate.Replace("*|THUMBNAME|*", item.Thumb.ObjectKey);
                        videoTemplate     = videoTemplate.Replace("*|TITLE|*", string.IsNullOrWhiteSpace(item.File.Title) ? item.File.Title : "A video has been uploaded");
                        templateContents += videoTemplate;

                        objectKeys.Add(item.File.ObjectKey);
                        objectKeys.Add(item.Thumb.ObjectKey);

                        break;

                    case FileStorageType.Text:
                        var textTemplate = File.ReadAllText("wwwroot/template/export_template/text.html");
                        textTemplate      = textTemplate.Replace("*|TITLE|*", item.File.Title ?? "Text message");
                        textTemplate      = textTemplate.Replace("*|DATE|*", item.CreatedAt.ToLocalTime().ToString(CultureInfo.InvariantCulture));
                        textTemplate      = textTemplate.Replace("*|CONTENT|*", item.File.Content);
                        templateContents += textTemplate;

                        break;

                    case FileStorageType.PushNotification:
                        var pushTemplate = File.ReadAllText("wwwroot/template/export_template/push.html");
                        pushTemplate      = pushTemplate.Replace("*|TITLE|*", item.File.Title ?? "Push Message");
                        pushTemplate      = pushTemplate.Replace("*|DATE|*", item.CreatedAt.ToLocalTime().ToString(CultureInfo.InvariantCulture));
                        pushTemplate      = pushTemplate.Replace("*|CONTENT|*", item.File.Content);
                        templateContents += pushTemplate;

                        break;

                    case FileStorageType.Thumb:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                templateToFill = templateToFill.Replace("*|CONTENT|*", templateContents);
                File.WriteAllText(Path.Combine(tempPath, "openME.html"), templateToFill);

                await objectKeys.ParallelForEachAsync(async key => { files.Add(key, await DownloadFileAsync(key, Path.Combine(tempPath, "files", key))); }, 8);

                ZipFile.CreateFromDirectory(tempPath, fileZipPath);

                await UploadFileAsync(fileZipPath, fileZipName, exportBucketName, S3StorageClass.ReducedRedundancy);
            } catch (Exception e) {
                return($"Exception: {e.Message}");
            } finally {
                if (File.Exists(fileZipPath))
                {
                    File.Delete(fileZipPath);
                }
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }

            return(GenerateUrl(fileZipName, "ver-exports"));
        }