コード例 #1
0
        /// <summary>
        /// A method is used to get a xml string from a WOPI Discovery type object. The xml string is used to response the discovery request.
        /// </summary>
        /// <param name="discoveryObject">A parameter represents the WOPI Discovery object which contain the discovery information.</param>
        /// <returns>A parameter represents the xml string which contains the discovery information.</returns>
        public static string GetDiscoveryXmlFromDiscoveryObject(wopidiscovery discoveryObject)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <wopidiscovery>(discoveryObject, "discoveryObject", "GetDiscoveryXmlFromDiscoveryObject");

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(wopidiscovery));
            string        xmlString     = string.Empty;

            MemoryStream memorySteam = null;

            try
            {
                memorySteam = new MemoryStream();
                StreamWriter streamWriter = null;
                try
                {
                    streamWriter = new StreamWriter(memorySteam, Encoding.UTF8);

                    // Remove w3c default namespace prefix in serialize process.
                    XmlSerializerNamespaces nameSpaceInstance = new XmlSerializerNamespaces();
                    nameSpaceInstance.Add(string.Empty, string.Empty);
                    xmlSerializer.Serialize(streamWriter, discoveryObject, nameSpaceInstance);

                    // Read the MemoryStream to output the xml string.
                    memorySteam.Position = 0;
                    using (StreamReader streamReader = new StreamReader(memorySteam))
                    {
                        xmlString = streamReader.ReadToEnd();
                    }
                }
                finally
                {
                    if (streamWriter != null)
                    {
                        streamWriter.Dispose();
                    }
                }
            }
            finally
            {
                if (memorySteam != null)
                {
                    memorySteam.Dispose();
                }
            }

            if (string.IsNullOrEmpty(xmlString))
            {
                throw new InvalidOperationException("Could not get the xml string.");
            }

            // Format the serialized xml string.
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlString);
            return(xmlDoc.OuterXml);
        }
コード例 #2
0
        /// <summary>
        /// This method is used to convert the XML date to the Discovery object.
        /// </summary>
        /// <param name="xmlValue">The value of the xml string.</param>
        /// <returns>The object value which is converted from the xml string.</returns>
        public static wopidiscovery DeserializeXmlToDiscoveryObject(string xmlValue)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(xmlValue, "xmlString", "DeserializeXmlToDiscoveryObject");

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(wopidiscovery));
            wopidiscovery discovery     = null;

            using (StringReader strReader = new StringReader(xmlValue))
            {
                discovery = xmlSerializer.Deserialize(strReader) as wopidiscovery;
                if (null == discovery)
                {
                    throw new ArgumentNullException("discovery", "Could not get the current xml string to the expected Discovery type.");
                }
            }

            return(discovery);
        }
コード例 #3
0
        /// <summary>
        /// A method is used to generate response of a WOPI discovery request. It indicates the WOPI client supports 3 types file extensions: ".txt", ".zip", ".one"
        /// </summary>
        /// <param name="currentTestClientName">A parameter represents the current test client name which is used to construct WOPI client's app name in WOPI discovery response.</param>
        /// <param name="progId">A parameter represents the id of program which is associated with folder level visit in discovery process. This value must be valid for WOPI server.</param>
        /// <returns>A return value represents the response of a WOPI discovery request.</returns>
        public static string GetDiscoveryResponseXmlString(string currentTestClientName, string progId)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(currentTestClientName, "currentTestClientName", "GetDiscoveryResponseXmlString");
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty <string>(progId, "progId", "GetDiscoveryResponseXmlString");

            wopidiscovery wopiDiscoveryInstance = new wopidiscovery();

            // Pass the prog id, so that the WOPI discovery response logic will use the prog id value.
            progIdValue = progId;

            // Add http and https net zone into the wopiDiscovery
            wopiDiscoveryInstance.netzone = GetNetZonesForWopiDiscoveryResponse(currentTestClientName);

            // ProofKey element
            wopiDiscoveryInstance.proofkey          = new ct_proofkey();
            wopiDiscoveryInstance.proofkey.oldvalue = RSACryptoContext.PublicKeyStringOfOld;
            wopiDiscoveryInstance.proofkey.value    = RSACryptoContext.PublicKeyStringOfCurrent;
            string xmlStringOfResponseDiscovery = WOPISerializerHelper.GetDiscoveryXmlFromDiscoveryObject(wopiDiscoveryInstance);

            return(xmlStringOfResponseDiscovery);
        }
コード例 #4
0
        /// <summary>
        /// A method is used to generate response of a WOPI discovery request. It indicates the WOPI client supports 3 types file extensions: ".txt", ".zip", ".one"  
        /// </summary>
        /// <param name="currentTestClientName">A parameter represents the current test client name which is used to construct WOPI client's app name in WOPI discovery response.</param>
        /// <param name="progId">A parameter represents the id of program which is associated with folder level visit in discovery process. This value must be valid for WOPI server.</param>
        /// <returns>A return value represents the response of a WOPI discovery request.</returns>
        public static string GetDiscoveryResponseXmlString(string currentTestClientName, string progId)
        {
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty<string>(currentTestClientName, "currentTestClientName", "GetDiscoveryResponseXmlString");
            DiscoveryProcessHelper.CheckInputParameterNullOrEmpty<string>(progId, "progId", "GetDiscoveryResponseXmlString");

            wopidiscovery wopiDiscoveryInstance = new wopidiscovery();

            // Pass the prog id, so that the WOPI discovery response logic will use the prog id value.
            progIdValue = progId;

            // Add http and https net zone into the wopiDiscovery
            wopiDiscoveryInstance.netzone = GetNetZonesForWopiDiscoveryResponse(currentTestClientName);

            // ProofKey element
            wopiDiscoveryInstance.proofkey = new ct_proofkey();
            wopiDiscoveryInstance.proofkey.oldvalue = RSACryptoContext.PublicKeyStringOfOld;
            wopiDiscoveryInstance.proofkey.value = RSACryptoContext.PublicKeyStringOfCurrent;
            string xmlStringOfResponseDiscovery = WOPISerializerHelper.GetDiscoveryXmlFromDiscoveryObject(wopiDiscoveryInstance);

            return xmlStringOfResponseDiscovery;
        }