Esempio n. 1
0
        public void DeleteFile(PortableDeviceFile file)
        {
            var variant = new PortableDeviceApiLib.tag_inner_PROPVARIANT();
            IPortableDeviceContent content = null;

            try
            {
                this._device.Content(out content);

                StringToPropVariant(file.Id, out variant, 2);

                PortableDeviceApiLib.IPortableDevicePropVariantCollection objectIds =
                    new PortableDeviceTypesLib.PortableDevicePropVariantCollection()
                    as PortableDeviceApiLib.IPortableDevicePropVariantCollection;
                objectIds.Add(variant);


                content.Delete(0, objectIds, null);
            }
            catch (Exception ex)
            {
                Logger.Basic.Error("Portable Device DeleteFile : " + ex.ToString(), ex);
            }
            finally {
                if (Marshal.IsComObject(variant))
                {
                    Marshal.ReleaseComObject(variant);
                }

                if (content != null && Marshal.IsComObject(content))
                {
                    Marshal.ReleaseComObject(content);
                }
            }
        }
Esempio n. 2
0
        private void RealDeleteOperation(PortableDevice device, PortableDeviceFile item, List <ImageItem> deletedFiles, List <ImageItem> willbeuploaded)
        {
            try
            {
                foreach (ImageItem imageItem in deletedFiles)
                {
                    if (imageItem.UniqueIdentifier == item.Id)
                    {
                        deleteoperationcanbedone = true;
                        _imgManager.DeleteImageFromDirectory(imageItem);
                        device.DeleteFile((PortableDeviceFile)item);
                        deleteditem++;
                        Action action = () => ImageNumber(deleteditem, deletedFiles.Count);
                        Dispatcher.CurrentDispatcher.Invoke(action);
                        Thread.Sleep(100);
                        break;
                    }
                }

                if (!deleteoperationcanbedone && willbeuploaded.Count > 0)
                {
                    SetNotification(1, PhotoUploader.Properties.Resources.main_msg_imagenoexist);

                    Action action1 = () => ImageNumber(-1, deletedFiles.Count);
                    Dispatcher.CurrentDispatcher.Invoke(action1);
                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Logger.Basic.Error("PWDManager Delete Operation : " + ex.ToString(), ex);
            }
        }
Esempio n. 3
0
        public bool DownloadFile(PortableDeviceFile file, string saveToPath)
        {
            bool isdownload = false;
            IPortableDeviceContent content;

            this._device.Content(out content);

            IPortableDeviceResources resources;

            content.Transfer(out resources);

            PortableDeviceApiLib.IStream wpdStream;
            uint optimalTransferSize = 0;

            System.Runtime.InteropServices.ComTypes.IStream sourceStream = null;

            IPortableDeviceValues values =
                new PortableDeviceTypesLib.PortableDeviceValues() as IPortableDeviceValues;

            DateTime  createdDate = GetObjectCreationTime(content, file.Id);
            ImageItem imageItem   = null;

            imageItem = new ImageItem(0, file.Id, file.Name, createdDate);


            var property = new _tagpropertykey();

            property.fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF, 0xB5, 0x3F, 0xF1, 0xA0, 0x6A, 0xE8, 0x78, 0x42);
            property.pid   = 0;
            string     imgpath      = string.Empty;
            FileStream targetStream = null;

            try
            {
                resources.GetStream(file.Id, ref property, 0, ref optimalTransferSize, out wpdStream);

                sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;

                var filename = Path.GetFileName(file.Id);
                imgpath      = saveToPath + "IMG_1_" + imageItem.TakenTime.ToString() + "_" + file.Id + ".jpg";
                targetStream = new FileStream(imgpath, FileMode.Create, FileAccess.Write);

                unsafe
                {
                    var buffer = new byte[2048];
                    int bytesRead;
                    do
                    {
                        sourceStream.Read(buffer, 2048, new IntPtr(&bytesRead));
                        targetStream.Write(buffer, 0, 2048);
                    } while (bytesRead > 0);
                    targetStream.Close();


                    isdownload = true;
                }
            }
            catch (Exception ex)
            {
                isdownload = false;
                Logger.Basic.Error("PortableDevice DownloadFile : " + ex.ToString(), ex);
            }
            finally
            {
                if (resources != null && Marshal.IsComObject(resources))
                {
                    Marshal.ReleaseComObject(resources);
                }

                if (content != null && Marshal.IsComObject(content))
                {
                    Marshal.ReleaseComObject(content);
                }

                if (sourceStream != null && Marshal.IsComObject(sourceStream))
                {
                    Marshal.ReleaseComObject(sourceStream);
                }

                if (!isdownload)
                {
                    if (File.Exists(imgpath))
                    {
                        if (targetStream != null)
                        {
                            targetStream.Close();
                        }

                        File.Delete(imgpath);
                    }
                }
            }

            return(isdownload);
        }
Esempio n. 4
0
        private void RealDownloadOperation(PortableDevice device, PortableDeviceFile item)
        {
            ImageItem imageItem = null;

            IPortableDeviceContent content = device.GetContentofDevice();

            DateTime createddate = device.GetObjectCreationTime(content, item.Id);

            imageItem = new ImageItem(0, item.Id, item.Id, createddate);

            if (_imageList.Exists((ImageItem t) => { return(t.UniqueIdentifier == item.Id); }))
            {
                countofimg++;
                Action action = () => FetchImageCount(countofimg, totalimagecount);
                Dispatcher.CurrentDispatcher.Invoke(action);
                Thread.Sleep(200);
            }
            else if ((!_imageList.Exists((ImageItem t) => { return(t.UniqueIdentifier == item.Id); }) ||
                      _imageList.Count == 0))
            {
                countofimg++;
                _imageList.Add(imageItem);

                bool isok = device.DownloadFile((PortableDeviceFile)item, ImageFolder);

                if (isok)
                {
                    Action action = () => FetchImageCount(countofimg, totalimagecount);
                    Dispatcher.CurrentDispatcher.Invoke(action);
                    Thread.Sleep(200);
                }
            }

            if (countofimg >= totalimagecount)
            {
                countofimg      = 0;
                totalimagecount = 0;
            }

            //else if (totalimagecount > 0 && countofimg < totalimagecount)
            //{

            //    countofimg++;
            //    Action action = () => FetchImageCount(countofimg, totalimagecount);
            //    Dispatcher.CurrentDispatcher.Invoke(action);
            //    Thread.Sleep(200);

            //    if (countofimg == totalimagecount)
            //    {
            //        countofimg = 0;
            //        totalimagecount = 0;
            //    }


            //}

            //if (totalimagecount > 0)
            //{
            //    if (countofimg == totalimagecount)
            //    {
            //        countofimg = 0;
            //        totalimagecount = 0;
            //    }
            //    device.DownloadFile((PortableDeviceFile)item, ImageFolder);
            //}
        }