static private Udbus.Core.ServiceConnectionParams TryServiceConnectionParams(Udbus.v4v.v4vConnection connection, Udbus.Core.Logging.ILog log) { Udbus.Core.ServiceConnectionParams result = null; try { Udbus.Core.ServiceConnectionParams create = new Udbus.Core.ServiceConnectionParams(connection); result = create; } catch (Udbus.Serialization.Exceptions.UdbusAuthorisationException authex) { log.Exception("Authorisation Error creating ServiceConnectionParams. {0}", authex); } catch (Exception ex) { log.Exception("Error creating ServiceConnectionParams. {0}", ex); } return(result); }
static private Udbus.v4v.v4vConnection TryV4VConnection(Udbus.Serialization.UdbusDelegates.D_io_debug io_debug, Udbus.Core.Logging.ILog log) { Udbus.v4v.v4vConnection result = null; try { Udbus.v4v.v4vConnection create = new Udbus.v4v.v4vConnection(io_debug); result = create; } catch (Udbus.Serialization.Exceptions.TransportFailureException transportEx) { log.Exception("Failed to create V4V transport. {0}", transportEx); } catch (Exception ex) { log.Exception("Error creating V4V transport. {0}", ex); } return(result); }
static private bool SetRegistryValue(Microsoft.Win32.RegistryKey key, string name, string value, Udbus.Core.Logging.ILog log) { bool result = false; try { key.SetValue(name, value); result = true; } catch (System.ArgumentNullException argnullEx) { if (log != null) { log.Exception("Failed to set registry key (argument null) \"{0}\\{1}\" to \"{2}\". {3}", key.Name, name, value, argnullEx); } } catch (System.ArgumentException argEx) { if (log != null) { log.Exception("Failed to set registry key (argument exception) \"{0}\\{1}\" to \"{2}\". {3}", key.Name, name, value, argEx); } } catch (System.ObjectDisposedException objdispEx) { if (log != null) { log.Exception("Failed to set registry key (object disposed) \"{0}\\{1}\" to \"{2}\". {3}", key.Name, name, value, objdispEx); } } catch (System.UnauthorizedAccessException unauthEx) { if (log != null) { log.Exception("Failed to set registry key (unauthorised) \"{0}\\{1}\" to \"{2}\". {3}", key.Name, name, value, unauthEx); } } catch (System.Security.SecurityException secEx) { if (log != null) { log.Exception("Failed to set registry key (security exception) \"{0}\\{1}\" to \"{2}\". {3}", key.Name, name, value, secEx); } } catch (System.IO.IOException ioEx) { if (log != null) { log.Exception("Failed to set registry key (io exception) \"{0}\\{1}\" to \"{2}\". {3}", key.Name, name, value, ioEx); } } return(result); }
internal bool Run(string uuid, string mode) { bool run = false; XcDiagProcessInfo xcdiagProcessInfo = GetXcDiagProcessInfo(mode); if (xcdiagProcessInfo != null) // If got xcdiag process info { this.log.Info("Received xcdiag request"); xcdiagProcessInfo.processStartInfo.CreateNoWindow = true; xcdiagProcessInfo.processStartInfo.ErrorDialog = false; xcdiagProcessInfo.processStartInfo.RedirectStandardError = true; xcdiagProcessInfo.processStartInfo.RedirectStandardOutput = true; xcdiagProcessInfo.processStartInfo.UseShellExecute = false; xcdiagProcessInfo.processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; System.Diagnostics.Process xcdiagProcess = null; try { xcdiagProcess = System.Diagnostics.Process.Start(xcdiagProcessInfo.processStartInfo); if (xcdiagProcess == null) { log.Info("xcdiag process already running in: \"{0}\"", xcdiagProcessInfo.processStartInfo.FileName); } } catch (System.IO.FileNotFoundException filenotfoundEx) { log.Exception("Cannot launch xcdiag (file not found)", filenotfoundEx); } catch (System.ObjectDisposedException objdisposedEx) { log.Exception("Cannot launch xcdiag (object disposed)", objdisposedEx); } catch (System.InvalidOperationException invalidopEx) { log.Exception("Cannot launch xcdiag (invalid operation)", invalidopEx); } catch (System.ComponentModel.Win32Exception win32Ex) { log.Exception("Cannot launch xcdiag (win32 error)", win32Ex); } catch (System.Exception ex) { log.Exception("Cannot launch xcdiag", ex); } if (xcdiagProcess != null) // If launched xcdiag { // Tends to block until process finishes. string xcdiagError = xcdiagProcess.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(xcdiagError)) { log.Error("xcdiag produced error output: {0}", xcdiagError); } xcdiagProcess.WaitForExit(); // Oooooh. if (xcdiagProcess.ExitCode != 0) // If xcdiag reported an error { log.Error("xcdiag exited with error code '{0}'", xcdiagProcess.ExitCode); } // Ends if xcdiag reported an error else // else xcdiag ran ok { System.Text.StringBuilder dataBuffer = null; // Make a big ol' string containing the data, encoding each byte as 2-digit ASCII hex. #if MEMORYMAPFILE_SUPPORTED using (System.IO.MemoryMappedFiles.MemoryMappedFile memmapXcDiag = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(xcdiagProcessInfo.xcDiagOutputPath)) #else // !MEMORYMAPFILE_SUPPORTED //// Create a memory mapped view of the zip file //hFile = CreateFileA(szXcDiagOut, // GENERIC_READ | GENERIC_WRITE, // 0, // NULL, // OPEN_EXISTING, // FILE_ATTRIBUTE_NORMAL, // NULL); using (Microsoft.Win32.SafeHandles.SafeFileHandle mapHandle = wcf.Native.FileFunctions.CreateFile(xcdiagProcessInfo.xcDiagOutputPath , global::XenClientGuestService.Native.EFileAccess.FILE_GENERIC_READ | global::XenClientGuestService.Native.EFileAccess.FILE_GENERIC_WRITE , System.IO.FileShare.None , IntPtr.Zero , System.IO.FileMode.Open , System.IO.FileAttributes.Normal , IntPtr.Zero)) #endif // MEMORYMAPFILE_SUPPORTED { // Finish creating the native mapping, and then work out how to read bytes... #if MEMORYMAPFILE_SUPPORTED using (System.IO.MemoryMappedFiles.MemoryMappedViewStream streamXcDiag = memmapXcDiag.CreateViewStream()) #else // !MEMORYMAPFILE_SUPPORTED long fileSize = new System.IO.FileInfo(xcdiagProcessInfo.xcDiagOutputPath).Length; //hMapFile = CreateFileMapping( // hFile, // current file handle // NULL, // default security // PAGE_READWRITE, // read/write permission // 0, // size of mapping object, high // filesize, // size of mapping object, low // NULL); // name of mapping object using (Microsoft.Win32.SafeHandles.SafeFileHandle xcDiagOutputMappingHandle = wcf.Native.MappingFunctions.CreateFileMapping(mapHandle , IntPtr.Zero , global::XenClientGuestService.Native.FileMapProtection.PageReadWrite , 0 , checked ((uint)fileSize) , null)) #endif // MEMORYMAPFILE_SUPPORTED { #if MEMORYMAPFILE_SUPPORTED long fileSize = streamXcDiag.Length; #else // !MEMORYMAPFILE_SUPPORTED //// Map the view //lpMapAddress = (unsigned char *)MapViewOfFile( // hMapFile, // handle to mapping object // FILE_MAP_ALL_ACCESS, // read/write // 0, // high-order 32 bits of file offset // 0, // low-order 32 bits of file offset // filesize); // number of bytes to map using (wcf.Native.FileMappingViewHandle mappingViewHandler = wcf.Native.MappingFunctions.MapViewOfFile(xcDiagOutputMappingHandle , global::XenClientGuestService.Native.FileMapAccess.FileMapAllAccess , 0 , 0 , (checked ((UInt32)fileSize)))) #endif // !MEMORYMAPFILE_SUPPORTED { #if MEMORYMAPFILE_SUPPORTED System.IO.BinaryReader reader = new System.IO.BinaryReader(streamXcDiag); #else // !MEMORYMAPFILE_SUPPORTED wcf.Native.FileMappingViewHandle.ViewReader reader = mappingViewHandler.CreateViewReader(); #endif // !MEMORYMAPFILE_SUPPORTED int resultSize = checked ((int)(fileSize * 2)); dataBuffer = new StringBuilder(resultSize, resultSize); for (int byteIter = 0; byteIter < fileSize; ++byteIter) { byte b = reader.ReadByte(); dataBuffer.Append(b.ToString("x2")); } // Ends loop over bytes } // Ends using map view handle } // Ends using Memory Map view } // Ends using Memory Map file string data = dataBuffer.ToString(); byte[] stringBytes = System.Text.Encoding.Default.GetBytes(data); byte[] asciiBytes = System.Text.ASCIIEncoding.Convert(Encoding.Default, Encoding.ASCII, stringBytes); data = System.Text.Encoding.ASCII.GetString(asciiBytes); Gather(uuid, data); } // Ends else xcdiag ran ok } // Ends if launched xcdiag } // Ends if got xcdiag process info return(run); }