コード例 #1
0
 private NameValueCollection GetHeadersForRequest(Item expoTvsettings)
 {
     NameValueCollection headers = new NameValueCollection();
     headers.Add("X-Expo_API_version", (expoTvsettings.FieldHasValue(Templates.VideoReviewsSettings.Fields.ApiVersion) ?
         expoTvsettings.GetString(Templates.VideoReviewsSettings.Fields.ApiVersion) : "2.0"));
     headers.Add("X-Expo_API_client_id", (expoTvsettings.FieldHasValue(Templates.VideoReviewsSettings.Fields.ClientId) ?
         expoTvsettings.GetString(Templates.VideoReviewsSettings.Fields.ClientId) : string.Empty));
     return headers;
 }
コード例 #2
0
 public virtual VideoReviews GetReviews(Item expoTvsettings, string sku)
 {
     VideoReviews videoReviewResponse = null;
     if (expoTvsettings != null && !string.IsNullOrWhiteSpace(sku))
     {
         string expoTvUrl = 
               expoTvsettings.GetString(Templates.VideoReviewsSettings.Fields.DetailedReviewURL) + "/" + sku;
         if (!string.IsNullOrWhiteSpace(expoTvUrl))
         {
             NameValueCollection headers = GetHeadersForRequest(expoTvsettings);
             string expoTvResponse = ExpoTvExternalProviderClient.GetDataFromExpoTvProvider(expoTvUrl, headers).Result;
             XDocument expoResponseDoc = XDocument.Parse(expoTvResponse);
             if (expoResponseDoc != null && expoResponseDoc.Root != null &&
                 expoResponseDoc.Root.Element("reviews") != null)
             {
                 IEnumerable<XElement> reviewItems = expoResponseDoc.Root.Element("reviews").Elements("review_item");
                 
                 videoReviewResponse = GetReviewsFromXml(reviewItems);
             }
         }
     }
     return videoReviewResponse;
 }
コード例 #3
0
ファイル: DataHandler.cs プロジェクト: zmalmquist/XBlog
        private static object GetSitecoreItemFieldValue(Type propertyType, Item item, SitecoreItemFieldAttribute attribute, bool isLazyLoad)
        {
            if (propertyType == _types[DataTypes.String])
            {
                return item.GetString(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.DateTime])
            {
                return item.GetDateTime(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.Int])
            {
                return item.GetInt(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.Double])
            {
                return item.GetDouble(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.Bool])
            {
                return item.GetBool(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.Item])
            {
                return item.GetItem(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.ItemEnumerable])
            {
                return item.GetItems(attribute.FieldId);
            }
            if (propertyType == _types[DataTypes.CustomField] || propertyType.IsSubclassOf(_types[DataTypes.CustomField]))
            {
                Field field = item.Fields[attribute.FieldId];
                if (field != null)
                    return ReflectionUtil.CreateObject(propertyType, new object[] { field });
            }
            // got to figure out a better way to do this
            if (propertyType == _types[DataTypes.SitecoreItem] || propertyType.IsSubclassOf(_types[DataTypes.SitecoreItem]))
            {
                Item fieldValueItem = item.GetItem(attribute.FieldId);
                if (fieldValueItem != null && ItemExtensions.IsItemValidForType(propertyType, fieldValueItem))
                    return TypeMapper.CreateObject(item.GetItem(attribute.FieldId), propertyType, isLazyLoad);
            }
            // got to figure out a better way to do this

            if (_types[DataTypes.SitecoreItemEnumerable].IsAssignableFrom(propertyType))
            {
                Type[] types = propertyType.GetGenericArguments();
                if (!types.Any())
                    throw new Exception("XCore needs at least one type argument");
                if (types.Count() > 1)
                    throw new Exception("XCore only supports one type argument");
                Type classType = types[0];
                Type listType = typeof(List<>).MakeGenericType(classType);
                IList list = Activator.CreateInstance(listType) as IList;
                if (list == null)
                    throw new Exception("XCore could not create a list of object type" + listType);
                foreach (Item itm in item.GetItems(attribute.FieldId))
                {
                    if (itm == null || !ItemExtensions.IsItemValidForType(classType, itm)) continue;
                    object typeObject = TypeMapper.CreateObject(itm, classType, isLazyLoad);
                    if (typeObject != null)
                        list.Add(typeObject);
                }
                return list;
            }
            return null;
        }