internal StaffAccountInfo GetStaffAccountInformation(int id)
        {
            var request = new QueryCSVRequest(getClientInfoHeader(),
                                              string.Format(@"SELECT DisplayName, CustomFields.Oracle_Cti.acd_id, CustomFields.Oracle_Cti.acd_password, CustomFields.c.AgentID, CustomFields.c.Password, CustomFields.c.Extension,CustomFields.c.Queue FROM Account WHERE id= {0}", id), 1, ",", false, true);

            var rightNowChannel = getChannel();

            var result = rightNowChannel.QueryCSV(request);

            var staffAccount = new StaffAccountInfo();

            if (result.CSVTableSet != null && result.CSVTableSet.CSVTables.Length > 0 && result.CSVTableSet.CSVTables[0].Rows.Length > 0)
            {
                var resultRow = result.CSVTableSet.CSVTables[0].Rows[0].Split(',');
                staffAccount.Name        = resultRow[0];
                staffAccount.AcdId       = resultRow[1];
                staffAccount.AcdPassword = resultRow[1];
                int val;
                int.TryParse(resultRow[3], out val);
                staffAccount.AgentID  = val;
                staffAccount.Password = resultRow[4];
                int.TryParse(resultRow[5], out val);
                staffAccount.Extension = val;
                int.TryParse(resultRow[6], out val);
                staffAccount.Queue = val;
            }

            return(staffAccount);
        }
        public IEnumerable <T> GetObjects <T>(string predicate = null) where T : class, new()
        {
            var objectType = typeof(T);
            var result     = new QueryCSVResponse();

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

                var query = string.Format("SELECT * from {0}.{1} {2}", customObjectAttribute.PackageName, customObjectAttribute.ObjectName, predicate ?? string.Empty);

                var request = new QueryCSVRequest(getClientInfoHeader(), query, 100, ",", false, true);

                var rightNowChannel = getChannel();
                result = rightNowChannel.QueryCSV(request);
            }
            catch (Exception ex)
            {
                Logger.Logger.Log.Error(string.Format("Exception at calling GetObject  >> {0}", ex.Message));
            }
            return(materializeObjects <T>(result, objectType));
        }
Пример #3
0
        /// <summary>
        /// Async method for performing a ROQL query.
        /// </summary>
        /// <param name="queryString"></param>
        /// <returns></returns>
        public async Task <string[]> queryDataAsync(string queryString)
        {
            try
            {
                var request  = new QueryCSVRequest(_rnowClientInfoHeader, queryString, 100, ",", false, false);
                var response = await _rnowClient.QueryCSVAsync(request);

                if (response.CSVTableSet.CSVTables.Length > 0)
                {
                    var        tableSet  = response.CSVTableSet;
                    CSVTable[] csvTables = tableSet.CSVTables;
                    CSVTable   table     = csvTables[0];
                    string[]   rowData   = table.Rows;

                    return(rowData);
                }
            }
            catch (Exception e)
            {
                //Write an exception to the debugger.  Since this is an async method, an exception may be thrown by
                //a continuace exception.
                System.Diagnostics.Debug.WriteLine(string.Format("{0}\n{1}", e.Message, e.StackTrace));
            }

            return(null);
        }
        public IncidentInfo GetFirstIncidentDetails(int accountid)
        {
            var firstincident = new IncidentInfo();

            try {
                var request = new QueryCSVRequest(getClientInfoHeader(),
                                                  string.Format(@"SELECT 
	                                                    ID,
	                                                    Channel,
	                                                    Queue.Name,
	                                                    ReferenceNumber,
	                                                    Source.Name SourceName,
                                                        PrimaryContact.Contact ContactId,
                                                        PrimaryContact.Contact.Name ContactName,
                                                        PrimaryContact.ParentContact.Emails.Address Email,
	                                                    Subject,
                                                        UpdatedTime
                                                    FROM Incident
                                                    WHERE AssignedTo.Account.Id = {0}
                                                    AND StatusWithType.StatusType.Id = 1
                                                    ORDER BY UpdatedTime DESC 
                                                    LIMIT 1"
                                                                , accountid), 1000, ",", false, true);
                var rightNowChannel = getChannel();

                var result = rightNowChannel.QueryCSV(request);

                if (result.CSVTableSet != null && result.CSVTableSet.CSVTables.Length == 1)
                {
                    var resultRow = result.CSVTableSet.CSVTables[0].Rows[0].Split(',');
                    firstincident.Id              = long.Parse(resultRow[0]);
                    firstincident.Channel         = getRightNowChannel(resultRow[1]);
                    firstincident.QueueName       = resultRow[2];
                    firstincident.ReferenceNumber = resultRow[3];
                    firstincident.SourceName      = resultRow[4];
                    firstincident.ContactId       = long.Parse(resultRow[5]);
                    firstincident.ContactName     = resultRow[6];
                    firstincident.ContactEmail    = resultRow[7];
                    firstincident.Subject         = resultRow[8];
                    firstincident.LastUpdate      = DateTime.Parse(resultRow[9]);
                }
            }
            catch (Exception ex) {
                _globalContext.LogMessage(string.Format("Error polling incidents: {0}", ex));
                Logger.Logger.Log.Error("RightNowObjectProvider: ", ex);
            }
            return(firstincident);
        }
Пример #5
0
        public T GetObject <T>(string predicate = null) where T : class, new()
        {
            var objectType = typeof(T);

            var objectAttribute = objectType.GetCustomAttributes(typeof(RightNowObjectAttribute), true).FirstOrDefault() as RightNowObjectAttribute;

            if (objectAttribute == null)
            {
                throw new InvalidOperationException("The type provided is not a RightNow custom object type. Please use the RightNowCustomObjectAttribute to associate the proper metadata with the type");
            }

            var query = string.Format("SELECT * from {0}.{1} {2}", objectAttribute.PackageName, objectAttribute.ObjectName, predicate ?? string.Empty);

            var request = new QueryCSVRequest(ClientHeader, query, 1, ",", false, true);

            var rightNowChannel = GetChannel();
            var result          = rightNowChannel.QueryCSV(request);

            return(MaterializeObjects <T>(result, objectType, 1).FirstOrDefault());
        }
        public IList <long> GetObjectIds(string entityName, string predicate)
        {
            var request = new QueryCSVRequest(getClientInfoHeader(),
                                              string.Format("SELECT id FROM {0} WHERE {1}", entityName, predicate), 1000, ",", false, true);

            var rightNowChannel = getChannel();

            var result = rightNowChannel.QueryCSV(request);

            var ids = new List <long>();

            if (result.CSVTableSet != null && result.CSVTableSet.CSVTables.Length > 0)
            {
                foreach (var row in result.CSVTableSet.CSVTables[0].Rows)
                {
                    var resultRow = row.Split(',');
                    ids.Add(long.Parse(resultRow[0]));
                }
            }
            return(ids);
        }
        public IList <IncidentInfo> GetPendingIncidents(DateTime cutOffTime)
        {
            var incidents = new List <IncidentInfo>();

            try
            {
                //  cutOffTime = cutOffTime.AddSeconds(_globalContext.TimeOffset);
//                var request = new QueryCSVRequest(getClientInfoHeader(),
//                    string.Format(@"SELECT
//	                                                    ID,
//	                                                    Channel,
//	                                                    Queue.Name,
//	                                                    ReferenceNumber,
//	                                                    Source.Name SourceName,
//                                                        PrimaryContact.Contact ContactId,
//                                                        PrimaryContact.Contact.Name ContactName,
//                                                        PrimaryContact.ParentContact.Emails.Address Email,
//	                                                    Subject,
//                                                        UpdatedTime
//                                                    FROM Incident
//                                                    WHERE UpdatedTime > '{0}'
//                                                    AND StatusWithType.StatusType.Id = 1
//                                                    AND AssignedTo.Account.Id IS NULL
//                                                    AND PrimaryContact.ParentContact.Emails.Address IS NOT NULL", cutOffTime.ToString("yyyy-MM-dd HH:mm:ss")),
//                    1000, ",", false, true);
                var request = new QueryCSVRequest(getClientInfoHeader(),
                                                  string.Format(@"SELECT 
	                                                    ID,
	                                                    Channel,
	                                                    Queue.Name,
	                                                    ReferenceNumber,
	                                                    Source.Name SourceName,
                                                        PrimaryContact.Contact ContactId,
                                                        PrimaryContact.Contact.Name ContactName,
                                                        PrimaryContact.ParentContact.Emails.Address Email,
	                                                    Subject,
                                                        UpdatedTime
                                                    FROM Incident
                                                    WHERE UpdatedTime > '{0}'", cutOffTime.ToString("yyyy-MM-dd HH:mm:ss")),
                                                  1000, ",", false, true);

                var rightNowChannel = getChannel();

                var result = rightNowChannel.QueryCSV(request);

                if (result.CSVTableSet != null && result.CSVTableSet.CSVTables.Length > 0)
                {
                    foreach (var row in result.CSVTableSet.CSVTables[0].Rows)
                    {
                        var resultRow = row.Split(',');
                        var incident  = new IncidentInfo
                        {
                            Id              = long.Parse(resultRow[0]),
                            Channel         = getRightNowChannel(resultRow[1]),
                            QueueName       = resultRow[2],
                            ReferenceNumber = resultRow[3],
                            SourceName      = resultRow[4],
                            ContactId       = long.Parse(resultRow[5]),
                            ContactName     = resultRow[6],
                            ContactEmail    = resultRow[7],
                            Subject         = resultRow[8],
                            LastUpdate      = DateTime.Parse(resultRow[9])
                        };
                        incidents.Add(incident);
                    }
                }
            }
            catch (Exception exc)
            {
                _globalContext.LogMessage(string.Format("Error polling incidents: {0}", exc));
                Logger.Logger.Log.Error("RightNowObjectProvider: ", exc);
            }

            return(incidents);
        }