Exemplo n.º 1
0
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                element.SetAttributeValue(attribute.ElementName, null);
            }
            else
            {
                Guid guid = element.IsAttributeSet(parent, attribute.ElementName)
                                ? element.GetGuid(attribute.ElementName)
                                : Guid.Empty;

                var languageVariantName = element.GetAttributeValue("languagevariantid");
                var languageVariant     = parent.Project.LanguageVariants[languageVariantName];
                try
                {
                    Guid textGuid = parent.Project.SetTextContent(guid, languageVariant,
                                                                  ((int)Type).ToString(CultureInfo.InvariantCulture),
                                                                  value);

                    element.SetAttributeValue(attribute.ElementName, textGuid.ToRQLString());
                } catch (Exception e)
                {
                    throw new SmartAPIException(parent.Session.ServerLogin,
                                                string.Format("Could not set {0} text for {1} in language {2}",
                                                              Type.ToString().ToLower(), parent, languageVariantName), e);
                }
            }
        }
Exemplo n.º 2
0
 private static void SetValuesFromSameServer(IXmlReadWriteWrapper element, IContentClassElement value)
 {
     //element.SetAttributeValue("eltlanguagevariantid", element.GetAttributeValue());
     element.SetAttributeValue("eltelementguid", value.Guid.ToRQLString());
     element.SetAttributeValue("elttemplateguid", value.ContentClass.Guid.ToRQLString());
     element.SetAttributeValue("eltprojectguid", value.Project.Guid.ToRQLString());
 }
Exemplo n.º 3
0
        private static void SetFromSameProject(IProjectObject parent, IXmlReadWriteWrapper element, IFile value)
        {
            var folderGuid     = element.GetGuid(ELTFOLDERGUID);
            var topLevelFolder = value.Folder;

            if (value.Folder.IsAssetManager)
            {
                var assetFolder = (IAssetManagerFolder)value.Folder;
                if (assetFolder.IsSubFolder)
                {
                    topLevelFolder = assetFolder.ParentFolder;
                }
            }

            if (topLevelFolder.Guid != folderGuid)
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format(
                                                "Cannot set sample file '{0}', because it isn't in the current folder branch '{1}/'",
                                                value, parent.Project.Folders.GetByGuid(folderGuid).Name));
            }

            //TODO at least cms 7.5 stores undefined as value, maybe "" is allowed, too, try this out
            element.SetAttributeValue(ELTSRCSUBDIRGUID,
                                      value.Folder.Guid == folderGuid ? "undefined" : value.Folder.Guid.ToRQLString());

            element.SetAttributeValue(ELTSRC, value.Name);
        }
Exemplo n.º 4
0
        private static void SetValuesFromDifferentProjects(IProjectObject parent, IXmlReadWriteWrapper element,
                                                           RedDotAttribute attribute, IFile value)
        {
            IFolder ownFolder;

            if (!parent.Project.Folders.TryGetByName(value.Folder.Name, out ownFolder))
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format("No such folder {0} in project {1} for setting of {2}",
                                                          value.Folder.Name, parent.Project, attribute.Description));
            }

            var ownFile = ownFolder.Files.GetByNamePattern(value.Name).SingleOrDefault();

            if (ownFile == null)
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format(
                                                "No such file {3} in folder {0} in project {1} for setting of {2}",
                                                value.Folder.Name, parent.Project, attribute.Description, value.Name));
            }

            element.SetAttributeValue(ELTFOLDERGUID, ownFolder.Guid.ToRQLString());
            element.SetAttributeValue(ELTXSLFILE, ownFile.Name);
        }
Exemplo n.º 5
0
 private static void SetValuesToNull(IXmlReadWriteWrapper element)
 {
     //element.SetAttributeValue("eltlanguagevariantid", null);
     element.SetAttributeValue("eltelementguid", null);
     element.SetAttributeValue("elttemplateguid", null);
     element.SetAttributeValue("eltprojectguid", null);
 }
Exemplo n.º 6
0
        public virtual void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                                    T value)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException(string.Format("{0}.WriteTo must be called from a project object",
                                                                  GetType().Name));
            }

            CheckReadOnly(parent.Project, attribute);

            if (value == null)
            {
                element.SetAttributeValue(attribute.ElementName, null);
                return;
            }

            if (ConverterHelper.AreFromTheSameProject(parent, value))
            {
                element.SetAttributeValue(attribute.ElementName, value.Guid.ToRQLString());
            }
            else
            {
                T resolvedValue = GetFromName(parent, element, attribute, value);
                element.SetAttributeValue(attribute.ElementName,
                                          resolvedValue != null ? resolvedValue.Guid.ToRQLString() : null);
            }
        }
Exemplo n.º 7
0
 private static void SetValuesFromSubFolder(IProjectObject parent, IXmlReadWriteWrapper writeElement, IFile value,
                                            IAssetManagerFolder ownFolder)
 {
     ownFolder = ownFolder.SubFolders.GetByName(value.Folder.Name);
     writeElement.SetAttributeValue(ELTSRCSUBDIRGUID, ownFolder.Guid.ToRQLString());
     SetFilename(parent, value, ownFolder, writeElement);
 }
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                            IInfoAttribute value)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException("InfoElementConverter not called from a valid project object");
            }

            if (value == null)
            {
                element.SetAttributeValue(attribute.ElementName, null);
                return;
            }

            element.SetAttributeValue(attribute.ElementName, value.Id.ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 9
0
        private static void SetValuesFromTopLevelFolder(IProjectObject parent, IXmlReadWriteWrapper element, IFile value,
                                                        IFolder ownFolder)
        {
            var folderGuid = element.GetGuid(ELTFOLDERGUID);

            element.SetAttributeValue(ELTSRCSUBDIRGUID,
                                      ownFolder.Guid == folderGuid ? "undefined" : ownFolder.Guid.ToRQLString());

            SetFilename(parent, value, ownFolder, element);
        }
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                            EditorSettings value)
        {
            ConverterHelper.EnsureValidProjectObject(parent);

            var attributeValue = value == EditorSettings.NotSet
                                     ? null
                                     : ((int)value).ToString(CultureInfo.InvariantCulture);

            element.SetAttributeValue(attribute.ElementName, attributeValue);
        }
Exemplo n.º 11
0
        private static void SetFilename(IProjectObject parent, IFile value, IXmlReadWriteWrapper element,
                                        IFolder ownFolder)
        {
            var ownFile = ownFolder.Files.GetByNamePattern(value.Name).SingleOrDefault();

            if (ownFile == null)
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format("No file with name {0} found in folder {1} of project {2}",
                                                          value.Name, ownFolder.Name, parent.Project));
            }
            element.SetAttributeValue(ELTSRC, value.Name);
        }
        public override void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                                     ICategory value)
        {
            CheckReadOnly(parent.Project, attribute);

            if (value == ArbitraryCategory.INSTANCE)
            {
                element.SetAttributeValue(attribute.ElementName, ARBITRARY_CATEGORY_VALUE);
            }
            else
            {
                base.WriteTo(parent, element, attribute, value);
            }
        }
Exemplo n.º 13
0
        private void SetWithDefaultConversion <T>(IXmlReadWriteWrapper element, T value)
        {
            Type type = typeof(T);

            if (type == typeof(string))
            {
                element.SetAttributeValue(ElementName, (string)(object)value);
                return;
            }

            if (type == typeof(bool))
            {
                element.SetAttributeValue(ElementName, (bool)(object)value ? "1" : "0");
                return;
            }
            if (type == typeof(int?))
            {
                var i = ((int?)(object)value);
                element.SetAttributeValue(ElementName, i != null ? i.Value.ToString(CultureInfo.InvariantCulture) : null);
                return;
            }
            throw new SmartAPIInternalException(string.Format("No matching conversion for element {0} to type {1}",
                                                              ElementName, type.Name));
        }
Exemplo n.º 14
0
        private static void SetValuesFromTopLevelFolder(IProjectObject parent, IXmlReadWriteWrapper element, IFile value,
                                                        IFolder ownFolder)
        {
            var folderGuid = element.GetGuid(ELTFOLDERGUID);

            if (folderGuid != ownFolder.Guid)
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format(
                                                "Example file not from the folder or one of its subfolders is not allowed"));
            }

            element.SetAttributeValue(ELTSRCSUBDIRGUID, ownFolder.Guid.ToRQLString());
            SetFilename(parent, value, element, ownFolder);
        }
Exemplo n.º 15
0
        private static void SetValuesFromAssetManagerFolder(IProjectObject parent, IXmlReadWriteWrapper element,
                                                            IFile value)
        {
            var assetFolder = (IAssetManagerFolder)value.Folder;
            var folderGuid  = element.GetGuid(ELTFOLDERGUID);

            if (assetFolder.IsSubFolder)
            {
                var folder = parent.Project.Folders.GetByGuid(folderGuid) as IAssetManagerFolder;
                if (folder == null)
                {
                    throw new SmartAPIException(parent.Session.ServerLogin,
                                                string.Format(
                                                    "Setting a example file from a subfolder into a non asset manager folder is not possible"));
                }
                if (folder.Name != assetFolder.ParentFolder.Name)
                {
                    throw new SmartAPIException(parent.Session.ServerLogin,
                                                string.Format(
                                                    "Example file not from subfolder of the currently active folder is not allowed (active folder: {0}, file folder {1})",
                                                    folder, value.Folder));
                }

                var ownSubFolder = folder.SubFolders.GetByName(value.Folder.Name);
                element.SetAttributeValue(ELTSRCSUBDIRGUID, ownSubFolder.Guid.ToRQLString());
                SetFilename(parent, value, element, ownSubFolder);
            }
            else
            {
                IFolder ownFolder;
                if (!parent.Project.Folders.TryGetByName(value.Folder.Name, out ownFolder))
                {
                    throw new SmartAPIException(parent.Session.ServerLogin,
                                                string.Format("Missing folder {1} in project {0}", value.Folder.Name,
                                                              parent.Project));
                }
                SetValuesFromTopLevelFolder(parent, element, value, ownFolder);
            }
        }
Exemplo n.º 16
0
 private static void SetValuesFromSameProject(IXmlReadWriteWrapper element, IFile value)
 {
     element.SetAttributeValue(ELTFOLDERGUID, value.Folder.Guid.ToRQLString());
     element.SetAttributeValue(ELTXSLFILE, value.Name);
 }
Exemplo n.º 17
0
 public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                     ISystemLocale value)
 {
     element.SetAttributeValue(attribute.ElementName,
                               value == null ? null : value.LCID.ToString(CultureInfo.InvariantCulture));
 }
Exemplo n.º 18
0
 public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                     IDateTimeFormat value)
 {
     element.SetAttributeValue(attribute.ElementName, value.TypeId.ToString(CultureInfo.InvariantCulture));
 }
Exemplo n.º 19
0
 private static void ClearFile(IXmlReadWriteWrapper element)
 {
     element.SetAttributeValue(ELTSRCSUBDIRGUID, null);
     element.SetAttributeValue(ELTSRC, null);
 }
Exemplo n.º 20
0
 private static void SetEmptyValues(IXmlReadWriteWrapper element)
 {
     element.SetAttributeValue(ELTFOLDERGUID, null);
     element.SetAttributeValue(ELTXSLFILE, null);
 }
Exemplo n.º 21
0
 public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper writeElement, RedDotAttribute attribute, T value)
 {
     writeElement.SetAttributeValue(attribute.ElementName, StringEnumConversionRegistry.ConvertToRQLString(value));
 }