public IEntity GetEntity(IEntityReference entityReference) { var entities = GetEntities(entityReference.EntityType); var index = entityReference.Index; return(index >= 0 && index <= entities.Count ? entities[index] : null); }
public bool TryConvert(TPrimaryKey primaryKey, out IEntityReference <TEntity> entityReference) { var primaryKeyStr = primaryKey.ToString(); entityReference = _referenceFactory.Create(_typeInstanceFactory, primaryKeyStr); return(true); }
public override bool TryConvert(IEntityReference <T> from, out T to) { if (from == null) { to = default; return(false); } to = from.AsEntity(); return(true); }
public void Remove(IEntityReference <TEntity> reference) { var classReference = (ClassReference)reference; if (classReference.IsChild) { throw new EntitiesException("Can't remove referenced entity, remove root entity"); } Remove(classReference); }
public SingleDeferableSelect <T, T> Select(IEntityReference <T> entityReference) { var builder = QueryBuilder.Select(entityReference, out var resultReader); AttachCustomFactories(resultReader); return(new SingleDeferableSelect <T, T>( builder, _dataProvider, resultReader )); }
internal static void EnsureEntityReferenceLoaded <TInterface>(IEntityReference <TInterface> entityRef) where TInterface : class { Check.Argument.IsNotNull(entityRef, "entityRef"); if (entityRef == null || entityRef.IsLoaded) { return; } entityRef.Load(); }
public IEntitySelectQueryBuilder <T> Select <TView>(IEntityReference <T> entityReference, out IResultReader <TView> resultReader) where TView : class { if (_primaryKeys.Length == 0) { ExceptionHelper.ThrowNoPrimaryKey <T>(); } var entity = entityReference.AsEntity(); var builder = new SelectBuilder <T>(_schema, _entityModel); foreach (var field in _primaryKeys) { builder.Where.AndAlso(field, ComparisonOperator.AreEqual, entity); } builder.Range.Limit(1); resultReader = builder.Projection.AddView <TView>(); return(builder); }
internal static string GetEntityReferenceXmlAttributeValue(IEntityReference entRef) { var entRefTypeOverride = entRef.GetType(); //first attribute, which should be the overridden property if this isn't the base class var firstAttribute = entRefTypeOverride .GetProperties() .FirstOrDefault(); if (firstAttribute != null) { var xmlElement = firstAttribute.GetCustomAttributes(false) .OfType <XmlElementAttribute>().FirstOrDefault(); if (xmlElement != null) { return(xmlElement.ElementName); } } return(null); }
public void AddReferenced <TReference>(IEntityReference <TReference> baseReference, TEntity entity) { // Add entity var reference = GetReference(); reference.Index = entities.Count; references.SetAt(reference.Index, reference); entities.SetAt(reference.Index, entity); Added?.Invoke(entities.Buffer[reference.Index]); // Connect to parent reference.IsChild = true; var linkedReference = (LinkedReference)baseReference; while (linkedReference.Child != null) { linkedReference = linkedReference.Child; } linkedReference.Child = reference; }
public void SetEmailFacet(IReadOnlyDictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contact) { if (facets.TryGetValue(EmailAddressList.DefaultFacetKey, out Facet emailFacet)) { if (emailFacet is EmailAddressList email) { client.SetEmails(contact, email); } else { Log.Error($"{EmailAddressList.DefaultFacetKey} facet is not of expected type. Expected {typeof(EmailAddressList).FullName}", this); } } }
public void SetFacet(IReadOnlyDictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contact, [NotNull] string facetKey) { if (facets.TryGetValue(facetKey, out Facet facet)) { if (facet is StringValueListFacet typedFacet) { client.SetFacet(contact, facetKey, typedFacet); } else { Log.Error($"{facetKey} facet is not of expected type. Expected {typeof(StringValueListFacet).FullName}", this); } } }
protected abstract void SetContactFacets(Dictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contactId);
protected override void SetContactFacets(Dictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contactId) { var contact = client.Get <Contact>(contactId, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, DemographicsFacet.DefaultKey)); var personalFacet = GetFacetOrDefault(facets, PersonalInformation.DefaultFacetKey, contact, client); if (personalFacet is PersonalInformation personal) { client.SetPersonal(contact, personal); } var demographicsFacet = GetFacetOrDefault(facets, DemographicsFacet.DefaultKey, contact, client); if (demographicsFacet is DemographicsFacet demographics) { client.SetFacet(contact, DemographicsFacet.DefaultKey, demographics); } }
public IEntitySelectQueryBuilder <T> Select <TView>(IEntityReference <T> entityReference) where TView : class => Select <TView>(entityReference, out var _);
public void Remove(IEntityReference <TEntity> reference) { Remove((StructReference)reference); }
public IEntityDeleteQueryBuilder <T> Delete(IEntityReference <T> entityReference) => DeleteBuilder <T> .Create(_schema, _entityModel, entityReference);
public IEntitySelectQueryBuilder <T> Select(IEntityReference <T> entityReference) => Select(entityReference, out var _);
public JsEntityReference(IEntityReference baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public DeferableUpdate <T> Update <TView>(IEntityReference <T> entityReference, TView view) where TView : class => new DeferableUpdate <T>(QueryBuilder.Update(entityReference, view), _dataProvider);
public EntityPropertyDescriptor(IEntityReference eref, PropertyDescriptor desc) : base(desc.Name, desc.Attributes.Cast <Attribute>().ToArray()) { _eref = eref; _desc = desc; }
protected internal Attachments(IStorageEntitySetScope <IStoreSession> parentScope, IEntityReference <IItem> parentItem, AttachmentDataProvider attachmentDataProvider, IEntityCommandFactory <Attachments, IAttachment> commandFactory = null) : base(parentScope, "Attachments", commandFactory ?? EntityCommandFactory <Attachments, IAttachment, CreateAttachment, DeleteAttachment, FindAttachments, ReadAttachment, UpdateAttachment> .Instance) { this.ParentItem = parentItem; this.AttachmentDataProvider = attachmentDataProvider; }
/// <summary> /// Gets a list of the worst commenters. /// </summary> /// <returns>A list of commenters sorted by percentage of warnings received over total comments.</returns> public Dictionary <string, CommentsAndWarnings> GetWorstCommenters() { //var contacts = new List<ScoredContact>(); var contacts = new Dictionary <string, CommentsAndWarnings>(); using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { IAsyncQueryable <Interaction> queryable = client.Interactions .Where(x => x.Events.OfType <Event>().Any()); var enumerable = queryable.GetBatchEnumeratorSync(20); while (enumerable.MoveNext()) { var interactionBatch = enumerable.Current; foreach (var interaction in interactionBatch) { // if event is a search event and if it begins with our magic string, f*****g parse that shit var searchEvents = interaction.Events.OfType <SearchEvent>(); foreach (var searchEvent in searchEvents) { // sorry if (searchEvent.Data.StartsWith(Comments.CommentPrefix)) { // Congratulations! It's a comment! string s1 = searchEvent.Data.Substring(Comments.CommentPrefix.Length); int index = s1.IndexOf(Comments.WarningPrefix); string comment = s1.Substring(0, index); //we don't need this in v1 string warningCountString = s1.Substring(index + Comments.WarningPrefix.Length); int warningCount = 0; Int32.TryParse(warningCountString, out warningCount); IEntityReference <Contact> reference = interaction.Contact; Contact contact = client.Get(reference, new ExpandOptions()); string identifier = GetIdentifier(contact); SaveInformation(contacts, identifier, warningCount); // not sorry } } } } return(contacts); } catch (Exception ex) { // Awww jeez, this is bad Sitecore.Diagnostics.Log.Error("Tried to create the list of worst commenters, but we failed :(", ex, this); return(null); } } }
protected override void SetContactFacets(Dictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contactId) { var contact = client.Get <Contact>(contactId, new ContactExpandOptions(SportsFacet.DefaultKey)); var sportsFacet = GetFacetOrDefault(facets, SportsFacet.DefaultKey, contact, client); if (sportsFacet is SportsFacet sports) { client.SetFacet(contact, SportsFacet.DefaultKey, sportsFacet as SportsFacet); } }
protected override void SetContactFacets(Dictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contactId) { var keys = new List <string>() { FacetIDs.FavoriteEvents, FacetIDs.RegisteredEvents, FacetIDs.Subscriptions, FacetIDs.SubscriptionTokens }; var contact = client.Get <Contact>(contactId, new ContactExpandOptions(keys.ToArray())); foreach (var facetKey in keys) { var stringValueFacet = GetFacetOrDefault(facets, facetKey, contact, client); if (stringValueFacet is StringValueListFacet stringValue) { client.SetFacet(contact, facetKey, stringValue); } } }
public void SetFacet(IReadOnlyDictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contact) { if (facets.TryGetValue(SportsFacet.DefaultKey, out Facet sportsFacet)) { if (sportsFacet is SportsFacet sports) { client.SetFacet(contact, SportsFacet.DefaultKey, sports); } else { Log.Error($"{SportsFacet.DefaultKey} facet is not of expected type. Expected {typeof(SportsFacet).FullName}", this); } } }
public void SetPersonalFacet(IReadOnlyDictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contact) { if (facets.TryGetValue(PersonalInformation.DefaultFacetKey, out Facet personalFacet)) { if (personalFacet is PersonalInformation personal) { client.SetPersonal(contact, personal); } else { Log.Error($"{PersonalInformation.DefaultFacetKey} facet is not of expected type. Expected {typeof(PersonalInformation).FullName}", this); } } }
protected override void SetContactFacets(Dictionary <string, Facet> facets, XConnectClient client, IEntityReference <Contact> contactId) { var contact = client.Get <Contact>(contactId, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey)); var personalFacet = GetFacetOrDefault(facets, PersonalInformation.DefaultFacetKey, contact, client); if (personalFacet is PersonalInformation personal) { client.SetPersonal(contact, personal); } var emailFacet = GetFacetOrDefault(facets, EmailAddressList.DefaultFacetKey, contact, client); if (emailFacet is EmailAddressList email) { client.SetEmails(contact, email); } }
public DeferableDelete <T> Delete(IEntityReference <T> entityReference) => new DeferableDelete <T>(QueryBuilder.Delete(entityReference), _dataProvider);