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


C# Win32Exception.ToString方法代码示例

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


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

示例1: Run

        protected override void Run()
        {
            SafeToExit = false;
            Description = Messages.ACTION_EXPORT_DESCRIPTION_IN_PROGRESS;

            RelatedTask = XenAPI.Task.create(Session,
                string.Format(Messages.ACTION_EXPORT_TASK_NAME, VM.Name),
                string.Format(Messages.ACTION_EXPORT_TASK_DESCRIPTION, VM.Name));

            UriBuilder uriBuilder = new UriBuilder(this.Session.Url);
            uriBuilder.Path = "export";
            uriBuilder.Query = string.Format("session_id={0}&uuid={1}&task_id={2}",
                Uri.EscapeDataString(this.Session.uuid),
                Uri.EscapeDataString(this.VM.uuid),
                Uri.EscapeDataString(this.RelatedTask.opaque_ref));

            log.DebugFormat("Exporting {0} from {1} to {2}", VM.Name, uriBuilder.ToString(), _filename);

            // The DownloadFile call will block, so we need a separate thread to poll for task status.
            Thread taskThread = new Thread((ThreadStart)progressPoll);
            taskThread.Name = "Progress polling thread for ExportVmAction for " + VM.Name.Ellipsise(20);
            taskThread.IsBackground = true;
            taskThread.Start();

            // Create the file with a temporary name till it is fully downloaded
            String tmpFile = _filename + ".tmp";
            try
            {
                HttpGet(tmpFile, uriBuilder.Uri);
            }
            catch (Exception e)
            {
                if (XenAPI.Task.get_status(this.Session, this.RelatedTask.opaque_ref) == XenAPI.task_status_type.pending
                    && XenAPI.Task.get_progress(this.Session, this.RelatedTask.opaque_ref) == 0)
                {
                    // If task is pending and has zero progress, it probably hasn't been started,
                    // which probably means there was an exception in the GUI code before the
                    // action got going. Kill the task so that we don't block forever on
                    // taskThread.Join(). Brought to light by CA-11100.
                    XenAPI.Task.destroy(this.Session, this.RelatedTask.opaque_ref);
                }
                // Test for null: don't overwrite a previous exception
                if (_exception == null)
                    _exception = e;
            }

            taskThread.Join();

            using (FileStream fs = new FileStream(tmpFile, FileMode.Append))
            {
                // Flush written data to disk
                if (!Win32.FlushFileBuffers(fs.SafeFileHandle))
                {
                    Win32Exception exn = new Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
                    log.ErrorFormat("FlushFileBuffers failed in ExportVmAction.\nNativeErrorCode={0}\nMessage={1}\nToString={2}",
                        exn.NativeErrorCode, exn.Message, exn.ToString());
                }
            }

            if (verify && _exception == null)
            {
                long read = 0;
                int i = 0;
                long filesize = new FileInfo(tmpFile).Length / 50; //Div by 50 to save doing the * 50 in the callback

                Export.verifyCallback callback = new Export.verifyCallback(delegate(uint size)
                    {
                        read += size;
                        i++;

                        //divide number of updates by 10, so as not to spend all out time redrawing the control
                        //but try and send an update every second to keep the timer ticking
                        if (i > 10)
                        {
                            PercentComplete = 50 + (int)(read / filesize);
                            i = 0;
                        }
                    });

                try
                {
                    using (FileStream fs = new FileStream(tmpFile, FileMode.Open, FileAccess.Read))
                    {
                        log.DebugFormat("Verifying export of {0} in {1}", VM.Name, _filename);
                        this.Description = Messages.ACTION_EXPORT_VERIFY;

                        export = new Export();
                        export.verify(fs, null, (Export.cancellingCallback)delegate() { return Cancelling; }, callback);
                    }
                }
                catch (Exception e)
                {
                    if (_exception == null)
                        _exception = e;
                }
            }

            if (Cancelling || _exception is CancelledException)
            {
                log.InfoFormat("Export of VM {0} cancelled", VM.Name);
//.........这里部分代码省略.........
开发者ID:ChrisH4rding,项目名称:xenadmin,代码行数:101,代码来源:ExportVmAction.cs

示例2: RemoveVPrinter

        public void RemoveVPrinter(string printerName)
        {
            var printerProps = PrinterProps.getProps(printerName);

            //for removal we try to go ahead even if there are some failures

            //5 - Configure Virtual Port
            removeVirtualPort(printerProps._monitorName, printerProps.portName);
            _logHelper.Log("removeVirtualPort Completed");

            //4 - Add Printer
            try
            {
                var printerDefaults = new PrinterDefaults
                {
                    DesiredAccess = PrinterAccess.PrinterAllAccess,  //0x000F000C,//PRINTER_ALL_ACCESS
                    pDataType = IntPtr.Zero,
                    pDevMode = IntPtr.Zero
                };
                IntPtr printerHandle;
                if (!OpenPrinter(printerName, out printerHandle, ref printerDefaults))
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                _logHelper.Log("OpenPrinter Completed");

                try
                {
                    if (!DeletePrinter(printerHandle))
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    _logHelper.Log("DeletePrinter Completed");
                }
                finally
                {
                    if (IntPtr.Zero != printerHandle)
                        ClosePrinter(printerHandle);
                }
            }
            catch (Exception ex)
            {
                _logHelper.Log("Failed to renove printer : " + ex.Message);
            }

            //3 - Add Printer Driver
            if (DeletePrinterDriver(null, null, printerProps.driverName) == 0)
            {
                var ex = new Win32Exception(Marshal.GetLastWin32Error());
                _logHelper.Log("ERROR in custom action AddDeletePrinterPort : " + ex.ToString());
                //
            }
            _logHelper.Log("DeletePrinterDriver Completed");

            //2 - Add Printer Port
            try
            {
                AddDeletePrinterPort(printerProps.portName, printerProps._monitorName, true);
                _logHelper.Log("AddDeletePrinterPort Completed");
            }
            catch (Exception ex)
            {
                _logHelper.Log("ERROR in custom action AddDeletePrinterPort : " + ex.ToString());
            }

            //1 - Add Printer Monitor
            RemovePrinterMonitor(printerProps._monitorName);
            _logHelper.Log("RemovePrinterMonitor Completed");

            //6 - Restart Spool Service
            _logHelper.Log("Restarting Spool Service");
            GenericResult restartSpoolResult = RestartSpoolService();
            if (restartSpoolResult.Success == false)
                throw restartSpoolResult.Exception;
        }
开发者ID:shreedee,项目名称:EVOPrinter,代码行数:71,代码来源:SpoolerHelper.cs


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