Beispiel #1
0
        protected override void PerformDelete <T>(HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            var file = this.Get <File>(id);

            if (file == null)
            {
                throw new IOException(
                          string.Format("File with id '{0}' does not exist in this providers storage location", id));
            }

            if (!file.IsContainer)
            {
                System.IO.File.Delete(file.RootedPath);
            }
            else
            {
                System.IO.Directory.Delete(file.RootedPath, true);
            }

            // Delete any relations
            var entityMd5     = id.Value.ToString().ToMd5();
            var searchPattern = "*" + entityMd5 + "*.xml";

            if (Directory.Exists(Settings.RelationsStoragePath))
            {
                var files = Directory.GetFiles(Settings.RelationsStoragePath, searchPattern);
                foreach (var filePath in files)
                {
                    System.IO.File.Delete(filePath);
                }
            }
        }
        public ActionResult EditRule(HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            //The rule Id consists of both the stylesheet Id and the rule name
            var idParts      = id.StringParts().ToList();
            var stylesheetId = idParts[0];
            var ruleName     = idParts.Count > 1 ? idParts[1] : "";

            ViewBag.IsNew = string.IsNullOrWhiteSpace(ruleName);

            using (var uow = _hive.Create())
            {
                var stylesheet = uow.Repositories.Get <Umbraco.Framework.Persistence.Model.IO.File>(new HiveId(stylesheetId));
                var rule       = !string.IsNullOrWhiteSpace(ruleName) ?
                                 StylesheetHelper.ParseRules(stylesheet).Single(x => x.Name.Replace(" ", "__s__") == ruleName) :
                                 new StylesheetRule()
                {
                    StylesheetId = id
                };

                var ruleModel = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <StylesheetRuleEditorModel>(rule);

                return(View(ruleModel));
            }
        }
        public override EntitySnapshot <TEntity> PerformGetLatestSnapshot <TEntity>(HiveId hiveId, RevisionStatusType revisionStatusType = null)
        {
            Mandate.ParameterNotEmpty(hiveId, "hiveId");

            var latestRevision = GetLatestRevision <TEntity>(hiveId, revisionStatusType);

            if (latestRevision == null)
            {
                return(null);
            }



            //IEnumerable<Revision<TEntity>> revisions = GetAll<TEntity>(hiveId, revisionStatusType);

            //if (!revisions.Any()) return null;

            //if (revisionStatusType != null)
            //    revisions = revisions.Where(x => x.MetaData.StatusType.Id == revisionStatusType.Id);
            //var revision = revisions.OrderByDescending(x => x.MetaData.UtcStatusChanged).FirstOrDefault();

            IEnumerable <RevisionData> otherRevisionData = GetAllRevisionData(hiveId);

            return(new EntitySnapshot <TEntity>(latestRevision, otherRevisionData));
        }
Beispiel #4
0
        public void Delete <T>(HiveId entityId)
        {
            Mandate.ParameterNotEmpty(entityId, "entityId");

            var file = GetEntity <File>(entityId);

            if (file == null)
            {
                throw new IOException(
                          string.Format("File with id '{0}' does not exist in this providers storage location", entityId));
            }

            if (!file.IsContainer)
            {
                System.IO.File.Delete(file.Location);
            }
            else
            {
                System.IO.Directory.Delete(file.Location, true);
            }

            // Delete any relations
            var entityMd5     = entityId.ToString().ToMd5();
            var searchPattern = "*" + entityMd5 + "*.xml";

            if (Directory.Exists(_relationsFolder))
            {
                var files = Directory.GetFiles(_relationsFolder, searchPattern);
                foreach (var filePath in files)
                {
                    System.IO.File.Delete(filePath);
                }
            }
        }
        private IEnumerable <RevisionData> GetAllRevisionData(HiveId entityUri)
        {
            Mandate.ParameterNotEmpty(entityUri, "hiveId");

            //var entityStatusLog = Helper.NhSession.QueryOver<NodeVersionStatusHistory>()
            //    .OrderBy(x => x.Date).Desc
            //    .JoinQueryOver(x => x.NodeVersion).Where(x => x.Node.Id == (Guid)entityUri.Value)
            //    .List()
            //    .DistinctBy(x => x.Id);

            NodeVersionStatusHistory aliasHistory = null;
            NodeVersion           aliasVersion    = null;
            Node                  aliasNode       = null;
            NodeVersionStatusType aliasType       = null;
            var entityStatusLog = Helper.NhSession.QueryOver <NodeVersionStatusHistory>(() => aliasHistory)
                                  .OrderBy(x => x.Date).Desc
                                  .JoinQueryOver(x => x.NodeVersionStatusType, () => aliasType)
                                  .JoinQueryOver(x => aliasHistory.NodeVersion, () => aliasVersion)
                                  .JoinQueryOver(x => x.Node, () => aliasNode)
                                  .Where(x => x.Id == (Guid)entityUri.Value)
                                  .Fetch(x => aliasHistory.NodeVersionStatusType).Eager
                                  .Select(x => x.Date, x => x.Id, x => aliasNode.DateCreated, x => aliasType.Id, x => aliasType.IsSystem, x => aliasType.Alias, x => aliasType.Name, x => aliasVersion.Id)
                                  .List <object[]>()
                                  .Select(col => new
            {
                Date         = (DateTimeOffset)col[0],
                Id           = (Guid)col[1],
                DateCreated  = (DateTimeOffset)col[2],
                TypeId       = (Guid)col[3],
                TypeIsSystem = (bool)col[4],
                TypeAlias    = (string)col[5],
                TypeName     = (string)col[6],
                VersionId    = (Guid)col[7]
            });

            var otherRevisionData = new HashSet <RevisionData>();
            var changeset         = new Changeset(new Branch("default")); // Ignored for the moment in the persistence layer for this provider

            foreach (var statusQueryRow in entityStatusLog)
            {
                var nodeVersionStatusType = new NodeVersionStatusType
                {
                    Alias    = statusQueryRow.TypeAlias,
                    Name     = statusQueryRow.TypeName,
                    Id       = statusQueryRow.TypeId,
                    IsSystem = statusQueryRow.TypeIsSystem
                };

                var revisionStatusType = FrameworkContext.TypeMappers.Map <RevisionStatusType>(nodeVersionStatusType);
                var revisionData       = new RevisionData(changeset, (HiveId)statusQueryRow.VersionId, revisionStatusType)
                {
                    UtcCreated       = statusQueryRow.DateCreated,
                    UtcModified      = statusQueryRow.Date,
                    UtcStatusChanged = statusQueryRow.Date
                };

                otherRevisionData.Add(revisionData);
            }
            return(otherRevisionData);
        }
Beispiel #6
0
        /// <summary>
        /// Gets a revision matching the revision id, entity id and entity type
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entityId"></param>
        /// <param name="revisionId"></param>
        /// <returns></returns>
        public Revision <TEntity> PerformGetRevision <TEntity>(HiveId entityId, HiveId revisionId)
            where TEntity : class, IVersionableEntity
        {
            Mandate.ParameterNotEmpty(entityId, "entityId");
            Mandate.ParameterNotEmpty(revisionId, "revisionId");

            var key = ScopedCacheKey + "PerformGetRevision-" +
                      (typeof(TEntity).FullName + entityId.Value + revisionId.Value).ToMd5();

            return(GetOrCreateFromScopedCache <Revision <TEntity> >(key, () =>
            {
                var criteria = ExamineManager.CreateSearchCriteria()
                               .Must().HiveId(revisionId, FixedRevisionIndexFields.RevisionId)
                               .Must().HiveId(entityId, FixedIndexedFields.EntityId)
                               .Must().EntityType <TEntity>();
                var result = ExamineManager.Search(criteria.Compile());
                if (result.TotalItemCount > 1)
                {
                    throw new IndexOutOfRangeException("The search result returned more than one item");
                }

                if (result.TotalItemCount == 0)
                {
                    return null;
                }

                return _frameworkContext.TypeMappers.Map <Revision <TEntity> >(result.Single());
            }));
        }
        /// <summary>
        /// Enlists the id of an <see cref="IRelatableEntity"/> in a <see cref="RelationProxy"/> as a parent of the <see cref="IRelatableEntity"/> which owns this collection.
        /// </summary>
        /// <param name="parentId">The parent id.</param>
        /// <param name="type">The type.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="metaData">The meta data.</param>
        public void EnlistParentById(HiveId parentId, AbstractRelationType type, int ordinal = 0, params RelationMetaDatum[] metaData)
        {
            Mandate.ParameterNotEmpty(parentId, "parentId");
            var newRelation = new Relation(type, parentId, _collectionOwner, ordinal, metaData);

            AddToParentsWithLock(new RelationProxy(newRelation, RelationProxyStatus.ManuallyAdded));
        }
Beispiel #8
0
        public ActionResult EditForm(HiveId?id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = Hive.Create <ISecurityStore>())
            {
                var userEntity = uow.Repositories.Get <User>(id.Value);

                if (userEntity == null)
                {
                    throw new ArgumentException(string.Format("No entity for id: {0} on action EditForm", id));
                }

                var userViewModel = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <User, UserEditorModel>(userEntity);
                userViewModel.UserGroups =
                    uow.Repositories.GetParentRelations(userEntity.Id, FixedRelationTypes.UserGroupRelationType).Select
                        (x => x.SourceId).ToArray();

                //need to ensure that all of the Ids are mapped correctly, when editing existing content the only reason for this
                //is to ensure any new document type properties that have been created are reflected in the new content revision
                ReconstructModelPropertyIds(userViewModel);

                EnsureViewBagData();

                return(ProcessSubmit(userViewModel, userEntity));
            }
        }
        /// <summary>
        /// Enlists the id of an <see cref="IRelatableEntity"/> in a <see cref="RelationProxy"/> as a child of the <see cref="IRelatableEntity"/> which owns this collection.
        /// </summary>
        /// <param name="childId">The child id.</param>
        /// <param name="type">The type.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="metaData">The meta data.</param>
        public void EnlistChildById(HiveId childId, AbstractRelationType type, int ordinal, params RelationMetaDatum[] metaData)
        {
            Mandate.ParameterNotEmpty(childId, "childId");
            var newRelation = new Relation(type, _collectionOwner, childId, ordinal, metaData);

            AddToChildrenWithLock(new RelationProxy(newRelation, RelationProxyStatus.ManuallyAdded));
        }
Beispiel #10
0
        public ActionResult EditForm(HiveId?id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = Hive.Create <IContentStore>())
            {
                var item = uow.Repositories.Schemas.GetComposite <EntitySchema>(id.Value);

                if (item == null)
                {
                    throw new ArgumentException(string.Format("No document type found for id: {0} on action EditForm", id));
                }

                //create a editor model from it and map properties
                var model = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <EntitySchema, TEditorModel>(item);

                OnBeforeUpdate(model); //TODO: Make this an event/task?

                var redirectResult = ProcessSubmit(model, item, uow);

                uow.Complete();

                //Path generation needs to happen in a new unit of work to ensure update of relations
                using (var uow2 = Hive.Create <IContentStore>())
                {
                    //add path for entity for SupportsPathGeneration (tree syncing) to work
                    GeneratePathsForCurrentEntity(uow2.Repositories.Schemas.GetEntityPaths <EntitySchema>(id.Value, FixedRelationTypes.DefaultRelationType));
                }

                return(redirectResult);
            }
        }
Beispiel #11
0
        public ActionResult CreateNewForm(CreateUserModel createModel)
        {
            Mandate.ParameterNotNull(createModel, "createModel");
            Mandate.ParameterNotEmpty(createModel.ParentId, "createModel.ParentId");
            Mandate.ParameterNotEmpty(createModel.SelectedDocumentTypeId, "createModel.SelectedDocumentTypeId");

            //validate the model
            TryUpdateModel(createModel);
            //get the create new result view which will validate that the selected doc type id is in fact allowed
            var result = CreateNewView(createModel);

            //if at this point the model state is invalid, return the result which is the CreateNew view
            if (!ModelState.IsValid)
            {
                return(result);
            }

            using (var uow = BackOfficeRequestContext.Application.Hive.OpenReader <IContentStore>())
            {
                var schema = uow.Repositories.Schemas.GetComposite <EntitySchema>(createModel.SelectedDocumentTypeId);
                if (schema == null)
                {
                    throw new ArgumentException(string.Format("No schema found for id: {0} on action Create", createModel.SelectedDocumentTypeId));
                }

                //create the empty content item
                var userViewModel = CreateNewUserEntity(schema, createModel.Name, createModel.Username, createModel.Email, createModel.Password, createModel.ParentId);

                //map the Ids correctly to the model so it binds
                ReconstructModelPropertyIds(userViewModel);

                return(ProcessSubmit(createModel, userViewModel, null));
                //return View(createModel);
            }
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RelationById"/> class.
 /// </summary>
 /// <param name="sourceId">The source id.</param>
 /// <param name="destinationId">The destination id.</param>
 /// <param name="relationType">Type of the relation.</param>
 /// <param name="ordinal">The ordinal.</param>
 /// <param name="metaData">The meta data.</param>
 public RelationById(HiveId sourceId, HiveId destinationId, AbstractRelationType relationType, int ordinal, params RelationMetaDatum[] metaData)
     : this(relationType, ordinal, metaData)
 {
     Mandate.ParameterNotEmpty(sourceId, "sourceId");
     Mandate.ParameterNotEmpty(destinationId, "destinationId");
     _sourceId      = sourceId;
     _destinationId = destinationId;
     Ordinal        = ordinal;
 }
        public virtual UmbracoTreeResult Index(HiveId id, FormCollection querystrings)
        {
            Mandate.ParameterNotEmpty(id, "id");

            //if its the root node, render it otherwise render normal nodes
            return(AddRootNodeToCollection(id, querystrings)
                ? UmbracoTree()
                : GetTreeData(id, querystrings));
        }
        public override IEnumerable <Revision <TEntity> > PerformGetLatestRevisions <TEntity>(bool allOrNothing, RevisionStatusType revisionStatusType = null, params HiveId[] entityIds)
        {
            Mandate.ParameterNotNull(entityIds, "entityIds");
            entityIds.ForEach(x => Mandate.ParameterNotEmpty(x, "entityIds"));
            Guid[] nodeIds   = entityIds.Where(x => x.Value.Type == HiveIdValueTypes.Guid).Select(x => (Guid)x.Value).ToArray();
            var    revisions = Helper.GetNodeVersionsByStatusDesc(nodeIds, revisionStatusType, true).Distinct();

            return(nodeIds.Select(x => revisions.SingleOrDefault(y => y.Node.Id == x)).WhereNotNull().Select(x => FrameworkContext.TypeMappers.Map <Revision <TEntity> >(x)));
        }
Beispiel #15
0
        public virtual JsonResult LanguageForm(LanguageModel model)
        {
            Mandate.ParameterNotEmpty(model.Id, "Id");

            using (var uow = Hive.Create <IContentStore>())
            {
                //get the content entity for the language assignment
                var entity = uow.Repositories.Get <TypedEntity>(model.Id);
                if (entity == null)
                {
                    throw new NullReferenceException("Could not find entity with id " + model.Id);
                }

                var languageRelations = uow.Repositories.GetParentRelations(model.Id, FixedRelationTypes.LanguageRelationType);
                var languageRelation  = languageRelations.SingleOrDefault();

                if (model.IsoCode.IsNullOrWhiteSpace())
                {
                    if (languageRelation != null)
                    {
                        uow.Repositories.RemoveRelation(languageRelation);
                    }
                }
                else
                {
                    if (languageRelation == null || languageRelation.MetaData.SingleOrDefault(x => x.Key == "IsoCode").Value != model.IsoCode)
                    {
                        var metaData = new List <RelationMetaDatum>
                        {
                            new RelationMetaDatum("IsoCode", model.IsoCode)
                        };

                        uow.Repositories.ChangeOrCreateRelationMetadata(FixedHiveIds.SystemRoot, entity.Id,
                                                                        FixedRelationTypes.LanguageRelationType, metaData.ToArray());
                    }
                }

                uow.Complete();

                //clears the domain cache
                //BackOfficeRequestContext.RoutingEngine.ClearCache(clearDomains: true, clearGeneratedUrls: true);

                var successMsg = "Language.Success.Message".Localize(this, new
                {
                    Name = entity.GetAttributeValue(NodeNameAttributeDefinition.AliasValue, "Name")
                });
                Notifications.Add(new NotificationMessage(successMsg, "Language.Title".Localize(this), NotificationType.Success));

                return(new CustomJsonResult(new
                {
                    success = true,
                    notifications = Notifications,
                    msg = successMsg
                }.ToJsonString));
            }
        }
        /// <summary>
        /// Returns a composite Id to be used for a relation
        /// </summary>
        /// <param name="relation"></param>
        /// <returns></returns>
        internal static string GetCompositeId(this IRelationById relation)
        {
            Mandate.ParameterNotEmpty(relation.SourceId, "relation.SourceId");
            Mandate.ParameterNotEmpty(relation.DestinationId, "relation.DestinationId");
            Mandate.ParameterNotEmpty(relation.SourceId.Value, "relation.SourceId.Value");
            Mandate.ParameterNotEmpty(relation.DestinationId.Value, "relation.SourceId.Value");
            Mandate.ParameterNotNull(relation.Type, "relation.Type");
            Mandate.ParameterNotNullOrEmpty(relation.Type.RelationName, "relation.Type.RelationName");

            return(relation.SourceId.Value + "," + relation.DestinationId.Value + "," + relation.Type.RelationName);
        }
        /// <summary>
        /// constructor for creating a property that has a multi-value
        /// </summary>
        /// <param name="id"></param>
        /// <param name="docTypeProperty">The DocumentTypeProperty associated with this content property</param>
        /// <param name="propertyValue">The value of the property, used to set the values of the editor model</param>
        public ContentProperty(HiveId id,
                               DocumentTypeProperty docTypeProperty,
                               IDictionary <string, object> propertyValue)
        {
            Mandate.ParameterNotEmpty(id, "id");
            Mandate.ParameterNotNull(docTypeProperty, "docTypeProperty");

            _propertyValue    = propertyValue;
            Id                = id;
            DocTypeProperty   = docTypeProperty;
            DocTypePropertyId = docTypeProperty.Id;
        }
Beispiel #18
0
        /// <summary>
        /// Creates a data type
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="alias"></param>
        /// <param name="propertyEditor">The PropertyEditor associated with the DataType</param>
        /// <param name="preValues">The pre values stored in the repository for the DataType</param>
        public DataType(HiveId id, string name, string alias, dynamic propertyEditor, string preValues)
        {
            Mandate.ParameterNotEmpty(id, "id");
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNullOrEmpty(alias, "alias");
            //Mandate.ParameterNotNull(propertyEditor, "propertyEditor");

            Name  = name;
            Alias = alias;
            InternalPropertyEditor = propertyEditor;
            Prevalues = preValues;
        }
        protected override IEnumerable <TEntity> PerformGet <TEntity>(bool allOrNothing, params HiveId[] ids)
        {
            Mandate.ParameterNotNull(ids, "ids");
            ids.ForEach(x => Mandate.ParameterNotEmpty(x, "id"));

            Type destinationType = GetDestinationTypeOrThrow <TEntity>();

            Guid[] values   = ids.Where(x => x.Value.Type == HiveIdValueTypes.Guid).Select(x => (Guid)x.Value).ToArray();
            var    entities = Helper.NhSession.CreateCriteria(destinationType).Add(Restrictions.In(Projections.Property <Node>(x => x.Id), values)).List();

            return(entities.Cast <IReferenceByGuid>().Select(x => FrameworkContext.TypeMappers.Map <TEntity>(x)));
        }
Beispiel #20
0
        public virtual JsonResult Delete(HiveId?id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = Hive.Create <IContentStore>())
            {
                uow.Repositories.Delete <TypedEntity>(id.Value);
                uow.Complete();
            }

            //return a successful JSON response
            return(Json(new { message = "Success" }));
        }
Beispiel #21
0
        public override bool Exists <TEntity>(HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            var value = (Guid)id.Value;

            var qo = Helper.NhSession.QueryOver <AttributeSchemaDefinition>()
                     .Where(x => x.Id == value)
                     .Select(Projections.RowCount())
                     .SingleOrDefault <int>();

            return(qo > 0);
        }
Beispiel #22
0
        public JsonResult Delete(HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = Hive.Create <IContentStore>())
            {
                uow.Repositories.Schemas.Delete <EntitySchema>(id);
                uow.Complete();
            }

            //return a successful JSON response
            return(Json(new { message = "Success" }));
        }
        public virtual JsonResult Delete(HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = Hive.Create())
            {
                uow.Repositories.Delete <File>(id);
                uow.Complete();
            }

            //return a successful JSON response
            return(Json(new { message = "Success" }));
        }
Beispiel #24
0
        public override IEnumerable <T> PerformGet <T>(bool allOrNothing, params HiveId[] ids)
        {
            Mandate.ParameterNotNull(ids, "ids");
            ids.ForEach(x => Mandate.ParameterNotEmpty(x, "id"));

            // We don't just ask for the Node by id here because some other types inherit from Node
            // like AttributeSchemaDefinition. Therefore, a Node that represents a TypedEntity is said
            // to exist if a NodeVersion exists
            Guid[] nodeIds      = ids.Where(x => x.Value.Type == HiveIdValueTypes.Guid).Select(x => (Guid)x.Value).ToArray();
            var    nodeVersions = Helper.GetNodeVersionsByStatusDesc(nodeIds, limitToLatestRevision: true).ToArray();

            return(nodeIds.Select(x => nodeVersions.SingleOrDefault(y => y.Node.Id == x)).WhereNotNull().Select(x => FrameworkContext.TypeMappers.Map <T>(x)));
        }
        /// <summary>
        /// Resolves the url for the specified id.
        /// </summary>
        /// <param name="routingEngine"></param>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static string GetUrl(this IRoutingEngine routingEngine, HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            var applicationContext = DependencyResolver.Current.GetService <IRebelApplicationContext>();

            var hive = applicationContext.Hive.GetReader <IContentStore>(id.ToUri());

            if (hive != null)
            {
                var key  = CacheKey.Create(new UrlCacheKey(id));
                var item = hive.HiveContext.GenerationScopedCache.GetOrCreate(key, () =>
                {
                    using (var uow = hive.CreateReadonly())
                    {
                        //var entity = uow.Repositories.Get<TypedEntity>(id);
                        var entity = uow.Repositories.OfRevisionType(FixedStatusTypes.Published).InIds(id).FirstOrDefault();
                        if (entity == null)
                        {
                            throw new NullReferenceException("Could not find a TypedEntity in the repository for a content item with id " + id.ToFriendlyString());
                        }

                        return(routingEngine.GetUrlForEntity(entity));
                    }
                });

                var urlResult = item.Value.Item;

                ////return from scoped cache so we don't have to lookup in the same session
                //var urlResult = applicationContext.FrameworkContext.ScopedCache.GetOrCreateTyped<UrlResolutionResult>("nice-url-" + id, () =>
                //    {
                //        using (var uow = hive.CreateReadonly())
                //        {
                //            var entity = uow.Repositories.Get<TypedEntity>(id);
                //            if (entity == null)
                //                throw new NullReferenceException("Could not find a TypedEntity in the repository for a content item with id " + id.ToFriendlyString());

                //            return routingEngine.GetUrlForEntity(entity);
                //        }
                //    });
                if (urlResult.IsSuccess())
                {
                    return(urlResult.Url);
                }

                //return a hashed url with the status
                return("#" + urlResult.Status);
            }

            return(id.ToString());
        }
Beispiel #26
0
        /// <summary>
        /// Gets entities matching the id
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="allOrNothing">if set to <c>true</c> [all or nothing].</param>
        /// <param name="idField">The id field to search on</param>
        /// <param name="ids">The ids.</param>
        /// <returns></returns>
        public IEnumerable <T> PerformGet <T>(bool allOrNothing, string idField, params HiveId[] ids)
        {
            Mandate.ParameterNotNull(ids, "ids");
            ids.ForEach(x => Mandate.ParameterNotEmpty(x, "id"));

            var key = ScopedCacheKey + "PerformGet-" +
                      (typeof(T).FullName + allOrNothing + idField + string.Join(".", ids.Select(x => x.Value))).ToMd5();

            return(GetOrCreateFromScopedCache <IEnumerable <T> >(key, () =>
            {
                //NOTE: Because of allOrNothing, we can't yield return anything.
                var toReturn = new List <T>();

                foreach (var i in ids)
                {
                    IQuery criteria;
                    if (TypeFinder.IsTypeAssignableFrom <TypedEntity>(typeof(T)))
                    {
                        criteria = ExamineManager.CreateSearchCriteria()
                                   .Must().HiveId(i, idField)
                                   .Must().Range(FixedRevisionIndexFields.IsLatest, 1, 1)
                                   .Must().EntityType <T>().Compile();
                    }
                    else
                    {
                        //anything else...
                        criteria = ExamineManager.CreateSearchCriteria()
                                   .Must().HiveId(i, idField)
                                   .Must().EntityType <T>().Compile();
                    }

                    // NOTE: We currently return the 'newest', not sure if that is the correct approach. SD.
                    var result = ExamineManager.Search(criteria)
                                 .OrderBy(x => x.Fields[FixedIndexedFields.UtcModified])
                                 .LastOrDefault();

                    if (result == null)
                    {
                        if (allOrNothing)
                        {
                            return Enumerable.Empty <T>();
                        }
                    }

                    var mapped = _frameworkContext.TypeMappers.Map <T>(result);

                    toReturn.Add(mapped);
                }
                return toReturn;
            }));
        }
Beispiel #27
0
        /// <summary>
        /// Creates a new TEditorModel based on the persisted doc type
        /// </summary>
        /// <param name="docTypeData"></param>
        /// <param name="name"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        protected virtual TEditorModel CreateNewContentEntity(EntitySchema docTypeData, string name, HiveId parentId)
        {
            Mandate.ParameterNotNull(docTypeData, "docTypeData");
            Mandate.ParameterNotEmpty(parentId, "parentId");

            //get doc type model
            var docType = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <EntitySchema, DocumentTypeEditorModel>(docTypeData);
            //map (create) content model from doc type model
            var contentModel = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <DocumentTypeEditorModel, TEditorModel>(docType);

            contentModel.ParentId = parentId;
            contentModel.Name     = name;
            return(contentModel);
        }
        public virtual JsonResult Delete(HiveId?id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = _hive.Create())
            {
                var oldFolder = uow.Repositories.Get <Rebel.Framework.Persistence.Model.IO.File>(id.Value);
                if (oldFolder != null)
                {
                    uow.Repositories.Delete <Rebel.Framework.Persistence.Model.IO.File>(oldFolder.Id);
                }
            }

            //return a successful JSON response
            return(Json(new { message = "Success" }));
        }
        public FileEditorModel(HiveId id, string name, DateTimeOffset created, DateTimeOffset updated, Func <string> content)
        {
            Mandate.ParameterNotEmpty(id, "id");
            Mandate.ParameterNotNullOrEmpty(name, "name");
            Mandate.ParameterNotNull(content, "content");


            Id          = id;
            UtcCreated  = created;
            UtcModified = updated;
            Name        = name;

            FileContent = content();

            PopulateUIElements();
        }
        public override EntitySnapshot <TEntity> GetSnapshot <TEntity>(HiveId hiveId, HiveId revisionId)
        {
            Mandate.ParameterNotEmpty(hiveId, "hiveId");
            Mandate.ParameterNotEmpty(revisionId, "revisionId");

            var revision = Get <TEntity>(hiveId, revisionId);

            if (revision == null)
            {
                return(null);
            }

            IEnumerable <RevisionData> otherRevisionData = GetAllRevisionData(hiveId);

            return(new EntitySnapshot <TEntity>(revision, otherRevisionData));
        }