Ejemplo n.º 1
0
        protected override void ReadData(Sitecore.DataExchange.Models.Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)
        {
            // do some null checks
            Assert.ArgumentNotNull(endpoint, nameof(endpoint));
            Assert.ArgumentNotNull(pipelineStep, nameof(pipelineStep));
            Assert.ArgumentNotNull(pipelineContext, nameof(pipelineContext));
            Assert.ArgumentNotNull(logger, nameof(logger));

            // get the configuration values for the endpoint
            var endpointSettings = endpoint.GetPlugin <JsonApiSettings>();

            if (endpointSettings == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(endpointSettings.ApiUrl))
            {
                logger.Error($"No API URL is specified on the endpoint. (pipeline step: { pipelineStep.Name }, endpoint: { endpoint.Name }");
            }

            // get the configuration values for the processor step
            var pipelineStepSettings = pipelineStep.GetPlugin <ReadPaginatedJsonApiStepSettings>();

            if (pipelineStepSettings == null)
            {
                return;
            }

            logger.Debug("Executing pipeline step: ", $"MaxCount: { pipelineStepSettings.MaxCount }", $"ResultsPerPage: { pipelineStepSettings.ResultsPerPage }", $"Page: { pipelineStepSettings.Page }", $"Offset: { pipelineStepSettings.Offset }");

            // execute the API to retrieve the data
            var uri   = new UriBuilder(endpointSettings.ApiUrl);
            var query = HttpUtility.ParseQueryString(uri.Query);

            query["per_page"] = pipelineStepSettings.ResultsPerPage.ToString();
            uri.Query         = query.ToString();

            var data = new List <JObject>();

            logger.Debug($"Executing API call { uri.Uri.AbsoluteUri }. ");
            var batch = GetDataAsync(uri.Uri.AbsoluteUri).GetAwaiter().GetResult().ToList();
            var page  = pipelineStepSettings.Page;

            while (batch.Any() && (pipelineStepSettings.MaxCount < 0 || pipelineStepSettings.MaxCount > 0 && data.Count < pipelineStepSettings.MaxCount))
            {
                data.AddRange(batch);
                page++;
                query["page"] = page.ToString();
                uri.Query     = query.ToString();
                logger.Debug($"Executing API call { uri.Uri.AbsoluteUri }. ");
                batch = GetDataAsync(uri.Uri.AbsoluteUri).GetAwaiter().GetResult().ToList();
                logger.Debug($"Retrieved { batch.Count } items.");
            }

            // add this data as a plugin to the pipeline context
            var dataSettings = new IterableDataSettings(data);

            pipelineContext.AddPlugin(dataSettings);
        }
        protected override void ReadData(
            Endpoint endpoint,
            PipelineStep pipelineStep,
            PipelineContext pipelineContext)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException("pipelinestep");
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException("pipelineContext");
            }
            var logger = pipelineContext.PipelineBatchContext.Logger;
            //
            //get the file path from the plugin on the endpoint
            var settings = endpoint.GetDatabaseSettings();

            if (settings == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(settings.ConnectionString))
            {
                logger.Error(
                    "No connection string is specified on the endpoint. " +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            var querySettings = pipelineStep.GetPlugin <QuerySettings>();

            if (string.IsNullOrWhiteSpace(querySettings.Query))
            {
                logger.Error(
                    "No query has been configured" +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            SynchronizationSettings     synchronizationSettings = pipelineContext.GetSynchronizationSettings();
            Dictionary <string, string> source = null;

            if (synchronizationSettings != null)
            {
                source = synchronizationSettings.Source as Dictionary <string, string>;
            }


            ////add the data that was read from the file to a plugin
            var dataSettings = new IterableDataSettings(GetEnumerable(settings.ConnectionType, settings.ConnectionString, querySettings.Query, source, logger));

            pipelineContext.Plugins.Add(dataSettings);
        }
Ejemplo n.º 3
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (CanProcess(pipelineStep, pipelineContext))
            {
                var identifierValue = GetIdentifierValue(pipelineStep, pipelineContext);
                if (string.IsNullOrWhiteSpace(identifierValue))
                {
                    logger.Error("Pipeline step processing will abort because no identifier value was resolved. (pipeline step: {0})", (object)pipelineStep.Name);
                }
                else
                {
                    var readJsonObjectsSettings = pipelineStep.GetPlugin <ReadJsonObjectsSettings>();
                    var endpoint = pipelineStep.GetEndpointSettings().EndpointFrom;

                    JObject jObject = ReadJsonData(endpoint, pipelineContext, readJsonObjectsSettings.Api, identifierValue);

                    var resolvedObject = ExtractObject(readJsonObjectsSettings, logger, jObject);



                    SaveResolvedObject(pipelineStep, pipelineContext, resolvedObject);
                }
            }
        }
Ejemplo n.º 4
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            var settings = pipelineStep.GetPlugin <PublishContentSettings>();

            if (settings == null)
            {
                logger.Error(
                    "No Publish Content Settings Detected. " +
                    "(pipeline step: {0})",
                    pipelineStep.Name);
                return;
            }

            Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
            Sitecore.Data.Database target = Sitecore.Configuration.Factory.GetDatabase(settings.Target);

            var rootItem = master.GetItem(new Sitecore.Data.ID(settings.RootItem));

            logger.Info("About to Start Publish");

            Sitecore.Publishing.PublishManager.PublishItem(rootItem,
                                                           new Sitecore.Data.Database[] { target },
                                                           settings.Languages.ToArray(),
                                                           settings.ChildItems,
                                                           true, //always smart publish
                                                           settings.RelatedItems);

            logger.Info("Publish Started for {0}", rootItem.Name);
        }
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            Contact contact = this.GetTargetObjectAsContact(pipelineStep, pipelineContext);

            if (contact == null)
            {
                logger.Error("Target Item is not a contact. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            if (contact.ContactId == null || contact.ContactId == Guid.Empty)
            {
                logger.Error("Contact Id does not Exist. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var settings = pipelineStep.GetPlugin <ClearFacetCollectionSettings>();

            if (settings == null)
            {
                logger.Error("Cannot access ClearFacetCollectionSettings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            //Use Reflection to get Collection
            if (!contact.Facets.Keys.Contains(settings.FacetName))
            {
                logger.Warn("Facet {0} does not exist on contact)", settings.FacetName);
                return;
            }

            var facet = contact.Facets[settings.FacetName];

            var collectionProperty = facet.GetType().GetProperty(settings.CollectionMemberName).GetValue(facet) as IElementCollection <IElement>;

            if (collectionProperty == null)
            {
                logger.Error("Member Name {0} is not a IElementCollection of IElement", settings.CollectionMemberName);
                return;
            }

            int ctnRemoved = 0;

            while (collectionProperty.Count() > 0)
            {
                collectionProperty.Remove(0);
                ctnRemoved++;
            }

            logger.Info("Removed {0} elements.", ctnRemoved);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The process.
        /// </summary>
        /// <param name="pipelineStep">
        /// The pipeline step.
        /// </param>
        /// <param name="pipelineContext">
        /// The pipeline context.
        /// </param>
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var exampleSettings = pipelineStep.GetPlugin <ExampleSettings>();

            if (exampleSettings != null)
            {
                pipelineContext.PipelineBatchContext.Logger.Info(
                    "Hello world! Create some items here..." + exampleSettings.CreatePath);
            }
        }
Ejemplo n.º 7
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var settings = pipelineStep.GetPlugin <GroupIterableDataSettings>();

            if (settings == null)
            {
                logger.Error("Cannot access ClearFacetCollectionSettings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            IterableDataSettings iterableDataSettings = pipelineContext.GetIterableDataSettings();

            if (iterableDataSettings == null || iterableDataSettings.Data == null)
            {
                return;
            }

            var groupedData = new GroupedDataSettings();

            foreach (object element in iterableDataSettings.Data)
            {
                var record = element as Dictionary <string, string>;
                if (record != null)
                {
                    if (record.ContainsKey(settings.GroupFieldKey))
                    {
                        var key = record[settings.GroupFieldKey];
                        if (!groupedData.Data.ContainsKey(key))
                        {
                            groupedData.Data.Add(key, new List <Dictionary <string, string> >());
                        }
                        groupedData.Data[key].Add(record);
                    }
                }
            }

            pipelineContext.Plugins.Add(groupedData);

            if (settings.RemoveIterableSettingsPlugin)
            {
                // This should be checked if another pipeline step is going to add settings.
                pipelineContext.Plugins.Remove(iterableDataSettings);
            }
        }
Ejemplo n.º 8
0
        protected override DropBoxFile ResolveObject(string identifierValue, Endpoint endpoint, PipelineStep pipelineStep,
                                                     PipelineContext pipelineContext)
        {
            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                return(null);
            }

            SynchronizationSettings synchronizationSettings =
                Sitecore.DataExchange.Extensions.PipelineContextExtensions.GetSynchronizationSettings(pipelineContext);


            var settings = pipelineStep.GetPlugin <DropboxSettings>();

            var itemModel = synchronizationSettings.Source as ItemModel;

            var itemId = itemModel[ItemModel.ItemID];

            var dropboxRepository = new DropBoxRepository();
            var file = new DropBoxFile(new Metadata(), settings);
            DataAccessContext context = new DataAccessContext();

            var resolveSettings = pipelineStep.GetPlugin <ResolveDropboxFileSettings>();

            file.FileName = (string)resolveSettings.ItemNameValueAccessor.ValueReader.Read(synchronizationSettings.Source, context).ReadValue;

            var metaData = dropboxRepository.GetMetadata(file);

            if (metaData == null)
            {
                var customItemRepository = new CustomItemRepository();
                file.FileStream = customItemRepository.GetMediaItemFileStream(itemModel);

                var result = dropboxRepository.Update(file).Result;
                return(file);
            }
            return(null);
        }
        protected override void ReadData(Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext,
                                         ILogger logger)
        {
            var endpointSettings = endpoint.GetPlugin <FileSettings>();

            if (string.IsNullOrWhiteSpace(endpointSettings.FilePath))
            {
                logger.Error("File name should not be empty");
                return;
            }

            var jsonSettings = pipelineStep.GetPlugin <JsonSettings>();

            if ((jsonSettings == null) || (string.IsNullOrWhiteSpace(jsonSettings.JPath)))
            {
                logger.Error("Cannot read JToken settings");
                return;
            }

            IEnumerable jarray;

            using (StreamReader file = System.IO.File.OpenText(endpointSettings.FilePath))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JToken o2 = JToken.ReadFrom(reader);
                    logger.Info("File was read");
                    JToken token = o2.SelectToken(jsonSettings.JPath);
                    if (!(token is JArray))
                    {
                        logger.Error("Element specified is not a JSon Array");
                        return;
                    }

                    jarray = (JArray)token;
                }

            if (!(jarray is IEnumerable))
            {
                logger.Error("Trying to read object, that is not an IEnumerable");
                return;
            }

            logger.Info("Data were read from file");
            var dataSettings = new IterableDataSettings()
            {
                Data = jarray
            };

            pipelineContext.AddPlugin(dataSettings);
        }
Ejemplo n.º 10
0
        public override bool CanProcess(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var canProcess = false;
            var logger     = pipelineContext.PipelineBatchContext.Logger;

            if (base.CanProcess(pipelineStep, pipelineContext))
            {
                var endpointSettings = pipelineStep.GetEndpointSettings();
                var endpointFrom     = endpointSettings.EndpointFrom;
                if (endpointFrom == null)
                {
                    logger.Error("Pipeline processing will abort because the pipeline step is missing an endpoint to read from. (pipeline step: {0}, plugin: {1}, property: {2})", pipelineStep.Name, typeof(EndpointSettings).FullName, "EndpointFrom");
                }
                else if (IsEndpointValid(endpointFrom, pipelineStep, pipelineContext))
                {
                    var synchronizationSettings = pipelineContext.GetSynchronizationSettings();
                    if (synchronizationSettings.Source == null)
                    {
                        logger.Error("Pipeline processing will abort because the pipeline context has no source assigned. (pipeline step: {0}, plugin: {1}, property: {2})", pipelineStep.Name, typeof(SynchronizationSettings).FullName, "Source");
                    }
                    else
                    {
                        var jsonServiceSettings = endpointFrom.GetPlugin <JsonServiceEndpointSettings>();
                        if (jsonServiceSettings.Host == null || jsonServiceSettings.Protocol == null)
                        {
                            logger.Error("No 'Host' or 'Protocol' is specified on the endpoint. (pipeline step: {0}, endpoint: {1})", pipelineStep.Name, endpointFrom.Name);
                        }
                        else
                        {
                            var readJsonObjectsSettings = pipelineStep.GetPlugin <ReadJsonObjectsSettings>();
                            if (readJsonObjectsSettings.Api == null)
                            {
                                logger.Error("No 'Api' is specified on the reader. (pipeline step: {0}, endpoint: {1})", pipelineStep.Name, endpointFrom.Name);
                            }
                            else
                            {
                                canProcess = true;
                            }
                        }
                    }
                }
            }
            if (!canProcess)
            {
                logger.Error("Pipeline processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", pipelineStep.Name);
                pipelineContext.CriticalError = true;
            }
            return(canProcess);
        }
Ejemplo n.º 11
0
        protected override void ReadData(Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException(nameof(pipelineStep));
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException(nameof(pipelineContext));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            var formDataProvider = (IFormDataProvider)Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService(typeof(IFormDataProvider));

            if (formDataProvider == null)
            {
                throw new Exception("IFormDataProvider is missing");
            }

            var settings = endpoint.GetFormsSettings();

            if (settings == null)
            {
                return;
            }
            var readDataSettings = pipelineStep.GetPlugin <ReadDataSettings>();

            if (readDataSettings == null || readDataSettings.FormID == Guid.Empty)
            {
                logger.Error("Form is not selected for Read Form Entries Step Processor");
                return;
            }

            var data         = this.GetIterableData(settings, readDataSettings, formDataProvider);
            var dataSettings = new IterableDataSettings(data);

            pipelineContext.AddPlugin(dataSettings);
        }
        protected override void ReadData(Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;
            var readJsonObjectsSettings = pipelineStep.GetPlugin <ReadJsonObjectsSettings>();

            //read data
            JToken jToken = ReadJsonData(endpoint, pipelineContext, readJsonObjectsSettings.Api);

            //extract array
            JArray result = ExtractArray(readJsonObjectsSettings, logger, jToken);

            logger.Info("{0} json objects were read from endpoint. (pipeline step: {1}, endpoint: {2})", result?.Count ?? 0, pipelineStep.Name, endpoint.Name);

            //add the data that was read to a plugin
            var dataSettings = new IterableDataSettings(result);

            //add the plugin to the pipeline context
            pipelineContext.Plugins.Add(dataSettings);
        }
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var settings = pipelineStep.GetPlugin <AuditDictionarySettings>();

            if (settings == null)
            {
                logger.Error("Cannot access AuditDictionarySettings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var synchronizationSettings = pipelineContext.GetSynchronizationSettings();

            if (synchronizationSettings == null)
            {
                logger.Error("Cannot access synchronizationSettings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            Dictionary <string, string> record = settings.IsSource ?
                                                 synchronizationSettings.Source as Dictionary <string, string> :
                                                 synchronizationSettings.Target as Dictionary <string, string>;

            StringBuilder sb = new StringBuilder();

            sb.Append("Audit for Pipeline Run. Dictionary located in " + settings.Context);
            sb.Append(Environment.NewLine);
            foreach (var key in record.Keys)
            {
                sb.Append(string.Format("[{0}]:[{1}],", key, record[key]));
            }
            sb.Append(Environment.NewLine);

            logger.Info(sb.ToString());
        }
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            Contact contact = this.GetTargetObjectAsContact(pipelineStep, pipelineContext);

            if (contact == null)
            {
                logger.Error("Target Item is not a contact. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            if (contact.ContactId == null || contact.ContactId == Guid.Empty)
            {
                logger.Error("Contact Id does not Exist. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var settings = pipelineStep.GetPlugin <EnrollContactInEngagementPlanSettings>();

            if (settings == null)
            {
                logger.Error("Cannot access Engagement Plan Settings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            string state       = settings.EngagementPlanStateID;
            bool   wasEnrolled = AutomationContactManager.AddContact(contact.ContactId, new Sitecore.Data.ID(state));

            if (!wasEnrolled)
            {
                logger.Warn(@"Contact Was not Enrolled (contact: {0})", contact.ContactId);
            }
        }
        private IItemModelRepository GetItemModelRepository(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            UpdateSitecoreItemSettings settings = pipelineStep.GetPlugin <UpdateSitecoreItemSettings>();

            if (settings == null)
            {
                return(null);
            }
            Endpoint endpointTo = settings.EndpointFrom;

            if (endpointTo == null)
            {
                return(null);
            }
            ItemModelRepositorySettings repositorySettings = endpointTo.GetItemModelRepositorySettings();

            if (repositorySettings == null)
            {
                return(null);
            }

            return(repositorySettings.ItemModelRepository);
        }
Ejemplo n.º 16
0
 public static ResourceSettings GetResourceSettings(this PipelineStep pipelineStep)
 {
     return(pipelineStep.GetPlugin <ResourceSettings>());
 }
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            var logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            Contact contact = this.GetTargetObjectAsContact(pipelineStep, pipelineContext);

            if (contact == null)
            {
                logger.Error("Target Item is not a contact. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            if (contact.ContactId == null || contact.ContactId == Guid.Empty)
            {
                logger.Error("Contact Id does not Exist. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            var settings = pipelineStep.GetPlugin <MapChildRecordsToFacetCollectionSettings>();

            if (settings == null)
            {
                logger.Error("Cannot access ClearFacetCollectionSettings. (pipeline step: {0})", (object)pipelineStep.Name);
                return;
            }

            //Use Reflection to get Collection
            if (!contact.Facets.Keys.Contains(settings.FacetName))
            {
                logger.Warn("Facet {0} does not exist on contact)", settings.FacetName);
                return;
            }

            var facet = contact.Facets[settings.FacetName];

            var collectionProperty = facet.GetType().GetProperty(settings.CollectionMemberName).GetValue(facet) as IElementCollection <IElement>;

            if (collectionProperty == null)
            {
                logger.Error("Member Name {0} is not a IElementCollection of IElement", settings.CollectionMemberName);
                return;
            }

            var childRecordSettings = pipelineContext.GetPlugin <ChildRecordSettings>();

            if (childRecordSettings == null)
            {
                logger.Error("No Child Records Available to Process");
                return;
            }

            foreach (var record in childRecordSettings.Records)
            {
                var newEntry = collectionProperty.Create();
                foreach (var key in record.Keys)
                {
                    try
                    {
                        newEntry.GetType().GetProperty(key).SetValue(newEntry, record[key]);
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Could not Set property {0} on facet {1} {2}. exception details: {2}", key, settings.FacetName, settings.CollectionMemberName, ex);
                        return;
                    }
                }
            }

            if (settings.RemoveChildRecordsWhenComplete)
            {
                pipelineContext.Plugins.Remove(childRecordSettings);
            }
        }
        protected override object ResolveObject(object identifierValue, Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            if (identifierValue == null)
            {
                throw new ArgumentException("The value cannot be null.", "identifierValue");
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException("pipelineStep");
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException("pipelineContext");
            }
            ItemModelRepositorySettings repositorySettings = endpoint.GetItemModelRepositorySettings();

            if (repositorySettings == null)
            {
                return((object)null);
            }
            IItemModelRepository itemModelRepository = repositorySettings.ItemModelRepository;

            if (itemModelRepository == null)
            {
                return((object)null);
            }
            ResolveSitecoreItemSettings sitecoreItemSettings = pipelineStep.GetResolveSitecoreItemSettings();

            if (sitecoreItemSettings == null)
            {
                return((object)null);
            }
            ResolveObjectSettings resolveObjectSettings = pipelineStep.GetResolveObjectSettings();

            if (resolveObjectSettings == null)
            {
                return((object)null);
            }

            ResolveSitecoreItemWithLanguageSettings languageSettings = pipelineStep.GetPlugin <ResolveSitecoreItemWithLanguageSettings>();

            if (languageSettings == null)
            {
                return((ItemModel)null);
            }



            ItemModel sourceAsItemModel = this.GetSourceObjectAsItemModel(pipelineStep, pipelineContext);

            if (sourceAsItemModel == null)
            {
                return((ItemModel)null);
            }

            var language = sourceAsItemModel[languageSettings.LanguageField].ToString();

            ILogger logger = pipelineContext.Logger;
            RepositoryObjectStatus status = RepositoryObjectStatus.DoesNotExist;
            ItemModel itemModel           = this.DoSearch(identifierValue, sitecoreItemSettings, itemModelRepository, logger, pipelineContext);

            if (itemModel != null)
            {
                this.Log(new Action <string>(pipelineContext.Logger.Debug), pipelineContext, "Item was resolved.", string.Format("identifier: {0}", identifierValue), string.Format("item id: {0}", itemModel["ItemID"]));
                Sitecore.Diagnostics.Log.Error($"Item was resolved with identifierValue: {identifierValue} item id: {itemModel["ItemID"]}", this);
                status = RepositoryObjectStatus.Exists;
            }

            if (itemModel == null && !resolveObjectSettings.DoNotCreateIfObjectNotResolved)
            {
                this.Log(new Action <string>(logger.Debug), pipelineContext, "Item was not resolved. Will create it.", string.Format("identifier: {0}", identifierValue));
                Sitecore.Diagnostics.Log.Error($"Item was not resolved. Will create it: {identifierValue} ", this);

                itemModel = this.CreateNewItem(this.GetIdentifierObject(pipelineStep, pipelineContext), itemModelRepository, sitecoreItemSettings, logger, pipelineContext, language);
                if (itemModel == null)
                {
                    this.Log(new Action <string>(logger.Error), pipelineContext, "Unable to create new item.", string.Format("identifier: {0}", identifierValue));
                    Sitecore.Diagnostics.Log.Error($"Unable to create new item with identifierValue: {identifierValue} ", this);
                }
                else
                {
                    this.Log(new Action <string>(logger.Debug), pipelineContext, "New item was created.", string.Format("identifier: {0}", identifierValue));
                    Sitecore.Diagnostics.Log.Info($"Create new item with identifierValue: {identifierValue} ", this);
                }
            }
            this.SetRepositoryStatusSettings(status, pipelineContext);
            return((object)itemModel);
        }
Ejemplo n.º 19
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            ILogger logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
            }
            else
            {
                PipelinesSettings pipelinesSettings = pipelineStep.GetPipelinesSettings();
                if (pipelinesSettings == null || !pipelinesSettings.Pipelines.Any <Pipeline>())
                {
                    logger.Error("Pipeline step processing will abort because the pipeline step has no sub-pipelines assigned. (pipeline step: {0})", (object)pipelineStep.Name);
                }
                else
                {
                    var iterateGroupedDataSettings = pipelineStep.GetPlugin <IterateThroughGroupedDataSettings>();
                    if (iterateGroupedDataSettings == null || string.IsNullOrEmpty(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Error("No Iterated Group Settings was found with configured group field key");
                        return;
                    }

                    GroupedDataSettings groupedDataSettings = pipelineContext.GetPlugin <GroupedDataSettings>();
                    if (groupedDataSettings == null || groupedDataSettings.Data == null)
                    {
                        //let's try the parent context
                        var parentSettings = pipelineContext.GetPlugin <ParentPipelineContextSettings>();
                        if (parentSettings != null)
                        {
                            groupedDataSettings = parentSettings.ParentPipelineContext.GetPlugin <GroupedDataSettings>();
                        }

                        if (groupedDataSettings == null || groupedDataSettings.Data == null)
                        {
                            logger.Error("No Grouped Data Settings was found in the pipelineContext or parent Pipeline Context ");
                        }

                        return;
                    }

                    if (!groupedDataSettings.Data.ContainsKey(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Warn("No Records Exists for Configured Key: {0}", iterateGroupedDataSettings.GroupFieldKey);
                        return;
                    }

                    int num = 0;

                    try
                    {
                        foreach (object element in groupedDataSettings.Data[iterateGroupedDataSettings.GroupFieldKey])
                        {
                            if (!pipelineContext.PipelineBatchContext.Stopped)
                            {
                                PipelineContext         pipelineContext1        = new PipelineContext(pipelineContext.PipelineBatchContext);
                                SynchronizationSettings synchronizationSettings = this.ResolveSynchronizationSettingsAndSetElement(pipelineStep, pipelineContext, element);
                                pipelineContext1.Plugins.Add((IPlugin)synchronizationSettings);
                                ParentPipelineContextSettings pipelineContextSettings = new ParentPipelineContextSettings()
                                {
                                    ParentPipelineContext = pipelineContext
                                };
                                pipelineContext1.Plugins.Add((IPlugin)pipelineContextSettings);
                                this.ProcessPipelines(pipelineStep, pipelinesSettings.Pipelines, pipelineContext1);
                            }

                            num++;
                        }


                        logger.Info("{0} elements were iterated. (pipeline: {1}, pipeline step: {2})", (object)num, (object)pipelineContext.CurrentPipeline.Name, (object)pipelineContext.CurrentPipelineStep.Name, (object)pipelineContext);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        pipelineContext.CriticalError = true;
                    }
                }
            }
        }
        protected override void ReadData(
            Endpoint endpoint,
            PipelineStep pipelineStep,
            PipelineContext pipelineContext)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException("pipelinestep");
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException("pipelineContext");
            }
            var logger = pipelineContext.PipelineBatchContext.Logger;
            //
            //get the file path from the plugin on the endpoint
            var settings = endpoint.GetExcelSettings();

            if (settings == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(settings.FileLocation))
            {
                logger.Error(
                    "No File Location is specified on the endpoint. " +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            var excelSettings = pipelineStep.GetPlugin <ReadExcelTabSettings>();

            if (string.IsNullOrWhiteSpace(excelSettings.Sheet))
            {
                logger.Error(
                    "No tab has been configured" +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }



            SynchronizationSettings     synchronizationSettings = pipelineContext.GetSynchronizationSettings();
            Dictionary <string, string> source = null;

            if (synchronizationSettings != null)
            {
                source = synchronizationSettings.Source as Dictionary <string, string>;
            }


            try
            {
                ////add the data that was read from the file to a plugin
                var dataSettings = new IterableDataSettings(GetEnumerable(settings.FileLocation, excelSettings.Sheet, excelSettings.FirstRowHasColumnNames, logger));

                pipelineContext.Plugins.Add(dataSettings);
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error($"ReadExcelTabStepProcessor: error occurred.pipelineStep: {pipelineStep.Name}, endpoint: {endpoint.Name}", ex);
                return;
            }
        }
        protected override void ReadData(
            Endpoint endpoint,
            PipelineStep pipelineStep,
            PipelineContext pipelineContext)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException("pipelineContext");
            }
            var logger = pipelineContext.PipelineBatchContext.Logger;

            UpdateSitecoreItemSettings settings = pipelineStep.GetPlugin <UpdateSitecoreItemSettings>();

            if (settings == null || settings.LanguageField == string.Empty)
            {
                logger.Error("Language Field is not set");
                throw new ArgumentException("Language Field");
            }
            var langField = settings.LanguageField;

            var itemModelRepository = this.GetItemModelRepository(pipelineStep, pipelineContext);

            if (itemModelRepository == null)
            {
                logger.Error("Item Model Repository is null");
                return;
            }

            //assume language is in source, and not necessarily mapped to target.
            ItemModel sourceAsItemModel = this.GetSourceObjectAsItemModel(pipelineStep, pipelineContext);

            if (sourceAsItemModel == null)
            {
                logger.Error("Cannot read Source Objec to determine language");
                return;
            }

            var language = sourceAsItemModel[langField].ToString();

            ItemModel objectAsItemModel = this.GetTargetObjectAsItemModel(pipelineStep, pipelineContext);

            if (objectAsItemModel == null)
            {
                logger.Error("Target Item Is not an Item Model.");
                return;
            }


            this.FixItemModel(objectAsItemModel);

            //possible enhancement, wire up Version as well (figure out how to determine latest version of item

            if (itemModelRepository.Update(objectAsItemModel.GetItemId(), objectAsItemModel, language.Trim()))
            {
                logger.Info($"UpdateSitecoreItemWithLanguageVersionStepProcessor: item update succeeded for Id:{objectAsItemModel.GetItemId()}, Language:{language}");
            }
            else
            {
                logger.Error($"UpdateSitecoreItemWithLanguageVersionStepProcessor: item update failed for Id:{objectAsItemModel.GetItemId()}, Language:{language}");
            }
        }
Ejemplo n.º 22
0
        protected override void ReadData(
            Endpoint endpoint,
            PipelineStep pipelineStep,
            PipelineContext pipelineContext)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException("pipelinestep");
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException("pipelineContext");
            }
            var logger = pipelineContext.PipelineBatchContext.Logger;
            //
            //get the file path from the plugin on the endpoint
            var settings = endpoint.GetFileSystemSettings();

            if (settings == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(settings.Path))
            {
                logger.Error(
                    "No path is specified on the endpoint. " +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            //not a file or directory
            if (!System.IO.File.Exists(settings.Path) && !Directory.Exists(settings.Path))
            {
                logger.Error(
                    "The path specified on the endpoint does not exist. " +
                    "(pipeline step: {0}, endpoint: {1}, path: {2})",
                    pipelineStep.Name, endpoint.Name, settings.Path);
                return;
            }

            var moveSettings = pipelineStep.GetPlugin <MoveFileSettings>();

            if (moveSettings == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(moveSettings.DestinationDirectory))
            {
                //logger.Error(
                //    "The path specified on the endpoint does not exist. " +
                //    "(pipeline step: {0}, endpoint: {1}, path: {2})",
                //    pipelineStep.Name, endpoint.Name, settings.Path);
                return;
            }

            //TODO the copy or move and renaming

            //logger.Info(
            //    "{0} rows were read from the file. (pipeline step: {1}, endpoint: {2})",
            //    lines.Count, pipelineStep.Name, endpoint.Name);
        }
Ejemplo n.º 23
0
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            if (pipelineStep == null)
            {
                throw new ArgumentNullException(nameof(pipelineStep));
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException(nameof(pipelineContext));
            }

            var xml = pipelineContext.GetPlugin <SynchronizationSettings>();

            XmlNode xmlData = (XmlNode)xml.Source;

            if (null == xmlData)
            {
                return;
            }
            var childnodeSettings = pipelineStep.GetPlugin <ProcessChildSettings>();

            if (null == childnodeSettings)
            {
                return;
            }

            var           xmlNodes = xmlData.SelectNodes(childnodeSettings.Xpath);
            string        itemName = xmlData.Attributes["itemName"].Value;
            List <string> lstLang  = null;

            string parentPath = string.Empty;

            foreach (var step in pipelineContext.CurrentPipeline.PipelineSteps)
            {
                if (step.PipelineStepProcessor.GetType().UnderlyingSystemType.FullName == "Sitecore.DataExchange.Providers.Sc.Processors.PipelineSteps.ResolveMultilanguageSitecoreItemDictionaryPipelineStep")
                {
                    foreach (var plugin in step.Plugins)
                    {
                        if (plugin.GetType().Name == "ResolveSitecoreItemSettings")
                        {
                            ResolveSitecoreItemSettings settings = (ResolveSitecoreItemSettings)plugin;

                            Item parentItem = dbContext.GetItem(new ID(settings.ParentItemIdItem.ToString()));
                            parentPath = parentItem.Paths.FullPath;
                        }
                    }
                }
                else if (step.PipelineStepProcessor.GetType().UnderlyingSystemType.FullName == "Sitecore.DataExchange.Providers.Sc.Processors.PipelineSteps.SelectLanguagesPipelineStep")
                {
                    foreach (var plugin in step.Plugins)
                    {
                        if (plugin.GetType().Name == "SelectedLanguagesSettings")
                        {
                            lstLang = ((SelectedLanguagesSettings)plugin).Languages.ToList();
                        }
                    }
                }
            }

            if ((!string.IsNullOrEmpty(parentPath)) && lstLang != null)
            {
                foreach (string lang in lstLang)
                {
                    Item item = dbContext.GetItem(string.Format("{0}/{1}", parentPath, itemName), Sitecore.Globalization.Language.Parse(lang));

                    if (item != null)
                    {
                        if (item.Name == item.Fields["Identifier"].Value.ToString())
                        {
                            ChildItemCreatorML obj = new ChildItemCreatorML(xmlData.OuterXml, item.ID.ToString(), lang);
                            obj.CreateChildItems();

                            ItemRendering.AddRenderings(item);
                        }

                        if (item.Name != item.Fields["Identifier"].Value.ToString())
                        {
                            item.Versions.RemoveVersion();
                        }
                    }
                }
            }
        }
        public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            ILogger logger = pipelineContext.PipelineBatchContext.Logger;

            if (!this.CanProcess(pipelineStep, pipelineContext))
            {
                logger.Error("Pipeline step processing will abort because the pipeline step cannot be processed. (pipeline step: {0})", (object)pipelineStep.Name);
            }
            else
            {
                PipelinesSettings pipelinesSettings = pipelineStep.GetPipelinesSettings();
                if (pipelinesSettings == null || !pipelinesSettings.Pipelines.Any <Pipeline>())
                {
                    logger.Error("Pipeline step processing will abort because the pipeline step has no sub-pipelines assigned. (pipeline step: {0})", (object)pipelineStep.Name);
                }
                else
                {
                    var iterateGroupedDataSettings = pipelineStep.GetPlugin <IterateThroughGroupedDataSettings>();
                    if (iterateGroupedDataSettings == null || string.IsNullOrEmpty(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Error("No Iterated Group Settings was found with configured group field key");
                        return;
                    }

                    GroupedDataSettings groupedDataSettings = pipelineContext.GetPlugin <GroupedDataSettings>();
                    if (groupedDataSettings == null || groupedDataSettings.Data == null)
                    {
                        //let's try the parent context
                        var parentSettings = pipelineContext.GetPlugin <ParentPipelineContextSettings>();
                        if (parentSettings != null)
                        {
                            groupedDataSettings = parentSettings.ParentPipelineContext.GetPlugin <GroupedDataSettings>();
                        }

                        if (groupedDataSettings == null || groupedDataSettings.Data == null)
                        {
                            logger.Error("No Grouped Data Settings was found in the pipelineContext or parent Pipeline Context ");
                            return;
                        }
                    }

                    var parentSyncSettings = pipelineContext.GetPlugin <SynchronizationSettings>();
                    var source             = parentSyncSettings.Source as Dictionary <string, string>;
                    if (source == null || !source.ContainsKey(iterateGroupedDataSettings.GroupFieldKey))
                    {
                        logger.Warn("Group Field Key {0} doesn;t exist in source.", iterateGroupedDataSettings.GroupFieldKey);
                        return;
                    }

                    var groupValue = source[iterateGroupedDataSettings.GroupFieldKey];

                    int num = 0;

                    try
                    {
                        var childRecordSettings = new ChildRecordSettings();

                        foreach (object element in groupedDataSettings.Data[groupValue])
                        {
                            if (!pipelineContext.PipelineBatchContext.Stopped)
                            {
                                PipelineContext         pipelineContext1        = new PipelineContext(pipelineContext.PipelineBatchContext);
                                SynchronizationSettings synchronizationSettings = this.ResolveSynchronizationSettingsAndSetElement(pipelineStep, pipelineContext, element);

                                //instatiate Target for filling.
                                synchronizationSettings.Target = new Dictionary <string, string>();

                                pipelineContext1.Plugins.Add((IPlugin)synchronizationSettings);
                                ParentPipelineContextSettings pipelineContextSettings = new ParentPipelineContextSettings()
                                {
                                    ParentPipelineContext = pipelineContext
                                };
                                pipelineContext1.Plugins.Add((IPlugin)pipelineContextSettings);
                                this.ProcessPipelines(pipelineStep, pipelinesSettings.Pipelines, pipelineContext1);

                                var record = pipelineContext1.GetPlugin <SynchronizationSettings>().Target as Dictionary <string, string>;
                                if (record != null)
                                {
                                    childRecordSettings.Records.Add(record);
                                }
                            }

                            num++;
                        }

                        pipelineContext.Plugins.Add(childRecordSettings);

                        logger.Info("{0} elements were iterated. (pipeline: {1}, pipeline step: {2})", (object)num, (object)pipelineContext.CurrentPipeline.Name, (object)pipelineContext.CurrentPipelineStep.Name, (object)pipelineContext);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                        pipelineContext.CriticalError = true;
                    }
                }
            }
        }