/// <summary>
		///     Iterates through all values in the matrix or jagged array and finds maximum length required
		///     to show any of the values contained.
		/// </summary>
		/// <param name="array">Matrix or jagged array through which this method will iterate.</param>
		/// <returns>Number of characters sufficient to receive any formatted value contained in <paramref name="array" />.</returns>
		private int GetMaxValueLength(Array array)
		{
			var maxLength = 0;

			if (IsMultiLinedFormat)
			{
				var sfi = new ScalarFormatInfo(this);
				sfi.ShowDataType = false;
				sfi.ShowInstanceName = false;

				if (array.Rank == 2)
				{
					maxLength = sfi.GetMaxValueLength(array.GetEnumerator());
				}
				else
				{
					// In jagged array we have to iterate through rows manually

					var rowsEnumerator = array.GetEnumerator();
					while (rowsEnumerator.MoveNext())
					{
						var row = (Array) rowsEnumerator.Current;
						var curMaxLength = sfi.GetMaxValueLength(row.GetEnumerator());
						maxLength = Math.Max(maxLength, curMaxLength);
					}
				}
			}

			return maxLength;
		}
        /// <summary>
        /// Slices arrays of 2 and more dimensions.
        /// </summary>
        /// <param name="arr">Array to slice</param>
        /// <param name="sliceDimensionIndex">Dimension to slice</param>
        /// <param name="indexToSet">Index to set for the sliced dimension</param>
        /// <returns>Sliced array</returns>
        public static Array Slice(Array arr, int sliceDimensionIndex, int indexToSet)
        {
            var enumerator = arr.GetEnumerator();
            enumerator.MoveNext();
            Type elementType = enumerator.Current.GetType();

            int[] lengthsSliced =
                Enumerable.Range(0, arr.Rank)
                    .Where(i => i != sliceDimensionIndex)
                    .Select(arr.GetLength)
                    .ToArray();

            int[] lowerBoundsSliced =
                Enumerable.Range(0, arr.Rank)
                    .Where(i => i != sliceDimensionIndex)
                    .Select(arr.GetLowerBound)
                    .ToArray();

            var arraySliced = Array.CreateInstance(elementType, lengthsSliced, lowerBoundsSliced);
            var multiIndex1 = _firstIndex(arraySliced);
            var multiIndex2 = _firstIndexBounded(arr, sliceDimensionIndex, indexToSet);
            for (; multiIndex2 != null; multiIndex1 = _nextIndex(arraySliced, multiIndex1), multiIndex2 = _nextIndexBounded(arr, multiIndex2, sliceDimensionIndex))
            {
                arraySliced.SetValue(arr.GetValue(multiIndex2), multiIndex1);
            }
            return arraySliced;
        }
        private void Select_ListaWiadomosciOczekujacych_ExecuteCode(object sender, EventArgs e)
        {
            results = BLL.tabWiadomosci.Select_Batch(workflowProperties.Web);
            myEnum = results.GetEnumerator();

            logSelected_HistoryOutcome = results.Length.ToString();
        }
 public static IEnumerator ForEachInArr(Array ary)
 {
     IEnumerator enumerator = ary.GetEnumerator();
     if (enumerator == null)
     {
         throw ExceptionUtils.VbMakeException(0x5c);
     }
     return enumerator;
 }
        private void cmdGet_KartyKontrolne_ExecuteCode(object sender, EventArgs e)
        {
            logSelected_HistoryDescription = "Karty kontrolne do obsługi";

            results = BLL.tabKartyKontrolne.Get_ZwolnioneDoWysylki(workflowProperties.Web);
            myEnum = results.GetEnumerator();

            if (results != null) logSelected_HistoryOutcome = results.Length.ToString();
            else logSelected_HistoryOutcome = "0";
        }
Example #6
0
        /// <summary>
        /// Compare the two arrays
        /// </summary>
        /// <param name="a">Array A</param>
        /// <param name="b">Array B</param>
        /// <returns>True if the two array are equals, otherwise False.</returns>
        /// <example>
        /// <code>
        ///   int[] a = new int[] { 1, 2, 3, 4 };
        ///   int[] b = new int[] { 1, 2, 3, 4 };
        ///   Assert.IsTrue(Arrays.DeepEquals(a, b));
        /// </code>
        /// </example>
        public static bool DeepEquals(Array a, Array b)
        {
            if (a == null && b == null)
            {
                return true;
            }
            if (ReferenceEquals(a, b))
            {
                return true;
            }
            if (a.Length != b.Length)
            {
                return false;
            }

            bool result = true;

            IEnumerator enA = a.GetEnumerator();
            IEnumerator enB = b.GetEnumerator();

            while (enA.MoveNext() && enB.MoveNext())
            {
                if (enA.Current == null && enB.Current == null)
                {
                }
                else if (enA.Current == null || enB.Current == null)
                {
                    result = false;
                    break;
                }
                else if ((enA is Array) && (enB is Array))
                {
                    result = DeepEquals((Array)enA, (Array)enB);
                    if (!result)
                    {
                        break;
                    }
                }
                else if (enA.Current == enB.Current)
                {
                }
                else if (enA.Current.Equals(enB.Current))
                {
                }
                else
                {
                    result = false;
                    break;
                }
            }

            return result;
        }
        private static bool ItemsEquals(Array x, Array y, Func<object, object, bool> compare)
        {
            var xe = x.GetEnumerator();
            var ye = y.GetEnumerator();
            while (xe.MoveNext() && ye.MoveNext())
            {
                if (!compare(xe.Current, ye.Current))
                {
                    return false;
                }
            }

            return true;
        }
Example #8
0
 public static void PrintAllValues(Array myArr)
 {
     System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
     int i = 0;
     int cols = myArr.GetLength(myArr.Rank - 1);
     while (myEnumerator.MoveNext())
     {
         if (i < cols)
         {
             i++;
         }
         else
         {
             Console.WriteLine();
             i = 1;
         }
         Console.Write("\t{0}", myEnumerator.Current);
     }
     Console.WriteLine();
 }
Example #9
0
 private static void PrintValues(Array myArr, char mySeparator)
 {
     System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
     int i = 0;
     int cols = myArr.GetLength(myArr.Rank - 1);
     while (myEnumerator.MoveNext())
     {
         if (i < cols)
         {
             i++;
         }
         else
         {
             Console.WriteLine();
             i = 1;
         }
         Console.Write("{0}{1}", mySeparator, myEnumerator.Current);
     }
     Console.WriteLine();
 }
Example #10
0
        public static bool Equals(Array arr1, Array arr2)
        {
            if(object.ReferenceEquals(arr1, arr2))
            {
                return true;
            }

            if((arr1 == null && arr2 != null) || (arr1 != null && arr2 == null))
            {
                return false;
            }

            if(arr1.Length == arr2.Length)
            {
                IEnumerator e1 = arr1.GetEnumerator();
                IEnumerator e2 = arr2.GetEnumerator();
                while(e1.MoveNext())
                {
                    e2.MoveNext();
                    if(e1.Current == null)
                    {
                        if(e2.Current != null)
                        {
                            return false;
                        }
                    }
                    else if(!e1.Current.Equals(e2.Current))
                    {
                        return false;
                    }
                }

                return true;
            }

            return false;           
        }
Example #11
0
        public static bool IsEqualArray(Array a, Array b)
        {
            if (a == null && b == null)
                return true;
            if (a == null)
                return false;
            if (b == null)
                return false;

            Type aType = a.GetType();
            Type bType = b.GetType();

            if (aType != bType)
                return false;

            if (!aType.IsArray)
                return false;

            var aEnumerator = a.GetEnumerator();
            var bEnumerator = b.GetEnumerator();

            while (true)
            {
                bool aHasElement = aEnumerator.MoveNext();
                bool bHasElement = bEnumerator.MoveNext();

                if (aHasElement != bHasElement)
                    return false;

                if (!aHasElement)
                    return true;

                if (!IsEqualObject(aEnumerator.Current, bEnumerator.Current))
                    return false;
            }
        }
Example #12
0
        static public void CompareArrays(Array a1, Array a2, string value)
        {
            if (a1 == null &&
                a2 == null)
                return;
            Assert.IsFalse((a1 == null && a2 != null) || (a1 != null && a2 == null), value + " do not match - one array is null");
            Assert.IsTrue(a1.Length == a2.Length, value + " do not match - array lengths do not match");


            IEnumerator enum1 = a1.GetEnumerator();
            IEnumerator enum2 = a2.GetEnumerator();
            while (enum1.MoveNext() && enum2.MoveNext())
                Assert.IsTrue(enum1.Current.Equals(enum2.Current), value + " do not match");                
        }
Example #13
0
        /// <summary>Curl an input array up into a multi-dimensional array.</summary>
        /// <param name="input">The one dimensional array to be curled.</param>
        /// <param name="dimens">The desired dimensions</param>
        /// <returns>The curled array.</returns>
        public static Array Curl(Array input, int[] dimens)
        {
            if (CountDimensions(input) != 1)
            {
                throw new SystemException("Attempt to curl non-1D array");
            }

            int test = 1;
            for (int i = 0; i < dimens.Length; i += 1)
            {
                test *= dimens[i];
            }

            if (test != input.Length)
            {
                throw new SystemException("Curled array does not fit desired dimensions");
            }

            Array newArray = NewInstance(GetBaseClass(input), dimens);

            int[] index = new int[dimens.Length];
            index[index.Length - 1] = -1;
            for (int i = 0; i < index.Length - 1; ++i)
            {
                index[i] = 0;
            }

            for (IEnumerator i = input.GetEnumerator(); i.MoveNext() && NextIndex(index, dimens); )
            {
                //NewInstance call creates a jagged array. So we cannot set the value using Array.SetValue
                //as it works for multi-dimensional arrays and not for jagged
                //newArray.SetValue(i.Current, index);

                Array tarr = newArray;
                for (int i2 = 0; i2 < index.Length - 1; i2++)
                {
                    tarr = (Array)tarr.GetValue(index[i2]);
                }
                tarr.SetValue(i.Current, index[index.Length - 1]);
            }
            //int offset = 0;
            //DoCurl(input, newArray, dimens, offset);
            return newArray;
        }
	// Get the enumerator for an array.
	public static IEnumerator ForEachInArr(Array ary)
			{
				return ary.GetEnumerator();
			}
Example #15
0
 private void Select_ListaZadan_ExecuteCode(object sender, EventArgs e)
 {
     bool withAttachements = true;
     zadania = BLL.tabZadania.Get_ZakonczoneDoArchiwizacji(workflowProperties.Web, withAttachements);
     myEnum = zadania.GetEnumerator();
 }
Example #16
0
 private void Select_ListaWiadomosci_ExecuteCode(object sender, EventArgs e)
 {
     wiadomosci = BLL.tabWiadomosci.Get_GotoweDoArchiwizacji(workflowProperties.Web);
     myEnum = wiadomosci.GetEnumerator();
 }
Example #17
0
        private void Create_TargetList_ExecuteCode(object sender, EventArgs e)
        {
            Debug.WriteLine("Create_TargetList");

            klienci = BLL.tabKlienci.Get_AktywniKlienci(workflowProperties.Web);
            Debug.WriteLine("#klienci: " + klienci.Length.ToString());

            myEnum = klienci.GetEnumerator();
        }
		private	byte[] EncodeSlice(ArrayDesc desc, Array sourceArray, int length)
		{
			BinaryWriter	writer	= new BinaryWriter(new MemoryStream());
			IEnumerator		i		= sourceArray.GetEnumerator();
			Charset			charset = this.db.Charset;
			DbDataType		dbType	= DbDataType.Array;
			int				type	= 0;
			int				subtype = (this.Descriptor.Scale < 0) ? 2 : 0;

			// Infer data types
			type = TypeHelper.GetFbType(this.Descriptor.DataType);
			dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, subtype,	this.Descriptor.Scale);

			while (i.MoveNext())
			{
				switch (dbType)
				{
					case DbDataType.Char:
					{
						string value  = i.Current != null ?	(string)i.Current :	String.Empty;
						byte[] buffer = charset.GetBytes(value);

						writer.Write(buffer);

						if (desc.Length	> buffer.Length)
						{
							for	(int j = buffer.Length;	j <	desc.Length; j++)
							{
								writer.Write((byte)32);
							}
						}
					}
					break;

					case DbDataType.VarChar:
					{
						string value = i.Current !=	null ? (string)i.Current : String.Empty;

						value = value.TrimEnd();

						byte[] buffer = charset.GetBytes(value);
						writer.Write(buffer);

						if (desc.Length	> buffer.Length)
						{
							for	(int j = buffer.Length;	j <	desc.Length; j++)
							{
								writer.Write((byte)0);
							}
						}
						writer.Write((short)0);
					}
					break;
	
					case DbDataType.SmallInt:
						writer.Write((short)i.Current);
						break;
	
					case DbDataType.Integer:
						writer.Write((int)i.Current);
						break;

					case DbDataType.BigInt:
						writer.Write((long)i.Current);
						break;
					
					case DbDataType.Float:
						writer.Write((float)i.Current);
						break;
										
					case DbDataType.Double:
						writer.Write((double)i.Current);
						break;
					
					case DbDataType.Numeric:
					case DbDataType.Decimal:
					{
						object numeric = TypeEncoder.EncodeDecimal((decimal)i.Current, desc.Scale, type);

						switch (type)
						{
							case IscCodes.SQL_SHORT:
								writer.Write((short)numeric);
								break;

							case IscCodes.SQL_LONG:
								writer.Write((int)numeric);
								break;

							case IscCodes.SQL_QUAD:
							case IscCodes.SQL_INT64:
								writer.Write((long)numeric);
								break;
						}
					}
					break;

					case DbDataType.Date:
						writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
						break;
					
					case DbDataType.Time:
						writer.Write(TypeEncoder.EncodeTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
						break;

					case DbDataType.TimeStamp:
						writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
						writer.Write(TypeEncoder.EncodeTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
						break;
					
					default:
						throw new NotSupportedException("Unknown data type");
				}
			}

			return ((MemoryStream)writer.BaseStream).ToArray();
		}
Example #19
0
        public static void AreEqual(Array obj1, Array obj2, string failMessage)
        {
            if (obj1 == obj2)
            {
                return;
            }
            if (null == obj1)
            {
                if (null != obj2)
                {
                    throw new AssertionException(failMessage);
                }
                return;
            }
            if (null == obj2)
            {
                throw new AssertionException(failMessage);
            }
            if (!obj1.GetType().Equals(obj2.GetType()))
            {
                throw new AssertionException(failMessage + ". Expected object type: " + obj1.GetType().ToString() + ", but actual object type is: " + obj2.GetType().ToString());
            }
            if (!obj1.Length.Equals(obj2.Length))
            {
                throw new AssertionException(failMessage);
            }

            System.Collections.IEnumerator first = obj1.GetEnumerator();
            System.Collections.IEnumerator second = obj2.GetEnumerator();

            while (first.MoveNext() && second.MoveNext())
            {
                if (((null != first.Current) && !first.Current.Equals(second.Current)) || ((null == first.Current) && (null != second.Current)))
                {
                    throw new AssertionException(failMessage);
                }
            }
        }
Example #20
0
        static void EnumAsArray(Array arr)
        {
            TestLogger.Log("Testing foreach enumeration over Array...");
            foreach (var a in arr)
            {
                if (a != null)
                    TestLogger.Log(a.ToString());
            }

            TestLogger.Log("Testing untyped direct enumeration over Array...");
            var en1 = arr.GetEnumerator();
            while (en1.MoveNext())
            {
                if (en1.Current != null)
                    TestLogger.Log(en1.Current.ToString());
            }

            TestLogger.Log("Testing typed direct enumeration over Array...");
            var en2 = ((IEnumerable<B>)arr).GetEnumerator();
            while (en2.MoveNext())
            {
                if (en2.Current != null)
                    TestLogger.Log(en2.Current.ToString());
            }
        }
		private byte[] EncodeSliceArray(Array sourceArray)
		{
			IEnumerator i		= sourceArray.GetEnumerator();
			DbDataType	dbType	= DbDataType.Array;
			Charset		charset = this.db.Charset;
			XdrStream	xdr		= new XdrStream(this.db.Charset);
			int			type	= 0;
			int			subtype = (this.Descriptor.Scale < 0) ? 2 : 0;

			type = TypeHelper.GetFbType(this.Descriptor.DataType);
			dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, subtype, this.Descriptor.Scale);

			while (i.MoveNext())
			{
				switch (dbType)
				{
					case DbDataType.Char:
						byte[] buffer = charset.GetBytes(i.Current.ToString());
						xdr.WriteOpaque(buffer, this.Descriptor.Length);
						break;

					case DbDataType.VarChar:
						xdr.Write((string)i.Current);
						break;

					case DbDataType.SmallInt:
						xdr.Write((short)i.Current);
						break;

					case DbDataType.Integer:
						xdr.Write((int)i.Current);
						break;

					case DbDataType.BigInt:
						xdr.Write((long)i.Current);
						break;

					case DbDataType.Decimal:
					case DbDataType.Numeric:
						xdr.Write((decimal)i.Current, type, this.Descriptor.Scale);
						break;

					case DbDataType.Float:
						xdr.Write((float)i.Current);
						break;

					case DbDataType.Double:
						xdr.Write((double)i.Current);
						break;

					case DbDataType.Date:
						xdr.WriteDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
						break;

					case DbDataType.Time:
						xdr.WriteTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
						break;

					case DbDataType.TimeStamp:
						xdr.Write(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
						break;

					default:
						throw new NotSupportedException("Unknown data type");
				}
			}

			return xdr.ToArray();
		}