private async Task <Tuple <DocumentUnit, DocumentUnit> > EvaluateMappingDocumentUnitAsync(TCommand command, IBaseCommonExecutor baseCommonExecutor, IContentBase entity, bool isCommandUpdate) { DocumentUnit documentUnit = null; DocumentUnit existDocumentUnit = null; if (typeof(IDocumentUnitEntity).IsAssignableFrom(baseCommonExecutor.GetType())) { documentUnit = await baseCommonExecutor.Mapping(entity, command.Identity, isCommandUpdate); documentUnit.TenantAOO = new TenantAOO() { UniqueId = command.TenantAOOId }; existDocumentUnit = await _webApiClient.GetDocumentUnitAsync(documentUnit); bool skipSendDocument = existDocumentUnit != null && existDocumentUnit.UniqueId == documentUnit.UniqueId && existDocumentUnit.Year == documentUnit.Year && existDocumentUnit.Number == documentUnit.Number && existDocumentUnit.Subject == existDocumentUnit.Subject && existDocumentUnit.Environment == documentUnit.Environment; if ((!isCommandUpdate && !skipSendDocument) || isCommandUpdate) { await baseCommonExecutor.SendDocumentAsync(documentUnit, isCommandUpdate); _logger.WriteDebug(new LogMessage($"DocumentUnit - {entity.GetType()} - {entity.UniqueId} has been successfully created."), LogCategories); } else { _logger.WriteWarning(new LogMessage($"DocumentUnit - {entity.GetType()} - {entity.UniqueId} already exists and CQRS structures has been skipped."), LogCategories); } } return(new Tuple <DocumentUnit, DocumentUnit>(documentUnit, existDocumentUnit)); }
internal SyncAttempt <XElement> SerializeBase(IContentBase item, string contentTypeAlias) { var node = new XElement(contentTypeAlias); node.Add(new XAttribute("guid", item.Key.ToString().ToLower())); node.Add(new XAttribute("id", item.Id)); node.Add(new XAttribute("nodeName", item.Name)); node.Add(new XAttribute("isDoc", "")); node.Add(new XAttribute("updated", item.UpdateDate)); foreach (var prop in item.Properties.Where(p => p != null)) { XElement propNode = null; try { propNode = prop.ToXml(); } catch { propNode = new XElement(prop.Alias, prop.Value); } string xml = ""; xml = GetExportIds(prop.PropertyType, propNode); var updatedNode = XElement.Parse( string.Format("<{0}>{1}</{0}>", propNode.Name.ToString(), xml), LoadOptions.PreserveWhitespace); node.Add(updatedNode); } return(SyncAttempt <XElement> .Succeed(item.Name, node, item.GetType(), ChangeType.Export)); }
/// <summary> /// Gets the entity identifier of the entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns>The entity identifier of the entity.</returns> public static GuidUdi GetUdi(this IContentBase entity) { if (entity == null) { throw new ArgumentNullException("entity"); } string type; if (entity is IContent) { type = Constants.UdiEntityType.Document; } else if (entity is IMedia) { type = Constants.UdiEntityType.Media; } else if (entity is IMember) { type = Constants.UdiEntityType.Member; } else { throw new NotSupportedException(string.Format( "ContentBase type {0} is not supported.", entity.GetType().FullName)); } return(new GuidUdi(type, entity.Key).EnsureClosed()); }
public IContentTypeBaseService For(IContentBase contentBase) { if (contentBase == null) { throw new ArgumentNullException(nameof(contentBase)); } switch (contentBase) { case IContent _: return(_contentTypeService); case IMedia _: return(_mediaTypeService); case IMember _: return(_memberTypeService); default: throw new ArgumentException($"Invalid contentBase type: {contentBase.GetType().FullName}", nameof(contentBase)); } }
public async Task <DocumentUnit> Mapping(IContentBase entity, IIdentityContext identity, bool isUpdate) { DocumentUnit doc = null; DocumentUnit currentDocumentUnit; if (!isUpdate) { doc = await MappingInsertAsync(entity, identity); } if (isUpdate) { currentDocumentUnit = await _webApiClient.GetDocumentUnitAsync(new DocumentUnit(entity.UniqueId)); if (currentDocumentUnit == null) { string message = string.Concat("DoumentUnit ", entity.GetType().Name, " not found with UniqueId ", entity.UniqueId); _logger.WriteError(new LogMessage(message), LogCategories); throw new NullReferenceException(message); } doc = await MappingUpdateAsync(entity, currentDocumentUnit, identity); } return(doc); }
public static IContentTypeComposition GetContentType(this IContentBase contentBase) { if (contentBase == null) { throw new ArgumentNullException("contentBase"); } var content = contentBase as IContent; if (content != null) { return(content.ContentType); } var media = contentBase as IMedia; if (media != null) { return(media.ContentType); } var member = contentBase as IMember; if (member != null) { return(member.ContentType); } throw new NotSupportedException("Unsupported IContentBase implementation: " + contentBase.GetType().FullName + "."); }
public static void RenameFile(string path, IContentBase node, string oldName) { LogHelper.Info<FileHelper>("Rename {0} {1} {2}", () => path, ()=> oldName, ()=> node.GetType().Name); string _root = _mappedRoot ; string _ext = ".content"; if (node.GetType() == typeof(Media)) { LogHelper.Info<FileHelper>("Renaming a Media Item"); _root = _mappedMediaRoot; _ext = ".media"; } string folderRoot = String.Format("{0}{1}", _root, path); string oldFile = Path.Combine(folderRoot, String.Format("{0}{1}", CleanFileName(oldName), _ext)); if (System.IO.File.Exists(oldFile)) System.IO.File.Delete(oldFile); string oldFolder = Path.Combine(folderRoot, CleanFileName(oldName)); string newFolder = Path.Combine(folderRoot, CleanFileName(node.Name)); if (Directory.Exists(oldFolder)) Directory.Move(oldFolder, newFolder); }
private Document GetDocumentToIndex(IContentBase content, SearchField[] searchFields) { try { var c = new Document(); var type = content.GetType(); foreach (var field in GetStandardUmbracoFields()) { try { object propertyValue = null; // handle special case properties switch (field.Name) { case "SearchablePath": propertyValue = content.Path.TrimStart('-'); break; case "Path": propertyValue = content.Path.Split(','); break; case "CreatorName": propertyValue = content.GetCreatorProfile(UmbracoContext.Current.Application.Services.UserService).Name; break; case "ParentID": propertyValue = content.ParentId; break; default: // try get model property PropertyInfo modelProperty; if (!_propertyCache.ContainsKey(type.Name)) { _propertyCache[type.Name] = new Dictionary <string, PropertyInfo>(); } var cache = _propertyCache[type.Name]; if (cache.ContainsKey(field.Name)) { modelProperty = cache[field.Name]; } else { modelProperty = type.GetProperty(field.Name); cache[field.Name] = modelProperty; } if (modelProperty != null) { propertyValue = modelProperty.GetValue(content); } else { // try get umbraco property if (content.HasProperty(field.Name)) { propertyValue = content.GetValue(field.Name); } } break; } // handle datatypes switch (field.Type.ToString()) { case "Edm.String": propertyValue = propertyValue?.ToString(); break; case "Edm.Boolean": bool.TryParse((propertyValue ?? "False").ToString(), out var val); propertyValue = val; break; } if (propertyValue?.ToString().IsNullOrWhiteSpace() == false) { c[field.Name] = propertyValue; } } catch (Exception ex) { throw; } } switch (type.Name) { case "Media": c["IsMedia"] = true; break; case "Content": c["IsContent"] = true; break; case "Member": c["IsMember"] = true; break; } bool cancelIndex = AzureSearch.FireContentIndexing( new AzureSearchEventArgs() { Item = content, Entry = c }); if (cancelIndex) { // cancel was set in an event, so we don't index this item. return(null); } var umbracoFields = searchFields.Where(x => !x.IsComputedField()).ToArray(); var computedFields = searchFields.Where(x => x.IsComputedField()).ToArray(); c = FromUmbracoContentBase(c, content, umbracoFields); c = FromComputedFields(c, content, computedFields); // todo: content isn't actually indexed at this point, consider moving the event to the callback from azure after sending to index AzureSearch.FireContentIndexed( new AzureSearchEventArgs() { Item = content, Entry = c }); return(c); } catch (Exception ex) { throw; } }
public static IContentTypeComposition GetContentType(this IContentBase contentBase) { if (contentBase == null) { throw new ArgumentNullException(nameof(contentBase)); } if (contentBase is IContent content) { return(content.ContentType); } if (contentBase is IMedia media) { return(media.ContentType); } if (contentBase is IMember member) { return(member.ContentType); } throw new NotSupportedException("Unsupported IContentBase implementation: " + contentBase.GetType().FullName + "."); }