Exemplo n.º 1
0
    /// <summary>
    /// Get the transformation to interpret task related object data.
    /// </summary>
    /// <param name="row">Grid row</param>
    /// <returns>Transformation that displays object identified by object type and ID.</returns>
    private object RenderRelatedObject(DataRowView row)
    {
        if (row == null)
        {
            return(String.Empty);
        }

        int    objectId    = ValidationHelper.GetInteger(row.Row["SearchTaskRelatedObjectID"], 0);
        string taskTypeRaw = ValidationHelper.GetString(row.Row["SearchTaskType"], "");

        SearchTaskTypeEnum taskType;
        string             objectType = null;


        // try to get search task type. Type doesn't have a default value.
        try
        {
            taskType = ValidationHelper.GetString(taskTypeRaw, "").ToEnum <SearchTaskTypeEnum>();
        }
        catch (Exception ex)
        {
            EventLogProvider.LogEvent(
                EventType.ERROR,
                "Smart search",
                "LISTSEARCHTASKS",
                "Unknown search task type: " + taskTypeRaw + ". Original exception:" + Environment.NewLine + EventLogProvider.GetExceptionLogMessage(ex)
                );

            return(String.Empty);
        }

        // Object type
        objectType = SearchTaskInfoProvider.GetSearchTaskRelatedObjectType(ValidationHelper.GetString(row.Row["SearchTaskObjectType"], ""), taskType);

        // Object cannot be interpreted
        if (String.IsNullOrEmpty(objectType) || (objectId == 0))
        {
            return(String.Empty);
        }

        // create transformation
        ObjectTransformation transformation = new ObjectTransformation(objectType, objectId);

        transformation.Transformation = String.Format("{{% Object.GetFullObjectName(false, true) %}}");

        ObjectTypeInfo typeInfo = ObjectTypeManager.GetTypeInfo(objectType);

        if (typeInfo != null)
        {
            transformation.NoDataTransformation = LocalizationHelper.GetStringFormat("smartsearch.searchtaskrelatedobjectnotexist", typeInfo.GetNiceObjectTypeName(), objectId);
        }

        return(transformation);
    }