Пример #1
0
 public AddNoteWindow(VideoNote note, NoteTag tag)
 {
     Note       = note;
     Location   = tag.Location;
     TagContent = tag.Content;
     InitializeComponent();
 }
Пример #2
0
        private void UpdateThumbnail(MessageViewModel message, VideoNote videoNote, File file, bool download)
        {
            var thumbnail     = videoNote.Thumbnail;
            var minithumbnail = videoNote.Minithumbnail;

            if (thumbnail != null && thumbnail.Format is ThumbnailFormatJpeg)
            {
                if (file.Local.IsFileExisting())
                {
                    Texture.ImageSource = PlaceholderHelper.GetBlurred(file.Local.Path);
                }
                else if (download)
                {
                    if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
                    {
                        if (minithumbnail != null)
                        {
                            Texture.ImageSource = PlaceholderHelper.GetBlurred(minithumbnail.Data);
                        }

                        message.ProtoService.DownloadFile(file.Id, 1);
                    }

                    UpdateManager.Subscribe(this, message, file, ref _thumbnailToken, UpdateThumbnail, true);
                }
            }
            else if (minithumbnail != null)
            {
                Texture.ImageSource = PlaceholderHelper.GetBlurred(minithumbnail.Data);
            }
            else
            {
                Texture.ImageSource = null;
            }
        }
Пример #3
0
        private List <VideoNote> MakeNotesFromPageNotes(List <VideoNoteCreate> pageNotes)
        {
            pageNotes = pageNotes.OrderBy(x => x.InPageId).ToList();
            var map        = new Dictionary <int, int>();
            var finalNotes = new List <VideoNote>();

            for (int i = 0; i < pageNotes.Count; i++)
            {
                var       pageNote = pageNotes[i];
                VideoNote dbNote;

                dbNote = new VideoNote
                {
                    Content    = pageNote.Content,
                    Formatting = pageNote.Formatting,
                    Name       = "PlaceHolder",
                    SeekTo     = pageNote.SeekTo,
                    Level      = pageNote.Level,
                    Order      = pageNote.InPageId,
                    Type       = pageNote.Type,
                };

                if (pageNote.InPageParentId != null)
                {
                    dbNote.Note = finalNotes[map[(int)pageNote.InPageParentId]];
                }

                map.Add(pageNote.InPageId, i);
                finalNotes.Add(dbNote);
            }

            return(finalNotes);
        }
Пример #4
0
        public static Video SeedVideosToUserWithNotes(MomentoDbContext context, string userId, bool nestedNote = false)
        {
            var user            = context.Users.SingleOrDefault(x => x.Id == userId);
            var rootDirectoryId = user.Directories.FirstOrDefault(x => x.Name.Contains("Root")).Id;

            var note1 = new VideoNote
            {
                Order      = 0,
                Id         = preExistingNote1Id,
                Content    = preExistingNote1Content,
                Formatting = DefaultNoteFormatting,
                SeekTo     = DefaultNoteSeekTo,
            };

            var note2 = new VideoNote
            {
                Order      = 2,
                Id         = preExistingNote2Id,
                Content    = preExistingNote2Content,
                Formatting = DefaultNoteFormatting,
                SeekTo     = DefaultNoteSeekTo,
            };

            var video = new Video
            {
                UserId      = userId,
                Name        = DefaultVideoName,
                Description = DefaultVideoDesctiption,
                SeekTo      = DefaultVideoSeekTo,
                Url         = DefaultVideoUrl,
                DirectoryId = rootDirectoryId,
                Notes       = new HashSet <VideoNote>
                {
                    note1,
                    note2,
                }
            };

            if (nestedNote)
            {
                var note3 = new VideoNote
                {
                    Order      = 1,
                    Id         = preExistingNote3Id,
                    Content    = preExistingNote3Content,
                    Formatting = DefaultNoteFormatting,
                    SeekTo     = DefaultNoteSeekTo,
                    Video      = video,
                };

                note1.ChildNotes = new HashSet <VideoNote> {
                    note3
                };
            }

            user.Videos.Add(video);
            context.SaveChanges();
            return(video);
        }
Пример #5
0
 private VideoNoteCreate MapVideoNoteToNoteCreate(VideoNote note)
 {
     return(new VideoNoteCreate
     {
         Content = note.Content,
         Formatting = note.Formatting,
         Id = note.Id,
         SeekTo = note.SeekTo,
         Type = note.Type,
         InPageId = note.Order,
     });
 }
Пример #6
0
 private VideoNoteView MapVideoNoteToView(VideoNote note)
 {
     return(new VideoNoteView()
     {
         ChildNotes = note.ChildNotes.Select(x => MapVideoNoteToView(x)).ToHashSet(),
         Content = note.Content,
         Formatting = note.Formatting,
         Id = note.Id,
         Level = note.Level,
         SeekTo = note.SeekTo,
     });
 }
        public static string GetDuration(this VideoNote videoNote)
        {
            var duration = TimeSpan.FromSeconds(videoNote.Duration);

            if (duration.TotalHours >= 1)
            {
                return(duration.ToString("h\\:mm\\:ss"));
            }
            else
            {
                return(duration.ToString("mm\\:ss"));
            }
        }
Пример #8
0
        private int Level(VideoNote note)
        {
            int val;

            if (note.NoteId == null)
            {
                val = 0;
            }
            else
            {
                val = Level(note.Note);
            }
            return(1 + val);
        }
Пример #9
0
        ///Tested
        private bool PartialSaveChangesToExistingNote(string[][] changes)
        {
            if (changes.Length == 0)
            {
                return(true);
            }

            var videoIds      = changes.Select(x => int.Parse(x[0])).ToArray();
            var notesToChange = context.VideoNotes.Where(x => videoIds.Contains(x.Id)).ToArray();

            ///Registering modification on the notes
            trackableService.RegisterModificationMany(notesToChange, DateTime.UtcNow, false);

            foreach (var change in changes)
            {
                var       noteId      = int.Parse(change[0]);
                var       prop        = change[1];
                var       newVal      = change[2];
                VideoNote currentNote = notesToChange.SingleOrDefault(x => x.Id == noteId);

                switch (prop)
                {
                case "Deleted":
                    currentNote.IsDeleted = true;
                    currentNote.DeletedOn = DateTime.UtcNow;
                    break;

                case "Content":
                    currentNote.Content = newVal;
                    break;

                case "Formatting":
                    currentNote.Formatting = (Formatting)int.Parse(newVal);
                    break;

                case "SeekTo":
                    currentNote.SeekTo = int.Parse(newVal);
                    break;
                    //case "Name":
                    //    ///not in use currently
                    //    currentNote.Name = newVal;
                    //    break;
                    //case "InPageId":
                    //    currentNote.Order = int.Parse(newVal);
                    //    break;
                }
            }
            return(true);
        }
        public static bool UpdateFile(this VideoNote videoNote, File file)
        {
            var any = false;

            if (videoNote.Thumbnail != null && videoNote.Thumbnail.Photo.Id == file.Id)
            {
                videoNote.Thumbnail.Photo = file;
                any = true;
            }

            if (videoNote.Video.Id == file.Id)
            {
                videoNote.Video = file;
                any             = true;
            }

            return(any);
        }
Пример #11
0
        bool IMultipartForm.UseMultipart()
        {
            if (VideoNote != default)
            {
                if (VideoNote.GetType() == typeof(InputFile))
                {
                    return(true);
                }
            }

            if (Thumb != default)
            {
                if (Thumb.GetType() == typeof(InputFile))
                {
                    return(true);
                }
            }

            return(AttachedFiles.Any());
        }
Пример #12
0
        private int FindDeepestNesting(VideoNote note, Dictionary <VideoNote, int> dict)
        {
            if (dict.ContainsKey(note))
            {
                return(dict[note]);
            }

            var deepestNesting = 0;

            foreach (var child in note.ChildNotes)
            {
                var tempDeepest = FindDeepestNesting(child, dict);
                if (tempDeepest > deepestNesting)
                {
                    deepestNesting = tempDeepest;
                }
            }

            var depth = deepestNesting + 1;

            dict[note] = depth;

            return(depth);
        }
Пример #13
0
 public AddNoteWindow(VideoNote note, TimeSpan location)
 {
     Note     = note;
     Location = location;
     InitializeComponent();
 }
Пример #14
0
        public static void ClassInitialize(TestContext context)
        {
            #region _privateChat

            _privateChat = new Chat
            {
                Id        = 170181775,
                FirstName = "Coffee",
                LastName  = "Jelly",
                Username  = "******",
                Type      = ChatType.Private
            };

            #endregion
            #region _groupChat

            _groupChat = new Chat
            {
                Id    = -200694086,
                Title = "testgrp",
                Type  = ChatType.Group,
                AllMembersAreAdministrators = true
            };

            #endregion
            #region _superGroupChat

            _superGroupChat = new Chat
            {
                Id    = -1001076966401,
                Title = "testgrp",
                Type  = ChatType.Supergroup,
            };

            #endregion
            #region _date
            _date = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(1490868721)).UtcDateTime;
            #endregion
            #region _user
            _user = new User
            {
                Id        = 170181775,
                FirstName = "Coffee",
                LastName  = "Jelly",
                Username  = "******"
            };
            #endregion
            #region _user1

            _user1 = new User
            {
                Id        = 208070915,
                FirstName = "testuser1",
                Username  = "******"
            };

            #endregion
            #region _user2

            _user2 = new User
            {
                Id        = 208070916,
                FirstName = "testuser2",
                Username  = "******"
            };

            #endregion
            #region _users

            _users = new List <User>
            {
                _user1,
                _user2
            };

            #endregion
            #region _urlEntity
            _urlEntity = new MessageEntity
            {
                Type   = MessageEntityType.Url,
                Offset = 0,
                Length = 24
            };
            #endregion
            #region _entities
            _entities = new List <MessageEntity>
            {
                _urlEntity,
            };
            #endregion
            #region _thumb
            _thumb = new PhotoSize
            {
                FileId   = "AAQCABOLx4ENAAT8_8aMR6FJKZeyAAIC",
                FileSize = 5056,
                Width    = 128,
                Height   = 128
            };
            #endregion
            #region _photoSize1
            _photoSize1 = new PhotoSize
            {
                FileId   = "AgADAgADvqcxG5h36EqtRLHi7G4IpthVtw0ABHZHxxRGwQQWJp4BAAEC",
                FileSize = 1104,
                Width    = 90,
                Height   = 66
            };
            #endregion
            #region _photoSize2
            _photoSize2 = new PhotoSize
            {
                FileId   = "AgADAgADvqcxG5h36EqtRLHi7G4IpthVtw0ABJcP22BBjoQSJ54BAAEC",
                FileSize = 8848,
                Width    = 270,
                Height   = 199
            };
            #endregion
            #region _photoSize3
            _photoSize3 = new PhotoSize
            {
                FileId   = "AgADAgADeKgxG4_EJAqofB1cykfvRrNJtw0ABAObNR5xowTDVqABAAEC",
                FileSize = 99685,
                Width    = 640,
                Height   = 640
            };
            #endregion
            #region _config
            _config = new ComparisonConfig
            {
                CompareChildren          = true,
                CompareFields            = false,
                CompareReadOnly          = true,
                ComparePrivateFields     = false,
                ComparePrivateProperties = false,
                CompareProperties        = true,
                MaxDifferences           = 50
            };
            #endregion
            #region _audio
            _audio = new Audio
            {
                Duration  = 195,
                MimeType  = "TestMimeType",
                Title     = "TestTitle",
                Performer = "TestPerformer",
                FileId    = "CQADAgADEgADmHfoSvnwZ3irGpuOAg",
                FileSize  = 3125626
            };
            #endregion
            #region _document

            _document = new Document
            {
                FileName = "Test.PDF",
                MimeType = "application/pdf",
                FileId   = "BQADAgADEwADmHfoSqJcnJwfHNTDAg",
                FileSize = 2972868
            };

            #endregion
            #region _sticker
            _sticker = new Sticker
            {
                Width    = 512,
                Height   = 512,
                Emoji    = "TestEmoji",
                Thumb    = _thumb,
                FileId   = "CAADAgADdQEAAsxUSQlymelYJqPjNwI",
                FileSize = 31896
            };
            #endregion
            #region _photo

            _photo = new List <PhotoSize>
            {
                _photoSize1,
                _photoSize2
            };

            #endregion
            #region _video

            _video = new Video
            {
                Duration = 7,
                Width    = 1280,
                Height   = 720,
                Thumb    = _thumb,
                FileId   = "BAADAgADFwADmHfoSinMsvYz1GJpAg",
                FileSize = 827579
            };

            #endregion
            #region _voice

            _voice = new Voice
            {
                Duration = 3,
                MimeType = "audio/ogg",
                FileId   = "AwADAgADFQADmHfoSt8RIvvK5Z47Ag",
                FileSize = 18020
            };

            #endregion
            #region _contact

            _contact = new Contact
            {
                PhoneNumber = "777777",
                FirstName   = "tiny",
                LastName    = "beast",
                UserId      = 220793091
            };

            #endregion
            #region _location
            _location = new Location
            {
                Latitude  = 53.901112F,
                Longitude = 27.562325F
            };
            #endregion
            #region _newChatPhoto

            _newChatPhoto = new List <PhotoSize>
            {
                _photoSize1,
                _photoSize2,
                _photoSize3
            };

            #endregion
            #region _replyTo

            _replyTo = new VoiceMessage
            {
                From  = _user,
                Voice = _voice
            };
            AttachGeneralProperties(_replyTo);

            #endregion
            #region _pinnedMessage

            _pinnedMessage = new TextMessage
            {
                From = _user,
                Text = "testpinned"
            };
            AttachGeneralProperties3(_pinnedMessage);

            #endregion
            #region _videoNote

            _videoNote = new VideoNote
            {
                //Duration = 7,
                //Length =
                //Thumb = _thumb,
                //FileId = "BAADAgADFwADmHfoSinMsvYz1GJpAg",
                //FileSize = 827579
            };

            #endregion
        }
Пример #15
0
        ///Tested
        private int[][] PartialSaveNewNotes(VideoNoteCreate[] newPageNotes, int videoId)
        {
            ///removing items which are created and deleted in the same save window
            newPageNotes = newPageNotes.Where(x => x.Deleted == false).ToArray();

            var existingParentNotesIds = newPageNotes
                                         .Select(x => x.ParentDbId)
                                         .Where(x => x > 0)
                                         .ToArray();

            var existingParentNotes = context.VideoNotes.
                                      Where(x => existingParentNotesIds.Contains(x.Id)).
                                      ToList();

            newPageNotes = newPageNotes.OrderBy(x => x.InPageId).ToArray();
            var dbNotesToBe = new List <VideoNote>();

            for (int i = 0; i < newPageNotes.Length; i++)
            {
                var pn      = newPageNotes[i];
                var newNote = new VideoNote()
                {
                    Content    = pn.Content,
                    Formatting = pn.Formatting,
                    Level      = pn.Level,
                    Name       = "PlaceHolder",
                    Order      = pn.InPageId,
                    VideoId    = videoId,
                    Type       = pn.Type,
                    SeekTo     = pn.SeekTo,
                };
                dbNotesToBe.Add(newNote);
            }

            for (int i = 0; i < dbNotesToBe.Count; i++)
            {
                var dbNoteToBe = dbNotesToBe[i];
                var pageNote   = newPageNotes[i];

                if (pageNote.ParentDbId > 0)
                {
                    existingParentNotes.SingleOrDefault(x => x.Id == pageNote.ParentDbId)
                    .ChildNotes.Add(dbNoteToBe);
                }
                ///0 means that it is not root and has parent that is not in the db, -1 means root
                else if (pageNote.ParentDbId == 0)
                {
                    var inPageParentId = pageNote.InPageParentId;
                    var pageParent     = newPageNotes.FirstOrDefault(x => x.InPageId == inPageParentId);

                    ///TODO: Remove This
                    if (pageParent == null)
                    {
                        throw new Exception("You done goofed!");
                    }

                    var indexOfPageParent = Array.IndexOf(newPageNotes, pageParent);
                    var dbParent          = dbNotesToBe[indexOfPageParent];
                    dbParent.ChildNotes.Add(dbNoteToBe);
                }
            }

            this.CheckTheNestringLevel(dbNotesToBe, existingParentNotes);

            context.VideoNotes.AddRange(dbNotesToBe);

            ///Final SaveChanges for the Save
            context.SaveChanges();

            ///inPageId and Order are the same thing,
            ///realigning them after putting them in
            ///the db in case they got reaordered
            dbNotesToBe  = dbNotesToBe.OrderBy(x => x.Order).ToList();
            newPageNotes = newPageNotes.OrderBy(x => x.InPageId).ToArray();

            var resultList = new List <int[]>();

            ///sending the OK status code
            resultList.Add(new int[] { 0 });
            ///mapping the new Ids to the in-page ids and
            ///sending them to the JS so the dbId can be send
            ///back in case of changes
            for (int i = 0; i < dbNotesToBe.Count; i++)
            {
                resultList.Add(new int[] { newPageNotes[i].InPageId, dbNotesToBe[i].Id });
            }

            return(resultList.ToArray());
        }