示例#1
0
        /// <summary>
        /// Apply the rule.
        /// </summary>
        /// <param name="ruleContext">Rule processing context.</param>
        public override void Apply(T ruleContext)
        {
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            Assert.ArgumentNotNull(ruleContext.Item, "ruleContext.Item");

            // for each language available in the item
            foreach (SC.Globalization.Language lang in ruleContext.Item.Languages)
            {
                SC.Data.Items.Item item = ruleContext.Item.Database.GetItem(
                    ruleContext.Item.ID,
                    lang);

                if (item == null)
                {
                    continue;
                }

                // to prevent the while loop from reaching MinVersions,
                // only process this number of items
                int limit = item.Versions.Count - this.MinVersions;
                int i     = 0;

                while (item.Versions.Count > this.MinVersions && i < limit)
                {
                    SC.Data.Items.Item version = item.Versions.GetVersions()[i++];
                    Assert.IsNotNull(version, "version");

                    if (this.MinUpdatedDays < 1 ||
                        version.Statistics.Updated.AddDays(this.MinUpdatedDays) < DateTime.Now)
                    {
                        this.HandleVersion(version);
                    }
                }
            }
        }
示例#2
0
        public static bool HasUnlockAccess(SC.Data.Items.Item item, SC.Security.Accounts.User user = null)
        {
            Assert.ArgumentNotNull(item, "item");

            if (user == null)
            {
                user = SC.Context.User;
                Assert.IsNotNull(user, "context user");
            }

            if (user.IsAdministrator)
            {
                return(true);
            }

            SC.Security.AccessControl.AccessRight checkIn = SC.Security.AccessControl.AccessRight.FromName("item:checkin");

            if (checkIn != null)
            {
                return(SC.Security.AccessControl.AuthorizationManager.IsAllowed(item, checkIn, user));
            }

            SC.Security.Accounts.Role control = SC.Security.Accounts.Role.FromName("sitecore\\Sitecore Client Maintaining");

            return(SC.Security.Accounts.Role.Exists(control.Name) && SC.Security.Accounts.RolesInRolesManager.IsUserInRole(SC.Context.User, control, true /*includeIndirectMembership*/));
        }
示例#3
0
        /// <summary>
        /// Triggered at interval to determine whether to rebuild the index.
        /// </summary>
        /// <param name="args">Event arguments (not used by this implementation)</param>
        internal void Handle(EventArgs args)
        {
            Assert.IsNotNull(this._index, "_index");
            string path = "/sitecore/system/Settings/Rules/Indexing/Rebuilding/Rules";

            using (new SC.SecurityModel.SecurityDisabler())
            {
                SC.Data.Items.Item ruleRoot = this._ruleDatabase.GetItem(path);
                SC.Diagnostics.Assert.IsNotNull(
                    ruleRoot,
                    string.Format("ruleRoot item {0} in database {1}", path, this._ruleDatabase.Name));
                SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext ruleContext =
                    new SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext(this._index)
                {
                    IndexedDatabaseName = this._indexedDatabaseName,
                };

                SC.Rules.RuleList <SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext> ruleList =
                    SC.Rules.RuleFactory.GetRules <SC.Sharedsource.Rules.Indexing.IndexRebuildingRuleContext>(ruleRoot.Axes.GetDescendants(), "Rule");
                Assert.IsNotNull(ruleList, "ruleList");
                Assert.IsTrue(
                    ruleList.Count > 0,
                    "ruleList.Count < 1 for " + path + " in database " + this._ruleDatabase.Name);
                ruleList.Run(ruleContext);

                if (ruleContext.ShouldRebuild)
                {
                    SC.ContentSearch.Diagnostics.CrawlingLog.Log.Info(
                        this + " : rebuild " + this._index.Name);
                    this._index.Rebuild();
                }
            }
        }
示例#4
0
        public override void Process(ServicePipelineArgs args)
        {
            ValidateArguments <CreateUserRequest, CreateUserResult>(args, out var request, out var result);
            Assert.IsNotNull(request.UserName, "request.UserName");
            Assert.IsNotNull(request.Password, "request.Password");
            Container container = GetContainer(request.Shop.Name, string.Empty, "", "", args.Request.CurrencyCode,
                                               new DateTime?());
            CommerceUser commerceUser1 = result.CommerceUser;

            if (commerceUser1 != null &&
                commerceUser1.UserName.Equals(request.UserName, StringComparison.OrdinalIgnoreCase))
            {
                string entityId = "Entity-Customer-" + request.UserName;
                ServiceProviderResult currentResult = new ServiceProviderResult();
                EntityView            entityView    = GetEntityView(container, entityId, string.Empty, "Details", string.Empty,
                                                                    currentResult);
                if (currentResult.Success && !string.IsNullOrEmpty(entityView.EntityId))
                {
                    base.Process(args);
                    return;
                }
            }

            EntityView entityView1 =
                GetEntityView(container, string.Empty, string.Empty, "Details", "AddCustomer", result);

            if (!result.Success)
            {
                return;
            }
            entityView1.Properties.FirstOrDefault(p => p.Name.Equals("Domain")).Value    = request.UserName.Split('\\')[0];
            entityView1.Properties.FirstOrDefault(p => p.Name.Equals("LoginName")).Value =
                request.UserName.Split('\\')[1];
            entityView1.Properties.FirstOrDefault(p => p.Name.Equals("AccountStatus")).Value = "ActiveAccount";
            if (!string.IsNullOrEmpty(request.Email))
            {
                entityView1.Properties.FirstOrDefault(p => p.Name.Equals("Email")).Value = request.Email;
            }
            CommerceCommand commerceCommand = DoAction(container, entityView1, result);

            if (commerceCommand != null &&
                commerceCommand.ResponseCode.Equals("ok", StringComparison.OrdinalIgnoreCase))
            {
                CommerceUser commerceUser2 = EntityFactory.Create <CommerceUser>("CommerceUser");
                commerceUser2.Email      = request.Email;
                commerceUser2.UserName   = request.UserName;
                commerceUser2.ExternalId = commerceCommand.Models.OfType <CustomerAdded>().FirstOrDefault()?.CustomerId;
                result.CommerceUser      = commerceUser2;
                request.Properties.Add(new PropertyItem()
                {
                    Key   = "UserId",
                    Value = result.CommerceUser.ExternalId
                });
                string entityId = "Entity-Customer-" + request.UserName;
                TestSave(container, entityId, request, result, commerceUser2.ExternalId);
            }

            base.Process(args);
        }
示例#5
0
        protected override void Render(HtmlTextWriter writer)
        {
            string itemId = S.Web.WebUtil.GetQueryString("id");

            Assert.IsNotNullOrEmpty(itemId, "itemId");
            string dbName = S.Web.WebUtil.GetQueryString("database");

            Assert.IsNotNullOrEmpty(dbName, "dbName");
            S.Data.Database db = S.Configuration.Factory.GetDatabase(dbName);
            Assert.IsNotNull(db, "db: " + dbName);
            S.Data.Items.Item item = db.GetItem(itemId);
            Assert.IsNotNull(item, "item: " + itemId + " in " + dbName);
            string value = item["Type"];

            Assert.IsNotNullOrEmpty(value, "value: Type of " + item.Paths.FullPath);
            string name  = string.Empty;
            string dll   = string.Empty;
            int    comma = value.IndexOf(',');

            if (comma >= 0)
            {
                name = value.Substring(0, comma).Trim();
                dll  = value.Substring(comma + 1).Trim();
            }

            Assembly assembly = S.Reflection.ReflectionUtil.LoadAssembly(dll);

            Assert.IsNotNull(assembly, "assembly: " + dll);
            Type type = assembly.GetType(name, false, true);

            if (type == null)
            {
                type = assembly.GetType(name + "`1");
            }

            Assert.IsNotNull(type, "Type : " + name);
            dll = S.IO.FileUtil.MapPath("/bin/" + dll + ".dll");
            Assert.IsTrue(File.Exists(dll), "dll.Exists(): " + dll);
            string tempFile = string.Format(
                "{0}.{1}.il",
                type,
                DateTime.Now.ToString("yyyyMMddTHHmmssffff"));

            S.IO.TempFolder.EnsureFolder();
            tempFile = S.IO.FileUtil.MapPath(
                S.IO.FileUtil.MakePath(S.IO.TempFolder.Folder, tempFile, '/'));
            S.Sharedsource.Diagnostics.CommandLineTool clt =
                new S.Sharedsource.Diagnostics.CommandLineTool(
                    "c:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.0A\\bin\\NETFX 4.0 Tools\\x64\\ildasm.exe");
            clt.Execute(
                true /*log*/,
                "/source /html /linenum /item=" + type + " /out=" + tempFile + " " + dll); // /pubonly
            Assert.IsTrue(File.Exists(tempFile), "tempFile.Exists(): " + tempFile);
            this.Response.Output.Write(S.IO.FileUtil.ReadFromFile(tempFile));
            this.Response.End();
            File.Delete(tempFile);
        }
示例#6
0
 internal static void ValidateArguments <TRequest, TResult>(ServicePipelineArgs args, out TRequest request,
                                                            out TResult result) where TRequest : ServiceProviderRequest where TResult : ServiceProviderResult
 {
     Assert.ArgumentNotNull(args, nameof(args));
     Assert.ArgumentNotNull(args.Request, "args.Request");
     Assert.ArgumentNotNull(args.Request.RequestContext, "args.Request.RequestContext");
     Assert.ArgumentNotNull(args.Result, "args.Result");
     request = args.Request as TRequest;
     result  = args.Result as TResult;
     Assert.IsNotNull(request,
                      "The parameter args.Request was not of the expected type.  Expected {0}.  Actual {1}.",
                      typeof(TRequest).Name, args.Request.GetType().Name);
     Assert.IsNotNull(result,
                      "The parameter args.Result was not of the expected type.  Expected {0}.  Actual {1}.",
                      typeof(TResult).Name, args.Result.GetType().Name);
 }
示例#7
0
        public static bool CanCheckIn(SC.Data.Items.Item item, SC.Security.Accounts.User user = null)
        {
            Assert.ArgumentNotNull(item, "item");

            if (user == null)
            {
                user = SC.Context.User;
                Assert.IsNotNull(user, "context user");
            }

            if (item.Appearance.ReadOnly || !item.Locking.IsLocked() || !item.Access.CanWrite() || !item.Access.CanWriteLanguage())
            {
                return(false);
            }

            return(user.IsAdministrator ||
                   string.Compare(item.Locking.GetOwner(), user.Name, System.StringComparison.OrdinalIgnoreCase) == 0 ||
                   CheckIn.HasUnlockAccess(item));
        }
示例#8
0
        /// <summary>
        /// Nested logic for argument processing and possible UI alerts.
        /// </summary>
        private void Apply(object[] parameters)
        {
            Assert.ArgumentCondition(
                parameters != null && parameters.Length == 1 && parameters[0] is ClientPipelineArgs,
                "parameters",
                "//TODO");
            ClientPipelineArgs args = parameters[0] as ClientPipelineArgs;

            // the FDA field of the item edited by the user
            Field field = this.Item.Fields[this.FieldID];

            Assert.IsNotNull(field, "field");

            FileDropAreaField fda = new FileDropAreaField(
                field,
                base.GetViewStateProperty("XmlValue", string.Empty) as string);
            ItemList mediaItems = fda.GetMediaItems();

            if (mediaItems.Count < 1)
            {
                SheerResponse.Alert(
                    Translate.Text("Add a media item."));
                args.AbortPipeline();
                return;
            }

            Item item = null;

            if (mediaItems.Count == 1)
            {
                item = mediaItems[0];
            }
            else if (mediaItems.Count > 1)
            {
                ItemList selectedItems = null;

                try
                {
                    // this may throw an exception; see 406891
                    selectedItems = this.GetSelectedItems();
                }
                catch (Exception ex)
                {
                    SheerResponse.Alert(
                        Translate.Text("Select an item from the list."));
                    args.AbortPipeline();
                    return;
                }

                if (selectedItems.Count != 1)
                {
                    SheerResponse.Alert(
                        Translate.Text("Select a single item from the list."));
                    args.AbortPipeline();
                    return;
                }

                item = selectedItems[0];
            }

            MediaItem mediaItem = new MediaItem(item);

            if (mediaItem.Extension != "docx")
            {
                SheerResponse.Alert(Translate.Text(
                                        "Seelect a Word document from the list."));
                args.AbortPipeline();
                return;
            }

            WordUtil.HandleWordDocument(this.Item, mediaItem);
        }