Exemplo n.º 1
0
        private SCItem ConvertSubmitButton(SCItem form, SCItem pageItem)
        {
            pageItem = CheckItemNotNullForAnalysis(pageItem);

            var    buttonMetadata = _metadataProvider.GetItemMetadataByTemplateName("Button");
            SCItem buttonItem;

            if (!_destMasterRepository.ItemHasChildrenOfTemplate(buttonMetadata.destTemplateId, pageItem))
            {
                var buttonItemId = ConvertSubmitFields(form, pageItem.ID);
                buttonItem = _destMasterRepository.GetSitecoreItem(buttonItemId);
                WriteDescendentItems(buttonMetadata, buttonItem);
            }
            else
            {
                buttonItem = _destMasterRepository.GetSitecoreDescendantsItems(buttonMetadata.destTemplateId, pageItem.ID).FirstOrDefault();
            }

            // Delete pre-existing submit actions
            if (buttonItem != null)
            {
                var submitActionDefinitionMetadata = _metadataProvider.GetItemMetadataByTemplateName("SubmitActionDefinition");
                var submitActions =
                    _destMasterRepository.GetSitecoreDescendantsItems(submitActionDefinitionMetadata.destTemplateId, buttonItem.ID);
                foreach (var submitAction in submitActions)
                {
                    _destMasterRepository.DeleteSitecoreItem(submitAction);
                }
            }

            return(buttonItem);
        }
Exemplo n.º 2
0
        private string ConvertFieldTokens(string fieldText)
        {
            // Find all tokens
            var matches = Regex.Matches(fieldText, @"\[(.*?)\]", RegexOptions.IgnoreCase);

            foreach (Match match in matches)
            {
                Guid fieldId;
                var  fieldName  = string.Empty;
                var  matchValue = match.Value.Replace("[", "").Replace("]", "");
                if (Guid.TryParse(matchValue, out fieldId))                 // case of token in subject field
                {
                    // find field name
                    fieldName = _destMasterRepository.GetSitecoreItem(fieldId)?.Name;
                }
                else                 // case of token in message field
                {
                    // get field label value
                    fieldName = XmlHelper.GetXmlElementValue(matchValue, "label", true);
                }

                if (!string.IsNullOrEmpty(fieldName))
                {
                    // replace token with label value
                    fieldText = fieldText.Replace(matchValue, fieldName);
                }
            }

            return(fieldText);
        }
        public void ConvertTitle(SCItem form, SCItem pageItem)
        {
            var titleItemName = "Title";
            var textMetadata  = _metadataProvider.GetItemMetadataByTemplateName("Text");

            pageItem = CheckItemNotNullForAnalysis(pageItem);

            DeleteItem(pageItem.ID, titleItemName, textMetadata);

            var showTitle = form.Fields.FirstOrDefault(field => field.FieldId == new Guid(FormConstants.FormShowTitleFieldId));

            if (showTitle == null || showTitle.Value == "1")
            {
                // Create Text Item with text in Title field using Title Tag HTML element
                var title = form.Fields.FirstOrDefault(field => field.FieldId == new Guid(FormConstants.FormTitleFieldId))?.Value;
                if (!string.IsNullOrEmpty(title))
                {
                    var titleTagField = form.Fields.FirstOrDefault(field => field.FieldId == new Guid(FormConstants.FormTitleTagFieldId));
                    var titleTag      = titleTagField != null ? titleTagField.Value : FormConstants.FormTitleTagStandardValue;

                    // Create Text item
                    var parentItem  = _destMasterRepository.GetSitecoreItem(pageItem.ID);
                    var fieldValues = _fieldProvider.GetFieldValues(form, new Guid(FormConstants.FormTitleFieldId), titleItemName);

                    // Set text field
                    textMetadata.fields.newFields.First(field => field.destFieldId == new Guid(TextConstants.TextFieldId)).values = fieldValues;
                    // Set Html Tag field
                    textMetadata.fields.newFields.First(field => field.destFieldId == new Guid(TextConstants.TextHtmlTagFieldId)).value =
                        ConvertTitleTag(titleTag);
                    // Set __Sortorder field
                    textMetadata.fields.newFields.First(field => field.destFieldId == new Guid(BaseTemplateConstants.SortOrderFieldId)).value = "-100";                     // First item in the page

                    WriteNewItem(textMetadata.destTemplateId, parentItem, titleItemName, textMetadata);
                }
            }
        }
Exemplo n.º 4
0
        public List <Guid> ConvertForms()
        {
            try
            {
                var sourceFormTemplateId = _metadataProvider.GetItemMetadataByTemplateName(FormTemplateName)?.sourceTemplateId;

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

                var destPageTemplateId = _metadataProvider.GetItemMetadataByTemplateName(PageTemplateName)?.destTemplateId;

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

                var sourceSectionTemplateId = _metadataProvider.GetItemMetadataByTemplateName(SectionTemplateName)?.sourceTemplateId;

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

                var sourceFieldTemplateId = _metadataProvider.GetItemMetadataByTemplateName(InputTemplateName)?.sourceTemplateId;

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

                var destButtonTemplateId = _metadataProvider.GetItemMetadataByTemplateName(ButtonTemplateName)?.destTemplateId;

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


                var forms = _sourceMasterRepository.GetSitecoreItems((Guid)sourceFormTemplateId);

                // Filter forms to select only included forms in appSettings "includeOnlyFormIds" parameter
                if (_appSettings.includeOnlyFormIds != null && _appSettings.includeOnlyFormIds.Any())
                {
                    forms = forms.Where(form => _appSettings.includeOnlyFormIds.Contains(form.ID)).ToList();
                }

                // Filter forms to exclude forms listed in appSettings "excludeFormIds" parameter
                if (_appSettings.excludeFormIds != null && _appSettings.excludeFormIds.Any())
                {
                    forms = forms.Where(form => !_appSettings.excludeFormIds.Contains(form.ID)).ToList();
                }

                // Filter sample forms out
                if (_appSettings.excludeSampleWffmForms)
                {
                    forms = forms.Where(form => form.ParentID != _appSettings.itemReferences["sourceSampleFormsFolderId"]).ToList();
                }

                if (_appSettings.enableOnlyAnalysisByDefault)
                {
                    Console.WriteLine($"  Found {forms.Count} forms to analyze.");
                    Console.WriteLine();
                    Console.WriteLine("  Starting forms analysis...");
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine($"  Found {forms.Count} forms to convert.");
                    Console.WriteLine();
                    Console.WriteLine("  Starting forms conversion...");
                    Console.WriteLine();
                }

                var formCounter = 0;
                // Start progress bar
                var formAction = _appSettings.enableOnlyAnalysisByDefault ? "analyzed" : "converted";
                ProgressBar.DrawTextProgressBar(formCounter, forms.Count, $"forms {formAction}");

                foreach (var form in forms)
                {
                    try
                    {
                        // Set current form being processed in a global variable for reporting
                        _conversionReporter.CurrentFormId   = form.ID.ToString("B").ToUpper();
                        _conversionReporter.CurrentFormName = form.Name;

                        // Convert and Migrate Form items
                        ConvertAndWriteItem(form, _appSettings.itemReferences["destFormFolderId"]);

                        // Create Page item
                        var    pageId   = Guid.Empty;
                        SCItem pageItem = null;
                        if (!_destMasterRepository.ItemHasChildrenOfTemplate((Guid)destPageTemplateId, form))
                        {
                            // Create Page items for each form (only once)
                            pageId = WriteNewItem((Guid)destPageTemplateId, form, "Page");
                        }
                        else
                        {
                            // Get Page Item Id
                            pageItem = _destMasterRepository.GetSitecoreChildrenItems((Guid)destPageTemplateId, form.ID).FirstOrDefault(item => string.Equals(item.Name, "Page", StringComparison.InvariantCultureIgnoreCase));
                            pageId   = pageItem?.ID ?? form.ID;
                        }
                        if (pageItem == null)
                        {
                            pageItem = _destMasterRepository.GetSitecoreItem(pageId);
                        }

                        // Convert and Migrate Section items
                        var sections = _sourceMasterRepository.GetSitecoreChildrenItems((Guid)sourceSectionTemplateId, form.ID);
                        foreach (var section in sections)
                        {
                            ConvertAndWriteItem(section, pageId);
                            _sectionAppearanceConverter.ConvertTitle(section);
                            _sectionAppearanceConverter.ConvertInformation(section);
                        }

                        // Convert and Migrate Form Field items
                        List <SCItem> formFields = new List <SCItem>();
                        formFields.AddRange(_sourceMasterRepository.GetSitecoreChildrenItems((Guid)sourceFieldTemplateId, form.ID));
                        foreach (var section in sections)
                        {
                            formFields.AddRange(_sourceMasterRepository.GetSitecoreChildrenItems((Guid)sourceFieldTemplateId, section.ID));
                        }

                        foreach (var formField in formFields)
                        {
                            var parentItem   = _sourceMasterRepository.GetSitecoreItem(formField.ParentID);
                            var destParentId = parentItem.TemplateID == sourceFormTemplateId ? pageId : parentItem.ID;
                            ConvertAndWriteItem(formField, destParentId);
                        }

                        // Convert Submit form section fields
                        _submitConverter.Convert(form, pageItem);

                        // Convert Form Appearance fields
                        _formAppearanceConverter.ConvertTitle(form, pageItem);
                        _formAppearanceConverter.ConvertIntroduction(form, pageItem);
                        _formAppearanceConverter.ConvertFooter(form, pageItem);

                        formCounter++;
                        // Update progress bar
                        ProgressBar.DrawTextProgressBar(formCounter, forms.Count, $"forms {formAction}");
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(new LogEntry(LoggingEventType.Error, string.Format("Error processing form ItemID = {0}", form.ID), ex));
                        throw;
                    }
                }

                if (_appSettings.enableOnlyAnalysisByDefault)
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("  Finished forms analysis.");
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("  Finished forms conversion.");
                    Console.WriteLine();
                }

                // Write analysis results
                _conversionReporter.GenerateOutput();

                return(forms.Select(form => form.ID).ToList());
            }
            catch (Exception ex)
            {
                _logger.Log(new LogEntry(LoggingEventType.Error, "Error while converting forms.", ex));
                throw;
            }
        }