当前位置: 首页>>代码示例>>C#>>正文


C# Session.logout方法代码示例

本文整理汇总了C#中XenAPI.Session.logout方法的典型用法代码示例。如果您正苦于以下问题:C# Session.logout方法的具体用法?C# Session.logout怎么用?C# Session.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XenAPI.Session的用法示例。


在下文中一共展示了Session.logout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: bundleUpload

        public string bundleUpload(IXenConnection connection, Session session, string uploadToken, System.Threading.CancellationToken cancel)
        {
            // Collect the server status report and generate zip file to upload.
            XenServerHealthCheckBugTool bugTool = new XenServerHealthCheckBugTool();
            try
            {
                bugTool.RunBugtool(connection, session);
            }
            catch (Exception e)
            {
                if (session != null)
                    session.logout();
                session = null;
                log.Error(e, e);
                return "";
            }

            string bundleToUpload = bugTool.outputFile;
            if(string.IsNullOrEmpty(bundleToUpload) || !File.Exists(bundleToUpload))
            {
                log.ErrorFormat("Server Status Report is NOT collected");
                return "";
            }

            // Upload the zip file to CIS uploading server.
            string upload_url = Registry.HealthCheckUploadDomainName;
            log.InfoFormat("Upload report to {0}", upload_url);
            XenServerHealthCheckUpload upload = new XenServerHealthCheckUpload(uploadToken, VERBOSITY_LEVEL, upload_url, connection);

            string upload_uuid = "";
            try
            {
                upload_uuid = upload.UploadZip(bundleToUpload, cancel);
            }
            catch (Exception e)
            {
                if (session != null)
                    session.logout();
                session = null;
                log.Error(e, e);
                return "";
            }

            if (File.Exists(bundleToUpload))
                File.Delete(bundleToUpload);

            // Return the uuid of upload.
            if(string.IsNullOrEmpty(upload_uuid))
            {
                // Fail to upload the zip to CIS server.
                log.ErrorFormat("Fail to upload the Server Status Report {0} to CIS server", bundleToUpload);
                return "";
            }

            return upload_uuid;
        }
开发者ID:agimofcarmen,项目名称:xenadmin,代码行数:56,代码来源:XenServerHealthCheckBundleUpload.cs

示例2: runUpload

        public void runUpload(System.Threading.CancellationToken serviceStop)
        {
            DateTime startTime = DateTime.UtcNow;
            string uploadToken = "";
            Session session = new Session(connection.Hostname, 80);
            session.APIVersion = API_Version.LATEST;

            try
            {
                session.login_with_password(connection.Username, connection.Password);
                connection.LoadCache(session);
                var pool = Helpers.GetPoolOfOne(connection);
                if (pool != null)
                {
                    try
                    {
                        string opaqueref = Secret.get_by_uuid(session, pool.HealthCheckSettings.UploadTokenSecretUuid);
                        uploadToken = Secret.get_value(session, opaqueref);
                    }
                    catch (Exception e)
                    {
                        log.Error("Exception getting the upload token from the xapi secret", e);
                        uploadToken = null;
                    }
                }

                if (string.IsNullOrEmpty(uploadToken))
                {
                    if (session != null)
                        session.logout();
                    session = null;
                    log.ErrorFormat("The upload token is not retrieved for {0}", connection.Hostname);
                    updateHealthCheckSettings(false, startTime);
                    server.task = null;
                    ServerListHelper.instance.UpdateServerInfo(server);
                    return;
                }

            }
            catch (Exception e)
            {
                if (session != null)
                    session.logout();
                session = null;
                log.Error(e, e);
                updateHealthCheckSettings(false, startTime);
                server.task = null;
                ServerListHelper.instance.UpdateServerInfo(server);
                return;
            }

            try
            {
                CancellationTokenSource cts = new CancellationTokenSource();
                Func<string> upload = delegate()
                {
                    try
                    {
                        return bundleUpload(connection, session, uploadToken, cts.Token);
                    }
                    catch (OperationCanceledException)
                    {
                        return "";
                    }
                };
                System.Threading.Tasks.Task<string> task = new System.Threading.Tasks.Task<string>(upload);
                task.Start();

                // Check if the task runs to completion before timeout.
                for (int i = 0; i < TIMEOUT; i += INTERVAL)
                {
                    // If the task finishes, set HealthCheckSettings accordingly.
                    if (task.IsCompleted || task.IsCanceled || task.IsFaulted)
                    {
                        if (task.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                        {
                            string upload_uuid = task.Result;
                            if (!string.IsNullOrEmpty(upload_uuid))
                                updateHealthCheckSettings(true, startTime, upload_uuid);
                            else
                                updateHealthCheckSettings(false, startTime);
                        }
                        else
                            updateHealthCheckSettings(false, startTime);

                        server.task = null;
                        ServerListHelper.instance.UpdateServerInfo(server);
                        return;
                    }

                    // If the main thread (XenServerHealthCheckService) stops,
                    // set the cancel token to notify the working task to return.
                    if (serviceStop.IsCancellationRequested)
                    {
                        cts.Cancel();
                        updateHealthCheckSettings(false, startTime);
                        task.Wait();
                        server.task = null;
                        ServerListHelper.instance.UpdateServerInfo(server);
                        return;
//.........这里部分代码省略.........
开发者ID:agimofcarmen,项目名称:xenadmin,代码行数:101,代码来源:XenServerHealthCheckBundleUpload.cs

示例3: updateHealthCheckSettings

        public void updateHealthCheckSettings(bool success, DateTime time, string uploadUuid = "")
        {
            Session session = new Session(connection.Hostname, 80);
            session.login_with_password(connection.Username, connection.Password);
            connection.LoadCache(session);

            // Round-trip format time
            DateTime rtime = DateTime.SpecifyKind(time, DateTimeKind.Utc);
            string stime = HealthCheckSettings.DateTimeToString(rtime);

            // record upload_uuid,
            // release the lock,
            // set the time of LAST_SUCCESSFUL_UPLOAD or LAST_FAILED_UPLOAD
            Dictionary<string, string> config = Pool.get_health_check_config(session, connection.Cache.Pools[0].opaque_ref);
            config[HealthCheckSettings.UPLOAD_LOCK] = "";
            if (success)
            {
                config[HealthCheckSettings.LAST_SUCCESSFUL_UPLOAD] = stime;
                config[HealthCheckSettings.UPLOAD_UUID] = uploadUuid;
                // reset the NEW_UPLOAD_REQUEST field, if the current successful upload was started after the request
                DateTime newUploadRequestTime;
                if (HealthCheckSettings.TryParseStringToDateTime(config[HealthCheckSettings.NEW_UPLOAD_REQUEST], out newUploadRequestTime))
                {
                    if (rtime > newUploadRequestTime)
                        config[HealthCheckSettings.NEW_UPLOAD_REQUEST] = "";
                }
            }
            else
                config[HealthCheckSettings.LAST_FAILED_UPLOAD] = stime;
            Pool.set_health_check_config(session, connection.Cache.Pools[0].opaque_ref, config);

            if (session != null)
                session.logout();
            session = null;
        }
开发者ID:agimofcarmen,项目名称:xenadmin,代码行数:35,代码来源:XenServerHealthCheckBundleUpload.cs

示例4: OnTimer

        public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            log.Info("XenServer Health Check Service start to refresh uploading tasks");

            //We need to check if CIS can be accessed in current enviroment

            List<ServerInfo> servers = ServerListHelper.instance.GetServerList();
            foreach (ServerInfo server in servers)
            {
                if (server.task != null && (!server.task.IsCompleted || !server.task.IsCanceled || !server.task.IsFaulted))
                {
                    continue;
                }

                XenConnection connectionInfo = new XenConnection();
                connectionInfo.Hostname = server.HostName;
                connectionInfo.Username = server.UserName;
                connectionInfo.Password = server.Password;
                log.InfoFormat("Check server {0} with user {1}", connectionInfo.Hostname, connectionInfo.Username);
                Session session = new Session(server.HostName, 80);
                session.APIVersion = API_Version.LATEST;
                try
                {
                    session.login_with_password(server.UserName, server.Password);
                    connectionInfo.LoadCache(session);
                    if (RequestUploadTask.Request(connectionInfo, session) || RequestUploadTask.OnDemandRequest(connectionInfo, session))
                    {
                        // Create a task to collect server status report and upload to CIS server
                        log.InfoFormat("Start to upload server status report for XenServer {0}", connectionInfo.Hostname);

                        XenServerHealthCheckBundleUpload upload = new XenServerHealthCheckBundleUpload(connectionInfo);
                        Action uploadAction = delegate()
                        {
                            upload.runUpload(cts.Token);
                        };
                        System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(uploadAction);
                        task.Start();

                        server.task = task;
                        ServerListHelper.instance.UpdateServerInfo(server);
                    }
                    session.logout();
                    session = null;
                }
                catch (Exception exn)
                {
                    if (session != null)
                        session.logout();
                    log.Error(exn, exn);
                }
            }
        }
开发者ID:jhuscott,项目名称:xenadmin,代码行数:52,代码来源:XenServerHealthCheckService.cs

示例5: OnTimer

        public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            log.Info("XenServer Health Check Service start to refresh uploading tasks");

            //We need to check if CIS can be accessed in current enviroment

            List<ServerInfo> servers = ServerListHelper.instance.GetServerList();
            foreach (ServerInfo server in servers)
            {
                if (server.task != null && (!server.task.IsCompleted || !server.task.IsCanceled || !server.task.IsFaulted))
                {
                    continue;
                }

                bool needReconnect = false;

                log.InfoFormat("Check server {0} with user {1}", server.HostName, server.UserName);

                Session session = new Session(server.HostName, 80);
                session.APIVersion = API_Version.LATEST;
                try
                {
                    session.login_with_password(server.UserName, server.Password, Helper.APIVersionString(API_Version.LATEST), Session.UserAgent);
                }
                catch (Exception exn)
                {
                    if (exn is Failure && ((Failure)exn).ErrorDescription[0] == Failure.HOST_IS_SLAVE)
                    {
                        string masterName = ((Failure)exn).ErrorDescription[1];
                        if (ServerListHelper.instance.UpdateServerCredential(server, masterName))
                        {
                            log.InfoFormat("Refresh credential to master {0} need refresh connection", masterName);
                            server.HostName = masterName;
                            needReconnect = true;
                        }
                        else
                        {
                            log.InfoFormat("Remove credential since it is the slave of master {0}", masterName);
                            if (session != null)
                                session.logout();
                            log.Error(exn, exn);
                            continue;
                        }
                    }
                    else
                    {
                        if (session != null)
                            session.logout();
                        log.Error(exn, exn);
                        continue;
                    }
                }

                try
                {
                    if (needReconnect)
                    {
                        if (session != null)
                            session.logout();
                        log.InfoFormat("Reconnect to master {0}", server.HostName);
                        session = new Session(server.HostName, 80);
                        session.APIVersion = API_Version.LATEST;
                        session.login_with_password(server.UserName, server.Password, Helper.APIVersionString(API_Version.LATEST), Session.UserAgent);
                    }
                    XenConnection connectionInfo = new XenConnection();
                    connectionInfo.Hostname = server.HostName;
                    connectionInfo.Username = server.UserName;
                    connectionInfo.Password = server.Password;
                    connectionInfo.LoadCache(session);
                    if (RequestUploadTask.Request(connectionInfo, session) || RequestUploadTask.OnDemandRequest(connectionInfo, session))
                    {
                        // Create a task to collect server status report and upload to CIS server
                        log.InfoFormat("Start to upload server status report for XenServer {0}", connectionInfo.Hostname);

                        XenServerHealthCheckBundleUpload upload = new XenServerHealthCheckBundleUpload(connectionInfo);
                        Action uploadAction = delegate()
                        {
                            upload.runUpload(cts.Token);
                        };
                        System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(uploadAction);
                        task.Start();

                        server.task = task;
                        ServerListHelper.instance.UpdateServerInfo(server);
                    }
                    session.logout();
                    session = null;
                }
                catch (Exception exn)
                {
                    if (session != null)
                        session.logout();
                    log.Error(exn, exn);
                }
            }
        }
开发者ID:robhoes,项目名称:xenadmin,代码行数:96,代码来源:XenServerHealthCheckService.cs

示例6: updateCallHomeSettings

        public void updateCallHomeSettings(bool success, DateTime time, string uploadUuid = "")
        {
            Session session = new Session(connection.Hostname, 80);
            session.login_with_password(connection.Username, connection.Password);
            connection.LoadCache(session);

            // Round-trip format time
            DateTime rtime = DateTime.SpecifyKind(time, DateTimeKind.Utc);
            string stime = CallHomeSettings.DateTimeToString(rtime);

            // record upload_uuid,
            // release the lock,
            // set the time of LAST_SUCCESSFUL_UPLOAD or LAST_FAILED_UPLOAD
            Dictionary<string, string> config = Pool.get_health_check_config(session, connection.Cache.Pools[0].opaque_ref);
            config[CallHomeSettings.UPLOAD_LOCK] = "";
            if (success)
            {
                config[CallHomeSettings.LAST_SUCCESSFUL_UPLOAD] = stime;
                config[CallHomeSettings.UPLOAD_UUID] = uploadUuid;
            }
            else
                config[CallHomeSettings.LAST_FAILED_UPLOAD] = stime;
            Pool.set_health_check_config(session, connection.Cache.Pools[0].opaque_ref, config);

            if (session != null)
                session.logout();
            session = null;
        }
开发者ID:0dr4c1R,项目名称:xenadmin,代码行数:28,代码来源:XenServerHealthCheckBundleUpload.cs

示例7: Connect

        public bool Connect(string server, int port, string vm_uuid, string username, string password, int width, int height, bool show_border)
        {
            // reinitiailize the VNC Control
            initSubControl(width, height, true, show_border);
            m_vncClient.ErrorOccurred += ConnectionErrorHandler;

            try {
                // Create a new XenAPI session
                m_session = new Session(Session.STANDARD_TIMEOUT, server, port);

                // Authenticate with username and password passed in. 
                // The third parameter tells the server which API version we support.
                m_session.login_with_password(username, password, API_Version.LATEST);
                m_vncPassword = password.ToCharArray();

                // Find the VM in question
                XenRef<VM> vmRef = VM.get_by_uuid(m_session, vm_uuid);
                m_sourceVM = VM.get_record(m_session, vmRef);

                // Check if this VM is PV or HVM
                m_sourceIsPV = (m_sourceVM.PV_bootloader.Length != 0); /* No PV bootloader specified implies HVM */

                // Get the console that uses the RFB (VNC) protocol
                List<XenRef<XenAPI.Console>> consoleRefs = VM.get_consoles(m_session, vmRef);
                XenAPI.Console console = null;
                foreach (XenRef<XenAPI.Console> consoleRef in consoleRefs)
                {
                    console = XenAPI.Console.get_record(m_session, consoleRef);
                    if (console.protocol == console_protocol.rfb)
                        break;
                    console = null;
                }

                if (console != null)
                    //ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectToConsole), new KeyValuePair<VNCGraphicsClient, XenAPI.Console>(m_vncClient, console));
                    ConnectHostedConsole(m_vncClient, console, m_session.uuid);

                // done with this session, log it out
                m_session.logout();
            }
            catch (Exception exn)
            {
                // call the expcetion handler directly
                this.ConnectionErrorHandler(this, exn);
            }
            return m_vncClient.Connected;
        }
开发者ID:ReSalles,项目名称:xenadmin,代码行数:47,代码来源:VNCControl.cs


注:本文中的XenAPI.Session.logout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。