/********************/


        public UpdateResponse UpdateObject <T>(T obj, long uniqueId) where T : class, new()
        {
            UpdateResponse updateResponse = null;

            Logger.Logger.Log.Debug(string.Format("Update : {0}", uniqueId));

            try
            {
                Type objType      = typeof(T);
                var  objAttribute = objType.GetCustomAttributes(typeof(RightNowCustomObjectAttribute), true).FirstOrDefault() as RightNowCustomObjectAttribute;
                if (objAttribute == null)
                {
                    throw new InvalidOperationException("The type provided is not a RightNow custom object type. Please use the RightNowObjectAttribute to associate the proper metadata with the type");
                }

                GenericObject genericObject = new GenericObject();
                RNObjectType  rnObjType     = new RNObjectType()
                {
                    Namespace = objAttribute.PackageName, TypeName = objAttribute.ObjectName
                };
                genericObject.ObjectType = rnObjType;

                List <GenericField> genericFields = new List <GenericField>();
                PropertyInfo[]      properties    = objType.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    RightNowCustomObjectFieldAttribute attribute = property.GetCustomAttributes(typeof(RightNowCustomObjectFieldAttribute), true).FirstOrDefault() as RightNowCustomObjectFieldAttribute;
                    if (attribute != null && attribute.CanUpdate)
                    {
                        var propValue = property.GetValue(obj, null);
                        //if (!string.IsNullOrWhiteSpace(propValue.ToString())) && !string.IsNullOrWhiteSpace(propValue.ToString())
                        if (propValue != null && !string.IsNullOrWhiteSpace(propValue.ToString()))
                        {
                            genericFields.Add(createGenericField(attribute, propValue));
                        }
                    }
                }

                genericObject.GenericFields = genericFields.ToArray();
                ID autoID = new ID();
                autoID.id          = uniqueId;
                autoID.idSpecified = true;
                genericObject.ID   = autoID;

                UpdateProcessingOptions options = new UpdateProcessingOptions();
                options.SuppressExternalEvents = false;
                options.SuppressRules          = false;
                UpdateRequest updateRequest = new UpdateRequest(getClientInfoHeader(), new RNObject[] { genericObject }, options);
                updateResponse = this.getChannel().Update(updateRequest);
            }
            catch (Exception ex)
            {
                Logger.Logger.Log.Error("RightNowObject:", ex);
            }
            return(updateResponse);
        }
        public void updateObject(RNObject[] objects)
        {
            //Create the update processiong options
            UpdateProcessingOptions options = new UpdateProcessingOptions();
            options.SuppressExternalEvents = false;
            options.SuppressRules = false;


            //Invoke the Update operation
            _rnowClient.Update(this._rnowClientInfoHeader, objects, options);
        }
Esempio n. 3
0
        public void updateObject(RNObject[] objects)
        {
            //Create the update processiong options
            UpdateProcessingOptions options = new UpdateProcessingOptions();

            options.SuppressExternalEvents = false;
            options.SuppressRules          = false;


            //Invoke the Update operation
            _rnowClient.Update(this._rnowClientInfoHeader, objects, options);
        }
Esempio n. 4
0
        private void updateIncidents(int incidentContactId)
        {
            // query incidents ids with the _socialChannelAccountId
            String query = "select I.ID from Incident I where I.CustomFields.Accelerator.srm_social_channel_account_id=" + _socialChannelAccountId;

            String[] rowData = null;

            rowData = ConfigurationSetting.rnSrv.queryData(query);

            if (rowData.Length == 0)
            {
                return;
            }

            RNObject[] updateIncidents = new RNObject[rowData.Length];
            int        i = 0;
            UpdateProcessingOptions updateProcessingOptions = new UpdateProcessingOptions();

            updateProcessingOptions.SuppressExternalEvents = false;
            updateProcessingOptions.SuppressRules          = false;
            foreach (String incidentIdString in rowData)
            {
                Incident incidentToUpdate   = new Incident();
                ID       incidentToUpdateId = new ID();
                incidentToUpdateId.id          = Convert.ToInt32(incidentIdString);
                incidentToUpdateId.idSpecified = true;

                incidentToUpdate.ID = incidentToUpdateId;

                NamedID contactIdNamedID =
                    new NamedID
                {
                    ID = new ID
                    {
                        id          = incidentContactId,
                        idSpecified = true
                    }
                };

                incidentToUpdate.PrimaryContact         = new IncidentContact();
                incidentToUpdate.PrimaryContact.Contact = contactIdNamedID;
                updateIncidents[i] = incidentToUpdate;
                i++;
                ConfigurationSetting.logWrap.DebugLog(logMessage: String.Format(Properties.Resources.UpdateIncidentMessage, incidentToUpdateId.id, incidentContactId));
            }

            ClientInfoHeader clientInfoHeader = new ClientInfoHeader();

            clientInfoHeader.AppID = "Update incidents";

            ConfigurationSetting.client.Update(clientInfoHeader, updateIncidents, updateProcessingOptions);
        }
Esempio n. 5
0
        /// <summary>
        /// To create Update Message for Batch
        /// </summary>
        /// <param name="coList"></param>
        /// <returns></returns>
        private UpdateMsg getUpdateMsg(List <RNObject> coList)
        {
            UpdateMsg updateMsg = new UpdateMsg();
            UpdateProcessingOptions updateProcessingOptions = new UpdateProcessingOptions();

            updateProcessingOptions.SuppressExternalEvents = true;
            updateProcessingOptions.SuppressRules          = true;
            updateMsg.ProcessingOptions = updateProcessingOptions;

            updateMsg.RNObjects = coList.ToArray();

            return(updateMsg);
        }
        internal void UpdateStaffAccountInformation(StaffAccountInfo staffActInfo)
        {
            try
            {
                Logger.Logger.Log.Debug("RightNowObjectProvider: Get User Account Details");
                Account acobj = new Account();
                acobj.ID = new ID()
                {
                    id = Global.Context.AccountId, idSpecified = true
                };
                GenericObject genericObject      = new GenericObject();
                GenericObject genericObjectFinal = new GenericObject();

                RNObjectType rnobj = new RNObjectType();

                List <GenericField> genericFields = new List <GenericField>();
                List <GenericField> genericField  = new List <GenericField>();
                //Convert.ToInt64(AgentID))
                staffActInfo.Password = string.IsNullOrEmpty(staffActInfo.Password) ? " " : staffActInfo.Password;
                genericFields.Add(createGenericField("AgentID", ItemsChoiceType.StringValue, staffActInfo.AgentID.ToString()));
                genericFields.Add(createGenericField("password", ItemsChoiceType.StringValue, staffActInfo.Password));
                genericFields.Add(createGenericField("Extension", ItemsChoiceType.StringValue, staffActInfo.Extension.ToString()));
                genericFields.Add(createGenericField("Queue", ItemsChoiceType.IntegerValue, staffActInfo.Queue));

                genericObject.GenericFields = genericFields.ToArray();
                rnobj.TypeName           = "AccountCustomFields";
                genericObject.ObjectType = rnobj;

                genericField.Add(createGenericField("c", ItemsChoiceType.ObjectValue, genericObject));
                genericObjectFinal.GenericFields = genericField.ToArray();
                genericObjectFinal.ObjectType    = new RNObjectType()
                {
                    TypeName = "AccountCustomFieldsc"
                };
                acobj.CustomFields = genericObjectFinal;

                UpdateProcessingOptions cpo = new UpdateProcessingOptions();
                cpo.SuppressExternalEvents = false;
                cpo.SuppressRules          = false;
                UpdateRequest  cre = new UpdateRequest(getClientInfoHeader(), new RNObject[] { acobj }, cpo);
                UpdateResponse res = getChannel().Update(cre);
            }
            catch (Exception ex)
            {
                Logger.Logger.Log.Error("RightNowObjectProvider:", ex);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Updates the latest values of the custome fields into database.
        /// </summary>
        /// <param name="staffAccount"></param>
        /// <returns></returns>
        public bool updateCustomFields(StaffAccount staffAccount)
        {
            try
            {
                Debug("RightNowConnectService - updateCustomFields() - Entry");

                GenericField csFldOOOEnd   = null;
                GenericField csFldOOOStart = null;

                Account account   = new Account();
                ID      accountID = new ID();
                accountID.id          = OutOfOfficeClientAddIn.GlobalContext.AccountId;
                accountID.idSpecified = true;
                account.ID            = accountID;


                // Out of Office Flag
                DataValue dv = new DataValue();
                dv.Items            = new Object[] { staffAccount.OooFlag };
                dv.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.BooleanValue };

                GenericField csFldOOOFlag = new GenericField();
                csFldOOOFlag.name              = CustomField.OooFlag;
                csFldOOOFlag.dataType          = DataTypeEnum.BOOLEAN;
                csFldOOOFlag.dataTypeSpecified = true;
                csFldOOOFlag.DataValue         = dv;

                // Out of Office Start
                csFldOOOStart                   = new GenericField();
                csFldOOOStart.name              = CustomField.OooStart;
                csFldOOOStart.dataType          = DataTypeEnum.DATETIME;
                csFldOOOStart.dataTypeSpecified = true;
                DataValue dvOooStart = null;
                if (staffAccount.OooStart != null && staffAccount.OooStart != default(DateTime))
                {
                    dvOooStart                  = new DataValue();
                    dvOooStart.Items            = new Object[] { staffAccount.OooStart };
                    dvOooStart.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.DateTimeValue };
                }
                csFldOOOStart.DataValue = dvOooStart;

                // Out of Office End
                csFldOOOEnd                   = new GenericField();
                csFldOOOEnd.name              = CustomField.OooEnd;
                csFldOOOEnd.dataType          = DataTypeEnum.DATETIME;
                csFldOOOEnd.dataTypeSpecified = true;
                DataValue dvOooEnd = null;
                if (staffAccount.OooEnd != null)
                {
                    dvOooEnd                  = new DataValue();
                    dvOooEnd.Items            = new Object[] { staffAccount.OooEnd };
                    dvOooEnd.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.DateTimeValue };
                }
                csFldOOOEnd.DataValue = dvOooEnd;

                // Out of Office Message Option
                DataValue dvOooMsgOption = new DataValue();
                dvOooMsgOption.Items            = new Object[] { staffAccount.OooMsgOption };
                dvOooMsgOption.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue };

                GenericField csFldOOOMsgOption = new GenericField();
                csFldOOOMsgOption.name              = CustomField.OooMsgOption;
                csFldOOOMsgOption.dataType          = DataTypeEnum.STRING;
                csFldOOOMsgOption.dataTypeSpecified = true;
                csFldOOOMsgOption.DataValue         = dvOooMsgOption;

                // Out of Office Message
                DataValue dvOooMsg = new DataValue();
                dvOooMsg.Items            = new Object[] { staffAccount.OooMsg };
                dvOooMsg.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue };

                GenericField csFldOOOMsg = new GenericField();
                csFldOOOMsg.name              = CustomField.OooMsg;
                csFldOOOMsg.dataType          = DataTypeEnum.STRING;
                csFldOOOMsg.dataTypeSpecified = true;
                csFldOOOMsg.DataValue         = dvOooMsg;

                // Out of Office Timezone
                GenericField csFldOOOTimezone = new GenericField();
                csFldOOOTimezone.name              = CustomField.OooTimezone;
                csFldOOOTimezone.dataType          = DataTypeEnum.STRING;
                csFldOOOTimezone.dataTypeSpecified = true;
                DataValue dvOooTimezone = null;
                if (null != staffAccount.OooTimezone)
                {
                    dvOooTimezone                  = new DataValue();
                    dvOooTimezone.Items            = new Object[] { staffAccount.OooTimezone };
                    dvOooTimezone.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue };
                }
                csFldOOOTimezone.DataValue = dvOooTimezone;


                GenericObject customFieldsc = new GenericObject();

                customFieldsc.GenericFields = new GenericField[] { csFldOOOFlag, csFldOOOStart, csFldOOOEnd, csFldOOOMsgOption, csFldOOOMsg, csFldOOOTimezone };

                customFieldsc.ObjectType = new RNObjectType()
                {
                    TypeName = CustomField.AccountCustomFieldCollectionTypeName
                };

                GenericField customFieldsPackage = new GenericField();
                customFieldsPackage.name                       = "c";
                customFieldsPackage.dataType                   = DataTypeEnum.OBJECT;
                customFieldsPackage.dataTypeSpecified          = true;
                customFieldsPackage.DataValue                  = new DataValue();
                customFieldsPackage.DataValue.Items            = new[] { customFieldsc };
                customFieldsPackage.DataValue.ItemsElementName = new[] { ItemsChoiceType.ObjectValue };

                account.CustomFields = new GenericObject
                {
                    GenericFields = new[] { customFieldsPackage },
                    ObjectType    = new RNObjectType {
                        TypeName = CustomField.AccountCustomFieldsTypeName
                    }
                };

                ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                clientInfoHeader.AppID = OracleRightNowOOOAddInNames.OutOfOfficeAddIn;

                RNObject[] contactObjects = new RNObject[] { account };
                UpdateProcessingOptions updateProcessingOptions = new UpdateProcessingOptions();
                _rightNowClient.Update(clientInfoHeader, contactObjects, updateProcessingOptions);

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(OOOExceptionMessages.UnexpectedError, Common.Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Error(e.Message, e.StackTrace);
            }

            Debug("RightNowConnectService - updateCustomFields() - Exit");
            return(false);
        }
Esempio n. 8
0
        public void updateContact(long id, string updatedfirstname)
        {
            Contact contacttobeUpdated = new Contact();
            ID contactID = new ID();
            contactID.id = id;
            contactID.idSpecified = true;
            contacttobeUpdated.ID = contactID;

            PersonName pn = new PersonName();
            pn.First = updatedfirstname;

            contacttobeUpdated.Name = pn;
            RNObject[] rnobjects = new RNObject[]{ contacttobeUpdated };
            UpdateProcessingOptions options = new UpdateProcessingOptions();
            options.SuppressExternalEvents = false;
            options.SuppressRules = false;
            try
            {
                ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                clientInfoHeader.AppID = "Basic Update";

                //Invoke the Update operation
                _client.Update(clientInfoHeader, rnobjects, options);
            }
            catch (FaultException ex)
            {
                Console.WriteLine(ex.Code);
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 9
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);
        }
        public UpdateResponse UpdateObjects <T>(List <T> lstobj)
        {
            List <GenericObject> lstgenericObject = new List <GenericObject>();

            foreach (T sam in lstobj)
            {
                ID autoID = new ID();

                Type objType      = typeof(T);
                var  objAttribute = objType.GetCustomAttributes(typeof(RightNowCustomObjectAttribute), true).FirstOrDefault() as RightNowCustomObjectAttribute;
                if (objAttribute == null)
                {
                    throw new InvalidOperationException("The type provided is not a RightNow custom object type. Please use the RightNowObjectAttribute to associate the proper metadata with the type");
                }

                GenericObject genericObject = new GenericObject();
                RNObjectType  rnObjType     = new RNObjectType()
                {
                    Namespace = objAttribute.PackageName, TypeName = objAttribute.ObjectName
                };
                genericObject.ObjectType = rnObjType;

                List <GenericField> genericFields = new List <GenericField>();
                PropertyInfo[]      properties    = objType.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    RightNowCustomObjectFieldAttribute attribute = property.GetCustomAttributes(typeof(RightNowCustomObjectFieldAttribute), true).FirstOrDefault() as RightNowCustomObjectFieldAttribute;
                    if (attribute != null && attribute.CanUpdate)
                    {
                        var propValue = property.GetValue(sam, null);
                        //if (!string.IsNullOrWhiteSpace(propValue.ToString())) && !string.IsNullOrWhiteSpace(propValue.ToString())
                        if (propValue != null && !string.IsNullOrWhiteSpace(propValue.ToString()))
                        {
                            genericFields.Add(createGenericField(attribute, propValue));
                        }
                    }
                    else
                    {
                        if (attribute.Name == "ID")
                        {
                            var propValue = property.GetValue(sam, null);
                            autoID.id = Convert.ToInt64(propValue);
                        }
                    }
                }

                genericObject.GenericFields = genericFields.ToArray();

                autoID.idSpecified = true;
                genericObject.ID   = autoID;
                lstgenericObject.Add(genericObject);
            }
            UpdateProcessingOptions options = new UpdateProcessingOptions();

            options.SuppressExternalEvents = false;
            options.SuppressRules          = false;
            RNObject[]     rnobj          = lstgenericObject.ToArray <RNObject>();
            UpdateRequest  updateRequest  = new UpdateRequest(getClientInfoHeader(), rnobj, options);
            UpdateResponse updateResponse = this.getChannel().Update(updateRequest);

            return(updateResponse);
        }
Esempio n. 11
0
        /// <summary>
        /// Method called to update the social channel
        /// </summary>
        /// <param name="incident"></param>
        private void updateSocialChannelAccount(IIncident incident)
        {
            // get it again
            _socialChannelAccountId = ConfigurationSetting.getSrmStringCustomAttrInt(incident, "srm_social_channel_account_id");

            if (_socialChannelAccountId == 0)
            {
                ConfigurationSetting.logWrap.DebugLog(logMessage: String.Format(Properties.Resources.SocialChannelEmptyError, incident.ID));
                return;
            }

            /* Custom Object: SocialChannelAccount
             *
             */
            int incidentContactId = 0;

            foreach (IInc2Contact c in incident.Contact)
            {
                if (c.Prmry == true)
                {
                    incidentContactId = (int)c.Cid;
                }
            }

            Boolean toUpdate = false;

            // if incident's contact is changed
            if (_incidentContactIdWhenLoaded != incidentContactId)
            {
                // check if updated incidentContactId same as SocialChannelAccount.ContactId
                if (_socialChannelAccountId != 0 && incidentContactId != _socialChannelAccountId)
                {
                    DialogResult result = MessageBox.Show(String.Format(Properties.Resources.ChangeContactReassignMessage, _socialChannelUserName), Properties.Resources.Info, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (result == DialogResult.OK)
                    {
                        toUpdate = true;
                    }
                }
                // update in Accelerator.SocialChannelAccount
                if (toUpdate)
                {
                    // create a row in SocialChannelAccount
                    ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                    clientInfoHeader.AppID = "Update a SocialChannelAccount";

                    GenericObject go = new GenericObject();

                    //Set the object type
                    RNObjectType objType = new RNObjectType();
                    objType.Namespace = "Accelerator";
                    objType.TypeName  = "SocialChannelAccount";
                    go.ObjectType     = objType;

                    List <GenericField> gfs = new List <GenericField>();

                    ID socialAccountId = new ID();
                    socialAccountId.id          = _socialChannelAccountId;
                    socialAccountId.idSpecified = true;

                    go.ID = socialAccountId;

                    NamedID contactIdNamedID =
                        new NamedID
                    {
                        ID = new ID
                        {
                            id          = incidentContactId,
                            idSpecified = true
                        }
                    };

                    gfs.Add(createGenericField("ContactId", ItemsChoiceType.NamedIDValue, contactIdNamedID));
                    go.GenericFields = gfs.ToArray();

                    RNObject[] objects = new RNObject[] { go };

                    UpdateProcessingOptions cpo = new UpdateProcessingOptions();
                    cpo.SuppressExternalEvents = false;
                    cpo.SuppressRules          = false;

                    ConfigurationSetting.logWrap.DebugLog(logMessage: String.Format(Properties.Resources.UpdateSocialChannelMessage, _socialChannelAccountId, incidentContactId));
                    ConfigurationSetting.client.Update(clientInfoHeader, objects, cpo);

                    DialogResult result = MessageBox.Show(String.Format(Properties.Resources.ReassignAllIncidentsMessage, _socialChannelUserName), Properties.Resources.Info, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (result == DialogResult.OK)
                    {
                        updateIncidents(incidentContactId);
                    }
                }
            }
        }