The arguments for a SharePoint conversion.
Inheritance: ConversionArguments
コード例 #1
0
 /// <summary>
 /// Converts the specified value back.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns>
 /// The converted value.
 /// </returns>
 public override object ConvertBack(object value, DataRowConversionArguments arguments)
 {
     var principal = value as UserValue;
     return principal != null
         ? string.Format(CultureInfo.InvariantCulture, "{0};#{1}", principal.Id, (principal.DisplayName ?? string.Empty).Replace(";", ";;"))
         : null;
 }
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, DataRowConversionArguments arguments)
        {
            var lookupValue = value as SPFieldLookupValue;

            if (value == DBNull.Value)
            {
                return null;
            }

            if (lookupValue == null)
            {
                var stringValue = value as string;
                if (!string.IsNullOrEmpty(stringValue))
                {
                    lookupValue = new SPFieldLookupValue(stringValue);
                }
            }

            if (lookupValue != null)
            {
                var lookupField = new SPFieldLookup(arguments.FieldCollection, arguments.ValueKey);

                if (lookupField.LookupWebId == Guid.Empty || lookupField.LookupWebId == arguments.Web.ID)
                {
                    return GetLookupFieldValue(arguments.Web, lookupField.LookupList, this._projectedFieldName, lookupValue.LookupId);
                }

                using (var web = arguments.Web.Site.OpenWeb(lookupField.LookupWebId))
                {
                    return GetLookupFieldValue(web, lookupField.LookupList, this._projectedFieldName, lookupValue.LookupId);
                }
            }

            return null;
        }
コード例 #3
0
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, DataRowConversionArguments arguments)
        {
            if (value == System.DBNull.Value)
            {
                return null;
            }

            TaxonomyValue convertedValue = null;

            var taxonomyFieldValue = value as TaxonomyFieldValue;

            if (taxonomyFieldValue == null)
            {
                var stringValue = value as string;
                if (!string.IsNullOrEmpty(stringValue))
                {
                    var fieldObject = arguments.FieldCollection.Cast<SPField>()
                        .FirstOrDefault(f => f.InternalName == arguments.ValueKey);

                    if (fieldObject != null)
                    {
                        taxonomyFieldValue = new TaxonomyFieldValue(fieldObject);
                        taxonomyFieldValue.PopulateFromLabelGuidPair(stringValue);
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            if (taxonomyFieldValue != null && !string.IsNullOrEmpty(taxonomyFieldValue.TermGuid))
            {
                if (SPContext.Current != null)
                {
                    // Resolve the Term from the term store, because we want all Labels and we want to
                    // create the TaxonomyValue object with a label in the correct LCID (we want one with
                    // LCID = CurrentUICUlture.LCID
                    Term underlyingTerm = this.taxonomyService.GetTermForId(SPContext.Current.Site, new Guid(taxonomyFieldValue.TermGuid));

                    if (underlyingTerm != null)
                    {
                        convertedValue = new TaxonomyValue(underlyingTerm);
                    }
                }
                else
                {
                    // We don't have access to a SPContext (needed to use the TaxonomyService), so we need to
                    // fall back on the non-UICulture-respecting TaxonomyValue constructor
                    convertedValue = new TaxonomyValue(taxonomyFieldValue);
                }
            }

            return convertedValue;
        }
コード例 #4
0
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, DataRowConversionArguments arguments)
        {
            if (value == DBNull.Value)
            {
                return null;
            }

            UserValue userValue = null;
            var sharepointUserValue = new SPFieldUserValue(arguments.Web, value as string);
            var principal = sharepointUserValue.User;
            userValue = principal != null ? new UserValue(principal) : null;

            return userValue;
        }
コード例 #5
0
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object Convert(object value, DataRowConversionArguments arguments)
        {
            if (value == DBNull.Value)
            {
                return null;
            }

            UserValue userValue = null;

            try
            {
                // TODO: this most definitely doesn't work at all.
                // Once in datarow value, the SPFieldUserValue ctor can't parse the value correctly
                var sharepointUserValue = new SPFieldUserValue(arguments.Web, value as string);
                var principal = sharepointUserValue.User;
                userValue = principal != null ? new UserValue(principal) : null;
            }
            catch (ArgumentException)
            {
                // failed to read SPUser value, will return null
            }

            return userValue;
        }
コード例 #6
0
 /// <summary>
 /// Converts the specified value back.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns>
 /// The converted value.
 /// </returns>
 public abstract object ConvertBack(object value, DataRowConversionArguments arguments);
 /// <summary>
 /// Converts the specified value back.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="arguments">The arguments.</param>
 /// <returns>
 /// The converted value.
 /// </returns>
 public override object ConvertBack(object value, DataRowConversionArguments arguments)
 {
     throw new NotSupportedException();
 }
        /// <summary>
        /// Converts the specified value back.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object ConvertBack(object value, DataRowConversionArguments arguments)
        {
            var terms = value as TaxonomyValueCollection;
            TaxonomyFieldValueCollection newTaxonomyFieldValueCollection = null;

            var taxonomyField = (TaxonomyField)arguments.FieldCollection.GetField(arguments.ValueKey);
            newTaxonomyFieldValueCollection = new TaxonomyFieldValueCollection(taxonomyField);

            var noteField = arguments.FieldCollection[taxonomyField.TextField];

            if (terms != null && terms.Count > 0)
            {
                string labelGuidPairs = string.Join(";", terms.Select(term => term.Label + "|" + term.Id).ToArray());

                // PopulateFromLabelGuidPairs takes care of looking up the WssId values and creating new items in the TaxonomyHiddenList if needed.
                // Main taxonomy field value format: WssID;#Label;WssID;#Label;WssID;#Label...
                // TODO - Make sure we support sub-level terms with format: WssID;#Label|RootTermGuid|...|ParentTermGuid|TermGuid
                // Reference: http://msdn.microsoft.com/en-us/library/ee577520.aspx
                newTaxonomyFieldValueCollection.PopulateFromLabelGuidPairs(labelGuidPairs);

                // Must write associated note field as well as the main taxonomy field.
                // Note field value format: Label|Guid;Label|Guid;Label|Guid...
                // Reference: http://nickhobbs.wordpress.com/2012/02/21/sharepoint-2010-how-to-set-taxonomy-field-values-programmatically/
                arguments.FieldValues[noteField.InternalName] = labelGuidPairs;
            }
            else
            {
                // No taxonomy value, make sure to empty the note field as well
                arguments.FieldValues[noteField.InternalName] = null;
            }

            return newTaxonomyFieldValueCollection;
        }
コード例 #9
0
        /// <summary>
        /// Converts the specified value back.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>
        /// The converted value.
        /// </returns>
        public override object ConvertBack(object value, DataRowConversionArguments arguments)
        {
            if (value == DBNull.Value)
            {
                return null;
            }

            var term = value as TaxonomyValue;
            TaxonomyFieldValue newTaxonomyFieldValue = null;

            TaxonomyField taxonomyField = (TaxonomyField)arguments.FieldCollection.GetField(arguments.ValueKey);
            newTaxonomyFieldValue = new TaxonomyFieldValue(taxonomyField);

            var noteField = arguments.FieldCollection[taxonomyField.TextField];

            if (term != null)
            {
                string labelGuidPair = term.Label + "|" + term.Id;

                // PopulateFromLabelGuidPair takes care of looking up the WssId value and creating a new item in the TaxonomyHiddenList if needed.
                // Main taxonomy field value format: WssID;#Label
                // TODO - Make sure we support sub-level terms with format: WssID;#Label|RootTermGuid|...|ParentTermGuid|TermGuid
                // Reference: http://msdn.microsoft.com/en-us/library/ee567833.aspx
                newTaxonomyFieldValue.PopulateFromLabelGuidPair(labelGuidPair);

                // Must write associated note field as well as the main taxonomy field.
                // Note field value format: Label|Guid
                // Reference: http://nickhobbs.wordpress.com/2012/02/21/sharepoint-2010-how-to-set-taxonomy-field-values-programmatically/
                arguments.FieldValues[noteField.InternalName] = labelGuidPair;
            }
            else
            {
                // No taxonomy value, make sure to empty the note field as well
                arguments.FieldValues[noteField.InternalName] = null;
            }

            return newTaxonomyFieldValue;
        }