Ejemplo n.º 1
0
        private void registerPluginWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                _service                 = new VimService();
                _service.Url             = vurl;
                _svcRef                  = new ManagedObjectReference();
                _svcRef.type             = "ServiceInstance";
                _svcRef.Value            = "ServiceInstance";
                _service.CookieContainer = new System.Net.CookieContainer();
                CreateServiceRef("ServiceInstance");
                _sic        = _service.RetrieveServiceContent(_svcRef);
                _propCol    = _sic.propertyCollector;
                _rootFolder = _sic.rootFolder;



                string userName = vusername;
                string password = vpassword;

                string companyStr = textBox4.Text;
                string descStr    = textBox3.Text;
                string keyStr     = "com.virtualizeplanet." + textBox2.Text;
                string ext_url    = pluginUrl;
                string adminEmail = "*****@*****.**";
                string versionStr = "4.0";


                Description description = new Description();
                description.label   = textBox3.Text;
                description.summary = descStr;
                ExtensionServerInfo esi = new ExtensionServerInfo();

                esi.url         = ext_url;
                esi.description = description;
                esi.company     = companyStr;
                esi.type        = "com.vmware.vim.viClientScripts"; //do not change;
                esi.adminEmail  = new String[] { adminEmail };
                ExtensionClientInfo eci = new ExtensionClientInfo();

                eci.version     = versionStr;
                eci.description = description;
                eci.company     = companyStr;
                eci.type        = "com.vmware.vim.viClientScripts";
                eci.url         = ext_url;
                Extension ext = new Extension();
                ext.description = description;
                ext.key         = keyStr;
                ext.version     = versionStr;
                ext.subjectName = "blank";
                ext.server      = new ExtensionServerInfo[] { esi };
                ext.client      = new ExtensionClientInfo[] { eci };

                ext.lastHeartbeatTime = DateTime.Now;



                if (_sic.sessionManager != null)
                {
                    _service.Login(_sic.sessionManager, userName, password, null);
                    ManagedObjectReference extMgrMof = _sic.extensionManager;
                    _service.RegisterExtension(extMgrMof, ext);
                }

                MessageBox.Show("Finished", "Completed");
            }
            catch
            {
                MessageBox.Show("Review your settings or plugin already exists");
            }
        }