Beispiel #1
0
        public VimDatastoreItem[] FindDatastoreItemsInFolder(string folderName, VimClientlContext ctx)
        {
            if (this.snapshotDiskPattern == null)
            {
                this.snapshotDiskPattern = new Regex("w*-[0-9][0-9][0-9][0-9][0-9][0-9]w*");
            }
            List <VimDatastoreItem>           vimDatastoreItemList   = new List <VimDatastoreItem>();
            HostDatastoreBrowserSearchResults datastoreSearchResults = this.GetDatastoreSearchResults(VCService.GetVolumeName(this.Name) + folderName, ctx);

            if (datastoreSearchResults != null && datastoreSearchResults.file != null && datastoreSearchResults.file.Length != 0)
            {
                foreach (VimApi.FileInfo fileInfo in datastoreSearchResults.file)
                {
                    VimDatastoreItem vimDatastoreItem = new VimDatastoreItem()
                    {
                        Name = fileInfo.path, Size = fileInfo.fileSize
                    };
                    if (fileInfo is FolderFileInfo)
                    {
                        vimDatastoreItem.Type = "FOLDER";
                    }
                    else if (fileInfo is VmDiskFileInfo && !this.snapshotDiskPattern.IsMatch(fileInfo.path))
                    {
                        vimDatastoreItem.Type = "VMDK";
                    }
                    else
                    {
                        continue;
                    }
                    vimDatastoreItemList.Add(vimDatastoreItem);
                }
            }
            return(vimDatastoreItemList.ToArray());
        }
Beispiel #2
0
        public Dictionary <string, VimDatastoreItem[]> FindDatastoreItems(VimClientlContext ctx)
        {
            if (this.snapshotDiskPattern == null)
            {
                this.snapshotDiskPattern = new Regex("w*-[0-9][0-9][0-9][0-9][0-9][0-9]w*");
            }
            Dictionary <string, VimDatastoreItem[]> dictionary = new Dictionary <string, VimDatastoreItem[]>((IEqualityComparer <string>)StringComparer.CurrentCultureIgnoreCase);

            HostDatastoreBrowserSearchResults[] datastoreSearchResults = this.GetDatastoreSearchResults(ctx);
            int length = VCService.GetVolumeName(this.Name).Length;

            if (datastoreSearchResults != null && datastoreSearchResults.Length != 0)
            {
                foreach (HostDatastoreBrowserSearchResults browserSearchResults in datastoreSearchResults)
                {
                    string str = browserSearchResults.folderPath.TrimEnd('/');
                    if (length > str.Length)
                    {
                        length = str.Length;
                    }
                    string key = str.Remove(0, length);
                    List <VimDatastoreItem> vimDatastoreItemList = new List <VimDatastoreItem>();
                    if (browserSearchResults.file != null)
                    {
                        foreach (VimApi.FileInfo fileInfo in browserSearchResults.file)
                        {
                            VimDatastoreItem vimDatastoreItem = new VimDatastoreItem()
                            {
                                Name = fileInfo.path, Size = fileInfo.fileSize
                            };
                            if (fileInfo is FolderFileInfo)
                            {
                                vimDatastoreItem.Type = "FOLDER";
                            }
                            else if (fileInfo is VmDiskFileInfo && !this.snapshotDiskPattern.IsMatch(fileInfo.path))
                            {
                                vimDatastoreItem.Type = "VMDK";
                            }
                            else
                            {
                                continue;
                            }
                            vimDatastoreItemList.Add(vimDatastoreItem);
                        }
                    }
                    dictionary.Add(key, vimDatastoreItemList.ToArray());
                }
            }
            return(dictionary);
        }