Inheritance: System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
Esempio n. 1
0
 public void PrintCollection(CollectionBase collection)
 {
     foreach(object o in collection)
     {
         Console.WriteLine("Collection contains {0}", o.ToString());
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Prüft ob das Argument Null oder leer ist
 /// </summary>
 /// <param name="argument">
 /// Argument das geprfüt werden soll
 /// </param>
 /// <param name="argumentName">
 /// Der verwendete Name des Argumentes
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Wird ausgelöst, wenn <paramref name="argument"/> null ist
 /// </exception>
 /// <exception cref="ArgumentException">
 /// Wird ausgelöst wenn <paramref name="argument"/> leer ist.
 /// </exception>
 public static void IsNotNullOrEmpty(CollectionBase argument, string argumentName)
 {
     IsNotNull(argument, argumentName);
     if (argument.Count == 0)
     {
         throw new ArgumentException(string.Format("Das Argument {0} darf nicht leer sein", argumentName));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Binds an object's properties to <see cref="Control"/>s with the same ID as the propery name. �����������ֵ���ֵ��ؼ���.
        /// </summary>
        /// <param name="obj">The object whose properties are being bound to forms Controls</param>
        /// <param name="container">The control in which the form Controls reside (usually a Page or ContainerControl)</param>
        public static void BindObjectToTableRow(CollectionBase cb, HtmlTable tb, string fileName)
        {
            if (cb == null) return;

            // Get the properties of the business object
            //
            //��ȡ�е���Ϣ
            PreViewColumnCollection pcc =(new PageBase()).GetColumns(fileName);
            //���ɱ�ͷ
            HtmlTableRow th =new HtmlTableRow();
            th.BgColor="#ffffff";
            foreach(PreViewColumn column in pcc)
            {
                HtmlTableCell tc = new HtmlTableCell();
                tc.Width=column.Width.ToString();
                tc.Align="center";
                tc.InnerHtml=column.Caption;
                tc.NoWrap=true;
                th.Cells.Add(tc);
            }
            tb.Rows.Add(th);

            //���ɱ������
            foreach(object obj in cb)
            {
                HtmlTableRow tr =new HtmlTableRow();
                tr.BgColor="#ffffff";

                Type objType = obj.GetType();
                PropertyInfo[] objPropertiesArray = objType.GetProperties();

                foreach(PreViewColumn column in pcc)
                {
                    foreach (PropertyInfo objProperty in objPropertiesArray)
                    {
                        if(objProperty.Name==column.ID)
                        {
                            string propertyValue = objProperty.GetValue(obj, null).ToString();
                            if(column.Fomat=="num")
                            {
                                propertyValue=(double.Parse(propertyValue)).ToString("n2");
                            }

                            HtmlTableCell tc = new HtmlTableCell();
                            tc.InnerText=propertyValue;
                            tc.Align=column.Align;
                            tc.Width=column.Width.ToString();

                            tr.Cells.Add(tc);

                        }
                    }
                    tb.Rows.Add(tr);
                }
            }
        }
    /// <summary>
    /// Called when the tool is activated.
    /// </summary>
    protected override void OnActivateTool() {
      if (this.Controller.Model.Selection.SelectedItems != null && this.Controller.Model.Selection.SelectedItems.Count > 0) {
        /*
       * They should give me a Nobel prize for so much thinking early in the morning...
       */
        #region Preparation of the ordering
        Debug.Assert(this.Controller.Model.Selection.SelectedItems[0] != null, "A selection cannot contain a 'null' entity.");
        //the items have to be moved in the order of the Paintables; the SortedList automatically orders things for us.
        SortedList<int, IDiagramEntity> list = new SortedList<int, IDiagramEntity>();
        //We fetch a flattened selection, which means that if there is a group the constituents will be
        //returned rather than the group itself.
        foreach (IDiagramEntity entity in this.Controller.Model.Selection.FlattenedSelectionItems) {
          //the addition will automatically put the item in increasing order
          list.Add(this.Controller.Model.Paintables.IndexOf(entity), entity);
        }
        //if the lowest z-value is the first one in the paintables we cannot shift anything, so we quit
        if (list.Keys[0] == 0) return;

        /*Send them forwards but make sure it's a visible effect!
        It's not enough to move it only once since the shape(s) above might be of
        high z-order degree, so we have to find which is the first shape overlapping with 
        the selection and take as many steps as it takes to surpass it.
         If there is no overlap we'll shift the z-order with just one unit.
        */
        int delta = 1;
        int lowestZInSelection = list.Keys[0];
        bool found = false;
        //we can speed up the loop by noticing that the previous shape in the z-stack is necessarily
        //below the first one of the selection
        for (int m = lowestZInSelection - 1; m >= 0 && !found; m--) {
          //the overlap has to be with an entity, not from the selection
          if (list.ContainsValue(this.Controller.Model.Paintables[m])) continue;
          for (int s = 0; s < list.Count; s++) {
            //if there is an overlap we found the required index
            if (this.Controller.Model.Paintables[m].Rectangle.IntersectsWith(list.Values[s].Rectangle)) {
              //an additional complication here; if the found shape is part of a group we have
              //to take the upper z-value of the group...
              if (this.Controller.Model.Paintables[m].Group != null) {
                int min = int.MaxValue;
                CollectionBase<IDiagramEntity> leafs = new CollectionBase<IDiagramEntity>();
                Utils.TraverseCollect(this.Controller.Model.Paintables[m].Group, ref leafs);
                foreach (IDiagramEntity groupMember in leafs) {
                  min = Math.Min(min, this.Controller.Model.Paintables.IndexOf(groupMember));
                }
                //take the found z-value of the group rather than the one of the group-child
                m = min;
              }
              delta = lowestZInSelection - m;
              found = true;
              break;
            }

          }
        }
        #endregion
        Debug.Assert(delta >= 1, "The shift cannot be less than one since we checked previous situations earlier.");
        for (int k = 0; k < list.Count; k++) {
          this.Controller.Model.SendBackwards(list.Values[k], delta);
        }
      }
      DeactivateTool();
    }
Esempio n. 5
0
        private static void ClearStrictCollectionAndDisposesItCommon(CollectionBase collection)
        {
            collection.Expect(x => x.Clear());
              ((IDisposable)collection).Expect(x => x.Dispose());

              CleanCollection(collection);
              collection.VerifyAllExpectations();
        }
Esempio n. 6
0
 private static void CleanCollection(CollectionBase collection)
 {
     collection.Clear();
       IDisposable disposable = collection as IDisposable;
       if (disposable != null)
     disposable.Dispose();
 }
Esempio n. 7
0
        /// <summary>
        /// Depth-first traversal of an <see cref="IGroup"/>
        /// </summary>
        /// <param name="group"></param>
        /// <param name="collection"></param>
        public static void TraverseCollect(IGroup group, ref CollectionBase<IDiagramEntity> collection)
        {
            #region Checks
            if(group == null)
                throw new InconsistencyException("Cannot collect entities of a 'null' IGroup");
            if(collection == null)
                throw new InconsistencyException("You need to instantiate a collection before using this method.");
            #endregion

            foreach(IDiagramEntity entity in group.Entities)
            {
                if(entity is IGroup)
                    TraverseCollect(entity as IGroup, ref collection);
                else
                    collection.Add(entity);
            }
        }
Esempio n. 8
0
 public virtual void AddObject(string xpath, CollectionBase __collection)
 {
     lock (lockHelper)
     {
         if (__collection.Count > 0)
         {
             AddObject(xpath + "flag", CacheFlag.CacheHaveData);
         }
         else
         {
             AddObject(xpath + "flag", CacheFlag.CacheNoData);
         }
         AddObject(xpath, (object)__collection);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Recursive internal method that loops through the object's properties and builds an XML tree.
        /// </summary>
        /// <param name="graph">The object graph to serialize.</param>
        /// <param name="w">The XmlTextWriter used to build the XML tree.</param>
        internal void SerializeGraph(XmlTextWriter w, object graph)
        {
            Type t = graph.GetType();

            if (t.BaseType == typeof(System.Collections.CollectionBase))
            {
                #region Process each item in the collection and serialize

                System.Collections.CollectionBase coll = (System.Collections.CollectionBase)graph;
                foreach (object obj in coll)
                {
                    SerializeGraph(w, obj);
                }

                #endregion
            }
            else
            {
                #region Loop through each property

                // Reflect only on the properties of the type that has been passed to us
                PropertyInfo[] ps = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);

                // Loop through each property...
                foreach (PropertyInfo p in ps)
                {
                    // Check the property for [XmlIgnore] and ignore if it's present
                    if (p.IsDefined(typeof(XmlIgnoreAttribute), false))
                    {
                        continue;
                    }

                    //Ignore read-only properties. We cannot deserialize them anyway
                    if (!p.CanWrite || !p.CanRead)
                    {
                        continue;
                    }

                    //Ignore static properties
                    if (p.GetGetMethod().IsStatic || p.GetSetMethod().IsStatic)
                    {
                        continue;
                    }

                    // Check the property for any attributes
                    object[] attribs = p.GetCustomAttributes(false);
                    object   attrib  = null;

                    // Pull out the first attribute and let's hope to God that it's an XmlAttribute :)
                    if (attribs.Length > 0)
                    {
                        int i = 0;
                        while (i < attribs.Length)
                        {
                            if (attribs[i].ToString().StartsWith("System.Xml.Serialization.Xml"))
                            {
                                attrib = attribs[i];
                                break;
                            }
                            i++;
                        }
                    }

                    #region Check for Enum

                    if (p.PropertyType.IsEnum)
                    {
                        object o = p.GetValue(graph, null);
                        if (attrib == null)
                        {
                            w.WriteElementString(p.Name, Convert.ToInt32(o).ToString());
                        }
                        else if (attrib.GetType() == typeof(XmlElementAttribute))
                        {
                            w.WriteElementString((attrib as XmlElementAttribute).ElementName, Convert.ToInt32(o).ToString());
                        }
                        else if (attrib.GetType() == typeof(XmlAttributeAttribute))
                        {
                            w.WriteAttributeString((attrib as XmlAttributeAttribute).AttributeName, Convert.ToInt32(o).ToString());
                        }
                        continue;
                    }

                    #endregion

                    #region Check for ValueType or String

                    if (p.PropertyType.IsValueType || p.PropertyType.FullName == "System.String")
                    {
                        object o = p.GetValue(graph, null);

                        // Is it a structure?
                        if (!p.PropertyType.IsPrimitive)
                        {
                            w.WriteStartElement(p.Name);
                            SerializeGraph(w, o);
                            w.WriteEndElement();
                            continue;
                        }

                        if (o != null)
                        {
                            if (attrib == null)
                            {
                                w.WriteElementString(p.Name, o.ToString());
                            }
                            else if (attrib.GetType() == typeof(XmlElementAttribute))
                            {
                                w.WriteElementString((attrib as XmlElementAttribute).ElementName, o.ToString());
                            }
                            else if (attrib.GetType() == typeof(XmlAttributeAttribute))
                            {
                                w.WriteAttributeString((attrib as XmlAttributeAttribute).AttributeName, o.ToString());
                            }
                        }
                        else
                        {
                            if (attrib == null)
                            {
                                w.WriteElementString(p.Name, "");
                            }
                            else if (attrib.GetType() == typeof(XmlElementAttribute))
                            {
                                w.WriteElementString((attrib as XmlElementAttribute).ElementName, "");
                            }
                            else if (attrib.GetType() == typeof(XmlAttributeAttribute))
                            {
                                w.WriteAttributeString((attrib as XmlAttributeAttribute).AttributeName, "");
                            }
                        }
                    }
                    #endregion

                    #region Check for Collection

                    else if (p.PropertyType.BaseType == typeof(System.Collections.CollectionBase))
                    {
                        bool bCollectionStart = false;                         // Are we at the beginning of a collection?

                        System.Collections.CollectionBase col = (System.Collections.CollectionBase)p.GetValue(graph, null);
                        foreach (object obj in col)
                        {
                            if (!bCollectionStart)
                            {
                                if (attrib == null)
                                {
                                    w.WriteStartElement(p.Name);
                                }
                                else if (attrib.GetType() == typeof(XmlRootAttribute))
                                {
                                    w.WriteStartElement((attrib as XmlRootAttribute).ElementName);
                                }
                                else if (attrib.GetType() == typeof(XmlElementAttribute))
                                {
                                    w.WriteStartElement((attrib as XmlElementAttribute).ElementName);
                                }

                                bCollectionStart = true;
                            }

                            // Recursion rocks! Recurse on the collection we found.
                            SerializeGraph(w, obj);
                        }
                        w.WriteEndElement();
                    }
                    #endregion

                    #region Check for ReferenceType

                    else if (t.Assembly.GetType(p.PropertyType.FullName, false) != null)
                    {
                        object objInstance = p.GetValue(graph, null);
                        if (objInstance != null)
                        {
                            if (attrib == null)
                            {
                                w.WriteStartElement(p.Name);
                            }
                            else if (attrib.GetType() == typeof(XmlRootAttribute))
                            {
                                w.WriteStartElement((attrib as XmlRootAttribute).ElementName);
                            }
                            else if (attrib.GetType() == typeof(XmlElementAttribute))
                            {
                                w.WriteStartElement((attrib as XmlElementAttribute).ElementName);
                            }

                            // Recursion rocks! Recurse on the reference type we found.
                            SerializeGraph(w, objInstance);

                            w.WriteEndElement();
                        }
                        else
                        {
                            if (attrib == null)
                            {
                                w.WriteElementString(p.Name, "");
                            }
                            else if (attrib.GetType() == typeof(XmlRootAttribute))
                            {
                                w.WriteElementString((attrib as XmlRootAttribute).ElementName, "");
                            }
                            else if (attrib.GetType() == typeof(XmlElementAttribute))
                            {
                                w.WriteAttributeString((attrib as XmlElementAttribute).ElementName, "");
                            }
                        }
                    }
                    #endregion
                }

                #endregion
            }
        }
Esempio n. 10
0
    /// <summary>
    /// Unwraps the given bundle to the diagram.
    /// </summary>
    /// <param name="collection">CollectionBase<IDiagramEntity></param>
    void UnwrapBundle(CollectionBase<IDiagramEntity> collection) {
      if (collection != null) {
        #region Unwrap the bundle
        this.Controller.Model.Unwrap(collection);

        Rectangle rec = Utils.BoundingRectangle(collection);

        // The InsertionPoint specifies where the pasted
        // entities should be.  So, shift each entity in the
        // collection to the InsertionPoint.
        Point delta = new Point(
            InsertionPoint.X - rec.Location.X,
            InsertionPoint.Y - rec.Location.Y);
        //delta.Offset(rec.Location);

        foreach (IDiagramEntity entity in collection) {
          entity.MoveBy(delta);
        }

        // Recalculate the bounding rectangle and invalidate
        // that area on the canvas.
        rec = Utils.BoundingRectangle(collection);
        rec.Inflate(30, 30);
        this.Controller.View.Invalidate(rec);
        #endregion
      }
    }
 private void InvokeProcessImportedType(CollectionBase collection)
 {
     object[] array = new object[collection.Count];
     ((ICollection) collection).CopyTo(array, 0);
     foreach (object obj2 in array)
     {
         CodeTypeDeclaration typeDeclaration = obj2 as CodeTypeDeclaration;
         if (typeDeclaration != null)
         {
             CodeTypeDeclaration declaration2 = DataContractSurrogateCaller.ProcessImportedType(this.dataContractSet.DataContractSurrogate, typeDeclaration, this.codeCompileUnit);
             if (declaration2 != typeDeclaration)
             {
                 ((IList) collection).Remove(typeDeclaration);
                 if (declaration2 != null)
                 {
                     ((IList) collection).Add(declaration2);
                 }
             }
             if (declaration2 != null)
             {
                 this.InvokeProcessImportedType(declaration2.Members);
             }
         }
     }
 }
Esempio n. 12
0
        void InvokeProcessImportedType(CollectionBase collection)
        {
            object[] objects = new object[collection.Count];
            ((ICollection)collection).CopyTo(objects, 0);
            foreach (object obj in objects)
            {
                CodeTypeDeclaration codeTypeDeclaration = obj as CodeTypeDeclaration;
                if (codeTypeDeclaration == null)
                    continue;

                CodeTypeDeclaration newCodeTypeDeclaration = DataContractSurrogateCaller.ProcessImportedType(
                                                                   dataContractSet.DataContractSurrogate,
                                                                   codeTypeDeclaration,
                                                                   codeCompileUnit);
                if (newCodeTypeDeclaration != codeTypeDeclaration)
                {
                    ((IList)collection).Remove(codeTypeDeclaration);
                    if (newCodeTypeDeclaration != null)
                        ((IList)collection).Add(newCodeTypeDeclaration);
                }
                if (newCodeTypeDeclaration != null)
                    InvokeProcessImportedType(newCodeTypeDeclaration.Members);
            }
        }
Esempio n. 13
0
		internal LdapMod[] BuildAttributes(CollectionBase directoryAttributes, ArrayList ptrToFree)
		{
			DirectoryAttribute item;
			byte[] bytes;
			IntPtr intPtr;
			LdapMod[] ldapMod = null;
			UTF8Encoding uTF8Encoding = new UTF8Encoding();
			DirectoryAttributeCollection directoryAttributeCollection = null;
			DirectoryAttributeModificationCollection directoryAttributeModificationCollection = null;
			if (directoryAttributes != null && directoryAttributes.Count != 0)
			{
				if (directoryAttributes as DirectoryAttributeModificationCollection == null)
				{
					directoryAttributeCollection = (DirectoryAttributeCollection)directoryAttributes;
				}
				else
				{
					directoryAttributeModificationCollection = (DirectoryAttributeModificationCollection)directoryAttributes;
				}
				ldapMod = new LdapMod[directoryAttributes.Count];
				for (int i = 0; i < directoryAttributes.Count; i++)
				{
					if (directoryAttributeCollection == null)
					{
						item = directoryAttributeModificationCollection[i];
					}
					else
					{
						item = directoryAttributeCollection[i];
					}
					ldapMod[i] = new LdapMod();
					if (item as DirectoryAttributeModification == null)
					{
						ldapMod[i].type = 0;
					}
					else
					{
						ldapMod[i].type = (int)((DirectoryAttributeModification)item).Operation;
					}
					LdapMod ldapMod1 = ldapMod[i];
					ldapMod1.type = ldapMod1.type | 128;
					ldapMod[i].attribute = Marshal.StringToHGlobalUni(item.Name);
					int count = 0;
					berval[] _berval = null;
					if (item.Count > 0)
					{
						count = item.Count;
						_berval = new berval[count];
						for (int j = 0; j < count; j++)
						{
							if (item[j] as string == null)
							{
								if (item[j] as Uri == null)
								{
									bytes = (byte[])item[j];
								}
								else
								{
									bytes = uTF8Encoding.GetBytes(((Uri)item[j]).ToString());
								}
							}
							else
							{
								bytes = uTF8Encoding.GetBytes((string)item[j]);
							}
							_berval[j] = new berval();
							_berval[j].bv_len = (int)bytes.Length;
							_berval[j].bv_val = Marshal.AllocHGlobal(_berval[j].bv_len);
							ptrToFree.Add(_berval[j].bv_val);
							Marshal.Copy(bytes, 0, _berval[j].bv_val, _berval[j].bv_len);
						}
					}
					ldapMod[i].values = Marshal.AllocHGlobal((count + 1) * Marshal.SizeOf(typeof(IntPtr)));
					int num = Marshal.SizeOf(typeof(berval));
					int num1 = 0;
					num1 = 0;
					while (num1 < count)
					{
						IntPtr intPtr1 = Marshal.AllocHGlobal(num);
						ptrToFree.Add(intPtr1);
						Marshal.StructureToPtr(_berval[num1], intPtr1, false);
						intPtr = (IntPtr)((long)ldapMod[i].values + (long)(Marshal.SizeOf(typeof(IntPtr)) * num1));
						Marshal.WriteIntPtr(intPtr, intPtr1);
						num1++;
					}
					intPtr = (IntPtr)((long)ldapMod[i].values + (long)(Marshal.SizeOf(typeof(IntPtr)) * num1));
					Marshal.WriteIntPtr(intPtr, (IntPtr)0);
				}
			}
			return ldapMod;
		}
Esempio n. 14
0
        /// <summary>
        /// Binds an object's properties to <see cref="Control"/>s with the same ID as the propery name. �����������ֵ���ֵ��ؼ���.
        /// </summary>
        /// <param name="obj">The object whose properties are being bound to forms Controls</param>
        /// <param name="container">The control in which the form Controls reside (usually a Page or ContainerControl)</param>
        public static void BindObjectToTableRow(CollectionBase cb,Table tb, string fileName)
        {
            if (cb == null) return;

            // Get the properties of the business object
            //
            //��ȡ�е���Ϣ
            PreViewColumnCollection pcc =(new PageBase()).GetColumns(fileName);
            //���ɱ�ͷ
            TableRow th =new TableRow();
            th.CssClass="tr_item";
            foreach(PreViewColumn column in pcc)
            {
                TableCell tc = new TableCell();
                if((object)column.Width!=null)
                {
                    if(column.Unit=="%")
                    {
                        tc.Width=Unit.Percentage((double)column.Width);
                    }
                    else
                    {
                        tc.Width=Unit.Pixel(column.Width);
                    }
                }
                tc.HorizontalAlign=HorizontalAlign.Center;
                tc.Text=column.Caption;
                tc.Wrap=false;
                tc.BorderWidth=Unit.Pixel(1);
                th.Cells.Add(tc);
            }
            tb.Rows.Add(th);

            //���ɱ������
            foreach(object obj in cb)
            {
                TableRow tr =new TableRow();
                tr.CssClass="tr_item";

                Type objType = obj.GetType();
                PropertyInfo[] objPropertiesArray = objType.GetProperties();

                foreach(PreViewColumn column in pcc)
                {
                    foreach (PropertyInfo objProperty in objPropertiesArray)
                    {
                        if(objProperty.Name==column.ID)
                        {
                            string propertyValue = objProperty.GetValue(obj, null).ToString();
                            if(column.Fomat=="num")
                            {
                                propertyValue=(double.Parse(propertyValue)).ToString("F");
                            }

                            TableCell tc = new TableCell();
                            tc.Text=propertyValue;
                            if(column.Align!=null && column.Align!="")
                            {
                                switch(column.Align)
                                {
                                    case "left":
                                        tc.HorizontalAlign=HorizontalAlign.Left;
                                        break;
                                    case "center":
                                        tc.HorizontalAlign=HorizontalAlign.Center;
                                        break;
                                    case "right":
                                        tc.HorizontalAlign=HorizontalAlign.Right;
                                        break;
                                }
                            }

                            if((object)column.Width!=null)
                            {
                                if(column.Unit=="%")
                                {
                                    tc.Width=Unit.Percentage((double)column.Width);
                                }
                                else
                                {
                                    tc.Width=Unit.Pixel(column.Width);
                                }
                            }
                            tc.BorderWidth=Unit.Pixel(1);
                            tr.Cells.Add(tc);

                        }
                    }
                    tb.Rows.Add(tr);
                }
            }
        }
Esempio n. 15
0
        private static void ClearStrictCollectionAndDisposesItCommon(MockRepository mocks, CollectionBase collection)
        {
            collection.Clear();
            ((IDisposable)collection).Dispose();

            mocks.ReplayAll();
            CleanCollection(collection);
            mocks.VerifyAll();
        }
Esempio n. 16
0
        internal LdapMod[] BuildAttributes(CollectionBase directoryAttributes, ArrayList ptrToFree)
        {
            LdapMod[] attributes = null;
            UTF8Encoding encoder = new UTF8Encoding();
            DirectoryAttributeCollection attributeCollection = null;
            DirectoryAttributeModificationCollection modificationCollection = null;
            DirectoryAttribute modAttribute = null;

            if (directoryAttributes != null && directoryAttributes.Count != 0)
            {
                if (directoryAttributes is DirectoryAttributeModificationCollection)
                {
                    modificationCollection = (DirectoryAttributeModificationCollection)directoryAttributes;
                }
                else
                {
                    attributeCollection = (DirectoryAttributeCollection)directoryAttributes;
                }

                attributes = new LdapMod[directoryAttributes.Count];
                for (int i = 0; i < directoryAttributes.Count; i++)
                {
                    // get the managed attribute first
                    if (attributeCollection != null)
                        modAttribute = attributeCollection[i];
                    else
                        modAttribute = modificationCollection[i];

                    attributes[i] = new LdapMod();

                    // operation type
                    if (modAttribute is DirectoryAttributeModification)
                    {
                        attributes[i].type = (int)((DirectoryAttributeModification)modAttribute).Operation;
                    }
                    else
                    {
                        attributes[i].type = (int)DirectoryAttributeOperation.Add;
                    }
                    // we treat all the values as binary
                    attributes[i].type |= (int)LDAP_MOD_BVALUES;

                    //attribute name
                    attributes[i].attribute = Marshal.StringToHGlobalUni(modAttribute.Name);

                    // values
                    int valuesCount = 0;
                    berval[] berValues = null;
                    if (modAttribute.Count > 0)
                    {
                        valuesCount = modAttribute.Count;
                        berValues = new berval[valuesCount];
                        for (int j = 0; j < valuesCount; j++)
                        {
                            byte[] byteArray = null;
                            if (modAttribute[j] is string)
                                byteArray = encoder.GetBytes((string)modAttribute[j]);
                            else if (modAttribute[j] is Uri)
                                byteArray = encoder.GetBytes(((Uri)modAttribute[j]).ToString());
                            else
                                byteArray = (byte[])modAttribute[j];

                            berValues[j] = new berval();
                            berValues[j].bv_len = byteArray.Length;
                            berValues[j].bv_val = Marshal.AllocHGlobal(berValues[j].bv_len);
                            // need to free the memory allocated on the heap when we are done
                            ptrToFree.Add(berValues[j].bv_val);
                            Marshal.Copy(byteArray, 0, berValues[j].bv_val, berValues[j].bv_len);
                        }
                    }

                    attributes[i].values = Utility.AllocHGlobalIntPtrArray(valuesCount + 1);
                    int structSize = Marshal.SizeOf(typeof(berval));
                    IntPtr controlPtr = (IntPtr)0;
                    IntPtr tempPtr = (IntPtr)0;
                    int m = 0;
                    for (m = 0; m < valuesCount; m++)
                    {
                        controlPtr = Marshal.AllocHGlobal(structSize);
                        // need to free the memory allocated on the heap when we are done
                        ptrToFree.Add(controlPtr);
                        Marshal.StructureToPtr(berValues[m], controlPtr, false);
                        tempPtr = (IntPtr)((long)attributes[i].values + Marshal.SizeOf(typeof(IntPtr)) * m);
                        Marshal.WriteIntPtr(tempPtr, controlPtr);
                    }
                    tempPtr = (IntPtr)((long)attributes[i].values + Marshal.SizeOf(typeof(IntPtr)) * m);
                    Marshal.WriteIntPtr(tempPtr, (IntPtr)0);
                }
            }

            return attributes;
        }
Esempio n. 17
0
 /// <summary>
 /// Returns the bounding rectangle of the given collection of entities.
 /// </summary>
 /// <param name="collection"></param>
 /// <returns></returns>
 public static Rectangle BoundingRectangle(CollectionBase<IDiagramEntity> collection)
 {
     //get the bounding rectangle
     bool first = true;
     Rectangle rec = Rectangle.Empty;
     foreach (IDiagramEntity entity in collection)
     {
         if (first)
         {
             rec = entity.Rectangle;
             first = false;
         }
         else
             rec = Rectangle.Union(rec, entity.Rectangle);
     }
     return rec;
 }
Esempio n. 18
0
 /// <summary>
 /// Returns a string with the array data, CollectionBase version.
 /// </summary>
 public static string WriteArrayData(CollectionBase collection)
 {
     StringBuilder ret = new StringBuilder();
     if (collection != null)
         foreach (object obj in collection)
             ret.Append((ret.Length == 0 ? "" : ", ") + obj.ToString());
     return ret.ToString();
 }
 internal LdapMod[] BuildAttributes(CollectionBase directoryAttributes, ArrayList ptrToFree)
 {
     LdapMod[] modArray = null;
     UTF8Encoding encoding = new UTF8Encoding();
     DirectoryAttributeCollection attributes = null;
     DirectoryAttributeModificationCollection modifications = null;
     DirectoryAttribute attribute = null;
     if ((directoryAttributes != null) && (directoryAttributes.Count != 0))
     {
         if (directoryAttributes is DirectoryAttributeModificationCollection)
         {
             modifications = (DirectoryAttributeModificationCollection) directoryAttributes;
         }
         else
         {
             attributes = (DirectoryAttributeCollection) directoryAttributes;
         }
         modArray = new LdapMod[directoryAttributes.Count];
         for (int i = 0; i < directoryAttributes.Count; i++)
         {
             if (attributes != null)
             {
                 attribute = attributes[i];
             }
             else
             {
                 attribute = modifications[i];
             }
             modArray[i] = new LdapMod();
             if (attribute is DirectoryAttributeModification)
             {
                 modArray[i].type = (int) ((DirectoryAttributeModification) attribute).Operation;
             }
             else
             {
                 modArray[i].type = 0;
             }
             LdapMod mod1 = modArray[i];
             mod1.type |= 0x80;
             modArray[i].attribute = Marshal.StringToHGlobalUni(attribute.Name);
             int count = 0;
             berval[] bervalArray = null;
             if (attribute.Count > 0)
             {
                 count = attribute.Count;
                 bervalArray = new berval[count];
                 for (int j = 0; j < count; j++)
                 {
                     byte[] source = null;
                     if (attribute[j] is string)
                     {
                         source = encoding.GetBytes((string) attribute[j]);
                     }
                     else if (attribute[j] is Uri)
                     {
                         source = encoding.GetBytes(((Uri) attribute[j]).ToString());
                     }
                     else
                     {
                         source = (byte[]) attribute[j];
                     }
                     bervalArray[j] = new berval();
                     bervalArray[j].bv_len = source.Length;
                     bervalArray[j].bv_val = Marshal.AllocHGlobal(bervalArray[j].bv_len);
                     ptrToFree.Add(bervalArray[j].bv_val);
                     Marshal.Copy(source, 0, bervalArray[j].bv_val, bervalArray[j].bv_len);
                 }
             }
             modArray[i].values = Marshal.AllocHGlobal((int) ((count + 1) * Marshal.SizeOf(typeof(IntPtr))));
             int cb = Marshal.SizeOf(typeof(berval));
             IntPtr zero = IntPtr.Zero;
             IntPtr ptr = IntPtr.Zero;
             int index = 0;
             index = 0;
             while (index < count)
             {
                 zero = Marshal.AllocHGlobal(cb);
                 ptrToFree.Add(zero);
                 Marshal.StructureToPtr(bervalArray[index], zero, false);
                 ptr = (IntPtr) (((long) modArray[i].values) + (Marshal.SizeOf(typeof(IntPtr)) * index));
                 Marshal.WriteIntPtr(ptr, zero);
                 index++;
             }
             ptr = (IntPtr) (((long) modArray[i].values) + (Marshal.SizeOf(typeof(IntPtr)) * index));
             Marshal.WriteIntPtr(ptr, IntPtr.Zero);
         }
     }
     return modArray;
 }