public void CommonDataTypesShouldBeSerialized()
        {
            var datetime = new DateTime(1980, 1, 1, 12, 0, 0);

            Set("string", "one");
            Set("int1", int.MaxValue);
            Set("int2", int.MinValue);
            Set("long1", long.MaxValue);
            Set("long2", long.MinValue);
            Set("datetime", datetime);
            Set("bool1", true);
            Set("bool2", false);
            Set("decimal1", decimal.MaxValue);
            Set("decimal2", decimal.MinValue);
            Set("double1", (double)123456.123456);
            Set("double2", (double)-123456.123456);

            _contentManager.Publish(_contentItem);
            _contentManager.Flush();

            Assert.That(Get <string>("string"), Is.EqualTo("one"));
            Assert.That(Get <int>("int1"), Is.EqualTo(int.MaxValue));
            Assert.That(Get <int>("int2"), Is.EqualTo(int.MinValue));
            Assert.That(Get <long>("long1"), Is.EqualTo(long.MaxValue));
            Assert.That(Get <long>("long2"), Is.EqualTo(long.MinValue));
            Assert.That(Get <DateTime>("datetime"), Is.EqualTo(datetime));
            Assert.That(Get <bool>("bool1"), Is.EqualTo(true));
            Assert.That(Get <bool>("bool2"), Is.EqualTo(false));
            Assert.That(Get <decimal>("decimal1"), Is.EqualTo(decimal.MaxValue));
            Assert.That(Get <decimal>("decimal2"), Is.EqualTo(decimal.MinValue));
            Assert.That(Get <double>("double1") - (double)123456.123456, Is.LessThan(1));
            Assert.That(Get <double>("double2") - (double)123456.123456, Is.LessThan(1));
        }
Ejemplo n.º 2
0
        public void GetCommentsShouldReturnAllComments()
        {
            for (int i = 0; i < 12; i++)
            {
                var commentedItem = _contentManager.New("commentedItem");
                _contentManager.Create(commentedItem);
                _contentManager.Create(commentedItem, VersionOptions.Published);
            }

            _contentManager.Flush();
            Assert.That(_commentService.GetComments().Count(), Is.EqualTo(12));
        }
Ejemplo n.º 3
0
        private static void RecalculateCount(IContentManager contentManager, ITaxonomyService taxonomyService, TermsPart part) {
            // submits any change to the db so that GetContentItemsCount is accurate
            contentManager.Flush();

            foreach (var term in part.Terms) {
                var termPart = taxonomyService.GetTerm(term.TermRecord.Id);
                term.TermRecord.Count = (int)taxonomyService.GetContentItemsCount(termPart);
            }
        }
Ejemplo n.º 4
0
        private static void RecalculateCount(IContentManager contentManager, ITaxonomyService taxonomyService, TermsPart part)
        {
            // submits any change to the db so that GetContentItemsCount is accurate
            contentManager.Flush();

            foreach (var term in part.Terms)
            {
                var termPart = taxonomyService.GetTerm(term.TermRecord.Id);
                term.TermRecord.Count = (int)taxonomyService.GetContentItemsCount(termPart);
            }
        }
        public bool SaveAvatarFile(int id, Stream stream, string extension)
        {
            extension = extension.StripExtension();
            var settings = GetSettings();

            if (stream.Length > settings.MaxFileSize)
            {
                ValidationDictionary.AddError(AvatarsServiceValidationKey.FileTooLarge, T("The file was too large for an avatar ({0}KB), maximum file size is {1}KB",
                                                                                          Math.Round((float)(stream.Length / 1024)),
                                                                                          Math.Round((float)(settings.MaxFileSize / 1024))));

                return(false);
            }

            var filePath = GetFilePath(id, extension);

            if (!IsFileAllowed(filePath))
            {
                ValidationDictionary.AddError(AvatarsServiceValidationKey.NotAllowedFileType, T("This file type is not allowed as an avatar."));

                return(false);
            }

            // This is the way to overwrite a file... We can't check its existence yet with IStorageProvider, but soon there will be such a method.
            try
            {
                _storageProvider.DeleteFile(filePath);
            }
            catch (Exception)
            {
            }

            _storageProvider.SaveStream(filePath, stream);

            var avatar = _contentManager.Get <AvatarProfilePart>(id);

            avatar.FileExtension = extension;
            _contentManager.Flush();

            return(true);
        }
Ejemplo n.º 6
0
        public void Create()
        {
            // flushes before doing a query in case a previous command created the menu
            _contentManager.Flush();

            var menu = _menuService.GetMenu(MenuName);

            if (menu == null)
            {
                Context.Output.WriteLine(T("Menu not found.").Text);
                return;
            }

            var menuItem = _contentManager.Create("MenuItem");

            menuItem.As <MenuPart>().MenuPosition = MenuPosition;
            menuItem.As <MenuPart>().MenuText     = T(MenuText).ToString();
            menuItem.As <MenuPart>().Menu         = menu.ContentItem;
            menuItem.As <MenuItemPart>().Url      = Url;

            Context.Output.WriteLine(T("Menu item created successfully.").Text);
        }
Ejemplo n.º 7
0
        public void Create(string name)
        {
            Context.Output.WriteLine(T("Creating Layer {0}", name));

            IContent layer = _contentManager.Create <LayerPart>("Layer", t => {
                t.Record.Name        = name;
                t.Record.LayerRule   = LayerRule;
                t.Record.Description = Description ?? String.Empty;
            });

            _contentManager.Publish(layer.ContentItem);
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            layer.As <ICommonPart>().Owner = owner;
            _contentManager.Flush();

            Context.Output.WriteLine(T("Layer created successfully.").Text);
        }
Ejemplo n.º 8
0
        public void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           widgetTypeNames.Aggregate(String.Empty, (current, widgetType) => current + " " + widgetType)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
            var text   = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                // flushes before doing a query in case a previous command created the menu
                _contentManager.Flush();

                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().Menu = menu.ContentItem.Record;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }
Ejemplo n.º 9
0
        public void Create()
        {
            _contentManager.Flush();

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);
            var page  = _contentManager.Create("Page", VersionOptions.Draft);

            page.As <TitlePart>().Title   = Title;
            page.As <ICommonPart>().Owner = owner;

            if (!String.IsNullOrWhiteSpace(MenuText))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    var menuItem = _contentManager.Create <ContentMenuItemPart>("ContentMenuItem");
                    menuItem.Content = page;
                    menuItem.As <MenuPart>().MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
                    menuItem.As <MenuPart>().MenuText     = MenuText;
                    menuItem.As <MenuPart>().Menu         = menu;
                }
            }

            // (PH:Autoroute) Hackish way to leave Slug and Homepage switches intact without requiring a dependency on Autoroute. This may throw an Exception with
            // no AutoroutePart. But it means that normal setup recipes will still be able to give you a homepage without issue.
            if (Homepage || !String.IsNullOrWhiteSpace(Slug))
            {
                dynamic dpage = page;
                if (dpage.AutoroutePart != null)
                {
                    dpage.AutoroutePart.UseCustomPattern = true;
                    dpage.AutoroutePart.CustomPattern    = Homepage ? "/" : Slug;
                }
            }

            var text = String.Empty;

            if (UseWelcomeText)
            {
                text = T(
                    @"<p>You've successfully setup your Orchard Site and this is the homepage of your new site.
Here are a few things you can look at to get familiar with the application.
Once you feel confident you don't need this anymore, you can
<a href=""Admin/Contents/Edit/{0}"">remove it by going into editing mode</a>
and replacing it with whatever you want.</p>
<p>First things first - You'll probably want to <a href=""Admin/Settings"">manage your settings</a>
and configure Orchard to your liking. After that, you can head over to
<a href=""Admin/Themes"">manage themes to change or install new themes</a>
and really make it your own. Once you're happy with a look and feel, it's time for some content.
You can start creating new custom content types or start from the built-in ones by
<a href=""Admin/Contents/Create/Page"">adding a page</a>, or <a href=""Admin/Navigation"">managing your menus.</a></p>
<p>Finally, Orchard has been designed to be extended. It comes with a few built-in
modules such as pages and blogs or themes. If you're looking to add additional functionality,
you can do so by creating your own module or by installing one that somebody else built.
Modules are created by other users of Orchard just like you so if you feel up to it,
<a href=""http://orchardproject.net/contribution"">please consider participating</a>.</p>
<p>Thanks for using Orchard – The Orchard Team </p>", page.Id).Text;
            }
            else
            {
                if (!String.IsNullOrEmpty(Text))
                {
                    text = Text;
                }
            }
            page.As <BodyPart>().Text = text;
            if (Publish)
            {
                _contentManager.Publish(page);
            }

            Context.Output.WriteLine(T("Page created successfully.").Text);
        }
Ejemplo n.º 10
0
        public ContentItem Get(string id, string contentTypeHint = null)
        {
            var contentIdentity = new ContentIdentity(id);

            // lookup in local cache
            if (_identities.ContainsKey(contentIdentity))
            {
                var result = _contentManager.Get(_identities[contentIdentity], VersionOptions.DraftRequired);

                // if two identities are conflicting, then ensure that there types are the same
                // e.g., importing a blog as home page (alias=) and the current home page is a page, the blog
                // won't be imported, and blog posts will be attached to the page
                if (contentTypeHint == null || result.ContentType == contentTypeHint)
                {
                    return(result);
                }
            }

            // no result ? then check if there are some more content items to load from the db
            if (_lastIndex != int.MaxValue)
            {
                var equalityComparer = new ContentIdentity.ContentIdentityEqualityComparer();
                IEnumerable <ContentItem> block;

                // load identities in blocks
                while ((block = _contentManager.HqlQuery()
                                .ForVersion(VersionOptions.Latest)
                                .OrderBy(x => x.ContentItemVersion(), x => x.Asc("Id"))
                                .Slice(_lastIndex, BulkPage)).Any())
                {
                    foreach (var item in block)
                    {
                        _lastIndex++;

                        // ignore content item if it has already been imported
                        if (_contentItemIds.ContainsKey(item.Id))
                        {
                            continue;
                        }

                        var identity = _contentManager.GetItemMetadata(item).Identity;

                        // ignore content item if the same identity is already present
                        if (_identities.ContainsKey(identity))
                        {
                            continue;
                        }

                        _identities.Add(identity, item.Id);
                        _contentItemIds.Add(item.Id, identity);

                        if (equalityComparer.Equals(identity, contentIdentity))
                        {
                            return(_contentManager.Get(item.Id, VersionOptions.DraftRequired));
                        }
                    }

                    _contentManager.Flush();
                    _contentManager.Clear();
                }
            }

            _lastIndex = int.MaxValue;

            if (!_contentTypes.ContainsKey(contentIdentity))
            {
                throw new ArgumentException("Unknown content type for " + id);
            }

            var contentItem = _contentManager.Create(_contentTypes[contentIdentity], VersionOptions.Draft);

            _identities[contentIdentity]    = contentItem.Id;
            _contentItemIds[contentItem.Id] = contentIdentity;

            return(contentItem);
        }
Ejemplo n.º 11
0
        public ContentItem Get(string id)
        {
            var contentIdentity = new ContentIdentity(id);

            // lookup in local cache
            if (_identities.ContainsKey(contentIdentity))
            {
                return(_contentManager.Get(_identities[contentIdentity], VersionOptions.DraftRequired));
            }

            // no result ? then check if there are some more content items to load from the db
            if (_lastIndex != int.MaxValue)
            {
                var equalityComparer = new ContentIdentity.ContentIdentityEqualityComparer();
                IEnumerable <ContentItem> block;

                // load identities in blocks
                while ((block = _contentManager.HqlQuery()
                                .ForVersion(VersionOptions.Latest)
                                .OrderBy(x => x.ContentItemVersion(), x => x.Asc("Id"))
                                .Slice(_lastIndex, BulkPage)).Any())
                {
                    foreach (var item in block)
                    {
                        _lastIndex++;

                        // ignore content item if it has already been imported
                        if (_contentItemIds.ContainsKey(item.Id))
                        {
                            continue;
                        }

                        var identity = _contentManager.GetItemMetadata(item).Identity;

                        // ignore content item if the same identity is already present
                        if (_identities.ContainsKey(identity))
                        {
                            continue;
                        }

                        _identities.Add(identity, item.Id);
                        _contentItemIds.Add(item.Id, identity);

                        if (equalityComparer.Equals(identity, contentIdentity))
                        {
                            return(_contentManager.Get(item.Id, VersionOptions.DraftRequired));
                        }
                    }

                    _contentManager.Flush();
                    _contentManager.Clear();
                }
            }

            _lastIndex = int.MaxValue;

            if (!_contentTypes.ContainsKey(contentIdentity))
            {
                throw new ArgumentException("Unknown content type for " + id);
            }

            var contentItem = _contentManager.Create(_contentTypes[contentIdentity], VersionOptions.Draft);

            _identities.Add(contentIdentity, contentItem.Id);
            _contentItemIds.Add(contentItem.Id, contentIdentity);

            return(contentItem);
        }