Ejemplo n.º 1
0
 public void _contentView_UserAction(object sender, UserActionEventArgs e)
 {
     if (e.ActionName == "save")
     {
         e.ContentView.UpdateContent();
         if (e.ContentView.IsUserInputValid && _content.IsValid)
         {
             string t = RepositoryPath.Combine(_content.ContentHandler.ParentPath, _content.Fields["Name"].GetData() as string);
             //PathInfoRemove:
             //if (RepositoryPathInfo.GetPathInfo(t) == null)
             if (NodeHead.Get(t) == null)
             {
                 _content.Save();
                 ProcessUserAction();
             }
             else
             {
                 if (_content.ContentHandler.Id > 0)
                 {
                     _content.Save();
                     ProcessUserAction();
                 }
                 else
                 {
                     this._recreateEditContentView = false;
                     this._recreateNewContentView  = false;
                     this._displayMode             = GetViewModeName(ViewMode.Browse);
                     this._errorMessage            = HttpContext.GetGlobalResourceObject("SingleContentPortlet", "ContentNameAlreadyExists") as string;
                 }
             }
         }
         else
         {
             this._recreateNewContentView = true;
             _content.DontSave();
         }
     }
     else if (e.ActionName == "cancel")
     {
         _recreateNewContentView  = false;
         _recreateEditContentView = false;
         _displayMode             = GetViewModeName(ViewMode.Browse);
         _container.Controls.Clear();
         CreateChildControls();
     }
     else
     {
         this._recreateNewContentView  = false;
         this._recreateEditContentView = false;
         _container.Controls.Clear();
     }
 }
Ejemplo n.º 2
0
        internal void CreateNewWorkspace()
        {
            try
            {
                var state          = WizardState;
                var newName        = state.WorkspaceNewName;
                var sourceNodePath = state.SelectedWorkspacePath;
                var targetNode     = PortalContext.Current.ContextNodeHead ?? NodeHead.Get(TargetPath);

                var sourceNode      = Node.LoadNode(sourceNodePath);
                var contentTypeName = sourceNode.Name;


                Content workspace = null;

                workspace = ContentTemplate.HasTemplate(contentTypeName)
                    ? ContentTemplate.CreateTemplated(Node.LoadNode(targetNode.Id), ContentTemplate.GetTemplate(contentTypeName), newName)
                    : Content.CreateNew(contentTypeName, Node.LoadNode(targetNode.Id), newName);

                workspace.Fields["Description"].SetData(state.WorkspaceNewDescription);
                workspace.Save();

                var newPath = new StringBuilder(PortalContext.Current.OriginalUri.GetLeftPart(UriPartial.Authority)).Append(targetNode.Path).Append("/").Append(newName);
                NewWorkspaceLink.HRef = newPath.ToString();
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                HasError = true;
                ErrorMessageControl.Visible = true;
                ErrorMessageControl.Text    = exc.Message;
                // log exception
            }
        }
        // Internals ////////////////////////////////////////////////////
        private void SaveUser(UserActionEventArgs e, bool createNew)
        {
            try
            {
                if (createNew)
                {
                    GenerateActivationId();
                }

                if (!Configuration.ActivationEnabled)
                {
                    EnableAndActivateUser();
                }

                _content.Save();

                if (createNew)
                {
                    AddToSecurityGroups(e);
                }
            }
            catch (InvalidOperationException ex) //logged
            {
                Logger.WriteException(ex);
                //TODO: Biztos, hogy UserAlreadyExists?
                WriteErrorMessageOnly(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "UserAlreadyExists") as string);
            }
        }
Ejemplo n.º 4
0
        public void Content_UsingFieldControls_ReadWriteWithConversion()
        {
            Node automobileNode = LoadOrCreateAutomobile(@"<?xml version='1.0' encoding='utf-8'?>
<ContentType name='Automobile' parentType='GenericContent' handler='SenseNet.ContentRepository.Tests.ContentHandlers.AutomobileHandler' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
	<Fields>
		<Field name='Manufacturer' type='ShortText'>
			<Configuration>
				<Compulsory>true</Compulsory>
				<MaxLength>100</MaxLength>
				<Format>TitleCase</Format>
			</Configuration>
		</Field>
		<Field name='Driver' type='ShortText'>
			<Configuration>
				<Compulsory>true</Compulsory>
				<MaxLength>100</MaxLength>
			</Configuration>
		</Field>
		<Field name='BodyColor' type='Color'>
			<Bind property='BodyColor' />
		</Field>
	</Fields>
</ContentType>
", "Automobile12", "Trabant", "Netudki");

            SNC.Content automobileContent = SNC.Content.Create(automobileNode);

            automobileContent["BodyColor"] = Color.Red;
            automobileContent.Save();
            automobileContent = SNC.Content.Load(automobileContent.ContentHandler.Id);

            ColorEditorControl   colorControl    = new ColorEditorControl();
            ColorControlAccessor colorControlAcc = new ColorControlAccessor(colorControl);

            colorControl.FieldName = "BodyColor";
            colorControlAcc.ConnectToField(automobileContent.Fields["BodyColor"]);
            ShortText         manuControl    = new ShortText();
            ShortTextAccessor manuControlAcc = new ShortTextAccessor(manuControl);

            manuControl.FieldName = "Manufacturer";
            manuControlAcc.ConnectToField(automobileContent.Fields["Manufacturer"]);
            ShortText         driverControl    = new ShortText();
            ShortTextAccessor driverControlAcc = new ShortTextAccessor(driverControl);

            driverControl.FieldName = "Driver";
            driverControlAcc.ConnectToField(automobileContent.Fields["Driver"]);

            string colorString = colorControl.textBox1.Text;
            Color  color       = colorControl.textBox1.BackColor;
            string manu        = manuControlAcc.Text;
            string driver      = driverControlAcc.Text;

            Assert.IsTrue(colorString == "#FF0000", "#1");
            Assert.IsTrue(color == ColorField.ColorFromString(ColorField.ColorToString(Color.Red)), "#2");
            Assert.IsTrue(manu == "Trabant", "#2");
            Assert.IsTrue(driver == "Netudki", "#2");
            //-- Ha nincs hiba: sikeres
        }
Ejemplo n.º 5
0
        public void Content_CarContentChoiceField()
        {
            SNC.Content content = SNC.Content.Load(String.Concat(_testRoot.Path, "/Car123"));
            if (content == null)
            {
                content = SNC.Content.CreateNew("Car", _testRoot, "Car123");
            }
            content["Style"] = new List <string>(new string[] { "Sedan" });
            content.Save();
            content = SNC.Content.Load(String.Concat(_testRoot.Path, "/Car123"));

            Assert.IsTrue(((List <string>)content["Style"])[0] == "Sedan");
        }
Ejemplo n.º 6
0
        public void Content_UsingFields_WriteNodeAttribute()
        {
            string contentTypeDef = @"<?xml version='1.0' encoding='utf-8'?>
				<ContentType name='Automobile' parentType='GenericContent' handler='SenseNet.ContentRepository.Tests.ContentHandlers.AutomobileHandler' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
					<Fields>
						<Field name='Name' type='ShortText' />
						<Field name='Path' type='ShortText' />
						<Field name='Created' type='WhoAndWhen'>
							<Bind property='CreatedBy' />
							<Bind property='CreationDate' />
						</Field>
						<Field name='Modified' type='WhoAndWhen'>
							<Bind property='ModifiedBy' />
							<Bind property='ModificationDate' />
						</Field>
						<Field name='Manufacturer' type='ShortText' />
						<Field name='Driver' type='ShortText' />
					</Fields>
				</ContentType>"                ;

            ContentTypeInstaller.InstallContentType(contentTypeDef);

            Node automobileNode = Node.LoadNode(String.Concat(_testRoot.Path, "/Automobile12"));

            if (automobileNode != null)
            {
                automobileNode.ForceDelete();
            }


            automobileNode                 = new AutomobileHandler(_testRoot);
            automobileNode.Name            = "Automobile12";
            automobileNode["Manufacturer"] = "Honda";
            automobileNode["Driver"]       = "Gyeby";
            automobileNode.Save();

            string path = automobileNode.Path;

            SNC.Content automobileContent = SNC.Content.Create(automobileNode);
            automobileContent["Index"] = 987;
            automobileContent.Save();

            automobileNode = Node.LoadNode(path);
            int index = automobileNode.Index;

            automobileNode.ForceDelete();

            Assert.IsTrue(index == 987);
        }
Ejemplo n.º 7
0
        public ActionResult CreateContent(string node, string contentName, string contentType, string templateName, string back)
        {
            AssertPermission();

            node         = HttpUtility.UrlDecode(node);
            contentName  = HttpUtility.UrlDecode(contentName);
            contentType  = HttpUtility.UrlDecode(contentType);
            templateName = HttpUtility.UrlDecode(templateName);
            back         = HttpUtility.UrlDecode(back);

            if (string.IsNullOrEmpty(contentName))
            {
                contentName = !string.IsNullOrEmpty(templateName) ? templateName : contentType;
            }

            var parent = Node.LoadNode(node);

            if (parent == null)
            {
                return(this.Redirect(back));
            }

            //var template = SNCR.ContentTemplateResolver.Instance.GetNamedTemplate(contentType, templateName);
            var template = ContentTemplate.GetNamedTemplate(contentType, templateName);

            SNCR.Content newContent = null;

            if (template != null)
            {
                newContent = ContentTemplate.CreateTemplated(parent, template, contentName);
            }
            //else
            //    SNCR.Content.CreateNew(contentType, parent, contentName, null);

            try
            {
                if (newContent != null)
                {
                    newContent.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
            }

            return(this.Redirect(back));
        }
Ejemplo n.º 8
0
        public void Content_NonGeneric_FieldReadWrite()
        {
            ContentTypeInstaller.InstallContentType(NonGenericHandler.ContentTypeDefinition);
            SNC.Content content = SNC.Content.CreateNew("NonGeneric", _testRoot, "Test123");
            content["Index"]      = 123;
            content["TestString"] = "TestString123";
            content.Save();

            Node   node       = Node.LoadNode(RepositoryPath.Combine(_testRoot.Path, "Test123"));
            int    index      = node.Index;
            string testString = (string)node["TestString"];

            node.Delete();

            Assert.IsTrue(index == 123, "#1");
            Assert.IsTrue(testString == "TestString123", "#2");
        }
Ejemplo n.º 9
0
        public void Content_CreateList()
        {
            string contentTypeName = "Automobile";

            if (ContentTypeManager.Current.GetContentTypeByName(contentTypeName) == null)
            {
                ContentTypeInstaller.InstallContentType(AutomobileHandler.ExtendedCTD);
            }

            var idList = new List <int>();

            for (int i = 1; i <= 5; i++)
            {
                string      contentName = "AutoListItem" + i;
                SNC.Content auto        = SNC.Content.Load(RepositoryPath.Combine(_testRoot.Path, contentName));
                if (auto == null)
                {
                    auto = SNC.Content.CreateNew(contentTypeName, _testRoot, contentName);
                }
                auto["Manufacturer"] = "Manuf" + i;
                auto.Save();
                idList.Add(auto.Id);
            }

            //----

            NodeQuery query = new NodeQuery();

            query.Add(new TypeExpression(ActiveSchema.NodeTypes[contentTypeName]));
            query.Add(new StringExpression(StringAttribute.Name, StringOperator.StartsWith, "AutoListItem"));
            IEnumerable <SNC.Content> contentList = SNC.Content.Query(query);
            var contentListCount = contentList.ToList().Count;

            //----

            foreach (var id in idList)
            {
                Node.ForceDelete(id);
            }

            //----

            Assert.IsTrue(contentListCount == 5);
        }
Ejemplo n.º 10
0
        public static StepResult InstallContent(Content content)
        {
            bool isNewContent;

            try
            {
                SnC.Content snContent = CreateOrLoadContent(content, out isNewContent);
                foreach (var attachment in content.Attachments)
                {
                    var data = new BinaryData()
                    {
                        FileName = attachment.FileName
                    };
                    data.SetStream(attachment.Manifest.GetStream(attachment.FileName));
                    snContent[attachment.FieldName] = data;
                }
                snContent.Save();
                content.IsNewContent = isNewContent;
                if (!SetMetadata(snContent, content, isNewContent, false))
                {
                    Logger.LogWarningMessage(PrintFieldErrors(snContent));
                    return(new StepResult {
                        Kind = StepResultKind.Warning
                    });
                }
            }
            catch (Exception transferEx)
            {
                Logger.LogException(transferEx);
                return(new StepResult {
                    Kind = StepResultKind.Error
                });
            }
            return(new StepResult {
                Kind = StepResultKind.Successful
            });
        }
Ejemplo n.º 11
0
        public void Content_UsingFields_WriteProperties()
        {
            string[] propset0 = new string[] { "Trabant", "Netudki" };
            string[] propset1 = new string[] { "Honda", "Gyeby" };
            string[] propset2 = new string[] { "Ferrari", "Kavics" };

            Node automobileNode = LoadOrCreateAutomobileAndSave(AutomobileHandler.ExtendedCTD, "Automobile12", propset0[0], propset0[1]);

            SNC.Content automobileContent = SNC.Content.Create(automobileNode);

            //-- Betoltes utan:
            //-- A field-ek erteke megegyezik a teljes es a gyors eleressel is (propset0).
            //-- A property-k es a Field.OriginalValues alapallapotban (propset0)
            Assert.IsTrue((string)automobileContent["Manufacturer"] == propset0[0], "#01");
            Assert.IsTrue((string)automobileContent["Driver"] == propset0[1], "#02");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].GetData() == propset0[0], "#03");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].GetData() == propset0[1], "#04");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].OriginalValue == propset0[0], "#05");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].OriginalValue == propset0[1], "#06");
            Assert.IsTrue((string)automobileNode["Manufacturer"] == propset0[0], "#07");
            Assert.IsTrue((string)automobileNode["Driver"] == propset0[1], "#08");

            //-- Field set (teljes eleresu) utan:
            //-- A field-ek erteke felveszi az uj erteket, de megegyezik a teljes es a gyors eleressel is (propset1).
            //-- A property-k es a Field.OriginalValues alapallapotban (propset0)
            automobileContent.Fields["Manufacturer"].SetData(propset1[0]);
            automobileContent.Fields["Driver"].SetData(propset1[1]);
            Assert.IsTrue((string)automobileContent["Manufacturer"] == propset1[0], "#11");
            Assert.IsTrue((string)automobileContent["Driver"] == propset1[1], "#12");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].GetData() == propset1[0], "#13");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].GetData() == propset1[1], "#14");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].OriginalValue == propset0[0], "#15");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].OriginalValue == propset0[1], "#16");
            Assert.IsTrue((string)automobileNode["Manufacturer"] == propset0[0], "#17");
            Assert.IsTrue((string)automobileNode["Driver"] == propset0[1], "#18");

            //-- Field set (gyors eleresu) utan:
            //-- A field-ek erteke felveszi az uj erteket, de megegyezik a teljes es a gyors eleressel is (propset2).
            //-- A property-k es a Field.OriginalValues alapallapotban (propset0)
            automobileContent["Manufacturer"] = propset2[0];
            automobileContent["Driver"]       = propset2[1];
            Assert.IsTrue((string)automobileContent["Manufacturer"] == propset2[0], "#21");
            Assert.IsTrue((string)automobileContent["Driver"] == propset2[1], "#22");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].GetData() == propset2[0], "#23");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].GetData() == propset2[1], "#24");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].OriginalValue == propset0[0], "#25");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].OriginalValue == propset0[1], "#26");
            Assert.IsTrue((string)automobileNode["Manufacturer"] == propset0[0], "#27");
            Assert.IsTrue((string)automobileNode["Driver"] == propset0[1], "#28");

            //-- Save utan:
            //-- A field-ek erteke nem valtozik (propset2).
            //-- A property-kbe es a Field.OriginalValues-be beirodik a Field.Values (propset2)
            automobileContent.Save();
            Assert.IsTrue((string)automobileContent["Manufacturer"] == propset2[0], "#31");
            Assert.IsTrue((string)automobileContent["Driver"] == propset2[1], "#32");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].GetData() == propset2[0], "#33");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].GetData() == propset2[1], "#34");
            Assert.IsTrue((string)automobileContent.Fields["Manufacturer"].OriginalValue == propset2[0], "#35");
            Assert.IsTrue((string)automobileContent.Fields["Driver"].OriginalValue == propset2[1], "#36");
            Assert.IsTrue((string)automobileNode["Manufacturer"] == propset2[0], "#37");
            Assert.IsTrue((string)automobileNode["Driver"] == propset2[1], "#38");
        }