示例#1
0
        public Boolean initializeLogger(IGlobalContext globalContext)
        {
            EndpointAddress endPointAddr = new EndpointAddress(globalContext.GetInterfaceServiceUrl(ConnectServiceType.Soap));

            // Minimum required
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);

            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

            // Optional depending upon use cases
            binding.MaxReceivedMessageSize = 1024 * 1024;
            binding.MaxBufferSize          = 1024 * 1024;
            binding.MessageEncoding        = WSMessageEncoding.Mtom;

            // Create client proxy class
            RightNowSyncPortClient client = new RightNowSyncPortClient(binding, endPointAddr);

            // Ask the client to not send the timestamp
            BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();

            elements.Find <SecurityBindingElement>().IncludeTimestamp = false;
            client.Endpoint.Binding = new CustomBinding(elements);

            // Ask the Add-In framework the handle the session logic
            globalContext.PrepareConnectSession(client.ChannelFactory);

            this.client    = client;
            this.extObject = getExtension();
            return(true);
        }
示例#2
0
        internal void CreateNoFilesToProcessIntegrationJob(IntegrationJobType jobType)
        {
            var gfs = new List <GenericField>
            {
                RightNowServiceBaseObjectBuilder.CreateGenericField("JobStatus", DataTypeEnum.NAMED_ID, RightNowServiceBaseObjectBuilder.CreateNamedID((int)IntegrationJobStatus.Completed)),
                RightNowServiceBaseObjectBuilder.CreateGenericField("JobType", DataTypeEnum.NAMED_ID, RightNowServiceBaseObjectBuilder.CreateNamedID((int)jobType)),
                RightNowServiceBaseObjectBuilder.CreateGenericField("Detail", DataTypeEnum.STRING, "No files were available to process")
            };

            var package = new RNObject[]
            {
                new GenericObject
                {
                    ObjectType = new RNObjectType
                    {
                        Namespace = "IJ",
                        TypeName  = "Job"
                    },
                    GenericFields = gfs.ToArray(),
                }
            };

            GlobalContext.Log("Creating an Integration Job showing that no files were available to process", true);
            _serviceWrapper.CreateObjects(package);
        }
示例#3
0
        public void queryObjects()
        {
            ClientInfoHeader clientHeaderInfo = new ClientInfoHeader();
            clientHeaderInfo.AppID = "Chandu test query objects";
             string queryString = "SELECT O.Opportunities FROM Organization O WHERE O.ID = 1;";
               // string queryString = "Select * from contact";

            Opportunity opportunity = new Opportunity();

            RNObject[] objectTemplates = new RNObject[] { opportunity };

            try
            {
                QueryResultData[] queryObjects = _client.QueryObjects(clientHeaderInfo, queryString, objectTemplates, 10000);
                RNObject[] rnObjects = queryObjects[0].RNObjectsResult;

                foreach (RNObject obj in rnObjects)
                {
                    Opportunity Opportunity = (Opportunity)obj;
                    Console.WriteLine("Opportunity of the organization is - " + Opportunity.Name);
                }

            }
            catch (System.ServiceModel.FaultException ex)
            {
                Console.WriteLine(ex.Code);
                Console.WriteLine(ex.Message);
            }
        }
示例#4
0
        internal long?CreateIntegrationJob(CreateIntegrationJobRequest request)
        {
            var gfs = new List <GenericField>
            {
                // always default status to in-progress when creating a job
                RightNowServiceBaseObjectBuilder.CreateGenericField("JobStatus", DataTypeEnum.NAMED_ID, RightNowServiceBaseObjectBuilder.CreateNamedID((int)IntegrationJobStatus.InProgress)),
                RightNowServiceBaseObjectBuilder.CreateGenericField("JobType", DataTypeEnum.NAMED_ID, RightNowServiceBaseObjectBuilder.CreateNamedID((int)request.JobType)),
                RightNowServiceBaseObjectBuilder.CreateGenericField("FileName", DataTypeEnum.STRING, request.FileName),
                RightNowServiceBaseObjectBuilder.CreateGenericField("HostName", DataTypeEnum.STRING, request.HostName),
            };

            var package = new RNObject[]
            {
                new GenericObject
                {
                    ObjectType = new RNObjectType
                    {
                        Namespace = "IJ",
                        TypeName  = "Job"
                    },
                    GenericFields = gfs.ToArray()
                }
            };

            GlobalContext.Log("Creating an Integration Job in RightNow for tracking purposes", true);
            var result = _serviceWrapper.CreateObjects(package);

            if (result.Successful && result.CreatedObjects.Any())
            {
                return(result.CreatedObjects.First().ID.id);
            }

            return(null);
        }
        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);
        }
        internal GetFileAttachmentDataResponse GetFileData(RNObject rnObject, long fileID, bool disableMTOM)
        {
            var result = new List <RNObject>();

            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
                {
                    ID idObj = new ID
                    {
                        id          = fileID,
                        idSpecified = true
                    };

                    byte[] fileData = _client.GetFileData(_clientInfoHeader, rnObject, idObj, disableMTOM);

                    return(new GetFileAttachmentDataResponse
                    {
                        FileData = fileData,
                        Successful = true,
                        SuccessfulSet = true
                    });
                }
                catch (Exception ex)
                {
                    GlobalContext.Log(string.Format("Failed GetFileData: Retry {0}: {1}", retryTimes, ex.Message), true);
                    GlobalContext.Log(string.Format("Failed GetFileData: 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 GetFileAttachmentDataResponse
                        {
                            FileData = null,
                            Successful = false,
                            SuccessfulSet = true,
                            Details = ex.Message
                        });
                    }
                }
                GlobalContext.Log(string.Format("GetFileData Must Retry {0}", mustRetry), false);
            } while (mustRetry);
            GlobalContext.Log("GetFileData End: This code should never be hit.", false);
            return(null);        // this code should never be hit
        }
示例#7
0
        public RNObject[] createObject(RNObject[] objects)
        {
            //Create the update processiong options
            CreateProcessingOptions options = new CreateProcessingOptions();
            options.SuppressExternalEvents = false;
            options.SuppressRules = false;

            //Invoke the Update operation
            RNObject[] results = _rnowClient.Create(this._rnowClientInfoHeader, objects, options);
            return results;
        }
示例#8
0
        public Boolean initializeLogger(RightNowSyncPortClient client)
        {
            // Ask the client to not send the timestamp
            BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();

            elements.Find <SecurityBindingElement>().IncludeTimestamp = false;
            client.Endpoint.Binding = new CustomBinding(elements);

            this.client    = client;
            this.extObject = getExtension();
            return(true);
        }
示例#9
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);
        }
示例#10
0
        public static void Main(string[] args)
        {
            BasicHttpBinding basicHttpBinding = null;
            EndpointAddress endpointAddress = null;
            

            basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            endpointAddress = new EndpointAddress(new Uri("url-soap-aqui"));

            try
            {
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

                ServiceReference1.RightNowSyncPortClient syncClient = new RightNowSyncPortClient(basicHttpBinding,endpointAddress);
                syncClient.ClientCredentials.UserName.UserName = "******";
                syncClient.ClientCredentials.UserName.Password = "******";

                Contact contact = new Contact();
                ID cID = new ID();
                cID.id = 0;
                cID.idSpecified = true;
                contact.ID = cID;

                var api = new APIAccessRequestHeader();
                GetProcessingOptions getProcessiongOptions = new GetProcessingOptions();
                getProcessiongOptions.FetchAllNames = false;
                ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
                clientInfoHeader.AppID = "Read Contact";
                RNObject[] orgObjects = new RNObject[] { contact };
                RNObject[] readReturn;

                var resp = syncClient.GetAsync(clientInfoHeader, api,
                    orgObjects, getProcessiongOptions);
                
                
                readReturn  = resp.Result.RNObjectsResult;
                
                Contact readContact = (Contact)readReturn[0];

                Console.WriteLine("Lookup name: " + readContact.LookupName);
                Console.WriteLine("Login: "******"Digite \"ENTER\" para sair...");
            Console.ReadLine();
        }
示例#11
0
        internal void UpdateIntegrationJob(UpdateIntegrationJobRequest request, bool updateJobStatus)
        {
            IntegrationJobStatus jobStatus = request.RecordsFailed > 0
                                                 ? IntegrationJobStatus.CompletedWithErrors
                                                 : IntegrationJobStatus.Completed;

            var gfs = new List <GenericField>
            {
                RightNowServiceBaseObjectBuilder.CreateGenericField("CountOfRowsInFile", DataTypeEnum.INTEGER, request.RecordsTotal),
                RightNowServiceBaseObjectBuilder.CreateGenericField("CountOfUniqueRowsInFile", DataTypeEnum.INTEGER, request.RecordsTotalUnique),
                RightNowServiceBaseObjectBuilder.CreateGenericField("CountOfSuccess", DataTypeEnum.INTEGER, request.RecordsSuccessful),
                RightNowServiceBaseObjectBuilder.CreateGenericField("CountOfFailure", DataTypeEnum.INTEGER, request.RecordsFailed)
            };

            if (updateJobStatus)
            {
                gfs.Add(RightNowServiceBaseObjectBuilder.CreateGenericField("JobStatus", DataTypeEnum.NAMED_ID, RightNowServiceBaseObjectBuilder.CreateNamedID((int)jobStatus)));
            }

            if (request.AttachmentData != null)
            {
                gfs.Add(RightNowServiceBaseObjectBuilder.CreateAttachmentText(request.AttachmentData));
            }

            if (!string.IsNullOrEmpty(request.Detail))
            {
                gfs.Add(RightNowServiceBaseObjectBuilder.CreateGenericField("Detail", DataTypeEnum.STRING, request.Detail));
            }

            var package = new RNObject[]
            {
                new GenericObject
                {
                    ObjectType = new RNObjectType
                    {
                        Namespace = "IJ",
                        TypeName  = "Job"
                    },
                    GenericFields = gfs.ToArray(),
                    ID            = new ID
                    {
                        id          = request.ID,
                        idSpecified = true
                    },
                }
            };

            GlobalContext.Log("Updating the Integration Job with results", true);
            _serviceWrapper.UpdateObjects(package);
        }
示例#12
0
        protected RNObject getExtension()
        {
            RNObject currentExt = lookupExtension();

            if (currentExt == null)
            {
                currentExt = createExtension();
            }
            GenericObject extentionObj  = (GenericObject)currentExt;
            string        extConfigJson = extentionObj.GenericFields.FirstOrDefault <GenericField>(c => c.name == "ExtConfiguration").DataValue.Items[0].ToString();
            var           serializer    = new JavaScriptSerializer();

            this.extConfigs = serializer.Deserialize <extConfig>(extConfigJson);
            return(currentExt);
        }
示例#13
0
 public RNObject[] CreateContact(string FirstName, string LastName,string EmailAddress)
 {
     Contact newContact = populateContactInfo(FirstName, LastName,EmailAddress);
         //Set the application ID in the client info header
         ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
         clientInfoHeader.AppID = ".NET Getting Started test in log API";
         //Set the create processing options, allow external events and rules to execute
         CreateProcessingOptions createProcessingOptions = new CreateProcessingOptions();
         createProcessingOptions.SuppressExternalEvents = false;
         createProcessingOptions.SuppressRules = false;
         RNObject[] createObjects = new RNObject[] { newContact };
         GetProcessingOptions options = new GetProcessingOptions();
         options.FetchAllNames = false;
         //Invoke the create operation on the server. This will create a contact
         RNObject[] createResults = _service.Create(clientInfoHeader, createObjects, createProcessingOptions);
         newContact = createResults[0] as Contact;
         RNObject[] rnObjects = _service.Get(clientInfoHeader, createResults, options);
         return rnObjects;
 }
    public long CreateContact()
    {
        Contact newContact = Contactinfo();
        //Set the application ID in the client info header
        ClientInfoHeader clientInfoHeader = new ClientInfoHeader();

        clientInfoHeader.AppID = ".NET Getting Started";
        //Set the create processing options, allow external events and rules to execute
        CreateProcessingOptions createProcessingOptions = new CreateProcessingOptions();

        createProcessingOptions.SuppressExternalEvents = false;
        createProcessingOptions.SuppressRules          = false;
        RNObject[] createObjects = new RNObject[] { newContact };
        //Invoke the create operation on the RightNow server
        RNObject[] createResults = _Service.Create(clientInfoHeader, createObjects, createProcessingOptions);
        //We only created a single contact, this will be at index 0 of the results
        newContact = createResults[0] as Contact;
        return(newContact.ID.id);
    }
示例#15
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);
            }
        }
        public AnalyticsReport getAnalyticsReport(long reportID)
        {
            AnalyticsReport analyticsReport = new AnalyticsReport();
            ID analyticsReportID            = new ID();

            analyticsReportID.id          = reportID;
            analyticsReportID.idSpecified = true;
            analyticsReport.ID            = analyticsReportID;

            AnalyticsReportFilter filter = new AnalyticsReportFilter();

            analyticsReport.Filters = (new AnalyticsReportFilter[] { filter });

            GetProcessingOptions processingOptions = new GetProcessingOptions();

            processingOptions.FetchAllNames = true;

            RNObject[]      getAnalyticsObjects = new RNObject[] { analyticsReport };
            RNObject[]      rnObjects           = _client.Get(_clientInfoHeader, getAnalyticsObjects, processingOptions);
            AnalyticsReport report = (AnalyticsReport)rnObjects[0];

            return(report);
        }
示例#17
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);
                    }
                }
            }
        }
        // Update Custom Attribute via SOAP API
        // After create/update incident, the custom attribute may need to update.
        protected void UpdateIncCustomAttr(int incidentID, string key, string value)
        {
            //Create an Incident object
            Accelerator.Siebel.SharedServices.RightNowServiceReference.Incident updateIncident = new Accelerator.Siebel.SharedServices.RightNowServiceReference.Incident();


            //Create and set the Id property
            ID incID = new ID();
            //Set the Id on the Incident Object
            incID.id = incidentID;
            incID.idSpecified = true;

            updateIncident.ID = incID;

            
            if (value != null && value != "")
            {
                GenericField customField = new GenericField();
                // Check update which custom attribute
                switch (key)
                {
                    case "siebel_sr_id":
                        customField.name = "siebel_sr_id";
                        customField.dataType = DataTypeEnum.STRING;
                        customField.dataTypeSpecified = true;
                        customField.DataValue = new DataValue();
                        customField.DataValue.Items = new object[1];
                        customField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                        customField.DataValue.Items[0] = value;
                        customField.DataValue.ItemsElementName[0] = ItemsChoiceType.StringValue;
                        break;
                    case "siebel_sr_num":
                        customField.name = "siebel_sr_num";
                        customField.dataType = DataTypeEnum.STRING;
                        customField.dataTypeSpecified = true;
                        customField.DataValue = new DataValue();
                        customField.DataValue.Items = new object[1];
                        customField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                        customField.DataValue.Items[0] = value;
                        customField.DataValue.ItemsElementName[0] = ItemsChoiceType.StringValue;
                        break;
                    case "siebel_max_thread_id":
                        customField.name = "siebel_max_thread_id";
                        customField.dataType = DataTypeEnum.INTEGER;
                        customField.dataTypeSpecified = true;
                        customField.DataValue = new DataValue();
                        customField.DataValue.Items = new object[1];
                        customField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                        customField.DataValue.Items[0] = Convert.ToInt32(value);
                        customField.DataValue.ItemsElementName[0] = ItemsChoiceType.IntegerValue;
                        break;
                    default:
                        return;
                }

                GenericObject customFieldsc = new GenericObject();
                customFieldsc.GenericFields = new GenericField[1];
                customFieldsc.GenericFields[0] = customField;
                customFieldsc.ObjectType = new RNObjectType();
                customFieldsc.ObjectType.TypeName = "IncidentCustomFieldsc";

                GenericField cField = new GenericField();
                cField.name = "Accelerator";
                cField.dataType = DataTypeEnum.OBJECT;
                cField.dataTypeSpecified = true;
                cField.DataValue = new DataValue();
                cField.DataValue.Items = new object[1];
                cField.DataValue.Items[0] = customFieldsc;
                cField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                cField.DataValue.ItemsElementName[0] = ItemsChoiceType.ObjectValue;

                updateIncident.CustomFields = new GenericObject();
                updateIncident.CustomFields.GenericFields = new GenericField[1];
                updateIncident.CustomFields.GenericFields[0] = cField;
                updateIncident.CustomFields.ObjectType = new RNObjectType();
                updateIncident.CustomFields.ObjectType.TypeName = "IncidentCustomFields";
            }
            else
            {
                return;
            }
            //Create the RNObject array
            RNObject[] objects = new RNObject[] { updateIncident };

            try
            {
                _rnSrv.updateObject(objects);  
            }
            catch (Exception ex)
            {
                if (_log != null)
                {
                    string logMessage = "Error in updating incident custom field via Cloud Service SOAP. Try to update incident(ID = " + incidentID + ") custom attribute " + key + " to value" + value + "; Error Message: "+ ex.Message;
                    _log.ErrorLog(incidentId:_logIncidentId, logMessage: logMessage);
                }
                MessageBox.Show("There has been an error communicating with Cloud Service SOAP. Please check log for detail.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
        // Create new contact via SOAP API - Created when an EBS Contact without association is selected
        public long CreateContact(String firstName, String lastName, String phone, String emailAdd, String contactPartyId, string orgId)
        {
            string logMessage;
            string logNote;
            //Create a Contact
            Accelerator.EBS.SharedServices.RightNowServiceReference.Contact newContact = new Accelerator.EBS.SharedServices.RightNowServiceReference.Contact();

            //Build a PersonName object for the Contact and add the PersonName to the new Contact object
            PersonName personName = new PersonName();
            if (firstName != null && firstName != "")
                personName.First = firstName;
            if (lastName != null && lastName != "")
                personName.Last = lastName;
            newContact.Name = personName;

            //Build an Email object and add the Email to the new Contact object
            if (emailAdd != null && emailAdd != "")
            {
                newContact.Emails = new Email[1];
                newContact.Emails[0] = new Email();
                newContact.Emails[0].Address = emailAdd;
                newContact.Emails[0].action = ActionEnum.add;
                newContact.Emails[0].actionSpecified = true;
                newContact.Emails[0].AddressType = new NamedID();
                newContact.Emails[0].AddressType.ID = new ID();
                newContact.Emails[0].AddressType.ID.id = 0;
                newContact.Emails[0].AddressType.ID.idSpecified = true;
            }

            //Build a Phone object and add the Phone to the new Contact object
            if (phone != null && phone != "")
            {
                newContact.Phones = new Phone[1];
                newContact.Phones[0] = new Phone();
                newContact.Phones[0].Number = phone;
                newContact.Phones[0].action = ActionEnum.add;
                newContact.Phones[0].actionSpecified = true;
                newContact.Phones[0].PhoneType = new NamedID();
                newContact.Phones[0].PhoneType.ID = new ID();
                newContact.Phones[0].PhoneType.ID.id = 0;
                newContact.Phones[0].PhoneType.ID.idSpecified = true;
            }

            //Set EBS Contact Party ID (custom field) to the new Contact
            if (contactPartyId != null && contactPartyId != "")
            {
                GenericField cfContactPartyIdField = new GenericField();
                cfContactPartyIdField.name = "ebs_contact_party_id";
                cfContactPartyIdField.dataType = DataTypeEnum.INTEGER;
                cfContactPartyIdField.dataTypeSpecified = true;
                cfContactPartyIdField.DataValue = new DataValue();
                cfContactPartyIdField.DataValue.Items = new object[1];
                cfContactPartyIdField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                cfContactPartyIdField.DataValue.Items[0] = Convert.ToInt32(contactPartyId);
                cfContactPartyIdField.DataValue.ItemsElementName[0] = ItemsChoiceType.IntegerValue;

                GenericField cfContactOrgIdField = new GenericField();
                cfContactOrgIdField.name = "ebs_contact_org_id";
                cfContactOrgIdField.dataType = DataTypeEnum.INTEGER;
                cfContactOrgIdField.dataTypeSpecified = true;
                cfContactOrgIdField.DataValue = new DataValue();
                cfContactOrgIdField.DataValue.Items = new object[1];
                cfContactOrgIdField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                cfContactOrgIdField.DataValue.Items[0] = Convert.ToInt32(orgId);
                cfContactOrgIdField.DataValue.ItemsElementName[0] = ItemsChoiceType.IntegerValue;

                GenericObject customFieldsc = new GenericObject();
                customFieldsc.GenericFields = new GenericField[2];
                customFieldsc.GenericFields[0] = cfContactPartyIdField;
                customFieldsc.GenericFields[1] = cfContactOrgIdField;
                customFieldsc.ObjectType = new RNObjectType();
                customFieldsc.ObjectType.TypeName = "ContactCustomFieldsc";

                GenericField cField = new GenericField();
                cField.name = "Accelerator";
                cField.dataType = DataTypeEnum.OBJECT;
                cField.dataTypeSpecified = true;
                cField.DataValue = new DataValue();
                cField.DataValue.Items = new object[1];
                cField.DataValue.Items[0] = customFieldsc;
                cField.DataValue.ItemsElementName = new ItemsChoiceType[1];
                cField.DataValue.ItemsElementName[0] = ItemsChoiceType.ObjectValue;

                newContact.CustomFields = new GenericObject();
                newContact.CustomFields.GenericFields = new GenericField[1];
                newContact.CustomFields.GenericFields[0] = cField;
                newContact.CustomFields.ObjectType = new RNObjectType();
                newContact.CustomFields.ObjectType.TypeName = "ContactCustomFields";

            }
            //Build the RNObject[]
            RNObject[] newObjects = new RNObject[] { newContact };
            RNObject[] results = null;
            try
            {
                results = _rnSrv.createObject(newObjects);
            }
            catch (Exception ex)
            {
                if (_log != null)
                {
                    logMessage = "Error in creating contact via CWSS. Contact " + firstName + " " + lastName + ": " + ex.Message;
                    logNote = "";
                    _log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);
                }
                MessageBox.Show("Cannot create contact: " + firstName + " " + lastName + ". Please check log for detail. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 0;
            }
            logMessage = "New Contact is created successfully. Contact ID = " + results[0].ID.id;
            logNote = "";
            _log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote);

            return results[0].ID.id;
        }
示例#20
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);
        }
示例#21
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);
        }
示例#22
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);
            }
        }
        internal RunAnalyticsResponse GetAnalyticsReportResults(long reportId, AnalyticsReportFilter[] filters,
                                                                int limit = 100, int start = 0, string delimiter = ",")
        {
            //Create new AnalyticsReport Object
            AnalyticsReport analyticsReport = new AnalyticsReport();
            //Specify a report ID of Public Reports>Common>Data integration>Opportunities
            ID reportID = new ID();

            reportID.id          = reportId;
            reportID.idSpecified = true;
            analyticsReport.ID   = reportID;

            analyticsReport.Filters = filters;

            GetProcessingOptions processingOptions = new GetProcessingOptions();

            processingOptions.FetchAllNames = true;

            RNObject[]  getAnalyticsObjects = new RNObject[] { analyticsReport };
            CSVTableSet thisSet             = new CSVTableSet();

            byte[] ignore;

            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
                {
                    thisSet = _client.RunAnalyticsReport(_clientInfoHeader, analyticsReport, limit, start, delimiter, false, true, out ignore);

                    return(new RunAnalyticsResponse
                    {
                        RunAnalyticsTableSet = thisSet,
                        Successful = true,
                        SuccessfulSet = true
                    });
                }
                catch (Exception ex)
                {
                    GlobalContext.Log(string.Format("Failed RunAnalyticsReport: Retry {0}: {1}", retryTimes, ex.Message), true);
                    GlobalContext.Log(string.Format("Failed RunAnalyticsReport: 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 RunAnalyticsResponse
                        {
                            Successful = false,
                            SuccessfulSet = false,
                            Details = ex.Message
                        });
                    }
                }
                GlobalContext.Log(string.Format("RunAnalyticsReport Must Retry {0}", mustRetry), false);
            } while (mustRetry);
            GlobalContext.Log("RunAnalyticsReport End: This code should never be hit.", false);
            return(null);        // this code should never be hit
        }