Ejemplo n.º 1
0
        protected override ResourceSaveOperation CreateSaveOperationForItem(IStorage storage, CatalogContext context, CatalogItem item, CancellationToken cancellationToken)
        {
            // This method decides what to do with the item.
            // If it's a RegistrationMakerCatalogItem and it already exists, then don't write content.
            var registrationMakerCatalogItem = item as RegistrationMakerCatalogItem;

            if (registrationMakerCatalogItem != null)
            {
                var content     = item.CreateContent(Context); // note: always do this first
                var resourceUri = item.GetItemAddress();

                var saveOperation = new ResourceSaveOperation();
                saveOperation.ResourceUri = resourceUri;

                if (!registrationMakerCatalogItem.IsExistingItem && content != null)
                {
                    saveOperation.SaveTask = storage.SaveAsync(resourceUri, content, cancellationToken);
                }
                else
                {
                    Trace.WriteLine(string.Format("Resource {0} already exists. Skipping.", resourceUri), "Debug");
                }

                return(saveOperation);
            }

            return(base.CreateSaveOperationForItem(storage, context, item, cancellationToken));
        }
        protected override ResourceSaveOperation CreateSaveOperationForItem(IStorage storage, CatalogContext context, CatalogItem item, CancellationToken cancellationToken)
        {
            // This method decides what to do with the item.
            // If it's a RegistrationMakerCatalogItem and it already exists, then don't write content.
            var registrationMakerCatalogItem = item as RegistrationMakerCatalogItem;
            if (registrationMakerCatalogItem != null)
            {
                var content = item.CreateContent(Context); // note: always do this first
                var resourceUri = item.GetItemAddress();

                var saveOperation = new ResourceSaveOperation();
                saveOperation.ResourceUri = resourceUri;

                if (!registrationMakerCatalogItem.IsExistingItem && content != null)
                {
                    saveOperation.SaveTask = storage.Save(resourceUri, content, cancellationToken);
                }
                else
                {
                    Trace.WriteLine(string.Format("Resource {0} already exists. Skipping.", resourceUri), "Debug");
                }

                return saveOperation;
            }

            return base.CreateSaveOperationForItem(storage, context, item, cancellationToken);
        }