/// <summary> /// Cleans the VirtualProductResolver caches. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.EventArgs"/> instance containing the event data.</param> public void OnItemSaved(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); Item item = Event.ExtractParameter(args, 0) as Item; if (item == null) { return; } var virtualProductResolver = Context.Entity.Resolve <VirtualProductResolver>(); Assert.IsNotNull(virtualProductResolver, "Virtual product resolver is null"); lock (virtualProductResolver.ProductsUrlsCollection.SyncRoot) { if (virtualProductResolver.ProductsUrlsCollection == null || virtualProductResolver.ProductsUrlsCollection.Count <= 0) { return; } var keysToRemove = new List <string>(); foreach (DictionaryEntry urlsCollection in virtualProductResolver.ProductsUrlsCollection) { if (!(urlsCollection.Value is ProductUriLine)) { continue; } var productUriLine = (ProductUriLine)urlsCollection.Value; var productUriValues = new[] { productUriLine.ProductCatalogItemUri, productUriLine.ProductItemUri, productUriLine.ProductPresentationItemUri }; foreach (var productUriValue in productUriValues) { if (string.IsNullOrEmpty(productUriValue) || !ItemUri.IsItemUri(productUriValue)) { continue; } var productUri = ItemUri.Parse(productUriValue); if (productUri.ItemID.Equals(item.ID)) { keysToRemove.Add(urlsCollection.Key as string); break; } } } keysToRemove.ForEach(k => virtualProductResolver.ProductsUrlsCollection.Remove(k)); } }
public static ItemUri ToItemUri(this string uri) { Assert.IsNotNullOrEmpty(uri, "Uri parameter is expected"); uri = uri.DecodeUrl(); Assert.IsTrue(ItemUri.IsItemUri(uri), "Uri parameter is not properly formed"); return(ItemUri.Parse(uri)); }
public Guid ReturnSourceID(IGlassBase i) { if (i == null) { return(Guid.Empty); } Item itm = _dependencies.SitecoreServiceMaster.GetItem <Item>(i._Id); if (itm == null) { return(Guid.Empty); } Field f = itm.Fields[Sitecore.FieldIDs.Source]; if (f == null) { return(Guid.Empty); } if (!ItemUri.IsItemUri(f.Value)) { return(Guid.Empty); } return(ItemUri.Parse(f.Value).ItemID.Guid); }
public static bool IsItemUri(this string uri) { if (uri.IsNullOrEmpty()) { return(false); } uri = uri.DecodeUrl(); return(ItemUri.IsItemUri(uri)); }
private DbItem GetSourceItem(DbItem fakeItem) { if (!fakeItem.Fields.ContainsKey(SourceFieldId)) { return(null); } var sourceUri = fakeItem.Fields[SourceFieldId].Value; if (!ItemUri.IsItemUri(sourceUri)) { return(null); } return(this.GetFakeItem(new ItemUri(sourceUri).ItemID)); }
protected void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); string[] uris = StringUtil.Split(args.Parameters["uris"], '|', false); if (args.IsPostBack) { if (args.HasResult) { string result = args.Result; if (result == "-") { result = string.Empty; } foreach (var uri in uris) { if (ItemUri.IsItemUri(uri)) { Item item = Database.GetItem(ItemUri.Parse(uri)); item.Editing.BeginEdit(); item[FieldIDs.Owner] = result; item.Editing.EndEdit(); Log.Audit(this, "Set owner: {0}", new string[] { AuditFormatter.FormatItem(item) }); } } } } else { if (ItemUri.IsItemUri(uris[0])) { ItemUri uri = ItemUri.Parse(uris[0]); UrlString str6 = new UrlString("/sitecore/shell/~/xaml/Sitecore.Shell.Applications.Security.SetOwner.aspx"); str6.Append("id", uri.Path); str6.Append("la", uri.Language.ToString()); str6.Append("vs", uri.Version.ToString()); str6.Append("db", uri.DatabaseName); SheerResponse.ShowModalDialog(str6.ToString(), "450", "180", string.Empty, true); args.WaitForPostBack(); } } }
public void Execute_WithOneItemInContext_RunsPipelineWithCorrectParameters() { // Arrange var item = MasterFakesFactory.CreateFakeItem(); var context = new CommandContext(item); var sheer = Substitute.For <ISheerResponse>(); var contextChecker = Substitute.For <ICommandContextChecker>(); var locator = Substitute.For <IDialogLocator>(); var processor = Substitute.For <IDialogResultProcessor>(); var command = Substitute.ForPartsOf <SelectBaseLayout>(sheer, contextChecker, locator, processor); command.When(c => c.RunClientPipeline(Arg.Any <NameValueCollection>())).DoNotCallBase(); // Act command.Execute(context); // Assert command.Received().RunClientPipeline(Arg.Is <NameValueCollection>(nvc => ItemUri.IsItemUri(nvc["items"]))); }
public WebSearchResult(SearchHit hit) { var result = new SearchResult(hit); PathAndQuery = hit.Document.Get(BuiltinFields.Path); Title = result.Title; Description = hit.Document.Get(CustomFields.Description); Score = hit.Position; if (!string.IsNullOrEmpty(result.Url) && ItemUri.IsItemUri(result.Url)) { var uri = ItemUri.Parse(result.Url); var db = !String.IsNullOrEmpty(uri.DatabaseName) ? Factory.GetDatabase(uri.DatabaseName) : global::Sitecore.Context.Database; if (db != null) { using (new SecurityDisabler()) { this.Item = db.GetItem(new DataUri(uri)); } } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } var itemUri = WebUtil.GetQueryString("itemUri"); var fieldName = WebUtil.GetQueryString("fieldName"); if (!ItemUri.IsItemUri(itemUri) || string.IsNullOrWhiteSpace(fieldName)) { return; } var item = Database.GetItem(ItemUri.Parse(itemUri)); if (item == null) { return; } var model = new HoursOfOperationModel(item[fieldName]); OpenTwentyFourHoursRaw.Value = model.OpenTwentyFourHours ? "1" : "0"; if (model[DayOfWeek.Monday] != null) { MondayOpeningTimeSelectRaw.Value = model[DayOfWeek.Monday].OpeningTime; MondayClosingTimeSelectRaw.Value = model[DayOfWeek.Monday].ClosingTime; MondayClosedCheckboxRaw.Value = model[DayOfWeek.Monday].IsClosed ? "1" : "0"; } if (model[DayOfWeek.Tuesday] != null) { TuesdayOpeningTimeSelectRaw.Value = model[DayOfWeek.Tuesday].OpeningTime; TuesdayClosingTimeSelectRaw.Value = model[DayOfWeek.Tuesday].ClosingTime; TuesdayClosedCheckboxRaw.Value = model[DayOfWeek.Tuesday].IsClosed ? "1" : "0"; } if (model[DayOfWeek.Wednesday] != null) { WednesdayOpeningTimeSelectRaw.Value = model[DayOfWeek.Wednesday].OpeningTime; WednesdayClosingTimeSelectRaw.Value = model[DayOfWeek.Wednesday].ClosingTime; WednesdayClosedCheckboxRaw.Value = model[DayOfWeek.Wednesday].IsClosed ? "1" : "0"; } if (model[DayOfWeek.Thursday] != null) { ThursdayOpeningTimeSelectRaw.Value = model[DayOfWeek.Thursday].OpeningTime; ThursdayClosingTimeSelectRaw.Value = model[DayOfWeek.Thursday].ClosingTime; ThursdayClosedCheckboxRaw.Value = model[DayOfWeek.Thursday].IsClosed ? "1" : "0"; } if (model[DayOfWeek.Friday] != null) { FridayOpeningTimeSelectRaw.Value = model[DayOfWeek.Friday].OpeningTime; FridayClosingTimeSelectRaw.Value = model[DayOfWeek.Friday].ClosingTime; FridayClosedCheckboxRaw.Value = model[DayOfWeek.Friday].IsClosed ? "1" : "0"; } if (model[DayOfWeek.Saturday] != null) { SaturdayOpeningTimeSelectRaw.Value = model[DayOfWeek.Saturday].OpeningTime; SaturdayClosingTimeSelectRaw.Value = model[DayOfWeek.Saturday].ClosingTime; SaturdayClosedCheckboxRaw.Value = model[DayOfWeek.Saturday].IsClosed ? "1" : "0"; } if (model[DayOfWeek.Sunday] != null) { SundayOpeningTimeSelectRaw.Value = model[DayOfWeek.Sunday].OpeningTime; SundayClosingTimeSelectRaw.Value = model[DayOfWeek.Sunday].ClosingTime; SundayClosedCheckboxRaw.Value = model[DayOfWeek.Sunday].IsClosed ? "1" : "0"; } }