internal async void SendToClipboard(ClipboardGetData clipboardGetData)
        {
            if (clipboardGetData.ContentTypeId == ContentTypes.Image)
            {
                var url  = SimpleFileTokenData.CreateUrl(clipboardGetData.FileContentUrl);
                var path = Path.Combine(this.tempPath, Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + Path.GetExtension(clipboardGetData.FileContentUrl));

                using (WebClient client = new WebClient())
                {
                    await client.DownloadFileTaskAsync(url, path);
                }

                var bs = new BitmapImage(new Uri(path));
                Clipboard.SetImage(bs);
            }
            if (clipboardGetData.ContentTypeId == ContentTypes.File)
            {
                var url = SimpleFileTokenData.CreateUrl(clipboardGetData.FileContentUrl);
                using (var client = new WebClient())
                {
                    string path = Path.Combine(this.tempPath, clipboardGetData.FileName);
                    await client.DownloadFileTaskAsync(url, path);

                    StringCollection paths = new StringCollection();
                    paths.Add(path);
                    Clipboard.SetFileDropList(paths);
                }
            }
            else if (clipboardGetData.ContentTypeId == ContentTypes.PlainText)
            {
                Clipboard.SetText(clipboardGetData.TextContent);
            }
        }
Exemple #2
0
        public async Task <ClipboardContainerGetData> GetLaneWithContext(Guid lane)
        {
            if (lane == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(lane));
            }
            using SqlConnection connection = this.authService.Connection;

            DatabaseContext         context = new DatabaseContext(connection);
            List <ClipboardGetData> entries = await(from cc in context.ClipboardContent
                                                    where cc.UserId == this.authService.UserId &&
                                                    cc.IsArchived == false &&
                                                    cc.LaneId == lane
                                                    select ClipboardGetData.CreateFromEntity(cc, cc.FileToken)).ToListAsync();

            List <LaneGetData> lanes = await LaneController.GetLanesForUser(context, this.authService.UserId);

            ClipboardContainerGetData result = new ClipboardContainerGetData()
            {
                Entries = entries,
                Lanes   = lanes
            };

            await connection.CloseAsync();

            return(result);
        }
Exemple #3
0
        public async Task <IEnumerable <ClipboardGetData> > GetLane(Guid lane)
        {
            using var connection = authService.Connection;

            var context = new DatabaseContext(connection);
            var result  = await(from cc in context.ClipboardContent
                                where cc.UserId == authService.UserId &&
                                cc.IsArchived == false &&
                                cc.LaneId == lane
                                select ClipboardGetData.CreateFromEntity(cc, cc.FileToken)).ToListAsync();

            await connection.CloseAsync();

            return(result);
        }
Exemple #4
0
        private void ClipboardItemsListChanged(object sender, ListChangedEventArgs e)
        {
            IList <ClipboardGetData> listSender = (IList <ClipboardGetData>)sender;

            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
                ClipboardGetData          addedData = listSender[e.NewIndex];
                HistoryPageEntryViewModel newEntry  = this.container.Resolve <HistoryPageEntryViewModel>().GetWithDataModel(addedData);
                this.Entries.Insert(e.NewIndex, newEntry);
            }
            else if (e.ListChangedType == ListChangedType.ItemDeleted)
            {
                this.Entries.RemoveAt(e.NewIndex);
            }
            else if (e.ListChangedType == ListChangedType.Reset)
            {
                if (listSender.Count == 0)
                {
                    this.Entries = new BindingList <HistoryPageEntryViewModel>();
                }
            }
        }
Exemple #5
0
        private async Task <ClipboardGetData> PostFileInternal(IFormFile file, string fileExtension, string fileName, Guid?laneId)
        {
            using SqlConnection connection = this.authService.Connection;

            DateTime now                = DateTime.Now;
            string   extension          = (fileExtension ?? Path.GetExtension(fileName) ?? Path.GetExtension(file.FileName));
            string   filename           = $"clip_{now:yyyyMMdd'_'HHmmss}" + extension;
            FileAccessTokenEntity token = await this.fileRepository.UploadInternal(filename,
                                                                                   file.OpenReadStream(),
                                                                                   connection,
                                                                                   false);

            Guid contentType = this.fileRepository.GetContentTypeForExtension(extension).StartsWith("image") ? Constants.ContentTypes.Image :
                               Constants.ContentTypes.File;

            ClipboardContentEntity entry = new ClipboardContentEntity()
            {
                ContentTypeId   = contentType,
                CreationDate    = now,
                LastUsedDate    = now,
                FileTokenId     = token.Id,
                UserId          = this.authService.UserId,
                DisplayFileName = fileName,
                LaneId          = laneId
            };

            using DatabaseContext context = new DatabaseContext(connection);
            await context.AddAsync(entry);

            await context.SaveChangesAsync();

            await connection.CloseAsync();

            connection.Close();

            return(contentType == Constants.ContentTypes.Image ? ClipboardGetData.CreateWithImageContent(entry.Id, entry.LaneId, token, fileName) :
                   ClipboardGetData.CreateWithFileContent(entry.Id, entry.LaneId, token, fileName));
        }
Exemple #6
0
        public async Task <ClipboardContainerGetData> GetWithContext(Guid?id = null)
        {
            using SqlConnection connection = this.authService.Connection;

            DatabaseContext         context = new DatabaseContext(connection);
            List <ClipboardGetData> entries = await(from cc in context.ClipboardContent
                                                    where cc.UserId == this.authService.UserId &&
                                                    cc.IsArchived == false &&
                                                    (cc.Id == id || id == null)
                                                    select ClipboardGetData.CreateFromEntity(cc, cc.FileToken)).ToListAsync();

            List <LaneGetData> lanes = await LaneController.GetLanesForUser(context, this.authService.UserId);

            ClipboardContainerGetData result = new ClipboardContainerGetData()
            {
                Entries = entries,
                Lanes   = lanes
            };

            await connection.CloseAsync();

            return(result);
        }
Exemple #7
0
        public async Task <ClipboardGetData> PostPlainText(ClipboardPostPlainTextData data)
        {
            using SqlConnection connection = this.authService.Connection;

            DateTime now = DateTime.Now;
            ClipboardContentEntity entry = new ClipboardContentEntity()
            {
                ContentTypeId = Constants.ContentTypes.PlainText,
                CreationDate  = now,
                LastUsedDate  = now,
                TextContent   = data.Content,
                UserId        = this.authService.UserId,
                LaneId        = data.LaneGuid
            };

            DatabaseContext context = new DatabaseContext(connection);
            await context.AddAsync(entry);

            await context.SaveChangesAsync();

            await connection.CloseAsync();

            return(ClipboardGetData.CreateWithPlainTextContent(entry.Id, entry.LaneId, entry.TextContent));
        }
Exemple #8
0
 private HistoryPageEntryViewModel CreateEntryViewModel(ClipboardGetData o)
 {
     return(this.container.Resolve <HistoryPageEntryViewModel>().SetHost(this).GetWithDataModel(o));
 }