Ejemplo n.º 1
0
        /// <summary>
        /// Sets a custom property.
        /// </summary>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value for the property.</param>
        /// <returns><c>true</c> if the property was successfully set, [otherwise] <c>false</c></returns>
        public bool SetCustomProperty(String property, Object value)
        {
            if (!String.IsNullOrWhiteSpace(property) && xDocumentProperties != null)
            {
                XPropertyContainer customProperties = xDocumentProperties.getUserDefinedProperties();
                if (customProperties != null && customProperties is XPropertySet)
                {
                    try
                    {
                        XPropertySetInfo info = ((XPropertySet)customProperties).getPropertySetInfo();
                        if (info != null && !info.hasPropertyByName(property))
                        {
                            customProperties.addProperty(property, 0, Any.Get(""));
                        }

                        if (info != null && info.hasPropertyByName(property))
                        {
                            ((XPropertySet)customProperties).setPropertyValue(property, Any.Get(value));
                            return(true);
                        }
                    }
                    catch (Exception) { }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all custom properties.
        /// </summary>
        /// <returns>a dictionary of names and string-values of properties</returns>
        public Dictionary <String, String> GetAllCustomProperties()
        {
            Dictionary <String, String> properties = new Dictionary <String, String>();

            if (xDocumentProperties != null)
            {
                XPropertyContainer customProperties = xDocumentProperties.getUserDefinedProperties();
                if (customProperties != null && customProperties is XPropertySet)
                {
                    if (customProperties != null && customProperties is XPropertySet)
                    {
                        XPropertySetInfo info = ((XPropertySet)customProperties).getPropertySetInfo();
                        if (info != null)
                        {
                            foreach (Property p in info.getProperties())
                            {
                                if (p != null)
                                {
                                    var val = ((XPropertySet)customProperties).getPropertyValue(p.Name);
                                    if (val.hasValue())
                                    {
                                        properties.Add(p.Name, val.Value.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(properties);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets a property.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="propName">Name of the property.</param>
        /// <param name="value">The value of the property.</param>
        /// <returns><c>true</c> if the property could been set without an error, otherwise <c>false</c></returns>
        internal static bool SetProperty(XPropertySet obj, String propName, Object value)
        {
            if (obj != null)
            {
                //var proInfo = obj.getPropertySetInfo();
                //var properties = proInfo.getProperties();
                //List<String> props = new List<String>();
                //foreach (var prop in properties)
                //{
                //    props.Add(prop.Name);
                //}

                if (obj.getPropertySetInfo() != null && obj.getPropertySetInfo().hasPropertyByName(propName))
                {
                    try
                    {
                        obj.setPropertyValue(propName, Any.Get(value));
                        return(true);
                    }
                    catch (unoidl.com.sun.star.beans.PropertyVetoException)
                    {
                        System.Diagnostics.Debug.WriteLine("Property value is unacceptable");
                    }
                    catch (unoidl.com.sun.star.uno.RuntimeException)
                    {
                        System.Diagnostics.Debug.WriteLine("Property value set cause internal error");
                        Logger.Instance.Log(LogPriority.IMPORTANT, "OoUtils", "[FATAL ERROR] Cannot set property '" + propName + "' to value: '" + (value != null ? value.ToString() : "NULL") + "' for the current object");
                    }
                }
                else
                {
                    XPropertyContainer pc = obj as XPropertyContainer;
                    if (pc != null)
                    {
                        try
                        {
                            pc.addProperty(propName, (short)2, Any.Get(value));
                            return(true);
                        }
                        catch { }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a custom property.
        /// </summary>
        /// <param name="property">The property name.</param>
        /// <returns>The property's value or <c>null</c>.</returns>
        public Object GetCustomProperty(String property)
        {
            if (!String.IsNullOrWhiteSpace(property) && xDocumentProperties != null)
            {
                XPropertyContainer customProperties = xDocumentProperties.getUserDefinedProperties();
                if (customProperties != null && customProperties is XPropertySet)
                {
                    XPropertySetInfo info = ((XPropertySet)customProperties).getPropertySetInfo();
                    if (info != null && info.hasPropertyByName(property))
                    {
                        var val = ((XPropertySet)customProperties).getPropertyValue(property);

                        if (val.hasValue())
                        {
                            // TODO: type the property
                            return(val.Value);
                        }
                    }
                }
            }
            return(null);
        }