Exemplo n.º 1
0
        // Determines if the item is a Product item.
        private Boolean canProcessItem(ID id)
        {
            var idTable = IDTable.GetKeys(IDTablePrefix, id);
            var result  = (idTable != null && idTable.Length > 0);

            Trace.WriteLineIf(result, String.Format("{0} can be processed.", id), "ProductDataProvider");
            return(result);
        }
Exemplo n.º 2
0
        private bool CanProcessItem(ID id, CallContext context)
        {
            if (IDTable.GetKeys(this.IdTablePrefix, id).Length > 0)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
 public override bool BlobStreamExists(Guid blobId, CallContext context)
 {
     IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, new ID(blobId));
     if (idList.Length > 0)
     {
         context.Abort();
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
 {
     IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, itemDefinition.ID);
     if (idList.Length > 0)
     {
         context.Abort();
         return(ID.Parse(_parentItem));
     }
     return(base.GetParentID(itemDefinition, context));
 }
Exemplo n.º 5
0
        private static IDTableEntry GetEntry(string prefix, ID itemId)
        {
            var keys = IDTable.GetKeys(prefix, itemId);

            if (keys == null || keys.Length == 0)
            {
                return(null);
            }
            return(keys[0]);
        }
Exemplo n.º 6
0
        private string GetIdTableExternalKey(ID id, string prefix)
        {
            var idEntries = IDTable.GetKeys(prefix, id);

            if (idEntries == null || !idEntries.Any() || string.IsNullOrEmpty(idEntries[0].Key))
            {
                return(null);
            }

            return(idEntries[0].Key);
        }
Exemplo n.º 7
0
 public override Stream GetBlobStream(Guid blobId, CallContext context)
 {
     IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, new ID(blobId));
     if (idList.Length > 0)
     {
         IDTableEntry mappedID = idList[0];
         context.Abort();
         return(GetThumbnailStream(mappedID.Key));
     }
     return(null);
 }
Exemplo n.º 8
0
        protected virtual Guid GenerateId(T externalItem)
        {
            Guid value = ToGuid(externalItem.Name);

            if (IDTable.GetKeys(IdTablePrefix, new ID(value)).Any())
            {
                return(Guid.NewGuid());
            }

            return(value);
        }
Exemplo n.º 9
0
        public override Sitecore.Data.FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, itemDefinition.ID);
            if (idList.Length > 0)
            {
                IDTableEntry mappedID = idList[0];
                context.Abort();
                XmlNode   video = VideoData.SelectSingleNode("/response/videos/video[@key='" + mappedID.Key + "']");
                FieldList list  = new FieldList();
                list.Add(ID.Parse(DISPLAY_NAME_FIELD), video[BOTR_TITLE].InnerText);
                list.Add(ID.Parse(VIDEO_KEY_FIELD), mappedID.Key);
                list.Add(ID.Parse(STATUS_FIELD), video[BOTR_STATUS].InnerText);
                list.Add(ID.Parse(BLOB_FIELD), itemDefinition.ID.ToString());
                list.Add(ID.Parse(TITLE_FIELD), video[BOTR_TITLE].InnerText);
                list.Add(ID.Parse(DESCRIPTION_FIELD), video[BOTR_DESCRIPTION].InnerText);
                list.Add(ID.Parse(KEYWORDS_FIELD), video[BOTR_TAGS].InnerText);
                list.Add(ID.Parse(ALT_FIELD), video[BOTR_TITLE].InnerText);
                list.Add(ID.Parse(EXTENSION_FIELD), EXTENSION);
                list.Add(ID.Parse(MIME_TYPE_FIELD), MIME_TYPE);
                list.Add(ID.Parse(VIDEO_URL_FIELD), video[BOTR_LINK].InnerText);
                XmlNode custom = video[BOTR_CUSTOM];
                if (custom != null && custom[BOTR_CUSTOM_LINK] != null)
                {
                    list.Add(ID.Parse(VIDEO_CUSTOM_URL_FIELD), custom[BOTR_CUSTOM_LINK].InnerText);
                }

                double videoTimestamp = Double.Parse(video[BOTR_DATE].InnerText);
                string videoDate      = Sitecore.DateUtil.ToIsoDate(UnixDateTime.FromUnixTimestamp(videoTimestamp));
                list.Add(ID.Parse(CREATED_FIELD), videoDate);
                list.Add(ID.Parse(UPDATED_FIELD), videoDate);

                //BotR puts width/height data with conversion data. just need the aspect ratio, so grab the first one in the doc
                XmlDocument conversionData  = GetVideoConversionData(mappedID.Key);
                XmlNode     videoConversion = conversionData.SelectSingleNode("/response/conversions/conversion");
                if (videoConversion != null)
                {
                    string heightStr = videoConversion[BOTR_HEIGHT].InnerText;
                    string widthStr  = videoConversion[BOTR_WIDTH].InnerText;
                    double height    = 0;
                    double width     = 0;
                    Double.TryParse(heightStr, out height);
                    Double.TryParse(widthStr, out width);
                    if (height != 0 && width != 0)
                    {
                        int thumbHeight = (int)(THUMBNAIL_SIZE * (height / width));
                        list.Add(ID.Parse(WIDTH_FIELD), THUMBNAIL_SIZE.ToString());
                        list.Add(ID.Parse(HEIGHT_FIELD), thumbHeight.ToString());
                    }
                }
                return(list);
            }
            return(base.GetItemFields(itemDefinition, versionUri, context));
        }
Exemplo n.º 10
0
        public override bool SaveItem(ItemDefinition itemDefinition, ItemChanges changes, CallContext context)
        {
            foreach (FieldChange change in changes.FieldChanges)
            {
                if (ShouldApplyChangeToDataStore(change))
                {
                    SaveChangeToDataStore(change, IDTable.GetKeys(IdTablePrefix, itemDefinition.ID).FirstOrDefault().Key);
                }
            }

            return(base.SaveItem(itemDefinition, changes, context));
        }
Exemplo n.º 11
0
        // Get's the parent id
        private ID getParentId(ID childId)
        {
            var keys = IDTable.GetKeys(IDTablePrefix, childId);

            if (keys != null && keys.Length > 0)
            {
                Trace.WriteLine(String.Format("{0}'s parent is {1}", childId, keys[0].ParentID), "ProductDataProvider");
                return(keys[0].ParentID);
            }
            Trace.WriteLine(String.Format("{0} doesn't have a parent", childId), "ProductDataProvider");
            return(null);
        }
Exemplo n.º 12
0
        private static IDTableEntry UpdateOrCreateIDTableEntry(string prefix, string key, ID id, ID parentId, string customData)
        {
            var keys = IDTable.GetKeys(prefix, id);

            if (keys != null && keys.Length > 0)
            {
                var entry = keys[0];
                if (entry.ParentID == parentId && string.Equals(entry.CustomData, customData))
                {
                    return(entry);
                }
                IDTable.RemoveID(prefix, id);
            }
            return(IDTable.Add(prefix, key, id, parentId, customData));
        }
Exemplo n.º 13
0
 public override VersionUriList GetItemVersions(ItemDefinition item, CallContext context)
 {
     IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, item.ID);
     if (idList.Length > 0)
     {
         context.Abort();
         VersionUriList     versions  = new VersionUriList();
         LanguageCollection languages = Sitecore.Data.Managers.LanguageManager.GetLanguages(this.Database);
         foreach (Language language in languages)
         {
             versions.Add(language, new Sitecore.Data.Version(1));
         }
         return(versions);
     }
     return(null);
 }
Exemplo n.º 14
0
        // From the Sitecore ID, get the original ID of the entity.
        private Guid getExternalId(ID id)
        {
            var tableEntries = IDTable.GetKeys(IDTablePrefix, id);

            if (tableEntries != null && tableEntries.Length > 0)
            {
                Guid guid;
                if (Guid.TryParse(tableEntries[0].Key, out guid))
                {
                    Trace.WriteLine(String.Format("{0} (in sitecore) == {1} (repository)", id, guid, "ProductRepository"));
                    return(guid);
                }
            }
            Trace.WriteLine(String.Format("{0} doesn't have a repository entry", id), "ProductDataProvider");
            return(Guid.Empty);
        }
Exemplo n.º 15
0
        public override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
        {
            if (this.CanProcessItem(itemDefinition.ID, context))
            {
                context.Abort();

                IDTableEntry[] idEntries = IDTable.GetKeys(this.IdTablePrefix, itemDefinition.ID);

                if (idEntries != null && idEntries.Length > 0)
                {
                    return(idEntries[0].ParentID);
                }

                return(null);
            }

            return(base.GetParentID(itemDefinition, context));
        }
Exemplo n.º 16
0
        public IDTableEntry[] GetKeys(string prefix, ID id)
        {
            var key = new IdTableIdKey(prefix, id.Guid);

            //if (_idById.ContainsKey(key))
            //{
            //    return _idById[key].ToArray();
            //}

            _idById[key] = IDTable.GetKeys(prefix, id).ToList();

            if (_idById.ContainsKey(key))
            {
                return(_idById[key].ToArray());
            }

            return(new IDTableEntry[0]);
        }
Exemplo n.º 17
0
 public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
 {
     IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, itemId);
     if (idList.Length > 0)
     {
         IDTableEntry mappedID = idList[0];
         context.Abort();
         XmlNode video = VideoData.SelectSingleNode("/response/videos/video[@key='" + mappedID.Key + "']");
         if (video == null)
         {
             IDTable.RemoveID(ID_TABLE_PREFIX, mappedID.ID);
             return(null);
         }
         ItemDefinition videoItem = new ItemDefinition(itemId, mappedID.Key, ID.Parse(TEMPLATE), ID.Null);
         return(videoItem);
     }
     return(base.GetItemDefinition(itemId, context));
 }
Exemplo n.º 18
0
 public override bool DeleteItem(ItemDefinition itemDefinition, CallContext context)
 {
     IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, itemDefinition.ID);
     if (idList.Length > 0)
     {
         IDTableEntry mappedID = idList[0];
         context.Abort();
         XmlDocument response = CallApi("/videos/delete", new Dictionary <string, string> {
             { BOTR_VIDEO_KEY, mappedID.Key }
         });
         XmlNode status = response.SelectSingleNode("/response/status");
         if (status != null && status.InnerText.ToLower() == "ok")
         {
             Cache.Clear();
             return(true);
         }
         return(false);
     }
     return(false);
 }
Exemplo n.º 19
0
        private void UpdateSelectedCategories(FieldChange fieldChange, Product product)
        {
            var selectedSitecoreCategoryIds = fieldChange.Value.Split('|');
            var selectedCategories          = new List <Category>();

            // Find categories from the sitecore ids
            foreach (var selectedSitecoreCategoryId in selectedSitecoreCategoryIds)
            {
                var categoryIdKeys = IDTable.GetKeys(SitecoreConstants.SitecoreIdTablePrefix, ID.Parse(selectedSitecoreCategoryId));

                foreach (var categoryIdKey in categoryIdKeys)
                {
                    var categoryId = Convert.ToInt32(categoryIdKey.Key.Split(';').Last());
                    selectedCategories.Add(Category.Get(categoryId));
                }
            }

            var existingRelations = CategoryProductRelation.Find(x => x.Product.ProductId == product.ProductId)
                                    .Select(x => x.Category.CategoryId).ToList();

            // Removing not selected categories
            var categoryIdsToBeRemoved = existingRelations.Except(selectedCategories.Select(x => x.CategoryId)).ToList();
            var categoriesToBeRemoved  = Category.Find(x => categoryIdsToBeRemoved.Contains(x.CategoryId)).ToList();

            foreach (var categoryToBeRemoved in categoriesToBeRemoved)
            {
                _loggingService.Log <ProductTemplatesBuilder>("Removing category " + categoryToBeRemoved.Name);
                product.RemoveCategory(categoryToBeRemoved);
            }

            // Adding new selected categories
            var categoriesToBeAdded = selectedCategories.Where(x => !existingRelations.Contains(x.CategoryId)).ToList();

            foreach (var categoryToBeAdded in categoriesToBeAdded)
            {
                _loggingService.Log <ProductTemplatesBuilder>("Adding category " + categoryToBeAdded.Name);
                categoryToBeAdded.AddProduct(product, 0);
            }
        }
 private static IEnumerable <IDTableEntry> GetAllUCommerceIdTableEntries()
 {
     return(IDTable.GetKeys("uCommerceDataProvider"));
 }
Exemplo n.º 21
0
 private List <IDTableEntry> GetEntries(string prefix, ID parentId)
 {
     return(IDTable.GetKeys(prefix).Where(x => x.ParentID == parentId).ToList());
 }
Exemplo n.º 22
0
        public override bool SaveItem(ItemDefinition itemDefinition, Sitecore.Data.Items.ItemChanges changes, CallContext context)
        {
            IDTableEntry[] idList = IDTable.GetKeys(ID_TABLE_PREFIX, itemDefinition.ID);
            if (idList.Length > 0 && changes.HasFieldsChanged)
            {
                IDTableEntry mappedID = idList[0];
                context.Abort();

                var values = new Dictionary <string, string>();
                values.Add(BOTR_VIDEO_KEY, mappedID.Key);

                FieldChangeList fieldChanges = changes.FieldChanges;
                lock (fieldChanges.SyncRoot)
                {
                    foreach (FieldChange change in fieldChanges)
                    {
                        if (change.FieldID == ID.Parse(DISPLAY_NAME_FIELD) || change.FieldID == ID.Parse(TITLE_FIELD) || change.FieldID == ID.Parse(ALT_FIELD))
                        {
                            values[BOTR_TITLE] = change.Value;
                        }
                        else if (change.FieldID == ID.Parse(DESCRIPTION_FIELD))
                        {
                            values[BOTR_DESCRIPTION] = change.Value;
                        }
                        else if (change.FieldID == ID.Parse(KEYWORDS_FIELD))
                        {
                            values[BOTR_TAGS] = change.Value;
                        }
                        else if (change.FieldID == ID.Parse(VIDEO_CUSTOM_URL_FIELD))
                        {
                            Sitecore.Links.UrlOptions options = Sitecore.Links.UrlOptions.DefaultOptions;
                            options.Site = Sitecore.Sites.SiteContextFactory.GetSiteContext(_vodeoLinkSite);
                            options.AlwaysIncludeServerUrl = false;
                            values[BOTR_CUSTOM + "." + BOTR_CUSTOM_LINK] = change.Value;
                            if (change.RemoveField || string.IsNullOrEmpty(change.Value))
                            {
                                values[BOTR_LINK] = string.Empty;
                            }
                            else
                            {
                                values[BOTR_LINK] = "http://" +
                                                    Sitecore.StringUtil.RemovePostfix('/', this._videoLinkHost) +
                                                    Sitecore.Links.LinkManager.GetItemUrl(context.DataManager.Database.GetItem(ID.Parse(change.Value)), options);
                            }
                        }
                        else if (change.FieldID == ID.Parse(CREATED_FIELD))
                        {
                            values[BOTR_DATE] = Sitecore.DateUtil.IsoDateToDateTime(change.Value).ToUnixTimestamp().ToString();
                        }
                    }

                    XmlDocument response = CallApi("/videos/update", values);
                    XmlNode     status   = response.SelectSingleNode("/response/status");
                    if (status != null && status.InnerText.ToLower() == "ok")
                    {
                        Cache.Clear();
                        return(true);
                    }
                }
                return(false);
            }
            return(false);
        }
 public IDTableEntry[] GetKeys(string prefix, ID id)
 {
     return(IDTable.GetKeys(prefix, id));
 }
Exemplo n.º 24
0
        private static bool IsItem(string prefix, ID itemId)
        {
            var keys = IDTable.GetKeys(prefix, itemId);

            return(keys != null && keys.Length > 0);
        }