private IEnumerable<NwdUriProcessEntry> GetDeviceSynergyFiles(NwdPortableDevice device)
        {
            List<NwdPortableDeviceObject> lst = FindByUri("NWD/synergy/[*]");
            List<NwdUriProcessEntry> output =
                new List<NwdUriProcessEntry>();

            if (lst.Count > 0)
            {
                foreach (NwdPortableDeviceObject pdo in lst)
                {
                    if (pdo is NwdPortableDeviceFile)
                    {
                        NwdUri uri = new NwdUri("NWD/synergy/" + pdo.Name);
                        NwdUriProcessEntry pe =
                            new NwdUriProcessEntry(uri);

                        pe.DeviceObject = pdo;

                        output.Add(pe);
                    }
                }
            }

            return output;
        }
 public NwdUriProcessEntry(NwdUri nwdUri)
 {
     this.nwdUri = nwdUri;
     Processed = false;
 }
        private MultiMap<string, NwdPortableDeviceObject> FindByUriCached(string uri)
        {
            MultiMap<string, NwdPortableDeviceObject> masterMap =
                new MultiMap<string, NwdPortableDeviceObject>();

            NwdUri nwdUri = new NwdUri(uri);

            var col = new NwdPortableDeviceCollection();

            try
            {
                col.Refresh();
            }
            catch (Exception ex)
            {
                Display.Exception(ex);
            }

            foreach (var device in col)
            {
                if (device.RootFolder != null)
                {
                    //device level
                    foreach (NwdPortableDeviceObject pdo
                        in device.RootFolder.Files)
                    {
                        //start a new multimap for each device/storage location
                        MultiMap<string, NwdPortableDeviceObject> found =
                            new MultiMap<string, NwdPortableDeviceObject>();

                        //need to reset Uri for each device/storage location
                        nwdUri.ResetStack();

                        //internal vs external storage level
                        if (pdo is NwdPortableDeviceFolder)
                        {
                            NwdPortableDeviceFolder folder =
                                (NwdPortableDeviceFolder)pdo;

                            Retrieve(device, folder, ref nwdUri, ref found);
                        }

                        //add found into master map
                        masterMap.AddAll(found);
                    }
                }
            }

            return masterMap;
        }
        private List<NwdPortableDeviceObject> FindByUri(string uri)
        {
            List<NwdPortableDeviceObject> found =
                new List<NwdPortableDeviceObject>();

            NwdUri nwdUri = new NwdUri(uri);

            var col = new NwdPortableDeviceCollection();

            try
            {
                col.Refresh();
            }
            catch (Exception ex)
            {
                Display.Exception(ex);
            }

            foreach (var device in col)
            {
                if (device.RootFolder != null)
                {
                    //device level
                    foreach (NwdPortableDeviceObject pdo
                        in device.RootFolder.Files)
                    {
                        //need to reset Uri for each device/storage location
                        nwdUri.ResetStack();

                        //internal vs external storage level
                        if (pdo is NwdPortableDeviceFolder)
                        {
                            NwdPortableDeviceFolder folder =
                                (NwdPortableDeviceFolder)pdo;

                            Retrieve(device, folder, ref nwdUri, ref found);
                        }
                    }
                }
            }

            return found;
        }
        private void Retrieve(NwdPortableDevice device,
                              NwdPortableDeviceFolder folder,
                              ref NwdUri uri,
                              ref MultiMap<string, NwdPortableDeviceObject> found)
        {
            folder.Refresh(device);

            string nodeName = uri.PopNodeName();

            if (found.ContainsKey(uri.CurrentTraversalUri))
            {
                //used cached lookup
                foreach (NwdPortableDeviceObject pdo in found[uri.CurrentTraversalUri])
                {
                    ProcessPdo(device, pdo, ref uri, ref found);
                }
            }
            else
            {
                //use standard lookup
                if (folder.Files != null)
                {
                    foreach (NwdPortableDeviceObject pdo in folder.Files)
                    {
                        if (NwdUri.MatchNodeName(nodeName, pdo.Name))
                        {
                            ProcessPdo(device, pdo, ref uri, ref found);
                        }
                    }
                }
            }
        }
        private void Retrieve(NwdPortableDevice device,
                              NwdPortableDeviceFolder folder,
                              ref NwdUri uri,
                              ref List<NwdPortableDeviceObject> found)
        {
            folder.Refresh(device);

            string nodeName = uri.PopNodeName();

            if (folder.Files != null)
            {
                foreach (NwdPortableDeviceObject pdo in folder.Files)
                {
                    if (NwdUri.MatchNodeName(nodeName, pdo.Name))
                    {
                        if (uri.HasNodeKeysInStack())
                        {
                            if (pdo is NwdPortableDeviceFolder)
                            {
                                NwdPortableDeviceFolder nextFolder =
                                    (NwdPortableDeviceFolder)pdo;

                                //uri has one level popped, pass the modified uri and
                                //the newly found folder to the next level of recursion
                                Retrieve(device, nextFolder, ref uri, ref found);
                            }
                            else
                            {
                                //bad key (found name but not a folder and keystack isn't empty, so just return)

                                //do nothing
                            }
                        }
                        else
                        {
                            //finished
                            found.Add(pdo);
                        }
                    }
                }
            }
        }
        private void ProcessPdo(NwdPortableDevice device,
                                NwdPortableDeviceObject pdo,
                                ref NwdUri uri,
                                ref MultiMap<string, NwdPortableDeviceObject> found)
        {
            if (uri.HasNodeKeysInStack())
            {
                if (pdo is NwdPortableDeviceFolder)
                {
                    NwdPortableDeviceFolder nextFolder =
                        (NwdPortableDeviceFolder)pdo;

                    found.Add(uri.CurrentTraversalUri, pdo);

                    //uri has one level popped, pass the modified uri and
                    //the newly found folder to the next level of recursion
                    Retrieve(device, nextFolder, ref uri, ref found);
                }
                else
                {
                    //bad key (found name but not a folder and keystack isn't empty, so just return)

                    //do nothing
                }
            }
            else
            {
                //finished
                found.Add(uri.CurrentTraversalUri, pdo);
            }
        }