示例#1
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);
        }
示例#2
0
        private static bool IsCertInstalled(X509Certificate2 certificate)
        {
            X509Store certificateStore = VCService.GetCertificateStore();

            try
            {
                certificateStore.Open(OpenFlags.ReadOnly);
                return(certificateStore.Certificates.Contains(certificate));
            }
            finally
            {
                certificateStore.Close();
            }
        }
示例#3
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()
            };
            Task              task   = new Task(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);
        }
示例#4
0
        public Dictionary <string, VmdkFileInfo> GetVmdksFileInfo(string fullName, VimClientlContext ctx)
        {
            fullName = fullName.Replace("\\", "/");
            string str1     = fullName.Substring(0, fullName.LastIndexOf("/"));
            string fileName = Path.GetFileName(fullName);
            Dictionary <string, VmdkFileInfo> dictionary = new Dictionary <string, VmdkFileInfo>((IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase);

            try
            {
                string str2 = VCService.GetVolumeName(this.Name) + str1;
                HostDatastoreBrowserSearchResults[] browserSearchResults1 = this.GetBrowserSearchResults(str2, ctx);
                if (browserSearchResults1 != null)
                {
                    if (browserSearchResults1.Length != 0)
                    {
                        foreach (HostDatastoreBrowserSearchResults browserSearchResults2 in browserSearchResults1)
                        {
                            string strA = browserSearchResults2.folderPath.TrimEnd('/');
                            if (browserSearchResults2.file != null && string.Compare(strA, str2, true) == 0)
                            {
                                foreach (VimApi.FileInfo fileInfo in browserSearchResults2.file)
                                {
                                    if (!dictionary.ContainsKey(fileInfo.path))
                                    {
                                        dictionary.Add(fileInfo.path, new VmdkFileInfo(fileInfo.path, browserSearchResults2.folderPath, (ulong)fileInfo.fileSize));
                                        if (dictionary[fileInfo.path].Name != fileName)
                                        {
                                            dictionary.Remove(fileInfo.path);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(dictionary);
        }
示例#5
0
 public void CreateDirectory(string folder)
 {
     this.VcService.Service.MakeDirectory(this.VcService.FileManager, VCService.GetVolumeName(this.Name) + folder, this.GetDatacenterAndProperties().ManagedObject, true, true);
 }
示例#6
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
                };
                Task              task   = new Task(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);
        }
示例#7
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());
        }