Пример #1
0
        /// <summary>
        /// Create a single session XML object from its detail information
        /// </summary>
        public static SessionXml ToSessionXml(Guid id, Guid?computerId, long version, bool deleted,
                                              bool IsComplete, bool IsNew, DateTimeOffset AddedDt, DateTimeOffset UpdatedDt,
                                              string UpdatedUser, string ProductName, string ApplicationName,
                                              string environmentName, string promotionLevelName, string ApplicationVersion,
                                              string ApplicationTypeName, string ApplicationDescription, string Caption, string StatusName,
                                              string TimeZoneCaption, DateTimeOffset StartDt, DateTimeOffset EndDt, int DurationSec,
                                              string AgentVersion, string UserName, string UserDomainName, string HostName,
                                              string DNSDomainName, int MessageCount, int CriticalMessageCount, int ErrorMessageCount,
                                              int WarningMessageCount, int OSPlatformCode, string OSVersion, string OSServicePack,
                                              string OSCultureName, string OSArchitectureName, string OSBootModeName, int OSSuiteMaskCode,
                                              int OSProductTypeCode, string RuntimeVersion, string RuntimeArchitectureName, string CurrentCultureName,
                                              string CurrentUICultureName, int MemoryMB, int Processors, int ProcessorCores, bool UserInteractive,
                                              bool TerminalServer, int ScreenWidth, int ScreenHeight, int ColorDepth, string CommandLine,
                                              bool fileAvailable, int fileSize, IDictionary <string, string> properties)
        {
            SessionXml newObject = ToSessionXml(id, version, deleted);

            SessionDetailXml newDetailObject = new SessionDetailXml();

            newDetailObject.addedDt                = ToDateTimeOffsetXml(AddedDt);
            newDetailObject.agentVersion           = AgentVersion;
            newDetailObject.applicationDescription = ApplicationDescription;
            newDetailObject.applicationName        = ApplicationName;
            newDetailObject.environmentName        = environmentName;
            newDetailObject.promotionLevelName     = promotionLevelName;
            newDetailObject.applicationType        = ToApplicationTypeXml(ApplicationTypeName);
            newDetailObject.applicationVersion     = ApplicationVersion;
            newDetailObject.caption                = Caption;
            newDetailObject.colorDepth             = ColorDepth;
            newDetailObject.commandLine            = CommandLine;
            newDetailObject.computerId             = computerId.HasValue ? computerId.ToString() : null;
            newDetailObject.criticalMessageCount   = CriticalMessageCount;
            newDetailObject.currentCultureName     = CurrentCultureName;
            newDetailObject.currentUiCultureName   = CurrentUICultureName;
            newDetailObject.dnsDomainName          = DNSDomainName;
            newDetailObject.durationSec            = DurationSec;
            newDetailObject.endDt               = ToDateTimeOffsetXml(EndDt);
            newDetailObject.errorMessageCount   = ErrorMessageCount;
            newDetailObject.fileAvailable       = fileAvailable;
            newDetailObject.fileSize            = fileSize;
            newDetailObject.hostName            = HostName;
            newDetailObject.isComplete          = IsComplete;
            newDetailObject.isNew               = IsNew;
            newDetailObject.memoryMb            = MemoryMB;
            newDetailObject.messageCount        = MessageCount;
            newDetailObject.osArchitecture      = ToProcessorArchitectureXml(OSArchitectureName);
            newDetailObject.osBootMode          = ToBootModeXml(OSBootModeName);
            newDetailObject.osCultureName       = OSCultureName;
            newDetailObject.osPlatformCode      = OSPlatformCode;
            newDetailObject.osProductTypeCode   = OSProductTypeCode;
            newDetailObject.osServicePack       = OSServicePack;
            newDetailObject.osSuiteMaskCode     = OSSuiteMaskCode;
            newDetailObject.osVersion           = OSVersion;
            newDetailObject.processorCores      = ProcessorCores;
            newDetailObject.processors          = Processors;
            newDetailObject.productName         = ProductName;
            newDetailObject.runtimeArchitecture = ToProcessorArchitectureXml(RuntimeArchitectureName);
            newDetailObject.runtimeVersion      = RuntimeVersion;
            newDetailObject.screenHeight        = ScreenHeight;
            newDetailObject.screenWidth         = ScreenWidth;
            newDetailObject.startDt             = ToDateTimeOffsetXml(StartDt);
            newDetailObject.status              = ToSessionStatusXml(StatusName);
            newDetailObject.terminalServer      = TerminalServer;
            newDetailObject.timeZoneCaption     = TimeZoneCaption;
            newDetailObject.updatedDt           = ToDateTimeOffsetXml(UpdatedDt);
            newDetailObject.updateUser          = UpdatedUser;
            newDetailObject.userDomainName      = UserDomainName;
            newDetailObject.userInteractive     = UserInteractive;
            newDetailObject.userName            = UserName;
            newDetailObject.warningMessageCount = WarningMessageCount;
            newDetailObject.properties          = ToSessionPropertiesXml(properties);
            newObject.sessionDetail             = newDetailObject;

            return(newObject);
        }
Пример #2
0
        /// <summary>
        /// Converts a session XML object to a byte array without relying on XML Serializer
        /// </summary>
        /// <param name="sessionXml"></param>
        /// <returns></returns>
        public static byte[] SessionXmlToByteArray(SessionXml sessionXml)
        {
            using (MemoryStream outputStream = new MemoryStream(2048))
            {
                using (TextWriter textWriter = new StreamWriter(outputStream, Encoding.UTF8))
                {
                    using (XmlWriter xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings()))
                    {
                        // Write XML using xmlWriter.  This has to be kept precisely in line with the XSD or we fail.
                        xmlWriter.WriteStartElement("SessionXml");

                        WriteXmlAttribute(xmlWriter, "id", sessionXml.id);
                        WriteXmlAttribute(xmlWriter, "version", sessionXml.version);
                        WriteXmlAttribute(xmlWriter, "deleted", sessionXml.deleted);

                        if (sessionXml.isCompleteSpecified)
                        {
                            WriteXmlAttribute(xmlWriter, "isComplete", sessionXml.isComplete);
                        }

                        //start the session detail
                        SessionDetailXml detailXml = sessionXml.sessionDetail;

                        if (detailXml != null)
                        {
                            xmlWriter.WriteStartElement("sessionDetail", "http://www.gibraltarsoftware.com/Gibraltar/Repository.xsd");

                            WriteXmlAttribute(xmlWriter, "productName", detailXml.productName);
                            WriteXmlAttribute(xmlWriter, "applicationName", detailXml.applicationName);
                            WriteXmlAttribute(xmlWriter, "environmentName", detailXml.environmentName);
                            WriteXmlAttribute(xmlWriter, "promotionLevelName", detailXml.promotionLevelName);
                            WriteXmlAttribute(xmlWriter, "applicationVersion", detailXml.applicationVersion);
                            WriteXmlAttribute(xmlWriter, "applicationType", detailXml.applicationType.ToString()); //enums won't auto-convert
                            WriteXmlAttribute(xmlWriter, "applicationDescription", detailXml.applicationDescription);
                            WriteXmlAttribute(xmlWriter, "caption", detailXml.caption);
                            WriteXmlAttribute(xmlWriter, "status", detailXml.status.ToString()); //enums won't auto-convert
                            WriteXmlAttribute(xmlWriter, "timeZoneCaption", detailXml.timeZoneCaption);
                            WriteXmlAttribute(xmlWriter, "durationSec", detailXml.durationSec);
                            WriteXmlAttribute(xmlWriter, "agentVersion", detailXml.agentVersion);
                            WriteXmlAttribute(xmlWriter, "userName", detailXml.userName);
                            WriteXmlAttribute(xmlWriter, "userDomainName", detailXml.userDomainName);
                            WriteXmlAttribute(xmlWriter, "hostName", detailXml.hostName);
                            WriteXmlAttribute(xmlWriter, "dnsDomainName", detailXml.dnsDomainName);
                            WriteXmlAttribute(xmlWriter, "isNew", detailXml.isNew);
                            WriteXmlAttribute(xmlWriter, "isComplete", detailXml.isComplete);
                            WriteXmlAttribute(xmlWriter, "messageCount", detailXml.messageCount);
                            WriteXmlAttribute(xmlWriter, "criticalMessageCount", detailXml.criticalMessageCount);
                            WriteXmlAttribute(xmlWriter, "errorMessageCount", detailXml.errorMessageCount);
                            WriteXmlAttribute(xmlWriter, "warningMessageCount", detailXml.warningMessageCount);
                            WriteXmlAttribute(xmlWriter, "updateUser", detailXml.updateUser);
                            WriteXmlAttribute(xmlWriter, "osPlatformCode", detailXml.osPlatformCode);
                            WriteXmlAttribute(xmlWriter, "osVersion", detailXml.osVersion);
                            WriteXmlAttribute(xmlWriter, "osServicePack", detailXml.osServicePack);
                            WriteXmlAttribute(xmlWriter, "osCultureName", detailXml.osCultureName);
                            WriteXmlAttribute(xmlWriter, "osArchitecture", detailXml.osArchitecture.ToString()); //enums won't auto-convert
                            WriteXmlAttribute(xmlWriter, "osBootMode", detailXml.osBootMode.ToString());         //enums won't auto-convert
                            WriteXmlAttribute(xmlWriter, "osSuiteMaskCode", detailXml.osSuiteMaskCode);
                            WriteXmlAttribute(xmlWriter, "osProductTypeCode", detailXml.osProductTypeCode);
                            WriteXmlAttribute(xmlWriter, "runtimeVersion", detailXml.runtimeVersion);
                            WriteXmlAttribute(xmlWriter, "runtimeArchitecture", detailXml.runtimeArchitecture.ToString()); //enums won't auto-convert
                            WriteXmlAttribute(xmlWriter, "currentCultureName", detailXml.currentCultureName);
                            WriteXmlAttribute(xmlWriter, "currentUiCultureName", detailXml.currentUiCultureName);
                            WriteXmlAttribute(xmlWriter, "memoryMb", detailXml.memoryMb);
                            WriteXmlAttribute(xmlWriter, "processors", detailXml.processors);
                            WriteXmlAttribute(xmlWriter, "processorCores", detailXml.processorCores);
                            WriteXmlAttribute(xmlWriter, "userInteractive", detailXml.userInteractive);
                            WriteXmlAttribute(xmlWriter, "terminalServer", detailXml.terminalServer);
                            WriteXmlAttribute(xmlWriter, "screenWidth", detailXml.screenWidth);
                            WriteXmlAttribute(xmlWriter, "screenHeight", detailXml.screenHeight);
                            WriteXmlAttribute(xmlWriter, "colorDepth", detailXml.colorDepth);
                            WriteXmlAttribute(xmlWriter, "commandLine", detailXml.commandLine);
                            WriteXmlAttribute(xmlWriter, "fileSize", detailXml.fileSize);
                            WriteXmlAttribute(xmlWriter, "fileAvailable", detailXml.fileAvailable);
                            WriteXmlAttribute(xmlWriter, "computerId", detailXml.computerId);

                            //and now the elements
                            DateTimeOffsetXmlToXmlWriter(xmlWriter, "startDt", detailXml.startDt);
                            DateTimeOffsetXmlToXmlWriter(xmlWriter, "endDt", detailXml.endDt);
                            DateTimeOffsetXmlToXmlWriter(xmlWriter, "addedDt", detailXml.addedDt);
                            DateTimeOffsetXmlToXmlWriter(xmlWriter, "updatedDt", detailXml.updatedDt);

                            xmlWriter.WriteEndElement();
                        }

                        xmlWriter.WriteEndElement();

                        xmlWriter.Flush(); // to make sure it writes it all out now.

                        return(outputStream.ToArray());
                    }
                }
            }
        }