Example #1
0
 public TransmittMedia(FileInfo info)
 {
     FileInfo = info;
     try
     {
         _imageStream = FFTools.CreateThumbnail(FileInfo.FullName, out hasInvalidInputData);
         if (!hasInvalidInputData)
         {
             _thumbnail = System.Drawing.Image.FromStream(_imageStream);
         }
     }
     catch
     {
     }
 }
Example #2
0
 public bool RegenerateThumbnail()
 {
     if (hasInvalidInputData)
     {
         return(false);
     }
     try
     {
         _imageStream = FFTools.CreateThumbnail(FileInfo.FullName, out hasInvalidInputData);
         _thumbnail   = System.Drawing.Image.FromStream(_imageStream);
         return(true);
     }
     catch (System.Exception ex)
     {
         return(false);
     }
 }
Example #3
0
        private async void Bot_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            int page = 0;

            if (lastFilesQuery == null)
            {
                await Task.FromResult(1);
            }
            else
            {
                int.TryParse(e.InlineQuery.Offset, out page);

                const int batchSize            = 30;
                var       accessor             = lastFilesQuery.Skip(page * batchSize).Take(batchSize);
                InlineQueryResultBase[] result = accessor.Select((file) => PhotoResult(file)).ToArray();

                var thrds = lastFilesQuery.Skip(page * batchSize).Take(batchSize).AsParallel().WithMergeOptions(ParallelMergeOptions.NotBuffered);
                Console.WriteLine("make file started " + thrds.Count());
                thrds.ForAll(storageItem =>
                {
                    if (!storageItem.IsFile)
                    {
                        return;
                    }
                    var mapa    = MemoryMappedFile.CreateOrOpen(storageItem.Hash, 8.KB(), MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.DelayAllocatePages, HandleInheritability.None);
                    var thumb   = mapa.CreateViewStream();
                    var command = FFTools.CreateInlineThumbnail(storageItem.FullPath, 120, ref thumb);
                    command.Wait();
                    thumb.Close();
                    memoryFiles.Add(mapa);
                });

                string nextPage = result.Length < batchSize ? "" :(page += 1).ToString();
                try
                {
                    await Task.Delay(1000).ContinueWith(t => Bot.AnswerInlineQueryAsync(e.InlineQuery.Id, result, 0, false, nextPage));
                }catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Console.WriteLine("method ended");
                Console.WriteLine("return");
            }
        }
Example #4
0
        public async void SendNotifyFileLoadSuccess(StorageItemInfo item)
        {
            TelegramContext.WithFileHash(item.Hash);
            if (!Subscribers.ContainsKey(item.Owner))
            {
                return;
            }
            var ChatId = Subscribers[item.Owner];

            try
            {
                try
                {
                    using (MemoryStream imageStream = FFTools.CreateThumbnail(item.FullPath))
                    {
                        Message result = await Bot.SendPhotoAsync(
                            ChatId,
                            imageStream,
                            string.Format("{0} ({1}) done", item.Name, item.GetFormatSize()), replyMarkup : Keyboards.CommonFileActions());

                        MessagesHystory.Push(result);
                    }
                }
                catch (Exception)
                {
                    await Bot.SendTextMessageAsync(ChatId, string.Format("{0} ({1}) done", item.Name, item.GetFormatSize()));
                }
            }
            catch (Exception)
            {
                await Task.Delay(3000).ContinueWith(async(a) =>
                {
                    await Bot.SendTextMessageAsync(ChatId, string.Format("{0} ({1}) done", item.Name, item.GetFormatSize()));
                });
            }
        }