예제 #1
0
        public void GetAllImagesFromCamera()
        {
            lock (this)
            {
                if (isdeleteoperation)
                {
                    Monitor.Wait(this);
                }

                isfetchingrunning = true;
                if (totalimagecount > 0 && countofimg < totalimagecount)
                {
                    var collection = new PortableDeviceCollection();

                    collection.Refresh();

                    foreach (var device in collection)
                    {
                        device.Connect();
                        var folder = device.GetContents();
                        foreach (var item in folder.Files)
                        {
                            DisplayObject(device, item);
                        }

                        device.Disconnect();
                    }
                }

                isfetchingrunning = false;
                Monitor.Pulse(this);
                Monitor.Wait(this);
            } //end of lock
        }     // end of  public void GetAllImagesFromCamera()
예제 #2
0
        public void watcher_EventArrived(object o, EventArrivedEventArgs e)
        {
            ManagementEventWatcher obj = (ManagementEventWatcher)o;

            obj.Stop();
            obj.EventArrived -= new EventArrivedEventHandler(watcher_EventArrived);

            //int deviceStatus = FindDevice();



            if (deviceStatus == 1 && devicestate == false)
            {
                var collection = new PortableDeviceCollection();

                collection.Refresh();

                foreach (var device in collection)
                {
                    device.Connect();
                    GetDeviceName(PhotoUploader.Properties.Resources.main_hdr_connected + " " + device.FriendlyName);
                    devicestate  = true;
                    deviceStatus = 2;
                    StatusChanged(true, PhotoUploader.Properties.Resources.main_hdr_connected + " " + device.FriendlyName);
                    device.Disconnect();
                    break;
                }
            }


            //obj = (ManagementEventWatcher)o;
            obj.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
            obj.Start();
        }
예제 #3
0
        private void m_mewWatcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            if (e.NewEvent.ClassPath.ClassName == "__InstanceCreationEvent")
            {
                //Console.WriteLine("USB was plugged in");
                foreach (PropertyData pdData in e.NewEvent.Properties)
                {
                    if (pdData.Value != null && pdData.Value.GetType() == typeof(ManagementBaseObject))
                    {
                        ManagementBaseObject mbo = (ManagementBaseObject)pdData.Value;
                        if (mbo != null)
                        {
                            foreach (PropertyData pdDataSub in mbo.Properties)
                            {
                                if (pdDataSub.Name == "ClassGuid" && pdDataSub.Value.ToString() == "{eec5ad98-8080-425f-922a-dabf3de3f69a}")
                                {
                                    var collection = new PortableDeviceCollection();

                                    collection.Refresh();

                                    foreach (var device in collection)
                                    {
                                        device.Connect();
                                        GetDeviceName("Connected " + device.FriendlyName);
                                        devicestate = true;
                                        StatusChanged(true, "Connected " + device.FriendlyName);
                                        device.Disconnect();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (e.NewEvent.ClassPath.ClassName == "__InstanceDeletionEvent")
            {
                foreach (PropertyData pdData in e.NewEvent.Properties)
                {
                    if (pdData.Value != null && pdData.Value.GetType() == typeof(ManagementBaseObject))
                    {
                        ManagementBaseObject mbo = (ManagementBaseObject)pdData.Value;
                        if (mbo != null)
                        {
                            foreach (PropertyData pdDataSub in mbo.Properties)
                            {
                                if (pdDataSub.Name == "ClassGuid" && pdDataSub.Value.ToString() == "{eec5ad98-8080-425f-922a-dabf3de3f69a}")
                                {
                                    devicestate = false;
                                    countofimg  = 0;
                                    deleteditem = 0;
                                    StatusChanged(false, "Disconnected");
                                    GetDeviceName("Disconnected");
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        public void GetCountOfImage(ImageManager imgManager)
        {
            int total = 0;

            _imgManager = imgManager;

            try
            {
                if (devicestate == true)
                {
                    var collection = new PortableDeviceCollection();

                    collection.Refresh();

                    foreach (var device in collection)
                    {
                        device.Connect();

                        var folder = device.GetContents();
                        foreach (var item in folder.Files)
                        {
                            total = GetCountOfImageRec(device, item);
                        }



                        device.Disconnect();
                    }
                }
                else
                {
                    total = -1;
                }


                totalimagecount = total > -1 ? total : 0;
                GetImageCount(total);
                _imageList = _imgManager.GetImagesFromDirectory();

                if (total == 0)
                {
                    Action action = () => FetchImageCount(0, 0);
                    Dispatcher.CurrentDispatcher.Invoke(action);
                    Thread.Sleep(200);
                }
            }
            catch (Exception ex)
            {
                Logger.Basic.Error("GetCountOfImage", ex);
            }
        }
예제 #5
0
        public void DeleteImagesFromCamera(ImageManager imgManager, List <ImageItem> deletedFiles, List <ImageItem> willbeuploaded)
        {
            lock (this)
            {
                if (isfetchingrunning)
                {
                    Monitor.Wait(this);
                }


                isdeleteoperation = true;
                _deletedFiles     = deletedFiles;
                _willbeuploaded   = willbeuploaded;
                _imgManager       = imgManager;


                var collection = new PortableDeviceCollection();

                collection.Refresh();

                foreach (var device in collection)
                {
                    device.Connect();
                    var folder = device.GetContents();
                    foreach (var item in folder.Files)
                    {
                        DisplayObject(device, item);
                    }

                    device.Disconnect();
                }

                isdeleteoperation = false;
                Monitor.Pulse(this);
                Monitor.Wait(this);
            } //end of lock
        }     //end of  public void DeleteImagesFromCamera()