예제 #1
0
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                            IContentClassElement 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)
            {
                SetValuesToNull(element);
                return;
            }

            if (AreFromTheSameServer(parent, value))
            {
                SetValuesFromSameServer(element, value);
                return;
            }

            SetValuesFromOtherServer(parent, element, value);
        }
 protected override IContentClassFolder GetFromGuid(IProjectObject parent, XmlElement element,
                                                    RedDotAttribute attribute, Guid guid)
 {
     return
         (parent.Project.ContentClassFolders.Union(parent.Project.ContentClassFolders.Broken)
          .First(folder => folder.Guid == guid));
 }
예제 #3
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);
                }
            }
        }
예제 #4
0
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute, IFile value)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException("Parent project object may not be null for SrcFileConverter");
            }

            if (value == null)
            {
                ClearFile(element);
                return;
            }

            if (ConverterHelper.AreFromTheSameProject(parent, value))
            {
                SetFromSameProject(parent, element, value);
            }
            else
            {
                if (value.Folder.IsAssetManager)
                {
                    SetValuesFromAssetManagerFolder(parent, element, value);
                }
                else
                {
                    var ownFolder = parent.Project.Folders.GetByName(value.Folder.Name);
                    SetValuesFromTopLevelFolder(parent, element, value, ownFolder);
                }
            }
        }
예제 #5
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);
        }
예제 #6
0
 protected void CheckReadOnly(IProject projectOfTarget, RedDotAttribute attribute)
 {
     if (IsReadOnly)
     {
         throw new SmartAPIException(projectOfTarget.Session.ServerLogin,
                                     string.Format("Writing to attribute {0} is forbidden", attribute.Description));
     }
 }
예제 #7
0
 public static void CheckReadOnly <T>(IAttributeConverter <T> converter, IProjectObject po,
                                      RedDotAttribute attribute) where T : IProjectObject
 {
     if (converter.IsReadOnly || attribute.IsReadOnly)
     {
         throw new SmartAPIException(po.Session.ServerLogin,
                                     string.Format("Writing to attribute {0} is forbidden", attribute.Description));
     }
 }
        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);
        }
예제 #9
0
        public ISystemLocale ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            string value = element.GetAttributeValue(attribute.ElementName);
            var    lcid  = element.IsAttributeSet(parent, attribute.ElementName) && !value.Contains("EmptyBuffer")
                           ? int.Parse(value)
                           : (int?)null;

            return(lcid == null
                       ? null
                       : ((IContentClassElement)parent).ContentClass.Project.Session.Locales[lcid.Value]);
        }
        protected override ICategory GetFromName(IProjectObject parent, IXmlReadWriteWrapper element,
                                                 RedDotAttribute attribute, ICategory value)
        {
            ICategory category;

            if (!parent.Project.Categories.TryGetByName(value.Name, out category))
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format("Cannot find category {0} in project {1}", value.Name, parent));
            }
            return(category);
        }
        public IInfoAttribute ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            if (!element.IsAttributeSet(parent, attribute.ElementName))
            {
                return(null);
            }

// ReSharper disable PossibleInvalidOperationException
            var id = element.GetIntAttributeValue(attribute.ElementName).Value;

// ReSharper restore PossibleInvalidOperationException
            return(parent.Project.InfoAttributes[id]);
        }
예제 #12
0
        public string ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            ILanguageVariant lang = parent.Project.LanguageVariants.Current;

            if (!element.IsAttributeSet(parent, attribute.ElementName))
            {
                return(string.Empty);
            }

            Guid guid = element.GetGuid(attribute.ElementName);

            return(parent.Project.GetTextContent(guid, lang, ((int)Type).ToString(CultureInfo.InvariantCulture)));
        }
        public EditorSettings ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            ConverterHelper.EnsureValidProjectObject(parent);

            if (!element.IsAttributeSet(parent, attribute.ElementName))
            {
                return(EditorSettings.NotSet);
            }

            var intValue = element.GetIntAttributeValue(attribute.ElementName);

            return((EditorSettings)(intValue ?? (int)EditorSettings.NotSet));
        }
        protected override ISyllable GetFromName(IProjectObject parent, IXmlReadWriteWrapper element,
                                                 RedDotAttribute attribute, ISyllable value)
        {
            ISyllable output;

            if (!parent.Project.Syllables.TryGetByName(value.Name, out output))
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format("Could not find a syllable with name {0} in project {1}",
                                                          value.Name, parent));
            }

            return(output);
        }
        protected override IContentClassElement GetFromGuid(IProjectObject parent, XmlElement element,
                                                            RedDotAttribute attribute, Guid guid)
        {
            if (!(parent is IContentClassElement))
            {
                throw new SmartAPIInternalException("Element converter can only be used from IContentClassElement");
            }

            var parentCcElement = (IContentClassElement)parent;

            IContentClassElement result;

            return(parentCcElement.ContentClass.Elements.TryGetByGuid(guid, out result) ? result : null);
        }
예제 #16
0
        public virtual T ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException(string.Format(
                                                        "{0}.ConvertFrom must be called from a project object", GetType().Name));
            }

            Guid guid;

            return(element.TryGetGuid(attribute.ElementName, out guid)
                       ? GetFromGuid(parent, element, attribute, guid)
                       : null);
        }
예제 #17
0
        protected override IFolder GetFromName(IProjectObject parent, IXmlReadWriteWrapper element,
                                               RedDotAttribute attribute, IFolder value)
        {
            var folders = parent.Project.Folders.AllIncludingSubFolders;
            var folder  = folders.FirstOrDefault(folder1 => folder1.Name == value.Name);

            if (folder == null)
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format("Could not find a folder with name {0} in project {1}",
                                                          value.Name, parent.Project));
            }
            return(folder);
        }
예제 #18
0
        public IFile ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            ConverterHelper.EnsureValidProjectObject(parent);

            Guid folderGuid;

            if (!element.TryGetGuid(ELTFOLDERGUID, out folderGuid) || !element.IsAttributeSet(parent, ELTXSLFILE))
            {
                return(null);
            }

            var folder = parent.Project.Folders.GetByGuid(folderGuid);

            return(new File(folder, element.GetAttributeValue(ELTXSLFILE)));
        }
        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));
        }
예제 #20
0
        public IFile ConvertFrom(IProjectObject parent, XmlElement readElement, RedDotAttribute attribute)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException("Parent project object may not be null for ExampleFileConverter");
            }

            var fileName = readElement.GetAttributeValue(ELTSRC);

            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            var folder = GetFolder(parent, readElement);

            return(new File(folder, fileName));
        }
        public T ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException(string.Format("EnumConverter can only be used on project objects"));
            }

            var strValue = element.GetAttributeValue(attribute.ElementName);

            if (string.IsNullOrEmpty(strValue) || strValue == "#" + parent.Session.SessionKey)
            {
                return(default(T));
            }

            const bool IGNORE_CASE = true;

            return((T)Enum.Parse(typeof(T), strValue, IGNORE_CASE));
        }
예제 #22
0
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute, IFile value)
        {
            ConverterHelper.EnsureValidProjectObject(parent);

            ConverterHelper.CheckReadOnly(this, parent, attribute);

            if (value == null)
            {
                SetEmptyValues(element);
                return;
            }

            if (ConverterHelper.AreFromTheSameProject(parent, value))
            {
                SetValuesFromSameProject(element, value);
                return;
            }

            SetValuesFromDifferentProjects(parent, element, attribute, value);
        }
예제 #23
0
        public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute, IFile value)
        {
            if (parent == null)
            {
                throw new SmartAPIInternalException("Parent project object may not be null for ExampleFileConverter");
            }

            if (value == null)
            {
                ClearFile(element);
                return;
            }

            if (!element.IsAttributeSet(parent, ELTFOLDERGUID))
            {
                throw new SmartAPIException(parent.Session.ServerLogin,
                                            string.Format(
                                                "Cannot set an example file ({0}) without an active folder in element {1}",
                                                value, parent));
            }

            if (ConverterHelper.AreFromTheSameProject(parent, value))
            {
                SetFromSameProject(parent, element, value);
            }
            else
            {
                if (value.Folder.IsAssetManager)
                {
                    SetValuesFromAssetManagerFolder(parent, element, value);
                }
                else
                {
                    var ownFolder = parent.Project.Folders.GetByName(value.Folder.Name);
                    SetValuesFromTopLevelFolder(parent, element, value, ownFolder);
                }
            }
        }
예제 #24
0
 public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                     ISystemLocale value)
 {
     element.SetAttributeValue(attribute.ElementName,
                               value == null ? null : value.LCID.ToString(CultureInfo.InvariantCulture));
 }
        protected override ICategory GetFromGuid(IProjectObject parent, XmlElement element, RedDotAttribute attribute,
                                                 Guid guid)
        {
            //after a deletion of a category, references to it can still be present in the system and
            //thus we can't throw an exception but have to handle it like no category is assigned (RedDot seems to handle it that way).
            ICategory result;

            return(parent.Project.Categories.TryGetByGuid(guid, out result) ? result : null);
        }
예제 #26
0
 public void WriteTo(IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
                     IDateTimeFormat value)
 {
     element.SetAttributeValue(attribute.ElementName, value.TypeId.ToString(CultureInfo.InvariantCulture));
 }
예제 #27
0
        public IDateTimeFormat ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute)
        {
            string value = element.GetAttributeValue(attribute.ElementName);

            int?type = element.IsAttributeSet(parent, attribute.ElementName) && !value.Contains("EmptyBuffer")
                            ? element.GetIntAttributeValue(attribute.ElementName)
                            : null;

            int  lcid;
            bool valid = int.TryParse(element.GetAttributeValue("eltlcid"), out lcid);

            if (!valid || type == null || IsCustomFormat(type))
            {
                return(null);
            }

            return
                (((IContentClassElement)parent).ContentClass.Project.Session.Locales[lcid].DateTimeFormats[type.Value]);
        }
예제 #28
0
 protected override IProjectVariant GetFromName(IProjectObject parent, IXmlReadWriteWrapper element,
                                                RedDotAttribute attribute, IProjectVariant value)
 {
     return(parent.Project.ProjectVariants.GetByName(value.Name));
 }
예제 #29
0
 protected override IProjectVariant GetFromGuid(IProjectObject parent, XmlElement element,
                                                RedDotAttribute attribute, Guid guid)
 {
     return(parent.Project.ProjectVariants.GetByGuid(guid));
 }
예제 #30
0
 public LanguageDependendTimeFormat(IPartialRedDotProjectObject parent, RedDotAttribute attribute)
     : base(parent, attribute)
 {
 }