示例#1
0
        // This Method return the qbXML for the deleting the event subscribing for this application
        // from QB
        private static string GetSubscriptionDeleteXML(QBSubscriptionType subscriptionType)
        {
            //Create the qbXML request
            XmlDocument requestXMLDoc = new XmlDocument();

            requestXMLDoc.AppendChild(requestXMLDoc.CreateXmlDeclaration("1.0", null, null));
            requestXMLDoc.AppendChild(requestXMLDoc.CreateProcessingInstruction("qbxml", "version=\"5.0\""));
            XmlElement qbXML = requestXMLDoc.CreateElement("QBXML");

            requestXMLDoc.AppendChild(qbXML);

            //subscription Message request
            XmlElement qbXMLMsgsRq = requestXMLDoc.CreateElement("QBXMLSubscriptionMsgsRq");

            qbXML.AppendChild(qbXMLMsgsRq);

            //Data Event Subscription ADD request
            XmlElement qbSubscriptionDelRq = requestXMLDoc.CreateElement("SubscriptionDelRq");

            qbXMLMsgsRq.AppendChild(qbSubscriptionDelRq);

            //Subscription ID
            qbSubscriptionDelRq.AppendChild(requestXMLDoc.CreateElement("SubscriberID")).InnerText = "{8327c7fc-7f05-41ed-a5b4-b6618bb27bf1}";

            //Subscription Type
            qbSubscriptionDelRq.AppendChild(requestXMLDoc.CreateElement("SubscriptionType")).InnerText = subscriptionType.ToString();


            string strRetString = requestXMLDoc.OuterXml;

            LogXmlData(@"C:\Temp\Unsubscribe.xml", strRetString);
            return(strRetString);
        }
示例#2
0
        //Subscribes this application to listen for Data event or UI extension event
        private static void SubscribeForEvents(QBSubscriptionType strType, string strData)
        {
            RequestProcessor2 qbRequestProcessor;

            try
            {
                // Get an instance of the qbXMLRP Request Processor and
                // call OpenConnection if that has not been done already.
                qbRequestProcessor = new RequestProcessor2();
                qbRequestProcessor.OpenConnection("", strAppName);

                StringBuilder strRequest = new StringBuilder();
                switch (strType)
                {
                case QBSubscriptionType.Data:
                    strRequest = new StringBuilder(GetDataEventSubscriptionAddXML());
                    break;

                case QBSubscriptionType.UIExtension:
                    strRequest = new StringBuilder(GetUIExtensionSubscriptionAddXML(strData));
                    break;

                default:
                    return;
                }

                string strResponse = qbRequestProcessor.ProcessSubscription(strRequest.ToString());

                //Parse the XML response to check the status
                XmlDocument outputXMLDoc = new XmlDocument();
                outputXMLDoc.LoadXml(strResponse);
                XmlNodeList qbXMLMsgsRsNodeList = outputXMLDoc.GetElementsByTagName("DataEventSubscriptionAddRs");
                if (qbXMLMsgsRsNodeList.Count == 1)
                {
                    XmlAttributeCollection rsAttributes = qbXMLMsgsRsNodeList.Item(0).Attributes;
                    //get the status Code, info and Severity
                    string retStatusCode     = rsAttributes.GetNamedItem("statusCode").Value;
                    string retStatusSeverity = rsAttributes.GetNamedItem("statusSeverity").Value;
                    string retStatusMessage  = rsAttributes.GetNamedItem("statusMessage").Value;

                    if ((retStatusCode != "0") && (retStatusCode != "3180"))// 3180 : if subscription already subscribed. NOT A NEAT WAY TO DO THIS, NEED TO EXPLORE THIS
                    {
                        Console.WriteLine("Error while subscribing for events\n\terror Code - {0},\n\tSeverity - {1},\n\tError Message - {2}\n", retStatusCode, retStatusSeverity, retStatusMessage);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while registering for QB events - " + ex.Message);
                qbRequestProcessor = null;
                return;
            }
        }
示例#3
0
        //Unsubscribes this application from listening to add/modify/delete custmor event
        private static void UnsubscribeForEvents(QBSubscriptionType strType, bool bSilent)
        {
            RequestProcessor2 qbRequestProcessor;

            try
            {
                // Get an instance of the qbXMLRP Request Processor and
                // call OpenConnection if that has not been done already.
                qbRequestProcessor = new RequestProcessor2();
                qbRequestProcessor.OpenConnection("", strAppName);

                StringBuilder strRequest  = new StringBuilder(GetSubscriptionDeleteXML(strType));
                string        strResponse = qbRequestProcessor.ProcessSubscription(strRequest.ToString());

                //Parse the XML response to check the status
                XmlDocument outputXMLDoc = new XmlDocument();
                outputXMLDoc.LoadXml(strResponse);
                XmlNodeList qbXMLMsgsRsNodeList = outputXMLDoc.GetElementsByTagName("SubscriptionDelRs");

                XmlAttributeCollection rsAttributes = qbXMLMsgsRsNodeList.Item(0).Attributes;
                //get the status Code, info and Severity
                string retStatusCode     = rsAttributes.GetNamedItem("statusCode").Value;
                string retStatusSeverity = rsAttributes.GetNamedItem("statusSeverity").Value;
                string retStatusMessage  = rsAttributes.GetNamedItem("statusMessage").Value;

                if ((retStatusCode != "0") && (!bSilent))
                {
                    Console.WriteLine("Error while unsubscribing from events\n\terror Code - {0},\n\tSeverity - {1},\n\tError Message - {2}\n", retStatusCode, retStatusSeverity, retStatusMessage);
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while unsubscribing from QB events - " + ex.Message);
                qbRequestProcessor = null;
                return;
            }
            return;
        }