コード例 #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);
                }
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
            }
        }