Ejemplo n.º 1
0
 private void RenderConditions(IEnumerable <Item> items)
 {
     System.Web.UI.HtmlTextWriter innerOutput = new System.Web.UI.HtmlTextWriter(new System.IO.StringWriter());
     foreach (var item in items)
     {
         string itemText = GetItemText(item);
         if (!string.IsNullOrEmpty(itemText))
         {
             var type = ItemScripts.GetGenericType <RuleContext>(item);
             var rule = ReflectionUtil.CreateObject(type) as IPersonalisationRule;
             if (rule != null)
             {
                 var currentValue =
                     global::Sitecore.Context.ClientPage.Request.Cookies[PersonalisationConstants.RequestPrefix + rule.RequestName];
                 innerOutput.Write("<div style=\"padding:0px 0px 4px 24px\">");
                 innerOutput.Write(string.Format("<input type=\"checkbox\" id=\"check_{0}\" {1} />&nbsp;",
                                                 item.ID.Guid, currentValue == null ? string.Empty : "checked"));
                 innerOutput.Write(string.Format("<input type=\"hidden\" id=\"request_{0}\" value=\"{1}\" />",
                                                 item.ID.Guid, rule.RequestName));
                 RenderText(innerOutput, item.ID.Guid.ToString(), itemText, currentValue == null ? string.Empty : currentValue.Value);
                 innerOutput.Write("</div>");
             }
         }
     }
     this.Conditions.InnerHtml = innerOutput.InnerWriter.ToString();
 }
Ejemplo n.º 2
0
 public VersionSafeEnforceVersionPresenceDisabler()
 {
     if (ReflectedTypeEnforcedVersionPresenceDisabler.Value != null)
     {
         _sitecoreEnforceVersionPresenceDisabler = (IDisposable)ReflectionUtil.CreateObject(ReflectedTypeEnforcedVersionPresenceDisabler.Value);
     }
 }
Ejemplo n.º 3
0
        protected virtual IEnumerable <Command> GetNewItemCommands()
        {
            var typeNames = new List <Command>();

            var xmlNode = Factory.GetConfigNode($"commands/command[@name='{Name}']/menucommands");

            if (xmlNode == null || !xmlNode.HasChildNodes)
            {
                return(typeNames);
            }

            foreach (XmlNode childNode in xmlNode.ChildNodes)
            {
                if (!childNode.Name.Is("menucommand"))
                {
                    continue;
                }

                var typeName = childNode.Attributes?["type"].Value;
                if (string.IsNullOrEmpty(typeName))
                {
                    continue;
                }

                var command = ReflectionUtil.CreateObject(typeName);
                if (command is Sitecore.Shell.Framework.Commands.ItemNew)
                {
                    typeNames.Add((Sitecore.Shell.Framework.Commands.ItemNew)command);
                }
            }

            return(typeNames);
        }
        public virtual void AddDynamicFields(XmlNode configNode)
        {
            Assert.ArgumentNotNull(configNode, "configNode");
            var type        = XmlUtil.GetAttribute("type", configNode);
            var fieldName   = XmlUtil.GetAttribute("name", configNode);
            var storageType = XmlUtil.GetAttribute("storageType", configNode);
            var indexType   = XmlUtil.GetAttribute("indexType", configNode);
            var vectorType  = XmlUtil.GetAttribute("vectorType", configNode);
            var boost       = XmlUtil.GetAttribute("boost", configNode);
            var field       = ReflectionUtil.CreateObject(type);

            if (field == null || !(field is BaseDynamicField))
            {
                return;
            }

            var dynamicField = field as BaseDynamicField;

            dynamicField.SetStorageType(storageType);
            dynamicField.SetIndexType(indexType);
            dynamicField.SetVectorType(vectorType);
            dynamicField.SetBoost(boost);
            dynamicField.FieldKey = fieldName.ToLowerInvariant();
            DynamicFields.Add(dynamicField);
        }
Ejemplo n.º 5
0
 protected virtual IProfileMap ToProfileMap()
 {
     return(ReflectionUtil.CreateObject(
                InnerItem[Templates.ProfileMap.Fields.ProfileMapAssembly],
                InnerItem[Templates.ProfileMap.Fields.ProfileMapClass],
                new object[] { }) as IProfileMap);
 }
Ejemplo n.º 6
0
        public void StartProcess(params object[] parameters)
        {
            var database       = (Database)parameters[0];
            var progressStatus = Sitecore.Context.Job.Status;

            progressStatus.Messages.Add("Loading number of blobs...");
            progressStatus.Total = 100;

            var conStringName = database.ConnectionStringName;
            var conString     = ConfigurationManager.ConnectionStrings[conStringName].ConnectionString;

            var blobManager = (IBlobManager)ReflectionUtil.CreateObject(BlobManagerHelper.BlobManagerType);

            blobManager.Initialize();

            var transferer    = new BlobTransferer(conString, blobManager);
            var numberOfBlobs = transferer.GetNumberOfDatabaseBlobs();

            progressStatus.Total     = numberOfBlobs;
            progressStatus.Processed = 0;
            progressStatus.Messages.Add($"Uploading blob 1 to {progressStatus.Total} out of {numberOfBlobs} blobs");

            var blobs = transferer.GetBlobIds();

            foreach (var blobId in blobs)
            {
                transferer.TransferToBlobManager(blobId);
                progressStatus.IncrementProcessed();
            }

            // TODO: Show confirmation dialog
        }
        /// <summary>
        ///     Gets the content of the <c>treeview</c>.
        /// </summary>
        /// <returns>
        ///     The <see cref="T:System.String" />.
        /// </returns>
        private string GetTreeViewContent()
        {
            Response.ContentType = "text/xml";
            var queryString = ItemUri.ParseQueryString();

            if (queryString == null)
            {
                return(string.Empty);
            }
            var parent = Database.GetItem(queryString);

            if (parent == null)
            {
                return(string.Empty);
            }
            var typeInfo = ReflectionUtil.GetTypeInfo(WebUtil.GetQueryString("typ"));

            if (typeInfo == null)
            {
                return(string.Empty);
            }
            var treeviewSource = ReflectionUtil.CreateObject(typeInfo) as TreeviewSource;

            if (treeviewSource == null)
            {
                return(string.Empty);
            }
            var treeview = new TreeView();

            treeviewSource.Render(treeview, parent);
            return(treeview.GetXml());
        }
 public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args, IPipelineController controller)
 {
     return(new[]
     {
         (Processor)ReflectionUtil.CreateObject(Type)
     });
 }
Ejemplo n.º 9
0
        public SqlServerWithExternalBlobDataProvider(string connectionString) : base(connectionString)
        {
            _blobLockSet = new LockSet();

            if (string.IsNullOrWhiteSpace(BlobManagerHelper.BlobManagerType))
            {
                Log.Error("ExternalBlobDataProvider not configured. Using Sitecore default.", this);
                _configured = false;
                return;
            }
            try
            {
                Log.Info($"Initializing ExternalBlobDataProvider using {BlobManagerHelper.BlobManagerType}", this);
                _blobManager = ReflectionUtil.CreateObject(BlobManagerHelper.BlobManagerType) as IBlobManager;
                if (_blobManager == null)
                {
                    Log.Error($"Unable to create IBlobManager of type {BlobManagerHelper.BlobManagerType}. Using Sitecore default.", this);
                    _configured = false;
                    return;
                }
                _blobManager.Initialize();
                _configured = true;
            }
            catch (Exception ex)
            {
                Log.Error($"Unable to initialize ExternalBlobDataProvider {BlobManagerHelper.BlobManagerType}. Using Sitecore default", ex, this);
                _configured = false;
            }
        }
Ejemplo n.º 10
0
        internal IndexData GetIndexData(IIndexable indexable, IProviderUpdateContext context)
        {
            Assert.ArgumentNotNull(indexable, "indexable");
            Assert.ArgumentNotNull(context, "context");
            Assert.Required((index.Configuration.DocumentOptions as AzureDocumentBuilderOptions), "IDocumentBuilderOptions of wrong type for this crawler");
            AzureDocumentBuilder documentBuilder = (AzureDocumentBuilder)ReflectionUtil.CreateObject(context.Index.Configuration.DocumentBuilderType, new object[2]
            {
                indexable,
                context
            });

            if (documentBuilder == null)
            {
                CrawlingLog.Log.Error("Unable to create document builder (" + context.Index.Configuration.DocumentBuilderType + "). Please check your configuration. We will fallback to the default for now.", (Exception)null);
                documentBuilder = new AzureDocumentBuilder(indexable, context);
            }
            documentBuilder.AddSpecialFields();
            documentBuilder.AddItemFields();
            documentBuilder.AddComputedIndexFields();
            documentBuilder.AddBoost();
            var indexData = new IndexData(index, indexable, documentBuilder);

            index.AzureSchema.AddAzureIndexFields(indexData.Fields.Where(f => f.Name != indexData.UpdateTerm.Name).ToList());
            index.AzureSchema.BuildAzureIndexSchema(indexData.UpdateTerm, indexData.FullUpdateTerm);
            return(indexData);
        }
 public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args)
 {
     return(new[]
     {
         (Processor)ReflectionUtil.CreateObject(Type)
     });
 }
Ejemplo n.º 12
0
        protected virtual string GetDestinationFolderPath(Item topParent, DateTime childItemCreationDateTime, Item itemToMove)
        {
            Assert.ArgumentNotNull(topParent, "topParent");
            Assert.ArgumentNotNull(childItemCreationDateTime, "childItemCreationDateTime");
            Assert.ArgumentNotNull(itemToMove, "itemToMove");
            Type type = Type.GetType(BucketConfigurationSettings.DynamicBucketFolderPath);
            IDynamicBucketFolderPath bucketFolderPath = ReflectionUtil.CreateObject(type) as IDynamicBucketFolderPath;

            if (bucketFolderPath == null)
            {
                Logger.Error("Could not instantiate DynamicBucketFolderPath of type " + type, this);
                throw new ConfigurationException("Could not instantiate DynamicBucketFolderPath of type " + type);
            }
            Database database = topParent.Database;

#if SC70
            string str = bucketFolderPath.GetFolderPath(itemToMove.ID, topParent.ID, childItemCreationDateTime);
#else
            string str = bucketFolderPath.GetFolderPath(database, itemToMove.Name, itemToMove.TemplateID, itemToMove.ID, topParent.ID, childItemCreationDateTime);
#endif
            if (BucketConfigurationSettings.BucketFolderPath == string.Empty && bucketFolderPath is DateBasedFolderPath)
            {
                str = "Repository";
            }
            return(String.IsNullOrEmpty(str)
                ? topParent.Paths.FullPath
                : topParent.Paths.FullPath + Sitecore.Buckets.Util.Constants.ContentPathSeperator + str);
        }
        protected void RunAgent(List <XmlNode> agentNodes, List <Item> scheduleItems)
        {
            Job.Total = agentNodes.Count + scheduleItems.Count;
            foreach (XmlNode node in agentNodes)
            {
                Job.AddMessage("Running {0}", new object[] { node.Attributes["type"] });
                if (node != null)
                {
                    object obj2       = ReflectionUtil.CreateObject(node);
                    string methodName = node.Attributes["method"].Value;
                    if (obj2 != null)
                    {
                        MethodInfo method = ReflectionUtil.GetMethod(obj2.GetType(), methodName, true, true, true,
                                                                     new object[0]);
                        if (method != null)
                        {
                            ReflectionUtil.InvokeMethod(method, new object[0], obj2);
                        }
                    }
                }
                Job.Processed += 1L;
            }

            scheduleItems.Where(itm => itm.TemplateID == TemplateIDs.Schedule).ToList().ForEach(itm =>
            {
                var scheduledItem = new ScheduleItem(itm);
                Job.AddMessage("Running {0}", new object[] { scheduledItem.DisplayName });
                scheduledItem.Execute();
                Job.Processed += 1L;
            });
        }
        protected virtual Dictionary <string, object> BuildIndexableDocument(IIndexable indexable, IProviderUpdateContext context)
        {
            var sitecoreIndexableItem = indexable as SitecoreIndexableItem;

            if (sitecoreIndexableItem != null)
            {
                sitecoreIndexableItem.IndexFieldStorageValueFormatter = context.Index.Configuration.IndexFieldStorageValueFormatter;
            }

            var builderObject = ReflectionUtil.CreateObject(
                context.Index.Configuration.DocumentBuilderType,
                new[] { indexable, context as object });

            var documentBuilder = (AbstractDocumentBuilder <ConcurrentDictionary <string, object> >)builderObject;

            if (documentBuilder == null)
            {
                throw new InvalidOperationException("Unable to create AbstractDocumentBuilder.");
            }

            documentBuilder.AddSpecialFields();
            documentBuilder.AddItemFields();
            documentBuilder.AddComputedIndexFields();
            documentBuilder.AddBoost();

            return(documentBuilder.Document.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
        }
Ejemplo n.º 15
0
        public static T GetField <T>(this Item item, string fieldID) where T : CustomField
        {
            Field field = item.Fields[new ID(fieldID)];

            Assert.IsNotNull(field, "item does not have field: " + fieldID);
            return((T)ReflectionUtil.CreateObject(typeof(T), new object[] { field }));
        }
        public override void AddComputedIndexField(XmlNode configNode)
        {
            Assert.ArgumentNotNull(configNode, "configNode");
            var fieldName = XmlUtil.GetAttribute("fieldName", configNode, true);
            var fieldType = XmlUtil.GetValue(configNode);

            if (string.IsNullOrEmpty(fieldName) || string.IsNullOrEmpty(fieldType))
            {
                throw new InvalidOperationException("Could not parse computed index field entry: " + configNode.OuterXml);
            }
            var field = ReflectionUtil.CreateObject(fieldType) as IComputedIndexField;

            if (field == null)
            {
                return;
            }

            field.FieldName = fieldName.ToLowerInvariant();
            var returnType = XmlUtil.GetAttribute("returnType", configNode, true);

            if (FieldMap != null && !string.IsNullOrWhiteSpace(returnType))
            {
                field.ReturnType = returnType;
                ((ElasticSearchFieldMap)FieldMap).AddFieldByFieldName(field.FieldName, field.ReturnType.ToLowerInvariant());
            }
            DocumentOptions.ComputedIndexFields.Add(field);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// The get field crawler values.
        /// </summary>
        /// <param name="field">
        /// The field.
        /// </param>
        /// <param name="fieldCrawlers">
        /// The field crawlers.
        /// </param>
        /// <returns>
        /// The IEnumerable of field crawler values.
        /// </returns>
        public static IEnumerable <string> GetFieldCrawlerValues(Field field, SafeDictionary <string, string> fieldCrawlers)
        {
            Assert.IsNotNull(field, "Field was not supplied");
            Assert.IsNotNull(fieldCrawlers, "Field Crawler collection is not specified");

            if (fieldCrawlers.ContainsKey(field.TypeKey))
            {
                var fieldCrawlerType = fieldCrawlers[field.TypeKey];

                if (!string.IsNullOrEmpty(fieldCrawlerType))
                {
                    var fieldCrawler = ReflectionUtil.CreateObject(fieldCrawlerType, new object[] { field });

                    if (fieldCrawler is IMultivaluedFieldCrawler)
                    {
                        return((fieldCrawler as IMultivaluedFieldCrawler).GetValues());
                    }

                    if (fieldCrawler is FieldCrawlerBase)
                    {
                        return(new[] { (fieldCrawler as FieldCrawlerBase).GetValue() });
                    }
                }
            }

            return(new[] { new DefaultFieldCrawler(field).GetValue() });
        }
        public SqlServerWithExternalBlobDataProvider(string connectionString) : base(connectionString)
        {
            _blobSetLocks = new LockSet();

            var externalBlobStorageProviderType = Configuration.Settings.Media.ExternalBlobStorageProviderType;

            if (string.IsNullOrWhiteSpace(externalBlobStorageProviderType))
            {
                Log.Info("ExternalBlobStorageProviderType isn't configured. So, using the Sitecore default provider.", this);
                _externalBlobStorageProviderConfigured = false;
                return;
            }

            try
            {
                Log.Info($"Initializing ExternalBlobStorageProviderType using {externalBlobStorageProviderType}", this);

                _blobStorageProvider = ReflectionUtil.CreateObject(externalBlobStorageProviderType) as IBlobStorageProvider;
                if (_blobStorageProvider == null)
                {
                    Log.Error($"Unable to create IBlobStorageProvider of type {externalBlobStorageProviderType}. So, using the Sitecore default provider.", this);
                    _externalBlobStorageProviderConfigured = false;
                    return;
                }

                _externalBlobStorageProviderConfigured = true;
            }
            catch (Exception ex)
            {
                Log.Error($"Unable to initialize ExternalBlobStorageProviderType {externalBlobStorageProviderType}. So, using the Sitecore default provider.", ex, this);
                _externalBlobStorageProviderConfigured = false;
            }
        }
Ejemplo n.º 19
0
        public Control GetEditor(Item fieldType)
        {
            if (!Arguments.ShowInputBoxes)
            {
                var str = fieldType.Name.ToLowerInvariant();
                if (str == "html" || str == "memo" || str == "rich text" || str == "security" ||
                    str == "multi-line text")
                {
                    return(new Memo());
                }

                return(fieldType.Name == "password" ? new Password() : new Text());
            }

            var control = Resource.GetWebControl(fieldType["Control"]);

            if (control == null)
            {
                var assembly  = fieldType["Assembly"];
                var className = fieldType["Class"];

                if (!string.IsNullOrEmpty(assembly) && !string.IsNullOrEmpty(className))
                {
                    control = ReflectionUtil.CreateObject(assembly, className, new object[0]) as Control;
                }
            }

            return(control ?? new Text());
        }
Ejemplo n.º 20
0
        private void AddStepToWizard(StepInfo stepInfo, WizardArgs wArgs)
        {
            Type ctrl = stepInfo.Control;

            Assert.IsNotNull(ctrl, "The {0} step contains null as a control".FormatWith(stepInfo.Title));
            var fullName = ctrl.FullName;

            Assert.IsTrue(ctrl.IsClass, "Control {0} is not class".FormatWith(fullName));

            if (!ctrl.GetInterfaces().Contains(typeof(IWizardStep)))
            {
                Log.Debug("Control {0} does not implement IWizardStep".FormatWith(fullName));
            }

            var param      = stepInfo.Param;
            var wizardStep = (UserControl)(!string.IsNullOrEmpty(param) ? ReflectionUtil.CreateObject(ctrl, param) : ReflectionUtil.CreateObject(ctrl));

            this.ProcessorArgs = wArgs;

            this.TabControl.Items.Insert(this.TabControl.Items.Count - 2, new TabItem
            {
                AllowDrop  = false,
                Content    = wizardStep,
                Visibility = Visibility.Collapsed
            });
        }
        /// <summary>
        /// Dynamically loads GenerateSchema class from target site, and uses it
        /// to applied required changes to the Solr schema.xml file.
        /// </summary>
        public virtual void InvokeSitecoreGenerateSchemaUtility(string dllPath, string inputPath, string outputPath)
        {
            Assembly assembly       = ReflectionUtil.GetAssembly(dllPath);
            Type     generateSchema = ReflectionUtil.GetType(assembly, GenerateSchemaClass);
            object   obj            = ReflectionUtil.CreateObject(generateSchema);

            ReflectionUtil.InvokeMethod(obj, GenerateSchemaMethod, inputPath, outputPath);
        }
Ejemplo n.º 22
0
        public void Process(PipelineArgs args)
        {
            var resolver = (IDependencyResolverWrapper)ReflectionUtil.CreateObject(DependencyResolverWrapper, new object[0]);

            resolver.RegisterType <ISecurityManager, SecurityManager>();

            DependencyResolver.SetResolver(resolver.DependencyResolver);
        }
Ejemplo n.º 23
0
        public void DoExecuteThrowsNotSupportedException(Type command, DataStorage dataStorage)
        {
            var sut = ReflectionUtil.CreateObject(command, new object[] { dataStorage });

            Action action = () => ReflectionUtil.CallMethod(sut, "CreateInstance");

            action.ShouldThrow <TargetInvocationException>().WithInnerException <NotSupportedException>();
        }
        protected virtual T GetProvider <T>(string providerName)
        {
            Type providerTypeByName = this.ContentTaggingProvidersConfigurationService.GetProviderTypeByName(providerName);

            if (providerTypeByName != (Type)null)
            {
                return((T)ReflectionUtil.CreateObject(providerTypeByName));
            }
            return(default(T));
        }
Ejemplo n.º 25
0
        public static object CreateInstance(string typeFullName, string reference = null, string param = null)
        {
            var type = GetType(typeFullName, reference);

            if (!string.IsNullOrEmpty(param))
            {
                return(ReflectionUtil.CreateObject(type, param));
            }

            return(ReflectionUtil.CreateObject(type));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Processes the specified args.
        /// </summary>
        /// <param name="args">The render form args.</param>
        public void Process(RenderFormArgs args)
        {
            // replaces legends with div tags
            var form = new HtmlFormModifier(args);

            form.ReplaceLegendWithDiv();
            form.RemoveEmptyTags("div", "scfSectionUsefulInfo");
            form.RemoveEmptyTags("div", "scfTitleBorder");
            form.RemoveEmptyTags("div", "scfIntroBorder");
            form.RemoveEmptyTags("span", "scfError");
            form.SurroundContentWithUlLi("scfError");

            form.RemoveNbsp();

            var saveActions = args.Item["Save Actions"];

            if (!string.IsNullOrEmpty(saveActions))
            {
                var commands  = XDocument.Parse(saveActions);
                var actionIds = (from c in commands.Descendants()
                                 where c.Name.LocalName == "li" &&
                                 (c.Attribute(XName.Get("id")) != null)
                                 select c.Attribute(XName.Get("id")).Value).ToList();

                foreach (var actionId in actionIds)
                {
                    var actionItem = args.Item.Database.GetItem(actionId);
                    if (null == actionItem)
                    {
                        continue;
                    }

                    var assembly  = actionItem["assembly"];
                    var className = actionItem["Class"];

                    if (string.IsNullOrEmpty(assembly) || string.IsNullOrEmpty(className))
                    {
                        continue;
                    }

                    var obj = ReflectionUtil.CreateObject(assembly, className, new object[] { });
                    if (obj == null)
                    {
                        throw new ConfigurationException("Could not load " + className + " from " + assembly);
                    }

                    var method = ReflectionUtil.GetMethod(obj, "Load", new object[] { IsPostback, args });
                    if (method != null)
                    {
                        ReflectionUtil.InvokeMethod(method, new object[] { IsPostback, args }, obj);
                    }
                }
            }
        }
        public virtual T Create(ITypeDefinition def)
        {
            var objectCreated = ReflectionUtil.CreateObject(def.TypeName);

            if (objectCreated is T)
            {
                AssignParameters(objectCreated, def);
                return((T)objectCreated);
            }
            throw new InvalidCastException();
        }
Ejemplo n.º 28
0
        private WizardArgs GetWizardArgs(Type argsType)
        {
            WizardArgs wArgs = null;

            if (argsType != null)
            {
                wArgs = (WizardArgs)ReflectionUtil.CreateObject(argsType, this.wizardParams ?? new object[0]);
                wArgs.WizardWindow = this;
            }

            return(wArgs);
        }
Ejemplo n.º 29
0
        public virtual IDatasourceProvider GetProviderByConfigPath(string path)
        {
            var configNode = Factory.GetConfigNode(path);

            if (configNode != null)
            {
                var provider = ReflectionUtil.CreateObject(configNode) as IDatasourceProvider;
                return(provider);
            }

            return(null);
        }
        public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args, IPipelineController controller)
        {
            var hive = (ProcessorHive)ReflectionUtil.CreateObject(Type, this);
            IEnumerable <Processor> proc = hive.CreateProcessors(args);

            if (controller != null)
            {
                this.SetControllerForDynamicNestedProcessors(proc, controller);
            }

            return(proc);
        }