Пример #1
0
        public Yield PostArchiveFilesRestore(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);

            // parameter parsing
            PageBE destPage = null;
            string to       = context.GetParam("to", string.Empty);

            if (to != string.Empty)
            {
                destPage = PageBL_GetPageFromPathSegment(false, to);
            }
            PageBE     parentPage;
            ResourceBE removedFile = GetAttachment(context, request, Permissions.NONE, true, true, out parentPage);

            if (!removedFile.ResourceIsDeleted)
            {
                throw new AttachmentArchiveFileNotDeletedNotFoundException();
            }

            //Optionally move the restored file to the given page
            if (null == destPage)
            {
                destPage = parentPage;
            }
            AttachmentBL.Instance.RestoreAttachment(removedFile, destPage, DateTime.UtcNow, 0);
            response.Return(DreamMessage.Ok());
            yield break;
        }
Пример #2
0
        private static ResourceBE PopulateFile(IDataRecord dr)
        {
            string   name              = GetUTF8String(dr, "img_name");
            uint     size              = DbUtils.Convert.To <uint>(dr["img_size"], 0);
            MimeType mimetype          = new MimeType(GetUTF8String(dr, "img_major_mime") + "/" + GetUTF8String(dr, "img_minor_mime"));
            string   changedescription = GetUTF8String(dr, "img_description");
            uint     userId;

            if (MediaWikiConverterContext.Current.Merge)
            {
                userId = MediaWikiConverterContext.Current.MergeUserId;
            }
            else
            {
                userId = DbUtils.Convert.To <uint>(dr["img_user"], 0);
            }

            // TODO (steveb): why is this not used?!?
            DateTime timestamp = DbUtils.ToDateTime(GetUTF8String(dr, "img_timestamp"));

            ResourceContentBE rc = new ResourceContentBE(true);

            rc.Size     = size;
            rc.MimeType = mimetype;

            ResourceBE file = ResourceBL.Instance.BuildRevForNewResource(0 /*parent page defined later*/, ResourceBE.ParentType.PAGE, name, mimetype, size, changedescription, ResourceBE.Type.FILE, userId, rc);

            file.MetaXml.Elem("physicalfilename", GetUTF8String(dr, "img_filename"));
            return(file);
        }
Пример #3
0
 private static void SaveCachedThumb(ResourceBE attachment, SizeType size, StreamInfo file)
 {
     if (file != null)
     {
         DekiContext.Current.Instance.Storage.PutFile(attachment, size, file);
     }
 }
Пример #4
0
        private void PropertyExport(PageBE page, ResourceBE file, ResourceBE property)
        {
            // Export the property
            XUri   propertyUri = null;
            string filename    = null;

            if (null != file)
            {
                propertyUri = property.PropertyContentUri(AttachmentBL.Instance.GetUri(file));
                filename    = file.Name;
            }
            else
            {
                propertyUri = property.PropertyContentUri(PageBL.GetUriCanonical(page));
            }
            if (!_uris.ContainsKey(propertyUri))
            {
                _uris.Add(propertyUri, null);
                XDoc manifestDoc = new XDoc("property").Elem("name", property.Name)
                                   .Elem("filename", filename)
                                   .Elem("path", page.Title.AsRelativePath(_relToTitle))
                                   .Start("contents").Attr("type", property.MimeType.ToString()).End();
                Add(propertyUri, manifestDoc);
            }
        }
Пример #5
0
        public Yield PostFileMove(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE     sourcePage = null;
            PageBE     destPage   = null;
            ResourceBE fileToMove = GetAttachmentFromUrl(context, true, out sourcePage, false, false);

            // parameter parsing
            string name = context.GetParam("name", null);
            string to   = context.GetParam("to", null);

            if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(to))
            {
                throw new AttachmentMoveInvalidArgumentException();
            }
            if (name == null)
            {
                name = fileToMove.Name;
            }
            destPage = to != null?PageBL_GetPageFromPathSegment(true, to) : sourcePage;

            //Check if we're actually doing anything
            if (sourcePage.ID == destPage.ID && fileToMove.Name.EqualsInvariant(name))
            {
                throw new AttachmentNotChangedInvalidOperationException(fileToMove.Name, destPage.Title.AsUserFriendlyName());
            }

            //Ensure write access to source and destination pages.
            IList <PageBE> pList = PermissionsBL.FilterDisallowed(DekiContext.Current.User, new PageBE[] { sourcePage, destPage }, true, Permissions.UPDATE);

            // perform the move
            ResourceBE ret = AttachmentBL.Instance.MoveAttachment(fileToMove, sourcePage, destPage, name, true);

            response.Return(DreamMessage.Ok(AttachmentBL.Instance.GetFileXml(ret, true, null, false)));
            yield break;
        }
Пример #6
0
        public Yield GetFileRevisions(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            CheckResponseCache(context, false);

            //Default change filter is CONTENT changes to preserve backwards compat
            string changeFilterStr = context.GetParam("changefilter", AttachmentBL.DEFAULT_REVISION_FILTER.ToString());

            ResourceBE.ChangeOperations changeFilter = ResourceBE.ChangeOperations.UNDEFINED;
            if (!string.IsNullOrEmpty(changeFilterStr))
            {
                if (StringUtil.EqualsInvariantIgnoreCase("all", changeFilterStr))
                {
                    changeFilter = ResourceBE.ChangeOperations.UNDEFINED;
                }
                else if (!SysUtil.TryParseEnum(changeFilterStr, out changeFilter))
                {
                    throw new DreamBadRequestException("changefilter value is invalid. Possible values are ALL, " + string.Join(",", Enum.GetNames(typeof(ResourceBE.ChangeOperations))));
                }
            }

            PageBE     parentPage   = null;
            ResourceBE fileRevision = GetAttachment(context, request, Permissions.READ, false, false, out parentPage);
            XUri       listUri      = AttachmentBL.Instance.GetUri(fileRevision).At("revisions").With("changefilter", changeFilterStr.ToLowerInvariant());
            XDoc       ret          = AttachmentBL.Instance.GetFileRevisionsXml(fileRevision, changeFilter, listUri, fileRevision.Revision);

            response.Return(DreamMessage.Ok(ret));
            yield break;
        }
Пример #7
0
        private void NotifyPropertyParent(DateTime eventTime, ResourceBE prop, UserBE user, ResourceBE.ParentType parentType, string action)
        {
            if (parentType == ResourceBE.ParentType.PAGE && prop.ParentPageId != null)
            {
                PageBE parentPage = PageBL.GetPageById(prop.ParentPageId.Value);
                if (parentPage != null)
                {
                    PageDependentChanged(eventTime, parentPage, user, PROPERTY, action);
                }
            }
            else if (parentType == ResourceBE.ParentType.USER)
            {
                // Owner of property may not be same as requesting user.
                // The dependentschanged event is triggered on the property owner.
                if (prop.ParentUserId != null)
                {
                    // Optimization to avoid a db call when operating on your own user property.
                    if (user.ID != prop.ParentUserId.Value)
                    {
                        user = UserBL.GetUserById(prop.ParentUserId.Value);
                        if (user == null)
                        {
                            _log.WarnFormat("Could not find owner user (id: {0}) of user property (key: {1})", prop.ParentUserId.Value, prop.Name);
                            return;
                        }
                    }
                }

                UserDependentChanged(eventTime, user, PROPERTY, action);
            }

            //TODO (maxm): trigger file property changes
        }
Пример #8
0
 public void ReAssociateResourceState(ResourceBE oldRev, ResourceBE newRev)
 {
     if (oldRev == null || newRev == null)
     {
         return;
     }
 }
Пример #9
0
 public XDoc GetFileXml(ResourceBE file, bool verbose, string fileSuffix, bool?explicitRevisionInfo)
 {
     return(GetFileXml(new List <ResourceBE>()
     {
         file
     }, verbose, false, fileSuffix, explicitRevisionInfo, null, null));
 }
Пример #10
0
        public virtual ResourceBE Delete(ResourceBE resource, PageBE parentPage, uint changeSetId)
        {
            //Build the new revision
            ResourceBE res = BuildRevForRemove(resource, DateTime.UtcNow, changeSetId);

            //Update db
            res = SaveResource(res);

            //Update indexes and parent page's timestamp

            //TODO MaxM: Changesink needs to accept a resource
            if (res.ResourceType == ResourceBE.Type.FILE)
            {
                DekiContext.Current.Instance.EventSink.AttachmentDelete(DekiContext.Current.Now, res, DekiContext.Current.User);

                // Recent changes
                RecentChangeBL.AddFileRecentChange(DekiContext.Current.Now, parentPage, DekiContext.Current.User, DekiResources.FILE_REMOVED(res.Name), changeSetId);
            }

            if (parentPage != null)
            {
                PageBL.Touch(parentPage, DateTime.UtcNow);
            }

            return(res);
        }
Пример #11
0
        public virtual ResourceBE UpdateResourceRevision(ResourceBE res)
        {
            ResourceBE ret = DbUtils.CurrentSession.Resources_UpdateRevision(res);

            ReAssociateResourceState(res, ret);
            return(ret);
        }
Пример #12
0
        protected ResourceBE BuildRevForRestore(ResourceBE currentResource, PageBE targetPage, string resourceName, uint changeSetId)
        {
            ResourceBE newRev = _resourceBL.BuildRevForRestore(currentResource, targetPage, resourceName, changeSetId);

            newRev.MetaXml.FileId = currentResource.MetaXml.FileId;
            return(newRev);
        }
Пример #13
0
        public ResourceBE CreateProperty(uint?parentId, XUri parentUri, ResourceBE.ParentType parentType, string name, ResourceContentBE content, string description, string etag, AbortEnum abort)
        {
            //TODO: The parent resource isn't verified when the resource name and the parent info is given
            ResourceBE prop = _resourceBL.GetResource(parentId, parentType, ResourceBE.Type.PROPERTY, name, DeletionFilter.ACTIVEONLY);

            if (prop != null)
            {
                switch (abort)
                {
                case AbortEnum.Exists:
                    throw new PropertyExistsConflictException(name);

                case AbortEnum.Modified:
                    _resourceBL.ValidateEtag(etag, prop, true);
                    break;
                }
                prop = _resourceBL.BuildRevForContentUpdate(prop, content.MimeType, content.Size, description, null, content);
                prop = _resourceBL.SaveResource(prop);
                DekiContext.Current.Instance.EventSink.PropertyUpdate(DekiContext.Current.Now, prop, DekiContext.Current.User, parentType, parentUri);
            }
            else
            {
                if ((abort == AbortEnum.Modified) && !string.IsNullOrEmpty(etag))
                {
                    throw new PropertyUnexpectedEtagConflictException();
                }
                prop = _resourceBL.BuildRevForNewResource(parentId, parentType, name, content.MimeType, content.Size, description, ResourceBE.Type.PROPERTY, DekiContext.Current.User.ID, content);
                prop = _resourceBL.SaveResource(prop);
                DekiContext.Current.Instance.EventSink.PropertyCreate(DekiContext.Current.Now, prop, DekiContext.Current.User, parentType, parentUri);
            }
            return(prop);
        }
Пример #14
0
        protected ResourceBE BuildRevForRemove(ResourceBE currentResource, DateTime timestamp, uint changeSetId)
        {
            ResourceBE newRev = _resourceBL.BuildRevForRemove(currentResource, timestamp, changeSetId);

            newRev.MetaXml.FileId = currentResource.MetaXml.FileId;
            return(newRev);
        }
Пример #15
0
        public ResourceBE[] IdentifyUnknownImages(IEnumerable <ResourceBE> attachments)
        {
            List <ResourceBE> ret = new List <ResourceBE>();

            foreach (ResourceBE file in attachments)
            {
                ResourceBE updatedFile = file;
                if (file != null && IsAllowedForImageMagickPreview(file) && (file.MetaXml.ImageHeight == null || file.MetaXml.ImageWidth == null))
                {
                    StreamInfo fileInfo = _dekiContext.Instance.Storage.GetFile(file, SizeType.ORIGINAL, false);
                    if (file != null)
                    {
                        int width;
                        int height;
                        int frames;
                        if (AttachmentPreviewBL.RetrieveImageDimensions(fileInfo, out width, out height, out frames))
                        {
                            file.MetaXml.ImageWidth  = width;
                            file.MetaXml.ImageHeight = height;

                            // check if we need to store the number of frames (default is 1)
                            if (frames > 1)
                            {
                                file.MetaXml.ImageFrames = frames;
                            }
                            updatedFile = _resourceBL.UpdateResourceRevision(file);
                        }
                    }
                }
                ret.Add(updatedFile);
            }
            return(ret.ToArray());
        }
Пример #16
0
        protected ResourceBE BuildRevForContentUpdate(ResourceBE currentResource, MimeType mimeType, uint size, string description, string name, ResourceContentBE newContent)
        {
            ResourceBE newRev = _resourceBL.BuildRevForContentUpdate(currentResource, mimeType, size, description, name, newContent);

            newRev.MetaXml.FileId = currentResource.MetaXml.FileId;
            return(newRev);
        }
Пример #17
0
 private static StreamInfo BuildThumb(ResourceBE attachment, StreamInfo file, FormatType format, RatioType ratio, uint width, uint height)
 {
     if (!AttachmentBL.Instance.IsAllowedForImageMagickPreview(attachment))
     {
         return(file);
     }
     return(BuildThumb(file, format, ratio, width, height));
 }
Пример #18
0
        internal Yield IndexFile(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            ResourceBE file = GetAttachment(context, request, Permissions.NONE);

            DekiContext.Current.Instance.EventSink.AttachmentPoke(DekiContext.Current.Now, file);
            response.Return(DreamMessage.Ok());
            yield break;
        }
Пример #19
0
        private void PropertyChanged(DateTime eventTime, ResourceBE prop, UserBE user, ResourceBE.ParentType parentType, XUri parentUri, params string[] path)
        {
            try {
                string parent = string.Empty;
                switch (parentType)
                {
                case ResourceBE.ParentType.PAGE:
                    parent = PAGES;
                    break;

                case ResourceBE.ParentType.FILE:
                    parent = FILES;
                    break;

                case ResourceBE.ParentType.USER:
                    parent = USERS;
                    break;

                case ResourceBE.ParentType.SITE:
                    parent = SITE;
                    break;
                }
                XUri     channel  = _channel.At(parent).At(PROPERTY).At(path);
                XUri     resource = prop.PropertyInfoUri(parentUri);
                string[] origin   = new string[] { resource.ToString() };
                XDoc     doc      = new XDoc("deki-event")
                                    .Elem("channel", channel)
                                    .Elem("name", prop.Name)
                                    .Elem("uri", resource)
                                    .Start("content")
                                    .Attr("mime-type", prop.MimeType.FullType)
                                    .Attr("size", prop.Size)
                                    .Attr("href", prop.PropertyContentUri(parentUri));
                if (prop.MimeType.MainType == MimeType.TEXT.MainType && prop.Size < 256)
                {
                    doc.Value(ResourceContentBL.Instance.Get(prop).ToText());
                }
                doc.End();
                if (parentType == ResourceBE.ParentType.PAGE)
                {
                    doc.Elem("pageid", prop.ParentPageId ?? 0);
                }
                else if (parentType == ResourceBE.ParentType.USER)
                {
                    doc.Elem("userid", prop.ParentUserId ?? 0);
                }
                else if (parentType == ResourceBE.ParentType.FILE)
                {
                    ResourceBE attachment = ResourceBL.Instance.GetResource(prop.ParentId.Value);
                    doc.Elem("fileid", attachment.MetaXml.FileId ?? 0);
                    PageDependentChanged(eventTime, PageBL.GetPageById(attachment.ParentPageId.Value), user, ArrayUtil.Concat(new string[] { FILES, PROPERTY }, path));
                }
                Queue(eventTime, channel, resource, origin, doc);
            } catch (Exception e) {
                _log.WarnExceptionMethodCall(e, "PropertyChanged", "event couldn't be created");
            }
        }
Пример #20
0
 //--- Methods ---
 public bool IsAllowedForImageMagickPreview(ResourceBE file)
 {
     // TODO (steveb): recognize mime-types as well
     if (Array.IndexOf(_dekiContext.Instance.ImageMagickExtensions, file.FilenameExtension.ToLowerInvariant()) == -1)
     {
         return(false);
     }
     return(_dekiContext.Instance.MaxImageSize >= file.Size);
 }
Пример #21
0
        public Yield PutFile(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            // Retrieve the file
            PageBE     page;
            string     userFileName;
            ResourceBE file = GetAttachmentFromUrl(context, false, out page, false, false);

            // If the file does not exist, attempt to retrieve the page
            if (null == file)
            {
                if (null == page)
                {
                    if (null != DreamContext.Current.GetParam <string>("fileid"))
                    {
                        throw new AttachmentNotFoundException();
                    }
                    page = PageBL_GetPageFromUrl(context, true);
                }
                userFileName = GetFilenameFromPathSegment(DreamContext.Current.GetParam <string>("filename"));
            }
            else
            {
                string fileNameParam = DreamContext.Current.GetParam("filename", null);
                if (fileNameParam == null)
                {
                    userFileName = file.Name;
                }
                else
                {
                    userFileName = GetFilenameFromPathSegment(fileNameParam);
                }
            }

            // Retrieve the file description
            string userDescription = context.GetParam("description", string.Empty);

            if (userDescription.Length > AttachmentBL.MAX_DESCRIPTION_LENGTH)
            {
                userDescription = userDescription.Substring(0, AttachmentBL.MAX_DESCRIPTION_LENGTH);
            }

            // Validate the page
            PageBL.AuthorizePage(DekiContext.Current.User, Permissions.UPDATE, page, false);

            // Get entire stream so it can be reused
            var        isMSWebDAV        = MSWEBDAV_USER_AGENT_REGEX.IsMatch(request.Headers.UserAgent ?? string.Empty);
            ResourceBE savedFileRevision = AttachmentBL.Instance.AddAttachment(file, request.AsStream(), request.ContentLength, request.ContentType, page, userDescription, userFileName, isMSWebDAV);

            // report an error on failure, and don't redirect
            if (savedFileRevision == null)
            {
                throw new AttachmentUploadSaveFatalException();
            }
            response.Return(DreamMessage.Ok(AttachmentBL.Instance.GetFileXml(savedFileRevision, true, null, null)));
            yield break;
        }
Пример #22
0
        public Yield PostFileRevisions(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            ResourceBE file = GetAttachment(context, request, Permissions.DELETE);

            ResourceBE[] modifiedRevs = AttachmentBL.Instance.ModifyRevisionVisibility(file, request.ToDocument(), context.GetParam("comment", string.Empty));
            XDoc         ret          = AttachmentBL.Instance.GetAttachmentRevisionListXml(modifiedRevs);

            response.Return(DreamMessage.Ok(ret));
            yield break;
        }
Пример #23
0
        private static StreamInfo GetCachedThumb(ResourceBE attachment, SizeType size)
        {
            StreamInfo result = null;

            if (size == SizeType.THUMB || size == SizeType.WEBVIEW)
            {
                result = DekiContext.Current.Instance.Storage.GetFile(attachment, size, false);
            }
            return(result);
        }
Пример #24
0
 public ResourceBE UpdatePropertyContent(ResourceBE prop, ResourceContentBE content, string changeDescription, string eTag, AbortEnum abort, XUri parentUri, ResourceBE.ParentType parentType)
 {
     if (abort == AbortEnum.Modified)
     {
         _resourceBL.ValidateEtag(eTag, prop, true);
     }
     prop = _resourceBL.BuildRevForContentUpdate(prop, content.MimeType, content.Size, changeDescription, null, content);
     prop = _resourceBL.SaveResource(prop);
     DekiContext.Current.Instance.EventSink.PropertyUpdate(DekiContext.Current.Now, prop, DekiContext.Current.User, parentType, parentUri);
     return(prop);
 }
Пример #25
0
        public virtual ResourceBE BuildRevForRemove(ResourceBE currentResource, DateTime timestamp, uint changeSetId)
        {
            ResourceBE newRev = BuildResourceRev(currentResource);

            newRev.ResourceIsDeleted = true;
            newRev.Deleted           = true;
            newRev.ChangeSetId       = changeSetId;
            newRev.Timestamp         = timestamp;
            newRev.ChangeMask        = newRev.ChangeMask | ResourceBE.ChangeOperations.DELETEFLAG;
            return(newRev);
        }
Пример #26
0
        public virtual ResourceBE BuildRevForRestore(ResourceBE currentResource, PageBE targetPage, string resourceName, uint changeSetId)
        {
            ResourceBE newRev = BuildResourceRev(currentResource);

            newRev.ResourceIsDeleted = false;
            newRev.ChangeSetId       = changeSetId;
            newRev.ParentPageId      = (uint)targetPage.ID;
            newRev.Name       = resourceName;
            newRev.ChangeMask = newRev.ChangeMask | ResourceBE.ChangeOperations.DELETEFLAG;
            return(newRev);
        }
Пример #27
0
        private ResourceBE BuildRevForExistingResource(ResourceBE currentResource, MimeType mimeType, uint size, string description)
        {
            ResourceBE newRev = BuildResourceRev(currentResource);

            newRev.MimeType          = mimeType;
            newRev.Size              = size;
            newRev.ChangeDescription = description;
            newRev.Content           = currentResource.Content;
            newRev.ContentId         = currentResource.ContentId;
            return(newRev);
        }
Пример #28
0
        public Dictionary <Title, ResourceBE> Resources_GetFileResourcesByTitlesWithMangling(IList <Title> fileTitles)
        {
            //A specialized query that retrieves file resources from titles. This is only used from DekiXmlParser.ConvertFileLinks

            Dictionary <Title, ResourceBE> ret = new Dictionary <Title, ResourceBE>();

            if (ArrayUtil.IsNullOrEmpty(fileTitles))
            {
                return(ret);
            }

            string query = @" /* Resources_GetFileResourcesByTitlesWithMangling */
select resources.*, resourcecontents.*, pages.page_id, pages.page_namespace, pages.page_title, pages.page_display_name
from pages
join resources
	on resrev_parent_page_id = page_id
left join resourcecontents
    on resources.resrev_content_id = resourcecontents.rescontent_id
where
        res_type = 2
    AND res_deleted = 0
AND(    
        {0}
)
    ";

            StringBuilder whereQuery = new StringBuilder();

            for (int i = 0; i < fileTitles.Count; i++)
            {
                if (i > 0)
                {
                    whereQuery.Append("\n OR ");
                }
                whereQuery.AppendFormat("(pages.page_namespace={0} AND pages.page_title='{1}' AND REPLACE(resources.resrev_name, ' ', '_') = REPLACE('{2}', ' ', '_'))",
                                        (uint)fileTitles[i].Namespace, DataCommand.MakeSqlSafe(fileTitles[i].AsUnprefixedDbPath()), DataCommand.MakeSqlSafe(fileTitles[i].Filename));
            }

            query = string.Format(query, whereQuery);

            Catalog.NewQuery(query).Execute(delegate(IDataReader dr) {
                while (dr.Read())
                {
                    Title title  = DbUtils.TitleFromDataReader(dr, "page_namespace", "page_title", "page_display_name", "resrev_name");
                    ResourceBE r = Resources_Populate(dr) as ResourceBE;
                    if (r != null)
                    {
                        ret[title] = r;
                    }
                }
            });

            return(ret);
        }
Пример #29
0
        public Yield PutFileDescription(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE     parentPage;
            ResourceBE file = GetAttachment(context, request, Permissions.UPDATE, false, false, out parentPage);

            // determine if description needs to be set or cleared
            string description = StringUtil.EqualsInvariant(context.Verb, "PUT") ? request.AsText() : string.Empty;

            file = AttachmentBL.Instance.SetDescription(file, description);
            response.Return(DreamMessage.Ok(AttachmentBL.Instance.GetFileXml(file, true, null, null)));
            yield break;
        }
Пример #30
0
        public Yield GetArchiveFileInfo(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);
            PageBE     parentPage  = null;
            ResourceBE removedFile = GetAttachment(context, request, Permissions.NONE, true, true, out parentPage);

            if (!removedFile.ResourceIsDeleted)
            {
                throw new AttachmentArchiveFileNotDeletedNotFoundException();
            }
            response.Return(DreamMessage.Ok(AttachmentBL.Instance.GetFileXml(removedFile, true, "archive", null)));
            yield break;
        }
Пример #31
0
        public void Rating_ResetUserResourceRating(uint userId, ulong resourceId, ResourceBE.Type resourceType, DateTime resetTimestamp) {
            Catalog.NewQuery(@" /* RatingDA::Rating_ResetUserResourceRating */
UPDATE  ratings
SET     rating_reset_timestamp = ?RATING_RESET_TIMESTAMP
WHERE   rating_resource_id = ?RATING_RESOURCE_ID
AND     rating_resource_type = ?RATING_RESOURCE_TYPE
AND     rating_user_id = ?RATING_USER_ID
AND     rating_reset_timestamp is NULL;")
           .With("RATING_RESOURCE_ID", resourceId)
           .With("RATING_RESOURCE_TYPE", (byte)resourceType)
           .With("RATING_USER_ID", userId)
           .With("RATING_RESET_TIMESTAMP", resetTimestamp)
           .Execute();

            Rating_Compute(resourceId, resourceType, resetTimestamp);
        }
Пример #32
0
        public RatingComputedBE Rating_GetResourceRating(ulong resourceId, ResourceBE.Type resourceType) {
            RatingComputedBE rc = null;
            string query = @" /* RatingDA::Rating_GetResourceRating */
SELECT *
FROM    ratingscomputed
WHERE   ratingscomputed_resource_id = ?RATINGSCOMPUTED_RESOURCE_ID
AND     ratingscomputed_resource_type = ?RATINGSCOMPUTED_RESOURCE_TYPE;
";
            Catalog.NewQuery(query)
                .With("RATINGSCOMPUTED_RESOURCE_ID", resourceId)
                .With("RATINGSCOMPUTED_RESOURCE_TYPE", (byte)resourceType)
            .Execute(delegate(IDataReader dr) {
                if(dr.Read()) {
                    rc = Rating_PopulateRatingComputed(dr);
                }
            });
            return rc;
        }
Пример #33
0
                // -- Constructors --
                public State() {
                    resourceBE = ResourceBE.New(ResourceBE.Type.UNDEFINED);
                    resourceDeletionFilter = DeletionFilter.ANY;
                    revisionVisibilityFilter = VisibilityFilter.ANY;
                    resourceIds = null;
                    nameFilter = null;
                    parentIds = null;
                    parentType = ResourceBE.Type.UNDEFINED;
                    resourceTypes = null;
                    changeSetId = null;
                    changeType = ResourceBE.ChangeOperations.UNDEFINED;

                    populateResourceCountOnly = false;
                    populateContent = true;
                    populateRevisions = false;
                    populateChildResourcesForRev = false;
                    populateChildResources = false;
                    orderClauses = null;
                    limit = null;
                    offset = null;
                }
Пример #34
0
        private void Rating_Compute(ulong resourceId, ResourceBE.Type resourceType, DateTime timestamp) {

            int sumRatingScore = 0;
            int ratingsCount = 0;
            int trendSumRatingScore = 0;
            int trendRatingsCount = 0;

            Catalog.NewQuery(@" /* RatingDA::Rating_Compute: determine score */
SELECT  CAST(SUM(rating_score) as UNSIGNED INTEGER) as sum_rating_score, COUNT(*) as count_ratings
FROM    ratings
WHERE   rating_resource_id = ?RATING_RESOURCE_ID
AND     rating_resource_type = ?RATING_RESOURCE_TYPE
AND     rating_reset_timestamp IS NULL;

SELECT  CAST(SUM(rating_score) as UNSIGNED INTEGER) as trend_sum_rating_score, COUNT(*) as trend_count_ratings
FROM    ratings
WHERE   rating_resource_id = ?RATING_RESOURCE_ID
AND     rating_resource_type = ?RATING_RESOURCE_TYPE
AND     rating_reset_timestamp IS NULL
ORDER BY rating_timestamp DESC
LIMIT ?TREND_SIZE;
")
            .With("RATING_RESOURCE_ID", resourceId)
            .With("RATING_RESOURCE_TYPE", (byte)resourceType)
            .With("TREND_SIZE", RATING_TREND_SIZE)
            .Execute(delegate(IDataReader dr) {
                if(dr.Read()) {
                    sumRatingScore = dr.Read<int>("sum_rating_score", 0);
                    ratingsCount = dr.Read<int>("count_ratings", 0);
                }
                if(dr.NextResult() && dr.Read()) {
                    trendSumRatingScore = dr.Read<int>("trend_sum_rating_score", 0);
                    trendRatingsCount = dr.Read<int>("trend_count_ratings", 0);
                }
            });

            if(ratingsCount > 0 && trendRatingsCount > 0) {
                float score = (float)sumRatingScore / (float)ratingsCount;
                float scoreTrend = (float)trendSumRatingScore / (float)trendRatingsCount;

                Catalog.NewQuery(@" /* RatingDA::Rating_Compute: set computed rating */
REPLACE INTO ratingscomputed
SET     ratingscomputed_resource_id = ?RATING_RESOURCE_ID,
        ratingscomputed_resource_type = ?RATING_RESOURCE_TYPE,
        ratingscomputed_timestamp = ?RATING_TIMESTAMP,
        ratingscomputed_score = ?RATING_SCORE,
        ratingscomputed_count = ?RATING_COUNT,
        ratingscomputed_score_trend = ?RATING_SCORE_TREND;
")
                .With("RATING_RESOURCE_ID", resourceId)
                .With("RATING_RESOURCE_TYPE", (byte)resourceType)
                .With("RATING_TIMESTAMP", timestamp)
                .With("RATING_SCORE", score)
                .With("RATING_COUNT", ratingsCount)
                .With("RATING_SCORE_TREND", scoreTrend)
                .Execute();
            } else {

                // if no active ratings exist for a page, remove the computed rating
                Catalog.NewQuery(@" /* RatingDA::Rating_Compute: delete computed rating */
DELETE FROM ratingscomputed
WHERE   ratingscomputed_resource_id = ?RATING_RESOURCE_ID
AND     ratingscomputed_resource_type = ?RATING_RESOURCE_TYPE;
")
                .With("RATING_RESOURCE_ID", resourceId)
                .With("RATING_RESOURCE_TYPE", (byte)resourceType)
                .Execute();
            }
        }
Пример #35
0
        public RatingBE Rating_GetUserResourceRating(uint userId, ulong resourceId, ResourceBE.Type resourceType) {
            RatingBE r = null;
            string query = @" /* RatingDA::Rating_GetUserResourceRating */
SELECT *
FROM    ratings
WHERE   rating_resource_id = ?RATING_RESOURCE_ID
AND     rating_resource_type = ?RATING_RESOURCE_TYPE
AND     rating_user_id = ?RATING_USER_ID
AND     rating_reset_timestamp is NULL;
";
            Catalog.NewQuery(query)
                .With("RATING_RESOURCE_ID", resourceId)
                .With("RATING_RESOURCE_TYPE", (byte)resourceType)
                .With("RATING_USER_ID", userId)
            .Execute(delegate(IDataReader dr) {
                if(dr.Read()) {
                    r = Rating_PopulateRating(dr);
                }
            });
            return r;
        }
Пример #36
0
        private static ResourceBE Resources_Populate(IDataReader dr) {
            ResourceBE.Type resourceType = (ResourceBE.Type)DbUtils.Convert.To<byte>(dr["res_type"]);
            ResourceBE res = new ResourceBE(resourceType);

            MimeType mimeTypeTmp = null;
            for(int i = 0; i < dr.FieldCount; i++) {

                #region ResourceBE and ResourceContentBE entity mapping
                switch(dr.GetName(i).ToLowerInvariant()) {
                case "res_id":
                    res.ResourceId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_res_id":
                    res.ResourceId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_rev":
                    res.Revision = DbUtils.Convert.To<int>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_user_id":
                    res.UserId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_change_mask":
                    res.ChangeMask = (ResourceBE.ChangeOperations)(DbUtils.Convert.To<ushort>(dr.GetValue(i)) ?? (ushort)ResourceBE.ChangeOperations.UNDEFINED);
                    break;
                case "resrev_name":
                    res.Name = dr.GetValue(i) as string;
                    break;
                case "resrev_change_description":
                    res.ChangeDescription = dr.GetValue(i) as string;
                    break;
                case "resrev_timestamp":
                    res.Timestamp = new DateTime(dr.GetDateTime(i).Ticks, DateTimeKind.Utc);
                    break;
                case "resrev_content_id":
                    res.ContentId = DbUtils.Convert.To<uint>(dr.GetValue(i), 0);
                    break;
                case "resrev_deleted":
                    res.Deleted = DbUtils.Convert.To<bool>(dr.GetValue(i), false);
                    break;
                case "resrev_size":
                    res.Size = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_mimetype":
                    MimeType.TryParse(dr.GetValue(i) as string, out mimeTypeTmp);
                    res.MimeType = mimeTypeTmp;
                    break;
                case "resrev_changeset_id":
                    res.ChangeSetId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_parent_id":
                    res.ParentId = DbUtils.Convert.To<uint>(dr.GetValue(i));
                    break;
                case "resrev_parent_page_id":
                    res.ParentPageId = DbUtils.Convert.To<uint>(dr.GetValue(i));
                    break;
                case "resrev_parent_user_id":
                    res.ParentUserId = DbUtils.Convert.To<uint>(dr.GetValue(i));
                    break;
                case "res_headrev":
                    res.ResourceHeadRevision = DbUtils.Convert.To<int>(dr.GetValue(i)) ?? 0;
                    break;
                case "res_type":

                    // this column was already read
                    break;
                case "res_deleted":
                    res.ResourceIsDeleted = DbUtils.Convert.To<bool>(dr.GetValue(i), false);
                    break;
                case "res_create_timestamp":
                    res.ResourceCreateTimestamp = new DateTime(dr.GetDateTime(i).Ticks, DateTimeKind.Utc);
                    break;
                case "res_update_timestamp":
                    res.ResourceUpdateTimestamp = new DateTime(dr.GetDateTime(i).Ticks, DateTimeKind.Utc);
                    break;
                case "res_create_user_id":
                    res.ResourceCreateUserId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "res_update_user_id":
                    res.ResourceUpdateUserId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "resrev_language":
                    res.Language = dr.GetValue(i) as string;
                    break;
                case "resrev_is_hidden":
                    res.IsHidden = DbUtils.Convert.To<bool>(dr.GetValue(i), false);
                    break;
                case "resrev_meta":
                    res.Meta = dr.GetValue(i) as string;
                    break;
                case "rescontent_id":
                    res.Content.ContentId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "rescontent_res_id":
                    res.Content.ResourceId = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "rescontent_res_rev":
                    res.Content.Revision = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                case "rescontent_value":
                    res.Content.SetData(dr.GetValue(i) as byte[]);
                    break;
                case "rescontent_location":
                    res.Content.Location = dr.GetValue(i) as string;
                    break;
                case "rescontent_mimetype":
                    MimeType.TryParse(dr.GetValue(i) as string, out mimeTypeTmp);
                    res.Content.MimeType = mimeTypeTmp;
                    break;
                case "rescontent_size":
                    res.Content.Size = DbUtils.Convert.To<uint>(dr.GetValue(i)) ?? 0;
                    break;
                default:
                    break;
                }

                #endregion
            }

            //Resource contents may not always be retrieved. Make sure it's null if it's not there.
            if(res.Content != null && res.Content.IsNewContent()) {
                res.Content = null;
            }

            return res;
        }
Пример #37
0
 private ResourceBE[] Resources_ExecuteInsertUpdateQuery(ResourceBE resource, string query) {
     List<ResourceBE> resources = new List<ResourceBE>();
     Catalog.NewQuery(query)
         .With("RES_ID", resource.ResourceId)
         .With("RES_HEADREV", resource.ResourceHeadRevision)
         .With("RES_TYPE", (uint) resource.ResourceType)
         .With("RES_CREATE_TIMESTAMP", resource.ResourceCreateTimestamp)
         .With("RES_UPDATE_TIMESTAMP", resource.ResourceUpdateTimestamp)
         .With("RES_CREATE_USER_ID", resource.ResourceCreateUserId)
         .With("RES_UPDATE_USER_ID", resource.ResourceUpdateUserId)
         .With("RES_DELETED", resource.ResourceIsDeleted)
         .With("RESREV_REV", resource.Revision)
         .With("RESREV_USER_ID", resource.UserId)
         .With("RESREV_PARENT_ID", resource.ParentId)
         .With("RESREV_PARENT_PAGE_ID", resource.ParentPageId)
         .With("RESREV_PARENT_USER_ID", resource.ParentUserId)
         .With("RESREV_CHANGE_MASK", (ushort) resource.ChangeMask)
         .With("RESREV_NAME", resource.Name)
         .With("RESREV_CHANGE_DESCRIPTION", resource.ChangeDescription)
         .With("RESREV_TIMESTAMP", resource.Timestamp)
         .With("RESREV_DELETED", resource.Deleted)
         .With("RESREV_CHANGESET_ID", resource.ChangeSetId)
         .With("RESREV_SIZE", resource.Size)
         .With("RESREV_MIMETYPE", resource.MimeType != null ? resource.MimeType.ToString() : null)
         .With("RESREV_CONTENT_ID", resource.ContentId)
         .With("RESREV_LANGUAGE", resource.Language)
         .With("RESREV_IS_HIDDEN", resource.IsHidden)
         .With("RESREV_META", resource.Meta)
         .With("RESCONTENT_RES_REV", resource.Content != null ? resource.Content.Revision : null)
         .Execute(delegate(IDataReader dr) {
         while(dr.Read()) {
             resources.Add(Resources_Populate(dr));
         }
     });
     return resources.ToArray();
 }
Пример #38
0
 public ResourceQuery WithResourceType(ResourceBE.Type resourceType) {
     return WithResourceType(new ResourceBE.Type[] { resourceType });                
 }
Пример #39
0
 public ResourceQuery WithChangeType(ResourceBE.ChangeOperations changeType) {
     State s = new State(_state);
     s.changeType = changeType;
     return new ResourceQuery(s);
 }
Пример #40
0
 public IList<ResourceBE> Resources_GetByQuery(IList<uint> parentIds, ResourceBE.Type parentType, IList<ResourceBE.Type> resourceTypes, IList<string> names, DeletionFilter deletionStateFilter, bool? populateRevisions, uint? offset, uint? limit) {
     ResourceQuery rq = new ResourceQuery();
     rq = rq.WithParent(parentIds, parentType);
     rq = rq.WithResourceType(resourceTypes);
     rq = rq.WithNames(names);
     rq = rq.WithDeletionFilter(deletionStateFilter);
     rq = rq.IncludeRevisions(populateRevisions ?? false);
     rq = rq.Limit(limit);
     rq = rq.Offset(offset);
     rq = rq.OrderBy(ResourceQuery.ResourceOrderClause.SortTable.RESOURCES, "res_id", SortDirection.ASC);
     return rq.SelectList(Catalog, "Resources_Get");
 }
Пример #41
0
 public IList<ResourceBE> Resources_GetRevisions(uint resourceId, ResourceBE.ChangeOperations changeTypesFilter, SortDirection sortRevisions, uint? limit) {
     return new ResourceQuery()
     .WithResourceId(resourceId)
     .WithChangeType(changeTypesFilter)
     .IncludeRevisions(true)
     .OrderBy(ResourceQuery.ResourceOrderClause.SortTable.RESOURCEREVISIONS, "resrev_rev", sortRevisions)
     .Limit(limit)
     .SelectList(Catalog, "Resources_GetRevisions");
 }
Пример #42
0
        public IList<ResourceBE> Resources_GetByChangeSet(uint changeSetId, ResourceBE.Type resourceType) {
            if(changeSetId == 0) {
                return new List<ResourceBE>();
            }

            return new ResourceQuery()
            .WithChangeSetIds(changeSetId)
            .WithResourceType(resourceType)
            .SelectList(Catalog, "Resources_GetByChangeSet");
        }
Пример #43
0
 public uint Resources_GetRevisionCount(uint resourceId, ResourceBE.ChangeOperations changeTypesFilter) {
     return new ResourceQuery()
     .WithResourceId(resourceId)
     .WithChangeType(changeTypesFilter)
     .IncludeRevisions(true)
     .SelectCount(Catalog, "Resources_GetRevisionCount") ?? 0;
 }
Пример #44
0
        public ResourceBE Resources_SaveRevision(ResourceBE resource) {
            string query = string.Empty;
            string contentUpdateQuery = string.Empty;
            bool contentUpdated = false;

            if(resource.Content != null && resource.Content.IsNewContent()){
                contentUpdated = true;
                ResourceContentBE content = Resources_ContentInsert(resource.Content);
                resource.Content = content;
                resource.ContentId = content.ContentId;
            }

            if(resource.IsNewResource()) {
                query = @" /* Resources_SaveRevision (new resource) */
set @resourceid = 0;

insert into resources set
res_headrev =               ?RES_HEADREV, 
res_type =                  ?RES_TYPE, 
res_deleted =               ?RES_DELETED, 
res_create_timestamp =      ?RES_CREATE_TIMESTAMP, 
res_update_timestamp =      ?RES_UPDATE_TIMESTAMP, 
res_create_user_id =        ?RES_CREATE_USER_ID, 
res_update_user_id =        ?RES_UPDATE_USER_ID, 
resrev_rev =                ?RESREV_REV, 
resrev_user_id =            ?RESREV_USER_ID, 
resrev_parent_id =          ?RESREV_PARENT_ID, 
resrev_parent_page_id =     ?RESREV_PARENT_PAGE_ID, 
resrev_parent_user_id =     ?RESREV_PARENT_USER_ID, 
resrev_change_mask =        ?RESREV_CHANGE_MASK, 
resrev_name =               ?RESREV_NAME, 
resrev_change_description = ?RESREV_CHANGE_DESCRIPTION, 
resrev_timestamp =          ?RESREV_TIMESTAMP, 
resrev_content_id =         ?RESREV_CONTENT_ID, 
resrev_deleted =            ?RESREV_DELETED, 
resrev_changeset_id =       ?RESREV_CHANGESET_ID, 
resrev_size =               ?RESREV_SIZE, 
resrev_mimetype =           ?RESREV_MIMETYPE, 
resrev_language =           ?RESREV_LANGUAGE,
resrev_is_hidden =          ?RESREV_IS_HIDDEN, 
resrev_meta =               ?RESREV_META;

select last_insert_id() into @resourceid;

insert into resourcerevs set 
resrev_res_id =             @resourceid,
resrev_rev =                ?RESREV_REV,
resrev_user_id =            ?RESREV_USER_ID,
resrev_parent_id =          ?RESREV_PARENT_ID,
resrev_parent_page_id =     ?RESREV_PARENT_PAGE_ID,
resrev_parent_user_id =     ?RESREV_PARENT_USER_ID,
resrev_change_mask =        ?RESREV_CHANGE_MASK,
resrev_name =               ?RESREV_NAME,
resrev_change_description = ?RESREV_CHANGE_DESCRIPTION,
resrev_timestamp =          ?RESREV_TIMESTAMP,
resrev_content_id =         ?RESREV_CONTENT_ID,
resrev_deleted =            ?RESREV_DELETED,
resrev_changeset_id =       ?RESREV_CHANGESET_ID,
resrev_size =               ?RESREV_SIZE,
resrev_mimetype =           ?RESREV_MIMETYPE,
resrev_language =           ?RESREV_LANGUAGE,
resrev_is_hidden =          ?RESREV_IS_HIDDEN,
resrev_meta =               ?RESREV_META;

update resourcecontents set 
rescontent_res_id =     @resourceid,
rescontent_res_rev =    ?RESREV_REV
where rescontent_id =   ?RESREV_CONTENT_ID;

select *
from resources
left join resourcecontents
    on resources.resrev_content_id = resourcecontents.rescontent_id
where res_id = @resourceid;

/* End of ResourceDA::InsertResourceRevision (new resource) */
";

            } else {

                resource.Revision = ++resource.ResourceHeadRevision;               
                if(contentUpdated) {
                    resource.Content.Revision = (uint) resource.Revision;
                }

                query = @" /* Resources_SaveRevision + concurrency check (new revision) */
update resources set 
res_headrev =               ?RES_HEADREV,
res_type =                  ?RES_TYPE,
res_deleted =               ?RES_DELETED,
res_update_timestamp =      ?RESREV_TIMESTAMP,
res_update_user_id =        ?RES_UPDATE_USER_ID,
resrev_rev =                ?RESREV_REV,
resrev_user_id =            ?RESREV_USER_ID,
resrev_parent_id =          ?RESREV_PARENT_ID,
resrev_parent_page_id =     ?RESREV_PARENT_PAGE_ID,
resrev_parent_user_id =     ?RESREV_PARENT_USER_ID,
resrev_change_mask =        ?RESREV_CHANGE_MASK,
resrev_name =               ?RESREV_NAME,
resrev_change_description = ?RESREV_CHANGE_DESCRIPTION,
resrev_timestamp =          ?RESREV_TIMESTAMP,
resrev_content_id =         ?RESREV_CONTENT_ID,
resrev_deleted =            ?RESREV_DELETED,
resrev_changeset_id =       ?RESREV_CHANGESET_ID,
resrev_size =               ?RESREV_SIZE,
resrev_mimetype =           ?RESREV_MIMETYPE,
resrev_language =           ?RESREV_LANGUAGE,
resrev_is_hidden =          ?RESREV_IS_HIDDEN,
resrev_meta =               ?RESREV_META
WHERE res_id =              ?RES_ID
AND res_headrev =           ?RES_HEADREV - 1
AND res_update_timestamp =  ?RES_UPDATE_TIMESTAMP;

select ROW_COUNT() into @affectedRows;

select *
from resources
where @affectedrows > 0
and res_id = ?RES_ID;
";
                if(ArrayUtil.IsNullOrEmpty(Resources_ExecuteInsertUpdateQuery(resource, query))) {
                    
                    //Cleanup content row if resource could not be updated
                    Resources_ContentDelete(resource.ContentId);
                    throw new ResourceConcurrencyException(resource.ResourceId);
                }
                query = @" /* Resources_SaveRevision (new revision) */
replace into resourcerevs set 
resrev_res_id =             ?RES_ID,
resrev_rev =                ?RESREV_REV,
resrev_user_id =            ?RESREV_USER_ID, 
resrev_parent_id =          ?RESREV_PARENT_ID,
resrev_parent_page_id =     ?RESREV_PARENT_PAGE_ID,
resrev_parent_user_id =     ?RESREV_PARENT_USER_ID,
resrev_change_mask =        ?RESREV_CHANGE_MASK,
resrev_name =               ?RESREV_NAME,
resrev_change_description = ?RESREV_CHANGE_DESCRIPTION,
resrev_timestamp =          ?RESREV_TIMESTAMP,
resrev_content_id =         ?RESREV_CONTENT_ID,
resrev_deleted =            ?RESREV_DELETED,
resrev_changeset_id =       ?RESREV_CHANGESET_ID,
resrev_size =               ?RESREV_SIZE,
resrev_mimetype =           ?RESREV_MIMETYPE,
resrev_language =           ?RESREV_LANGUAGE,
resrev_is_hidden =          ?RESREV_IS_HIDDEN,
resrev_meta =               ?RESREV_META;

update resourcecontents set 
rescontent_res_id =     ?RES_ID,
rescontent_res_rev =    ?RESCONTENT_RES_REV
where rescontent_id =   ?RESREV_CONTENT_ID;

select *
from resources
left join resourcecontents
    on resources.resrev_content_id = resourcecontents.rescontent_id
where res_id = ?RES_ID;
";
            }

            ResourceBE[] ret = Resources_ExecuteInsertUpdateQuery(resource, query);
            return (ArrayUtil.IsNullOrEmpty(ret)) ? null : ret[0];
        }
Пример #45
0
                public State(State s) {
                    resourceBE = ResourceBE.NewFrom(s.resourceBE);
                    resourceDeletionFilter = s.resourceDeletionFilter;
                    revisionVisibilityFilter = s.revisionVisibilityFilter;                    
                    populateContent = s.populateContent;
                    populateRevisions = s.populateRevisions;
                    populateChildResources = s.populateChildResources;
                    populateChildResourcesForRev = s.populateChildResourcesForRev;
                    populateResourceCountOnly = s.populateResourceCountOnly;
                    parentType = s.parentType;

                    if(!ArrayUtil.IsNullOrEmpty(s.resourceIds)) {
                        resourceIds = new List<uint>(s.resourceIds);
                    }

                    if(!ArrayUtil.IsNullOrEmpty(s.parentIds)) {
                        parentIds = new List<uint>(s.parentIds);
                    }

                    if(!ArrayUtil.IsNullOrEmpty(s.resourceTypes)) {
                        resourceTypes = new List<ResourceBE.Type>(s.resourceTypes);
                    }

                    if(!ArrayUtil.IsNullOrEmpty(s.nameFilter)) {
                        nameFilter = new List<string>(s.nameFilter);
                    }

                    if(!ArrayUtil.IsNullOrEmpty(s.orderClauses)) {
                        orderClauses = (ResourceOrderClause[]) s.orderClauses.Clone();
                    }

                    if(!ArrayUtil.IsNullOrEmpty(s.changeSetId)) {
                        changeSetId = new List<uint>(s.changeSetId).ToArray();
                    }

                    changeType = s.changeType;
                    limit = s.limit;
                    offset = s.offset;
                }
Пример #46
0
        public ResourceBE Resources_UpdateRevision(ResourceBE resource) {
            
            //Prepare query for retrieving the resource after updating
            string selectQuery = new ResourceQuery()
                                .WithResourceId(resource.ResourceId)
                                .WithRevision(resource.Revision)
                                .ToString();

            //Note: The resrev_timestamp is not updated in order to preserve the initial timeline of revisions
            string query = string.Format(@" /* Resources_UpdateRevision */
update resourcerevs set 
resrev_rev              = ?RESREV_REV,
resrev_user_id          = ?RESREV_USER_ID,
resrev_parent_id        = ?RESREV_PARENT_ID,
resrev_parent_page_id   = ?RESREV_PARENT_PAGE_ID,
resrev_parent_user_id   = ?RESREV_PARENT_USER_ID,
resrev_change_mask      = ?RESREV_CHANGE_MASK,
resrev_name             = ?RESREV_NAME,
resrev_change_description=?RESREV_CHANGE_DESCRIPTION,
resrev_content_id       = ?RESREV_CONTENT_ID,
resrev_deleted          = ?RESREV_DELETED,
resrev_changeset_id     = ?RESREV_CHANGESET_ID,
resrev_size             = ?RESREV_SIZE,
resrev_mimetype         = ?RESREV_MIMETYPE,
resrev_language         = ?RESREV_LANGUAGE,
resrev_is_hidden        = ?RESREV_IS_HIDDEN,
resrev_meta             = ?RESREV_META
WHERE 
resrev_res_id       = ?RES_ID
AND resrev_rev          = ?RESREV_REV;

{0}
", selectQuery);

            ResourceBE[] ret = Resources_ExecuteInsertUpdateQuery(resource, query);

            if(resource.IsHeadRevision()) {
                Resources_ResetHeadRevision(resource.ResourceId);
            }

            return (ArrayUtil.IsNullOrEmpty(ret)) ? null : ret[0];
        }
Пример #47
0
 public ResourceQuery WithParent(uint? parentId, ResourceBE.Type parentType) {
     if(parentId == null) {
         return WithParent(new uint[] { }, parentType);
     } else {
         return WithParent(new uint[] { parentId.Value }, parentType);
     }
 }
Пример #48
0
 public ResourceQuery WithParent(IList<uint> parentIds, ResourceBE.Type parentType) {
     State s = new State(_state);
     s.parentIds = parentIds;
     s.parentType = parentType;
     return new ResourceQuery(s);
 }