Beispiel #1
0
        public string[] GetVmdksFullName(string folderName, VimClientlContext ctx)
        {
            List <string> stringList = new List <string>();
            string        str1       = VimUtils.GetVolumeName(this.Name) + folderName;

            HostDatastoreBrowserSearchResults[] browserSearchResults1 = this.GetBrowserSearchResults(str1, ctx);
            if (browserSearchResults1 != null && browserSearchResults1.Length != 0)
            {
                foreach (HostDatastoreBrowserSearchResults browserSearchResults2 in browserSearchResults1)
                {
                    string strA = browserSearchResults2.folderPath.TrimEnd('/');
                    if (browserSearchResults2.file != null && string.Compare(strA, str1, true) == 0)
                    {
                        foreach (VimApi.FileInfo fileInfo in browserSearchResults2.file)
                        {
                            string pattern = "w*-[0-9][0-9][0-9][0-9][0-9][0-9]w*";
                            if (!Regex.Match(fileInfo.path, pattern, RegexOptions.IgnoreCase).Success)
                            {
                                string str2 = browserSearchResults2.folderPath + fileInfo.path;
                                if (!stringList.Contains(str2))
                                {
                                    stringList.Add(browserSearchResults2.folderPath + fileInfo.path);
                                }
                            }
                        }
                        break;
                    }
                }
            }
            return(stringList.ToArray());
        }
Beispiel #2
0
        public Dictionary <string, List <VmdkFileInfo> > GetAllFoldersAndFilesInfo(VimClientlContext ctx)
        {
            Dictionary <string, List <VmdkFileInfo> > dictionary = new Dictionary <string, List <VmdkFileInfo> >((IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase);
            string volumeName = VimUtils.GetVolumeName(this.Name);

            HostDatastoreBrowserSearchResults[] browserSearchResults1 = this.GetBrowserSearchResults(volumeName, ctx);
            if (browserSearchResults1 != null && browserSearchResults1.Length != 0)
            {
                foreach (HostDatastoreBrowserSearchResults browserSearchResults2 in browserSearchResults1)
                {
                    string str    = browserSearchResults2.folderPath.TrimEnd('/');
                    int    length = volumeName.Length;
                    if (length > str.Length)
                    {
                        length = str.Length;
                    }
                    string key = str.Remove(0, length);
                    List <VmdkFileInfo> vmdkFileInfoList = new List <VmdkFileInfo>();
                    if (browserSearchResults2.file != null)
                    {
                        foreach (VimApi.FileInfo fileInfo in browserSearchResults2.file)
                        {
                            string pattern = "w*-[0-9][0-9][0-9][0-9][0-9][0-9]w*";
                            if (!Regex.Match(fileInfo.path, pattern, RegexOptions.IgnoreCase).Success)
                            {
                                vmdkFileInfoList.Add(new VmdkFileInfo(fileInfo.path, browserSearchResults2.folderPath, (ulong)fileInfo.fileSize));
                            }
                        }
                    }
                    if (!dictionary.ContainsKey(key))
                    {
                        dictionary.Add(key, vmdkFileInfoList);
                    }
                }
            }
            return(dictionary);
        }
Beispiel #3
0
        public bool IsFolderOnRootExist(string folderName, VimClientlContext ctx)
        {
            VCTask task = new VCTask(this.VcService, this.VcService.Service.SearchDatastoreSubFolders_Task(this.GetManagedObjects(new string[1] {
                "browser"
            })[0], VimUtils.GetVolumeName(this.Name), new HostDatastoreBrowserSearchSpec()
            {
                matchPattern = new string[1] {
                    folderName
                }, searchCaseInsensitive = true, searchCaseInsensitiveSpecified = true
            }));
            string            op     = "Browse Datastore";
            VimClientlContext rstate = ctx;

            task.WaitForResult(op, rstate);
            string[] properties1 = new string[1] {
                "info.result"
            };
            Dictionary <string, object> properties2 = task.GetProperties(properties1);

            if (properties2.ContainsKey("info.result"))
            {
                HostDatastoreBrowserSearchResults[] browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])properties2["info.result"];
                if (browserSearchResultsArray != null && browserSearchResultsArray.Length != 0)
                {
                    string strB = VimUtils.GetVolumeName(this.Name).Trim();
                    foreach (HostDatastoreBrowserSearchResults browserSearchResults in browserSearchResultsArray)
                    {
                        if (browserSearchResults.file != null && browserSearchResults.file.Length != 0 && string.Compare(browserSearchResults.folderPath, strB) == 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }