Beispiel #1
0
        //Subscribes this application to listen for Data event or UI extension event
        private static void SubscribeForEvents(QBSubscriptionType strType, string strData)
        {
            RequestProcessor2Class qbRequestProcessor;

            try
            {
                // Get an instance of the qbXMLRP Request Processor and
                // call OpenConnection if that has not been done already.
                qbRequestProcessor = new RequestProcessor2Class();
                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;
            }
        }
Beispiel #2
0
        //Unsubscribes this application from listening to add/modify/delete custmor event
        private static void UnsubscribeForEvents(QBSubscriptionType strType, bool bSilent)
        {
            RequestProcessor2Class qbRequestProcessor;

            try
            {
                // Get an instance of the qbXMLRP Request Processor and
                // call OpenConnection if that has not been done already.
                qbRequestProcessor = new RequestProcessor2Class();
                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;
        }