Example #1
0
 private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     // This code executes in the UI thread, no problem to
     // work with Controls like the ListView
     try
     {
         ThumbSet ts = e.UserState as ThumbSet;
         if (ts.last)
         {
             CycleBackground();
         }
         else
         {
             if (imageList.Images.ContainsKey(ts.ID))
             {
                 imageList.Images.RemoveByKey(ts.ID);
             }
             imageList.Images.Add(ts.ID, ts.IMG);
             ListViewItem lvi = listView1.FindItemWithText(ts.ID);
             lvi.ImageKey = ts.ID;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            foreach (PartTypes.Part p in PARTS)
            {
                try
                {
                    List <string> files = Directory.GetFiles(p.Hyperlink).ToList();
                    foreach (string imgfile in files)
                    {
                        String extension = "";
                        if (imgfile.Contains(".jpg"))
                        {
                            extension = ".jpg";
                        }
                        else if (imgfile.Contains(".png"))
                        {
                            extension = ".png";
                        }
                        if (extension != "")
                        {
                            //p.thumb = (Bitmap)Bitmap.FromFile(imgfile);
                            ThumbSet ts             = new ThumbSet();
                            string   newPathAndName = @"C:\Documents\ExtrusionLibrary\Thumbnails\" + p.ID + extension;

                            if (!System.IO.Directory.Exists(newPathAndName))
                            {
                                System.IO.File.Copy(imgfile, newPathAndName);
                                ts.IMG = Image.FromFile(newPathAndName);
                                ts.ID  = p.ID;
                                worker.ReportProgress(100, ts);
                            }
                            else
                            {
                                if (System.IO.File.GetLastWriteTime(imgfile) != System.IO.File.GetLastWriteTime(newPathAndName))
                                {
                                    System.IO.File.Copy(imgfile, newPathAndName);
                                    ts.IMG = Image.FromFile(newPathAndName);
                                    ts.ID  = p.ID;
                                    worker.ReportProgress(100, ts);
                                }
                            }
                            break;
                        }
                    }
                }
                catch
                {
                }
                finally
                {
                }
            }
            ThumbSet tsLast = new ThumbSet();

            tsLast.last = true;
            worker.ReportProgress(100, tsLast);
        }
Example #3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            foreach (Autodesk.Connectivity.WebServices.Item f in PARTS)
            {
                try
                {
                    ThumbSet ts      = new ThumbSet();
                    Byte[]   imgbyte = v_Conn.WebServiceManager.PropertyService.GetProperties("ITEM", new long[] { f.Id }, new long[] { thumbID }).FirstOrDefault().Val as Byte[];
                    if (imgbyte == null)
                    {
                    }
                    else
                    {
                        using (var ms = new MemoryStream(imgbyte))
                        {
                            using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
                            {
                                // Vault saves thumbnails as jpeg per developer comments for 2013, assume same
                                // https://justonesandzeros.typepad.com/blog/2012/05/thumbnail-optimization.html#:~:text=One%20of%20the%20optimizations%20in,JPEG%20when%20at%20thumbnail%20size.

                                // the bytes do not represent a metafile, try to convert to an Image
                                ms.Seek(0, System.IO.SeekOrigin.Begin);
                                ts.IMG = Image.FromStream(ms, true, false);
                            }
                        }
                        ts.ID = v_Conn.WebServiceManager.PropertyService.GetProperties("ITEM", new long[] { f.Id }, new long[] { nameID }).FirstOrDefault().Val.ToString();
                        string newPathAndName = @"C:\Documents\ExtrusionLibrary\Thumbnails\" + ts.ID + ".jpeg";

                        if (System.IO.File.Exists(newPathAndName))
                        {
                        }
                        else
                        {
                            if (ts.IMG != null)
                            {
                                System.IO.File.WriteAllBytes(newPathAndName, imgbyte);
                                ts.IMG = Image.FromFile(newPathAndName);
                                worker.ReportProgress(100, ts);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("END | " + ex.Message);
                }
            }

            ThumbSet tsLast = new ThumbSet();

            tsLast.last = true;
            worker.ReportProgress(100, tsLast);
        }