コード例 #1
0
        private XcDiagProcessInfo GetXcDiagProcessInfo(string mode)
        {
            XcDiagProcessInfo xcdiagProcessInfo = null;
            string            xcDiagPath, xcDiagOutputPath;

            if (FindXcDiagCommandParameters(out xcDiagPath, out xcDiagOutputPath))
            {
                if (!System.IO.File.Exists(xcDiagPath))
                {
                    log.Error("Unable to find xcdiag with path: \"{0}\"", xcDiagPath);
                }
                else
                {
                    xcdiagProcessInfo = new XcDiagProcessInfo(xcDiagPath, xcDiagOutputPath, mode);
                }
            }

            return(xcdiagProcessInfo);
        }
コード例 #2
0
        private XcDiagProcessInfo GetXcDiagProcessInfo(string mode)
        {
            XcDiagProcessInfo xcdiagProcessInfo = null;
            string xcDiagPath, xcDiagOutputPath;
            if (FindXcDiagCommandParameters(out xcDiagPath, out xcDiagOutputPath))
            {
                if (!System.IO.File.Exists(xcDiagPath))
                {
                    log.Error("Unable to find xcdiag with path: \"{0}\"", xcDiagPath);
                }
                else
                {
                    xcdiagProcessInfo = new XcDiagProcessInfo(xcDiagPath, xcDiagOutputPath, mode);
                }
            }

            return xcdiagProcessInfo;
        }
コード例 #3
0
        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);
        }