Beispiel #1
0
 private void setChildContent(string tag, string value)
 {
     if ((value == null) || (value.Length == 0))
     {
         m_xml.RemoveChild(tag);
     }
     else
     {
         m_xml.UpdateChildContent(tag, value);
     }
 }
        /// <summary>
        /// converte file tsr in formato tsd (RFC 5544)
        /// </summary>
        /// <param name="pathFileTsr">file tsr</param>
        /// <param name="pathFileSign">file firmato</param>
        /// <param name="pathFileTsd">file tsd creato</param>
        /// <param name="lastError">ultimo errore della funzionalità</param>
        /// <returns>true se la funzionalità ha avuto successo</returns>
        public static bool CreaTsd(string pathFileTsr, string pathFileSign, out string pathFileTsd, ref string lastError)
        {
            bool success = false;

            pathFileTsd = null;
            try
            {
                if (Utilities.glob.UnlockStatus == 0)
                {
                    lastError = "Licenza bloccata";
                    return(success);
                }


                Chilkat.BinData bdTsr = new Chilkat.BinData();
                success = bdTsr.LoadFile(pathFileTsr);
                if (!success)
                {
                    lastError = "Errore nel caricare il file tsr!";
                    return(success);
                }

                // Carico il tsr in un oggetto ASN.1
                Chilkat.Asn asnTsr = new Chilkat.Asn();
                success = asnTsr.LoadEncoded(bdTsr.GetEncoded("base64"), "base64");
                if (!success)
                {
                    lastError = asnTsr.LastErrorText;
                    return(success);
                }

                // Prendo il timestamp nell'xml
                Chilkat.Xml xmlTsr = new Chilkat.Xml();
                xmlTsr.LoadXml(asnTsr.AsnToXml());

                // Il timestamp inizia in questo modo
                // Rimuovo la prima sub-tree

                //     <?xml version="1.0" encoding="utf-8"?>
                //     <sequence>
                //         <sequence>       <---- Remove this sub-tree.
                //             <int>00</int>
                //             <sequence>
                //                 <utf8>Operation Okay</utf8>
                //             </sequence>
                //         </sequence>
                //         <sequence>
                //             <oid>1.2.840.113549.1.7.2</oid>
                //             <contextSpecific tag="0" constructed="1">
                //             ...

                // Rimuovo la prima sub-tree..
                xmlTsr.RemoveChildByIndex(0);

                // Combiniamo il timestamp e il .p7m in un timestampData
                Chilkat.BinData bdContent = new Chilkat.BinData();
                success = bdContent.LoadFile(pathFileSign);
                if (!success)
                {
                    lastError = "Errore nel caricare il file p7m!";
                    return(success);
                }

                // Costruisco il TimeStampData.
                // Lo costruisco in XML e poi lo converto in ASN.1
                Chilkat.Xml xml = new Chilkat.Xml();
                xml.Tag = "sequence";
                xml.UpdateChildContent("oid", "1.2.840.113549.1.9.16.1.31");
                xml.UpdateAttrAt("contextSpecific", true, "tag", "0");
                xml.UpdateAttrAt("contextSpecific", true, "constructed", "1");
                xml.UpdateChildContent("contextSpecific|sequence|int", "01");
                xml.UpdateChildContent("contextSpecific|sequence|octets", bdContent.GetEncoded("base64"));
                xml.UpdateAttrAt("contextSpecific|sequence|contextSpecific", true, "tag", "0");
                xml.UpdateAttrAt("contextSpecific|sequence|contextSpecific", true, "constructed", "1");

                Chilkat.Xml xContext = xml.GetChildWithTag("contextSpecific|sequence|contextSpecific");
                xContext.AddChildTree(xmlTsr);

                // Converto il file XML in ASN.1
                Chilkat.Asn tsd = new Chilkat.Asn();
                tsd.LoadAsnXml(xml.GetXml());

                // scrivo il timestamped
                success = tsd.WriteBinaryDer(pathFileTsd);
            }
            catch
            {
                throw;
            }

            return(success);
        }
Beispiel #3
0
        // Convert method XML to its Async variant so that we can use the normal code generation methods..
        static private void convertMethodToAsync(Chilkat.Xml xml)
        {
            //<method cpp="1" dn="1" ax="1" events="1" name="QuickGetObj" axId="221">
            //    <gType>HttpResponse</gType>
            //    <cppType>CkHttpResponse *</cppType>

            string returnType = xml.GetChildContent("gType");
            // Is this an object?  If so, we'll add a link to the async_returnObject example
            int returnGt = ChilkatTypes.genericToGt(returnType);


            xml.UpdateChildContent("gType", "Task");
            xml.UpdateChildContent("cppType", "CkTask *");
            xml.RemoveAttribute("status");      // It returns a Task object, not a status bool..
            xml.RemoveAttribute("outArgName");  // If this method had an output arg, the async does not...

            int axId = xml.GetAttrValueInt("axId");

            axId += 500;
            xml.UpdateAttributeInt("axId", axId);

            string origMethodName = xml.GetAttrValue("name");

            xml.UpdateAttribute("name", origMethodName + "Async");

            xml.UpdateChildContent("descrip", "Creates an asynchronous task to call the " + origMethodName +
                                   " method with the arguments provided.  (Async methods are available starting in Chilkat v9.5.0.52.)");

            xml.RemoveChild("links");

            //bool bAlreadyHasAsyncExamples = false;

            // Check to see if this method already has async examples.
            // If so, when we leave it alone.
            // Otherwise, we add the default example..
            //RefdocLinks rdLinks = new RefdocLinks();
            // Chilkat.Xml xLinks2 = xml.FindChild("links2");
            //if (xLinks2 != null)
            //    {
            //    int numChildren = xLinks2.NumChildren;
            //    for (int i = 0; i < numChildren; i++)
            //        {
            //        Chilkat.Xml xLink = xLinks2.GetChild(i);
            //        if (xLink.HasAttrWithValue("async", "1"))
            //            {
            //            //bAlreadyHasAsyncExamples = true;
            //            break;
            //            }
            //        }
            //    }

            //if (!bAlreadyHasAsyncExamples)
            //    {
            //    xml.RemoveChild("links2");

            // Add to the links, because these standard links will be placed in the superscript link area..
            Chilkat.Xml xmlLinks2 = xml.FindChild("links2");
            if (xmlLinks2 == null)
            {
                xmlLinks2 = xml.NewChild("links2", "");
            }

            Chilkat.Xml xmlLink;

            xmlLink = xmlLinks2.NewChild("link", "");
            xmlLink.AddAttribute("lang", "activex");
            xmlLink.AddAttribute("linkType", "external");
            xmlLink.AddAttribute("async", "1");
            xmlLink.AddAttribute("superscriptAsync", "1");
            xmlLink.NewChild2("text", "VB6 Programs MUST Call FinalizeThreadPool Just Before Exiting");
            xmlLink.NewChild2("url", "https://www.example-code.com/vb6/async_finalize_thread_pool_on_exit.asp");

            xmlLink = xmlLinks2.NewChild("link", "");
            xmlLink.AddAttribute("lang", "nodejs");
            xmlLink.AddAttribute("linkType", "external");
            xmlLink.AddAttribute("async", "1");
            xmlLink.AddAttribute("superscriptAsync", "1");
            xmlLink.NewChild2("text", "How to Run a Node.js Asynchronous Task");
            xmlLink.NewChild2("url", "http://www.cknotes.com/asynchronous-chilkat-methods-in-node-js/");

            xmlLink = xmlLinks2.NewChild("link", "");
            xmlLink.AddAttribute("lang", "activex");
            xmlLink.AddAttribute("linkType", "external");
            xmlLink.AddAttribute("async", "1");
            xmlLink.AddAttribute("superscriptAsync", "1");
            xmlLink.NewChild2("text", "Asynchronous Methods in VB6 - Be Very Careful with Callbacks");
            xmlLink.NewChild2("url", "http://www.chilkatforum.com/questions/10870/asynchronous-methods-in-vb6-be-very-careful-with-callbacks");

            xmlLink = xmlLinks2.NewChild("link", "");
            xmlLink.AddAttribute("skiplang", "nodejs");
            xmlLink.AddAttribute("async", "1");
            xmlLink.AddAttribute("superscriptAsync", "1");
            xmlLink.AddAttribute("linkType", "example");
            xmlLink.NewChild2("text", "How to Run an Asynchronous Task");
            xmlLink.NewChild2("url", "async_task.asp");

            if (returnGt == ChilkatTypes.GT_OBJECT)
            {
                xmlLink = xmlLinks2.NewChild("link", "");
                xmlLink.AddAttribute("skiplang", "nodejs");
                xmlLink.AddAttribute("async", "1");
                xmlLink.AddAttribute("superscriptAsync", "1");
                xmlLink.AddAttribute("linkType", "example");
                xmlLink.NewChild2("text", "How to Return an Object from an Async Task");
                xmlLink.NewChild2("url", "async_returnObject.asp");
            }
            //}


            return;
        }