Пример #1
0
        public void CreateStack(AstroPhoto.LibRaw.Instance libraw, string name)
        {
            string dir = session.CreateStack(name, selectedImages);

            SuspendLayout();
            for (int i = Controls.Count - 1; i >= 0; i--)
            {
                Control control = Controls[i];
                Panel   panel   = (Panel)control;
                string  path    = (string)panel.Tag;
                if (selectedImages.Contains(path))
                {
                    if (path == currentObjectPath)
                    {
                        panel.Tag = dir;
                        ThumbnailData data = loadThumbnailData(libraw, dir);
                        panel.Height = buildThumbnail((Panel)(panel.Controls[0]), data).Height;
                    }
                    else
                    {
                        Controls.Remove(control);
                    }
                }
            }
            ResumeLayout();

            selectedImages.Clear();
            selectedImages.Add(dir);
            currentObjectPath = dir;
            updateThumbnails();
        }
Пример #2
0
        void addThumbnail(ThumbnailData data)
        {
            Panel exPanel = new Panel();

            exPanel.Padding          = new Padding(2, 2, 2, 2);
            exPanel.Margin           = new Padding(1, 1, 1, 1);
            exPanel.Tag              = data.path;
            exPanel.Click           += new EventHandler(thumbnail_Click);
            exPanel.ContextMenuStrip = ItemContextMenu;

            Panel panel = new Panel();

            panel.Dock             = DockStyle.Fill;
            panel.BackColor        = Color.Black;//Color.FromArgb( 44, 44, 44 );
            panel.Tag              = data.path;
            panel.Click           += new EventHandler(thumbnail_Click);
            panel.ContextMenuStrip = ItemContextMenu;

            var size = buildThumbnail(panel, data);

            exPanel.Width  = size.Width + 30;
            exPanel.Height = size.Height + 4;
            exPanel.Controls.Add(panel);
            Controls.Add(exPanel);
        }
Пример #3
0
 public int GetConvertedUri(string documentUri,
                            string fromExtension,
                            string toExtension,
                            string documentRevisionId,
                            string password,
                            ThumbnailData thumbnail,
                            SpreadsheetLayout spreadsheetLayout,
                            bool isAsync,
                            out string convertedDocumentUri)
 {
     Logger.Debug($"DocService convert from {fromExtension} to {toExtension} - {documentUri}, DocServiceConverterUrl:{FilesLinkUtility.DocServiceConverterUrl}");
     try
     {
         return(Web.Core.Files.DocumentService.GetConvertedUri(
                    FileUtility,
                    FilesLinkUtility.DocServiceConverterUrl,
                    documentUri,
                    fromExtension,
                    toExtension,
                    GenerateRevisionId(documentRevisionId),
                    password,
                    thumbnail,
                    spreadsheetLayout,
                    isAsync,
                    FileUtility.SignatureSecret,
                    out convertedDocumentUri));
     }
     catch (Exception ex)
     {
         throw CustomizeError(ex);
     }
 }
Пример #4
0
        public ActionResult GetUrl(string url)
        {
            try
            {
                var web          = new HtmlWeb();
                var doc          = web.Load(url);
                var title        = doc.GetTitle();
                var description  = doc.GetDescription();
                var thumbnailUrl = doc.GetThumbnailUrl();
                //var thumbnail = new WebClient().DownloadData(thumbnailUrl);

                var element = new ThumbnailData
                {
                    Description = description,
                    Title       = title,
                    //Thumbnail = thumbnail
                    ThumbnailUrl = thumbnailUrl
                };

                return(Ok(element));
            }
            catch (Exception)
            {
                return(Ok(new ThumbnailData()));
            }
        }
        /// <summary>
        /// Returns true if DocumentGetPreviewResponse instances are equal
        /// </summary>
        /// <param name="input">Instance of DocumentGetPreviewResponse to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(DocumentGetPreviewResponse input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Error == input.Error ||
                     (Error != null &&
                      Error.Equals(input.Error))
                     ) &&
                 (
                     RemainingTokens == input.RemainingTokens ||
                     RemainingTokens.Equals(input.RemainingTokens)
                 ) &&
                 (
                     PageCount == input.PageCount ||
                     PageCount.Equals(input.PageCount)
                 ) &&
                 (
                     ThumbnailData == input.ThumbnailData ||
                     (ThumbnailData != null &&
                      ThumbnailData.Equals(input.ThumbnailData))
                 ) &&
                 (
                     DocumentFormat == input.DocumentFormat ||
                     DocumentFormat.Equals(input.DocumentFormat)
                 ));
        }
        private void ThumbnailBuilt(object sender, ThumbnailBuiltEventArgs e)
        {
            ThumbnailData thumbnailData = null;

            if (e.ThumbnailStream != null)
            {
                var stream = new MemoryStream();
                e.ThumbnailStream.CopyTo(stream);
                thumbnailData = new BitmapThumbnailData(e.ThumbnailId, stream);
            }

            if (e.Result != ThumbnailBuildResult.Cancelled)
            {
                ThumbnailCompleted?.Invoke(this, new ThumbnailCompletedArgs(e.AssetId, thumbnailData));
            }

            lock (hashLock)
            {
                ThumbnailContinuation thumbnailContinuation;
                thumbnailsInProgressAndContinuation.TryGetValue(e.AssetId, out thumbnailContinuation);
                thumbnailsInProgressAndContinuation.Remove(e.AssetId);

                // Check if same asset has been requested again while it was compiling
                if (thumbnailContinuation != null)
                {
                    var priority = thumbnailContinuation.Position == QueuePosition.First ? firstPriority-- : lastPriority++;
                    var node     = assetBuilderService.PushBuildUnit(new ThumbnailAssetBuildUnit(thumbnailContinuation.UpdatedAssetToRecompile, currentGameSettings, this, priority));
                    thumbnailQueueHash.Add(thumbnailContinuation.UpdatedAssetToRecompile, node);
                }
            }
        }
Пример #7
0
 public async Task StoreAsync(ThumbnailData data, CancellationToken cancellationToken)
 {
     await _gridFSBucket.UploadFromBytesAsync(
         data.Id.ToString("N"),
         data.Data,
         options : null,
         cancellationToken);
 }
Пример #8
0
 private static ThumbnailData GetFolderThumbnail(IDispatcherService dispatcher)
 {
     using (var ds = new DigestStream(new MemoryStream()))
     {
         var bytes = Resources.Images.folder;
         ds.Write(bytes, 0, bytes.Length);
         var objectId = ds.CurrentHash;
         var data     = new ThumbnailData(objectId, new MemoryStream(bytes));
         data.PrepareForPresentation(dispatcher).Forget();
         return(data);
     }
 }
        private void Thumbnails_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_selectFromThis)
            {
                return;
            }
            _selectFromThis = true;
            ThumbnailData item = Thumbnails.SelectedItem as ThumbnailData;

            _selectedPosition = item != null ? item.start : 0;
            OnItemSelectedAction(item);
            _selectFromThis = false;
        }
Пример #10
0
        Size buildThumbnail(Panel panel, ThumbnailData data)
        {
            panel.Controls.Clear();

            int width  = 120;
            int height = 120;
            var size   = new Size(width, height);

            if (data.image != null)
            {
                PictureBox pictureBox = new PictureBox();
                pictureBox.SizeMode         = PictureBoxSizeMode.AutoSize;
                pictureBox.Dock             = DockStyle.Left;
                pictureBox.Tag              = data.path;
                pictureBox.Click           += new EventHandler(thumbnail_Click);
                pictureBox.ContextMenuStrip = ItemContextMenu;
                panel.Controls.Add(pictureBox);

                Label label = new Label();
                label.Dock             = DockStyle.Bottom;
                label.Width            = width;
                label.Tag              = data.path;
                label.TextAlign        = ContentAlignment.MiddleLeft;
                label.ForeColor        = Color.Gray;
                label.Click           += new EventHandler(thumbnail_Click);
                label.ContextMenuStrip = ItemContextMenu;
                panel.Controls.Add(label);

                pictureBox.Image = data.image;
                label.Text       = data.label;
                label.Height     = label.PreferredHeight;
                size.Height      = data.image.Height + 4 + label.Height;
            }
            else
            {
                Label label = new Label();
                label.Dock             = DockStyle.Left;
                label.Text             = data.label;
                label.Width            = width;
                label.Height           = height;
                label.Tag              = data.path;
                label.TextAlign        = ContentAlignment.MiddleCenter;
                label.ForeColor        = Color.LightGray;
                label.BackColor        = Color.DimGray;
                label.Click           += new EventHandler(thumbnail_Click);
                label.ContextMenuStrip = ItemContextMenu;
                panel.Controls.Add(label);
            }

            return(size);
        }
Пример #11
0
    private void SerializeThumbs()
    {
        Transform ThumbContainer = GameObject.FindGameObjectWithTag("ButtonList").transform;
        int       count          = ThumbContainer.childCount;

        SerializedThumbs = new ThumbnailData[count];

        for (int i = 0; i < count; i++)
        {
            Thumbnail thumb = ThumbContainer.GetChild(i).gameObject.GetComponent <Thumbnail>();
            if (thumb == null)
            {
                continue;
            }
            SerializedThumbs[i] = new ThumbnailData(ThumbContainer.GetChild(i).gameObject);
        }
    }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (Error != null)
         {
             hashCode = hashCode * 59 + Error.GetHashCode();
         }
         hashCode = hashCode * 59 + RemainingTokens.GetHashCode();
         hashCode = hashCode * 59 + PageCount.GetHashCode();
         if (ThumbnailData != null)
         {
             hashCode = hashCode * 59 + ThumbnailData.GetHashCode();
         }
         hashCode = hashCode * 59 + DocumentFormat.GetHashCode();
         return(hashCode);
     }
 }
Пример #13
0
 private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     SuspendLayout();
     while (true)
     {
         ThumbnailData data = null;
         lock ( thumbnailsData ) {
             if (thumbnailsData.Count > 0)
             {
                 data = thumbnailsData.Dequeue();
             }
         }
         if (data == null)
         {
             break;
         }
         addThumbnail(data);
     }
     ResumeLayout();
 }
        /// <summary>
        /// The method is to convert the file to the required format
        /// </summary>
        /// <param name="documentConverterUrl">Url to the service of conversion</param>
        /// <param name="documentUri">Uri for the document to convert</param>
        /// <param name="fromExtension">Document extension</param>
        /// <param name="toExtension">Extension to which to convert</param>
        /// <param name="documentRevisionId">Key for caching on service</param>
        /// <param name="password">Password</param>
        /// <param name="thumbnail">Thumbnail settings</param>
        /// <param name="isAsync">Perform conversions asynchronously</param>
        /// <param name="signatureSecret">Secret key to generate the token</param>
        /// <param name="convertedDocumentUri">Uri to the converted document</param>
        /// <returns>The percentage of completion of conversion</returns>
        /// <example>
        /// string convertedDocumentUri;
        /// GetConvertedUri("http://helpcenter.teamlab.com/content/GettingStarted.pdf", ".pdf", ".docx", "469971047", false, out convertedDocumentUri);
        /// </example>
        /// <exception>
        /// </exception>
        public static int GetConvertedUri(
            string documentConverterUrl,
            string documentUri,
            string fromExtension,
            string toExtension,
            string documentRevisionId,
            string password,
            ThumbnailData thumbnail,
            SpreadsheetLayout spreadsheetLayout,
            bool isAsync,
            string signatureSecret,
            out string convertedDocumentUri)
        {
            fromExtension = string.IsNullOrEmpty(fromExtension) ? Path.GetExtension(documentUri) : fromExtension;
            if (string.IsNullOrEmpty(fromExtension))
            {
                throw new ArgumentNullException("fromExtension", "Document's extension for conversion is not known");
            }
            if (string.IsNullOrEmpty(toExtension))
            {
                throw new ArgumentNullException("toExtension", "Extension for conversion is not known");
            }

            var title = Path.GetFileName(documentUri ?? "");

            title = string.IsNullOrEmpty(title) || title.Contains("?") ? Guid.NewGuid().ToString() : title;

            documentRevisionId = string.IsNullOrEmpty(documentRevisionId)
                                     ? documentUri
                                     : documentRevisionId;
            documentRevisionId = GenerateRevisionId(documentRevisionId);

            var request = (HttpWebRequest)WebRequest.Create(documentConverterUrl);

            request.Method      = "POST";
            request.ContentType = "application/json";
            request.Accept      = "application/json";
            request.Timeout     = Timeout;

            var body = new ConvertionBody
            {
                Async             = isAsync,
                FileType          = fromExtension.Trim('.'),
                Key               = documentRevisionId,
                OutputType        = toExtension.Trim('.'),
                Title             = title,
                Thumbnail         = thumbnail,
                SpreadsheetLayout = spreadsheetLayout,
                Url               = documentUri,
            };

            if (!string.IsNullOrEmpty(password))
            {
                body.Password = password;
            }

            if (!string.IsNullOrEmpty(signatureSecret))
            {
                var payload = new Dictionary <string, object>
                {
                    { "payload", body }
                };
                JsonWebToken.JsonSerializer = new JwtSerializer();
                var token = JsonWebToken.Encode(payload, signatureSecret, JwtHashAlgorithm.HS256);
                //todo: remove old scheme
                request.Headers.Add(FileUtility.SignatureHeader, "Bearer " + token);

                token      = JsonWebToken.Encode(body, signatureSecret, JwtHashAlgorithm.HS256);
                body.Token = token;
            }

            var bodyString = JsonConvert.SerializeObject(body);

            var bytes = Encoding.UTF8.GetBytes(bodyString ?? "");

            request.ContentLength = bytes.Length;
            using (var stream = request.GetRequestStream())
            {
                stream.Write(bytes, 0, bytes.Length);
            }

            // hack. http://ubuntuforums.org/showthread.php?t=1841740
            if (WorkContext.IsMono)
            {
                ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
            }

            string      dataResponse;
            WebResponse response       = null;
            Stream      responseStream = null;

            try
            {
                var countTry = 0;
                while (countTry < MaxTry)
                {
                    try
                    {
                        countTry++;
                        response       = request.GetResponse();
                        responseStream = response.GetResponseStream();
                        break;
                    }
                    catch (WebException ex)
                    {
                        if (ex.Status != WebExceptionStatus.Timeout)
                        {
                            throw new HttpException((int)HttpStatusCode.BadRequest, ex.Message, ex);
                        }
                    }
                }
                if (countTry == MaxTry)
                {
                    throw new WebException("Timeout", WebExceptionStatus.Timeout);
                }

                if (responseStream == null)
                {
                    throw new WebException("Could not get an answer");
                }
                using (var reader = new StreamReader(responseStream))
                {
                    dataResponse = reader.ReadToEnd();
                }
            }
            finally
            {
                if (responseStream != null)
                {
                    responseStream.Dispose();
                }
                if (response != null)
                {
                    response.Dispose();
                }
            }

            return(GetResponseUri(dataResponse, out convertedDocumentUri));
        }
Пример #15
0
 public static string AddData(ThumbnailData thumbnail)
 {
     return($"data:image/png;base64,{thumbnail.Content}");
 }
Пример #16
0
        public void NotifyThumbnailReady(ThumbnailData thumbnail)
        {
            if (null != CoreComponent.CurrentDispatcher) // If we're not running in NUnit mode.
            {
                CoreComponent.CurrentDispatcher.Invoke(new Action(() =>
                {
                    uint controllerId = ((uint)thumbnail.documentId);
                    uint nodeId = ((uint)thumbnail.packageId);

                    IGraphController controller = uiContainer.GetController(controllerId);
                    if (null != controller)
                    {
                        VisualNode visual = (controller as GraphController).GetVisualNode(nodeId);
                        if (null != visual)
                            visual.SetPreviewValue(thumbnail);
                    }
                }));
            }
        }
Пример #17
0
        private static ThumbnailData loadThumbnailData(AstroPhoto.LibRaw.Instance libraw, string path)
        {
            var thumbnailData = new ThumbnailData();

            thumbnailData.path = path;

            string ext = "";

            string[] stackFiles = null;
            if (System.IO.Directory.Exists(path))
            {
                var rawDir = System.IO.Path.Combine(path, "RAW");
                if (System.IO.Directory.Exists(rawDir))
                {
                    stackFiles = System.IO.Directory.GetFiles(rawDir, "*.arw");
                    ext        = ".arw";
                    if (stackFiles.Length == 0)
                    {
                        stackFiles = System.IO.Directory.GetFiles(rawDir, "*.cr2");
                        ext        = ".cr2";
                    }
                    if (stackFiles.Length == 0)
                    {
                        stackFiles = System.IO.Directory.GetFiles(rawDir, "*.cfa");
                        ext        = ".cfa";
                    }
                    if (stackFiles.Length == 0)
                    {
                        stackFiles = System.IO.Directory.GetFiles(rawDir, "*.fit");
                        ext        = ".fit";
                    }
                }
            }
            else
            {
                ext = System.IO.Path.GetExtension(path).ToLower();
            }

            if (ext.Length > 0)
            {
                if (ext == ".arw" || ext == ".cr2")
                {
                    string filePath = stackFiles == null ? path : stackFiles[0];
                    using (RawImage rawImage = libraw.load_thumbnail(filePath)) {
                        thumbnailData.image = createScaledImage(rawImage.Preview);
                        string shutter = rawImage.Shutter > 1 ? string.Format("{0:0}s", rawImage.Shutter) :
                                         string.Format("1/{0:0}s", 1 / rawImage.Shutter);
                        if (stackFiles == null)
                        {
                            thumbnailData.label = "ISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter;
                        }
                        else
                        {
                            thumbnailData.label = System.IO.Path.GetFileName(path) +
                                                  "\nISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter
                                                  + (stackFiles == null ? "" : " (" + stackFiles.Length + ")");
                        }
                    }
                }
                else if (ext == ".cfa" || ext == ".fit")
                {
                    string filePath = stackFiles == null ? path : stackFiles[0];
                    using (RawImage rawImage = new RawImage(filePath)) {
                        thumbnailData.image = createScaledImage(rawImage.Preview);
                        string shutter = rawImage.Shutter > 1 ? string.Format("{0:0}s", rawImage.Shutter) :
                                         string.Format("1/{0:0}s", 1 / rawImage.Shutter);
                        if (stackFiles == null)
                        {
                            thumbnailData.label = "ISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter;
                        }
                        else
                        {
                            thumbnailData.label = System.IO.Path.GetFileName(path) +
                                                  "\nISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter
                                                  + (stackFiles == null ? "" : " (" + stackFiles.Length + ")");
                        }
                    }
                }
                else if (ext == ".jpg" || ext == ".png")
                {
                    using (Image preview = Image.FromFile(path)) {
                        thumbnailData.image = createScaledImage(preview);
                    }
                    thumbnailData.label = System.IO.Path.GetFileName(path);
                }
            }
            else
            {
                thumbnailData.label = System.IO.Path.GetFileName(path);
            }
            return(thumbnailData);
        }