示例#1
0
        /// <summary>
        /// Event handler for the data loaded event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _recordContext_DataLoaded(object sender, System.EventArgs e)
        {
            try
            {
                IIncident incident = _recordContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Incident) as IIncident;

                _incidentStatusWhenLoaded = incident.Status.StatusID;

                if (incident.Threads.Count != 0 && incident.Threads[incident.Threads.Count - 1].ID == 0)
                {
                    _threadCountWhenLoaded = incident.Threads.Count - 1;
                }
                else
                {
                    _threadCountWhenLoaded = incident.Threads.Count;
                }

                if (incident.Subject == null)
                {
                    return;
                }

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

                /* get the Incident's custom attribute: srm_social_channel_id
                 * then, lookup in the Custom Object: SocialChannelAccount to get its ContactId,on ChannelUserName and ChannelType
                 * then, compare SocialChannelAccount.ContactId with incident.Contact.Cid
                 */
                _socialChannelAccountId = ConfigurationSetting.getSrmStringCustomAttrInt(incident, "srm_social_channel_account_id");

                if (_socialChannelAccountId != 0)
                {
                    //Query SocialChannelAccount from Cloud Service
                    String   query   = "select ChannelType,ChannelUserName,ContactId from Accelerator.SocialChannelAccount where Id=" + _socialChannelAccountId;
                    String[] rowData = null;
                    int      contactIdSocialChannelAccount = 0;

                    rowData = ConfigurationSetting.rnSrv.queryData(query);

                    if (rowData.Length != 0)
                    {
                        // rowData is "ChannelType,ChannelUserName,ContactId", eg: "facebook,jill.smith,1"
                        String[] socialData = rowData[0].Split(',');
                        // socialData[0]  is ChannelType, socialData[1] is ChannelUserName, socialData[2] is ContactId
                        if (!String.IsNullOrEmpty(socialData[2]))
                        {
                            contactIdSocialChannelAccount = Convert.ToInt32(socialData[2]);
                        }
                        else
                        {
                            var message = String.Format(Properties.Resources.ContactIDEmptyError, _socialChannelAccountId);
                            MessageBox.Show(message, Properties.Resources.Info, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ConfigurationSetting.logWrap.DebugLog(logMessage: message);
                            contactIdSocialChannelAccount = 0; // just default empty ContactId to 0
                        }
                        _socialChannelType     = socialData[0];
                        _socialChannelUserName = socialData[1];

                        if (_incidentContactIdWhenLoaded != contactIdSocialChannelAccount)
                        {
                            MessageBox.Show(Properties.Resources.ContactDoesNotMatchSocialError, Properties.Resources.Info, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Properties.Resources.SRMNotFoundError, Properties.Resources.Info, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    };
                }
                else
                {
                    ConfigurationSetting.logWrap.DebugLog(logMessage: String.Format(Properties.Resources.SocialChannelEmptyError, incident.ID));
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Properties.Resources.CommunicationError, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                ConfigurationSetting.logWrap.ErrorLog(logMessage: ex.Message, logNote: ex.InnerException != null ? ex.InnerException.Message : null);
            }
        }
示例#2
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);
                    }
                }
            }
        }