public static List <string> GetNames(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            int custom_prop_row_count = CustomPropertyHelper.GetCount(shape);

            if (custom_prop_row_count < 1)
            {
                return(new List <string>(0));
            }

            var prop_names   = new List <string>(custom_prop_row_count);
            var prop_section = shape.Section[vis_sec_prop];
            var query_names  = prop_section.ToEnumerable().Select(row => row.NameU);

            prop_names.AddRange(query_names);

            if (custom_prop_row_count != prop_names.Count)
            {
                throw new VisioAutomation.Exceptions.InternalAssertionException("Unexpected number of property names");
            }

            return(prop_names);
        }
        private static List <List <CustomPropertyNameCellsPair> > __GetListOfCpPairLists(
            ShapeIDPairs shapeidpairs,

            List <List <CustomPropertyCells> > listof_listof_cpcells)
        {
            if (listof_listof_cpcells.Count != shapeidpairs.Count)
            {
                throw new Exceptions.InternalAssertionException();
            }

            var listof_listof_cppairs = new List <List <CustomPropertyNameCellsPair> >(shapeidpairs.Count);

            var shape_indices = System.Linq.Enumerable.Range(0, shapeidpairs.Count);

            foreach (int i in shape_indices)
            {
                var shape          = shapeidpairs[i].Shape;
                var listof_cpnames = CustomPropertyHelper.GetNames(shape);
                var listof_cpcells = listof_listof_cpcells[i];

                int num_cps = listof_cpnames.Count;

                var cp_indices     = Enumerable.Range(0, num_cps);
                var listof_cppairs = new List <CustomPropertyNameCellsPair>(num_cps);
                foreach (int cprow in cp_indices)
                {
                    int shapeid = shapeidpairs[i].ShapeID;
                    var cppair  = new CustomPropertyNameCellsPair(shapeid, cprow, listof_cpnames[cprow], listof_cpcells[cprow]);
                    listof_cppairs.Add(cppair);
                }
                listof_listof_cppairs.Add(listof_cppairs);
            }
            return(listof_listof_cppairs);
        }
        private static List <CustomPropertyDictionary> create_dic(IList <IVisio.Shape> shapes, List <int> shapeids, List <List <CustomPropertyCells> > customprops_per_shape)
        {
            var customprops_dic = new List <CustomPropertyDictionary>(shapeids.Count);


            if (customprops_per_shape.Count != shapeids.Count)
            {
                throw new InternalAssertionException();
            }

            for (int shape_index = 0; shape_index < shapeids.Count; shape_index++)
            {
                var shape = shapes[shape_index];
                var customprops_for_shape = customprops_per_shape[shape_index];
                var prop_names            = CustomPropertyHelper.GetNames(shape);

                if (customprops_for_shape.Count != prop_names.Count)
                {
                    throw new InternalAssertionException();
                }

                var dic = new CustomPropertyDictionary(prop_names.Count);

                for (int prop_index = 0; prop_index < prop_names.Count; prop_index++)
                {
                    string prop_name = prop_names[prop_index];
                    dic[prop_name] = customprops_for_shape[prop_index];
                }

                customprops_dic.Add(dic);
            }
            return(customprops_dic);
        }
        // ----------------------------------------
        // ----------------------------------------
        // ----------------------------------------
        // ----------------------------------------

        private static List <CustomPropertyNameCellsPair> __GetPairs(IVisio.Shape shape, VASS.CellValueType type)
        {
            var shape_custprop_cells = CustomPropertyCells.GetCells(shape, type);
            var shape_custprop_names = CustomPropertyHelper.GetNames(shape);
            int shapeid = shape.ID16;
            var list    = __CreateListofPairs(shape_custprop_names, shape_custprop_cells, shapeid);

            return(list);
        }
        internal static void __CheckValidCustomPropertyName(string name)
        {
            string errmsg;

            if (!CustomPropertyHelper.__IsValidName(name, out errmsg))
            {
                string msg = string.Format("Invalid Property Name: \"{0}\". {1}", name, errmsg);
                throw new System.ArgumentException(msg);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets all the custom properties defined on a shape
        /// </summary>
        /// <remarks>
        /// If there are no custom properties then null will be returned</remarks>
        /// <param name="shape"></param>
        /// <returns>A list of custom properties</returns>
        public static CustomPropertyDictionary Get(IVisio.Shape shape)
        {
            var prop_names = CustomPropertyHelper.GetNames(shape);
            var dic        = new CustomPropertyDictionary(prop_names.Count);
            var cells      = CustomPropertyCells.GetCells(shape);

            for (int prop_index = 0; prop_index < prop_names.Count(); prop_index++)
            {
                string prop_name = prop_names[prop_index];
                dic[prop_name] = cells[prop_index];
            }

            return(dic);
        }
Esempio n. 7
0
        public static List <CustomPropertyDictionary> Get(IVisio.Page page, IList <IVisio.Shape> shapes)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            if (shapes == null)
            {
                throw new ArgumentNullException(nameof(shapes));
            }

            var shapeids              = shapes.Select(s => s.ID).ToList();
            var customprops_dic       = new List <CustomPropertyDictionary>(shapeids.Count);
            var customprops_per_shape = CustomPropertyCells.GetCells(page, shapeids);

            if (customprops_per_shape.Count != shapeids.Count)
            {
                throw new InternalAssertionException();
            }

            for (int shape_index = 0; shape_index < shapeids.Count; shape_index++)
            {
                var shape = shapes[shape_index];
                var customprops_for_shape = customprops_per_shape[shape_index];
                var prop_names            = CustomPropertyHelper.GetNames(shape);

                if (customprops_for_shape.Count != prop_names.Count)
                {
                    throw new InternalAssertionException();
                }

                var dic = new CustomPropertyDictionary(prop_names.Count);

                for (int prop_index = 0; prop_index < prop_names.Count(); prop_index++)
                {
                    string prop_name = prop_names[prop_index];
                    dic[prop_name] = customprops_for_shape[prop_index];
                }

                customprops_dic.Add(dic);
            }

            return(customprops_dic);
        }
        public static void Delete(IVisio.Shape shape, string name)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            CustomPropertyHelper.__CheckValidCustomPropertyName(name);

            string full_prop_name = CustomPropertyHelper.__GetRowName(name);

            short row = shape.CellsU[full_prop_name].Row;

            shape.DeleteRow(vis_sec_prop, row);
        }
        public static bool Contains(IVisio.Shape shape, string name)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            CustomPropertyHelper.__CheckValidCustomPropertyName(name);

            string full_prop_name = CustomPropertyHelper.__GetRowName(name);

            var exists = (short)IVisio.VisExistsFlags.visExistsAnywhere;

            return(0 != (shape.CellExistsU[full_prop_name, exists]));
        }
        public static void Set(IVisio.Shape shape, string name, string value, int type)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            CustomPropertyHelper.__CheckValidCustomPropertyName(name);

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            // create a new property
            var cp = new CustomPropertyCells();

            cp.Value = value;
            cp.Type  = type;

            CustomPropertyHelper.Set(shape, name, cp);
        }
        public static void Set(
            IVisio.Shape shape,
            string name,
            CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            CustomPropertyHelper.__CheckValidCustomPropertyName(name);

            if (CustomPropertyHelper.Contains(shape, name))
            {
                string full_prop_name = CustomPropertyHelper.__GetRowName(name);
                var    cell_propname  = shape.CellsU[full_prop_name];

                if (cell_propname == null)
                {
                    string msg = string.Format("Could not retrieve cell for custom property \"{0}\"", full_prop_name);
                    throw new Exceptions.InternalAssertionException(msg);
                }

                var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                writer.SetValues(cp, cell_propname.Row);

                writer.CommitFormulas(shape);

                return;
            }

            short row = shape.AddNamedRow(
                vis_sec_prop,
                name,
                (short)IVisio.VisRowIndices.visRowProp);

            CustomPropertyHelper.Set(shape, row, cp);
        }
        public static bool IsValidName(string name)
        {
            string errmsg;

            return(CustomPropertyHelper.__IsValidName(name, out errmsg));
        }