internal ObjectQueryResponse QueryObjects(string queryString, RNObject[] objectTemplates, int pageSize)
        {
            bool mustRetry  = false;    // used to determine if we should retry a failed job
            int  retryTimes = 0;        // we don't want to endlessly retry, so we only will retry 3 times

            do
            {
                try
                {
                    QueryResultData[] queryObjects = null;
                    queryObjects = _client.QueryObjects(_clientInfoHeader, queryString, objectTemplates, pageSize);

                    return(new ObjectQueryResponse
                    {
                        QueryObjects = queryObjects,
                        Successful = true,
                        SuccessfulSet = true
                    });
                }
                catch (Exception ex)
                {
                    GlobalContext.Log(string.Format("Failed QueryObjects: Retry {0}: {1}", retryTimes, ex.Message), true);
                    GlobalContext.Log(string.Format("Failed QueryObjects: Retry {0}: {1}{2}{3}", retryTimes, ex.Message, Environment.NewLine, ex.StackTrace), false);

                    if (retryTimes < 3)
                    {
                        // if we haven't retried 3 times then we retry the load again
                        mustRetry = true;
                        retryTimes++;
                    }
                    else
                    {
                        // don't retry for 3rd retry
                        return(new ObjectQueryResponse
                        {
                            QueryObjects = null,
                            Successful = false,
                            SuccessfulSet = true,
                            Details = ex.Message
                        });
                    }
                }
                GlobalContext.Log(string.Format("QueryObjects Must Retry {0}", mustRetry), false);
            } while (mustRetry);
            GlobalContext.Log("QueryObjects End: This code should never be hit.", false);
            return(null);        // this code should never be hit
        }
        /// <summary>
        /// Return  the results as a set of objects
        /// </summary>
        /// <param name="query"></param>
        /// <param name="objectTemplate"></param>
        /// <returns></returns>
        public RNObject[] GetRNDataObject(string query, GenericObject objectTemplate)
        {
            RNObject[]        rnDataObject     = null;
            QueryResultData[] data             = null;
            ClientInfoHeader  clientInfoHeader = new ClientInfoHeader {
                AppID = "Get RN Object"
            };

            try
            {
                data = _rightNowClient.QueryObjects(clientInfoHeader, query, new RNObject[] { objectTemplate }, 1000);
                if (data != null)
                {
                    return(data[0].RNObjectsResult);
                }
            }
            catch (Exception ex)
            {
                //  WorkspaceAddIn.InfoLog("Exception in GetRNDataObject: " + ex.Message);
            }
            return(rnDataObject);
        }
Beispiel #3
0
        private RNObject lookupExtension()
        {
            GenericObject generic = new GenericObject();
            RNObjectType  rnObj   = new RNObjectType();

            rnObj.Namespace    = "SvcVentures";
            rnObj.TypeName     = "scProductExtension";
            generic.ObjectType = rnObj;

            string query = "SELECT SvcVentures.scProductExtension FROM SvcVentures.scProductExtension where Signature like '" + this.extSignature + "';";

            RNObject[] objectTemplate = new RNObject[] { generic };
            RNObject[] result         = null;
            try
            {
                QueryResultData[] queryObjects = client.QueryObjects(
                    new ClientInfoHeader {
                    AppID = "SCLog"
                },
                    query,
                    objectTemplate, 10000);
                result = queryObjects[0].RNObjectsResult;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(null);
            }

            if (result != null && result.Length > 0)
            {
                return(result[0]);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        static void GetAllContacts(RightNowSyncPortClient client)
        {
            Contact contactTemplate = new Contact();

            contactTemplate.Phones = new Phone[] { };

            UpdateProcessingOptions options = new UpdateProcessingOptions();

            RNObject[] objectTemplates = new RNObject[] { contactTemplate };
            bool       hasMoreResults  = true;

            int currentOffset = 0;

            do
            {
                var resultTable = client.QueryObjects(s_clientInfoHeader, String.Format("SELECT Contact FROM Contact LIMIT {0} OFFSET {1}", PageSize, currentOffset), objectTemplates, PageSize);

                RNObject[] rnObjects = resultTable[0].RNObjectsResult;

                List <RNObject> updatedObjects = new List <RNObject>();

                foreach (RNObject obj in rnObjects)
                {
                    Contact contact = (Contact)obj;
                    Phone[] phones  = contact.Phones;
                    if (phones != null)
                    {
                        List <Phone> newPhoneNumbers = new List <Phone>();

                        foreach (Phone phone in phones)
                        {
                            var sanitizedNumber = SanitizeNumber(phone.Number);

                            System.Console.WriteLine(contact.Name.Last + " - " + phone.Number + " (" + phone.RawNumber + ") - " + sanitizedNumber);
                            if (sanitizedNumber != phone.Number)
                            {
                                //need to create a new Phone object, if we reuse/update the existing one, the update won't work.
                                var newNumber = new Phone()
                                {
                                    action          = ActionEnum.update,
                                    actionSpecified = true,
                                    Number          = SanitizeNumber(phone.Number),
                                    PhoneType       = phone.PhoneType
                                };
                                newPhoneNumbers.Add(newNumber);
                            }
                        }
                        if (newPhoneNumbers.Count > 0)
                        {
                            updatedObjects.Add(new Contact()
                            {
                                ID     = contact.ID,
                                Phones = newPhoneNumbers.ToArray(),
                            });
                        }
                    }
                }

                if (updatedObjects.Count > 0)
                {
                    client.Update(s_clientInfoHeader, updatedObjects.ToArray(), options);
                }

                hasMoreResults = resultTable[0].Paging.ReturnedCount == PageSize;
                currentOffset  = currentOffset + resultTable[0].Paging.ReturnedCount;

                Console.WriteLine(String.Format("Processed {0} contacts", currentOffset));
            } while (hasMoreResults);
        }