Esempio n. 1
0
        public bool FileExist(string fullName, VimClientlContext ctx)
        {
            fullName = fullName.Replace("\\", "/");
            string str1 = fullName.Substring(0, fullName.LastIndexOf("/"));
            string str2 = fullName.Substring(fullName.LastIndexOf("/") + 1);

            HostDatastoreBrowserSearchResults[] browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])null;
            VCTask task = new VCTask(this.VcService, this.VcService.Service.SearchDatastoreSubFolders_Task(this.GetManagedObjects(new string[1] {
                "browser"
            })[0], this.GetVolumeName(this.Name) + str1.Trim("/".ToCharArray()), new HostDatastoreBrowserSearchSpec()
            {
                matchPattern = new string[1] {
                    str2
                }, searchCaseInsensitive = true, searchCaseInsensitiveSpecified = true, sortFoldersFirst = true, sortFoldersFirstSpecified = 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"))
            {
                browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])properties2["info.result"];
            }
            return(browserSearchResultsArray != null && browserSearchResultsArray.Length != 0 && browserSearchResultsArray[0].file != null);
        }
Esempio n. 2
0
        private HostDatastoreBrowserSearchResults[] GetDatastoreSearchResults(VimClientlContext ctx)
        {
            string volumeName = VCService.GetVolumeName(this.Name);

            HostDatastoreBrowserSearchResults[] browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])null;
            ManagedObjectReference[]            managedObjects            = this.GetManagedObjects(new string[1] {
                "browser"
            });
            HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();

            searchSpec.matchPattern = new string[1] {
                "*.vmdk"
            };
            searchSpec.searchCaseInsensitive          = true;
            searchSpec.searchCaseInsensitiveSpecified = true;
            searchSpec.sortFoldersFirst               = true;
            searchSpec.sortFoldersFirstSpecified      = true;
            searchSpec.searchCaseInsensitiveSpecified = true;
            searchSpec.details                    = new FileQueryFlags();
            searchSpec.details.fileSize           = true;
            searchSpec.details.fileOwner          = false;
            searchSpec.details.fileType           = true;
            searchSpec.details.fileOwnerSpecified = true;
            searchSpec.query = new FileQuery[3]
            {
                (FileQuery) new FolderFileQuery(),
                (FileQuery) new VmDiskFileQuery(),
                new FileQuery()
            };
            VCTask            task   = new VCTask(this.VcService, this.VcService.Service.SearchDatastoreSubFolders_Task(managedObjects[0], volumeName, searchSpec));
            string            op     = "Search 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"))
            {
                browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])properties2["info.result"];
            }
            return(browserSearchResultsArray);
        }
Esempio n. 3
0
        private HostDatastoreBrowserSearchResults GetDatastoreSearchResults(string datastorePath, VimClientlContext ctx)
        {
            HostDatastoreBrowserSearchResults browserSearchResults = (HostDatastoreBrowserSearchResults)null;

            ManagedObjectReference[] managedObjects = this.GetManagedObjects(new string[1] {
                "browser"
            });
            HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
            VmDiskFileQuery vmDiskFileQuery           = new VmDiskFileQuery();

            vmDiskFileQuery.details            = new VmDiskFileQueryFlags();
            vmDiskFileQuery.details.capacityKb = true;
            searchSpec.details                    = new FileQueryFlags();
            searchSpec.details.fileSize           = true;
            searchSpec.details.fileOwner          = false;
            searchSpec.details.fileOwner          = false;
            searchSpec.details.fileType           = true;
            searchSpec.details.fileOwnerSpecified = true;
            searchSpec.query = new FileQuery[2]
            {
                (FileQuery) new FolderFileQuery(),
                (FileQuery)vmDiskFileQuery
            };
            VCTask            task   = new VCTask(this.VcService, this.VcService.Service.SearchDatastore_Task(managedObjects[0], datastorePath, searchSpec));
            string            op     = "Search 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"))
            {
                browserSearchResults = (HostDatastoreBrowserSearchResults)properties2["info.result"];
            }
            return(browserSearchResults);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public Dictionary <string, bool> GetVirtualDisksTypes(string folderName, VimClientlContext ctx)
        {
            Dictionary <string, bool> dictionary = new Dictionary <string, bool>((IEqualityComparer <string>)StringComparer.CurrentCultureIgnoreCase);

            try
            {
                string datastorePath = VCService.GetVolumeName(this.Name) + folderName;
                HostDatastoreBrowserSearchResults[] browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])null;
                ManagedObjectReference[]            managedObjects            = this.GetManagedObjects(new string[1] {
                    "browser"
                });
                HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
                searchSpec.matchPattern = new string[1] {
                    "*.vmdk"
                };
                searchSpec.searchCaseInsensitive          = true;
                searchSpec.searchCaseInsensitiveSpecified = true;
                searchSpec.sortFoldersFirst               = true;
                searchSpec.sortFoldersFirstSpecified      = true;
                searchSpec.searchCaseInsensitiveSpecified = true;
                searchSpec.details                    = new FileQueryFlags();
                searchSpec.details.fileOwner          = false;
                searchSpec.details.fileOwnerSpecified = true;
                searchSpec.details.fileSize           = true;
                searchSpec.details.modification       = true;
                searchSpec.details.fileType           = true;
                VmDiskFileQuery vmDiskFileQuery = new VmDiskFileQuery();
                vmDiskFileQuery.details               = new VmDiskFileQueryFlags();
                vmDiskFileQuery.details.thin          = true;
                vmDiskFileQuery.details.thinSpecified = true;
                FileQuery fileQuery = new FileQuery();
                searchSpec.query = new FileQuery[1]
                {
                    (FileQuery)vmDiskFileQuery
                };
                VCTask            task   = new VCTask(this._vimService, this._vimService.Service.SearchDatastoreSubFolders_Task(managedObjects[0], datastorePath, searchSpec));
                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"))
                {
                    browserSearchResultsArray = (HostDatastoreBrowserSearchResults[])properties2["info.result"];
                }
                if (browserSearchResultsArray != null)
                {
                    if (browserSearchResultsArray.Length != 0)
                    {
                        foreach (HostDatastoreBrowserSearchResults browserSearchResults in browserSearchResultsArray)
                        {
                            List <VmdkFileInfo> vmdkFileInfoList = new List <VmdkFileInfo>();
                            if (browserSearchResults.file != null)
                            {
                                foreach (VimApi.FileInfo fileInfo in browserSearchResults.file)
                                {
                                    if (fileInfo is VmDiskFileInfo && !dictionary.ContainsKey(fileInfo.path))
                                    {
                                        dictionary.Add(fileInfo.path, ((VmDiskFileInfo)fileInfo).thin);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(dictionary);
        }