Esempio n. 1
0
        /// <summary>
        /// Gets the time zone name from time zone.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="timeZoneId">The time zone id.</param>
        /// <param name="context">The context.</param>
        /// <param name="incidentId">The incident.</param>
        /// <returns>Get Offset</returns>
        public static string GetTimeZoneNameFromTimeZone(IOrganizationService service, Guid buildingId)
        {
            int    optionsetValue;
            string optionsetText = string.Empty;

            try
            {
                if (service != null)
                {
                    QueryExpression timezonequery = new QueryExpression()
                    {
                        EntityName = "smp_timezone",
                        ColumnSet  = new ColumnSet("smp_offset")
                    };
                    timezonequery.AddLink("smp_building", "smp_timezoneid", "smp_timezoneid", JoinOperator.Inner)
                    .LinkCriteria.AddCondition("smp_buildingid", ConditionOperator.Equal, buildingId);
                    EntityCollection zoneNames = service.RetrieveMultiple(timezonequery);
                    if (zoneNames.Entities.Count > 0)
                    {
                        optionsetValue = ((OptionSetValue)zoneNames.Entities[0]["smp_offset"]).Value;
                        optionsetText  = GetOptionsSetTextOnValue(service, "smp_timezone", "smp_offset", optionsetValue);
                    }
                }

                return(optionsetText);
            }
            catch (Exception ex)
            {
                CustomServiceManagementPortalException customEx = new CustomServiceManagementPortalException("Exception while getting offset from Time Zone", ex);
                throw customEx;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the options set text on value.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="selectedValue">The selected value.</param>
        /// <returns>Option Set Value</returns>
        public static string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
        {
            try
            {
                RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
                {
                    EntityLogicalName     = entityName,
                    LogicalName           = attributeName,
                    RetrieveAsIfPublished = true
                };
                //// Execute the request.
                RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
                //// Access the retrieved attribute.

                Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)

                                                                                                          retrieveAttributeResponse.AttributeMetadata; //// Get the current options list for the retrieved attribute.
                OptionMetadata[] optionList          = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
                string           selectedOptionLabel = string.Empty;
                foreach (OptionMetadata oMD in optionList)
                {
                    if (oMD.Value == selectedValue)
                    {
                        selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label;
                    }
                }

                return(selectedOptionLabel);
            }
            catch (Exception ex)
            {
                CustomServiceManagementPortalException customEx = new CustomServiceManagementPortalException("Error while getting time zone offset text.", ex);
                throw customEx;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Writes the specified exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="exceptionType">Type of the exception.</param>
        /// <param name="service">The service.</param>
        /// <param name="referencedEntityName">Name of the referenced entity.</param>
        /// <param name="referencedFieldName">Name of the referenced field.</param>
        /// <param name="referencedId">The referenced id.</param>
        /// <param name="missingData">The missing data.</param>
        public static void Write(Exception exception, ExceptionType exceptionType, IOrganizationService service, string referencedEntityName, string referencedFieldName, Guid?referencedId, string missingData)
        {
            try
            {
                if (service != null && exception != null && exceptionType != ExceptionType.None)
                {
                    Entity exceptionLog = new Entity();
                    exceptionLog.LogicalName          = "smp_exceptionlog";
                    exceptionLog["smp_exceptiontype"] = new OptionSetValue((int)exceptionType);
                    if (exception.ToString().Length > 1999)
                    {
                        exceptionLog["smp_exceptiondetails"] = exception.ToString().Substring(0, 1999);
                    }
                    else
                    {
                        exceptionLog["smp_exceptiondetails"] = exception.ToString();
                    }

                    if (!string.IsNullOrWhiteSpace(exception.Message))
                    {
                        if (exception.Message.Length > 99)
                        {
                            exceptionLog["smp_description"] = exception.Message.Substring(0, 99);
                        }
                        else
                        {
                            exceptionLog["smp_description"] = exception.Message;
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(missingData))
                    {
                        exceptionLog["smp_missingdatadetails"] = missingData;
                    }

                    if (referencedId.HasValue)
                    {
                        exceptionLog[referencedFieldName] = new EntityReference(referencedEntityName, referencedId.Value);
                    }

                    service.Create(exceptionLog);
                }
            }
            catch (Exception ex)
            {
                CustomServiceManagementPortalException customEx = new CustomServiceManagementPortalException("Error occurred while logging", ex);
                throw customEx;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the priority hours.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="priorityId">The priority id.</param>
        /// <param name="context">The context.</param>
        /// <param name="incidentId">The incident.</param>
        /// <returns>Get Priority hours.</returns>
        public static int GetPriorityHours(IOrganizationService service, ITracingService tracingService, Guid priorityId)
        {
            int hours = 0;

            try
            {
                if (service != null)
                {
                    Entity priority = service.Retrieve("smp_priority", priorityId, new ColumnSet("smp_noofminutes"));
                    if (priority != null)
                    {
                        hours = priority.Attributes.Contains("smp_noofminutes") ? Convert.ToInt32(priority.Attributes["smp_noofminutes"]) : 0;
                    }
                }

                return(hours);
            }
            catch (Exception ex)
            {
                tracingService.Trace("Error while getting priority minutes." + " ----Error Message----" + ex.Message + " -----Stack Trace---- " + ex.StackTrace);
                CustomServiceManagementPortalException customEx = new CustomServiceManagementPortalException("Error while getting priority minutes.", ex);
                throw customEx;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the time zone id from building.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="buildingId">The building id.</param>
        /// <param name="incidentId">The incident.</param>
        /// <returns>Time Zone Id.</returns>
        public static string GetTimeZoneIdFromBuilding(IOrganizationService service, Guid buildingId, Guid incidentId)
        {
            Guid   timeZoneID           = Guid.Empty;
            string timeZoneDetails      = string.Empty;
            string finalcialStateCampus = string.Empty;

            try
            {
                if (service != null)
                {
                    Entity buildiing = service.Retrieve("smp_building", buildingId, new ColumnSet("smp_timezoneid", "smp_isfinancialstatecampus"));
                    if (buildiing != null)
                    {
                        if (buildiing.Attributes.Contains("smp_timezoneid"))
                        {
                            timeZoneID = ((Microsoft.Xrm.Sdk.EntityReference)buildiing.Attributes["smp_timezoneid"]).Id;
                        }

                        if (buildiing.Attributes.Contains("smp_isfinancialstatecampus"))
                        {
                            finalcialStateCampus = buildiing.Attributes["smp_isfinancialstatecampus"].ToString();
                        }

                        timeZoneDetails = timeZoneID + "@" + finalcialStateCampus;
                    }
                }

                return(timeZoneDetails);
            }
            catch (Exception ex)
            {
                PopulateExceptionLog(ex, service, incidentId);
                CustomServiceManagementPortalException customEx = new CustomServiceManagementPortalException("Exception while getting time zone details from building", ex);
                throw customEx;
            }
        }