public void TestArray_Scenario_Result()
 {
     var strings = new[] { "Acme", "WB", "Universal" };
     Console.WriteLine(strings.Length);
     Console.WriteLine(strings.Rank);
     Console.WriteLine(strings.GetLength(0));
     Console.WriteLine(strings.GetUpperBound(0));
     Console.WriteLine(strings.Count());
 }
        /// <summary>
        /// Add the common C++ fix-up expressions
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnCPPFixes_Click(object sender, EventArgs e)
        {
            TreeNode node = null;

            string[,] cppExpressions = new[,] {
                // Strip out "`" followed by digits
                { "`[0-9]+(\\{)", "$1" },
                // Strip out superfluous "^"
                { "(member name=\".*?System\\.Collections\\.Generic.*?)(\\^)", "$1" },
                // Fix-up valid cref attributes that the compiler couldn't figure out
                { "cref=\"!:([EFGMNPT]|Overload):", "cref=\"$1:" },
                // Convert interior_ptr<T> to an explicit dereference
                { @"cli\.interior_ptr{([^}]+?)}", "[email protected]!System.Runtime.CompilerServices.IsExplicitlyDereferenced" } };

            for(int i = 0; i <= cppExpressions.GetUpperBound(0); i++)
                if(!tvExpressions.Nodes.OfType<TreeNode>().Any(t => t.Text == cppExpressions[i, 0]))
                {
                    node = new TreeNode
                    {
                        Text = cppExpressions[i, 0],
                        Tag = new MemberIdMatchExpression
                        {
                            MatchExpression = cppExpressions[i, 0],
                            ReplacementValue = cppExpressions[i, 1],
                            MatchAsRegEx = true
                        }
                    };

                    tvExpressions.Nodes.Add(node);
                }

            if(node != null)
            {
                tvExpressions.SelectedNode = node;
                node.EnsureVisible();
                txtMatchExpression.Focus();
            }
        }
        /// <summary>
        /// Validates a CPF (Brazilian personal document)
        /// </summary>
        /// <param name="cpf">CPF to be validated</param>
        /// <returns>If it is a valid CPF, returns true, else returns false</returns>
        public static bool ValidateCpf(this string cpf)
        {
            //variáveis
            int digito1, digito2;
            var adicao = 0;

            var cpfComparacao = cpf.RemovePunctuation();

            // Se o tamanho for < 11 entao retorna como inválido
            if (cpfComparacao.Length != 11) return false;

            // Pesos para calcular o primeiro número 
            var array1 = new[] { 10, 9, 8, 7, 6, 5, 4, 3, 2 };

            // Pesos para calcular o segundo número
            var array2 = new[] { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 };

            // Caso coloque todos os numeros iguais
            if (Regex.Match(cpfComparacao, "0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}").Success) return false;

            // Calcula cada número com seu respectivo peso 
            for (var i = 0; i <= array1.GetUpperBound(0); i++)
                adicao += array1[i] * Convert.ToInt32(cpfComparacao[i].ToString());

            // Pega o resto da divisão 
            var resto = adicao % 11;

            if (resto == 1 || resto == 0)
                digito1 = 0;
            else
                digito1 = 11 - resto;

            adicao = 0;

            // Calcula cada número com seu respectivo peso 
            for (var i = 0; i <= array2.GetUpperBound(0); i++)
                adicao += array2[i] * Convert.ToInt32(cpfComparacao[i].ToString());

            // Pega o resto da divisão 
            resto = adicao % 11;

            if (resto == 1 || resto == 0)
                digito2 = 0;
            else
                digito2 = 11 - resto;

            var calculo = digito1.ToString() + digito2.ToString();
            var digito = cpfComparacao.Substring(9, 2);

            // Se os ultimos dois digitos calculados bater com 
            // os dois ultimos digitos do cpf entao é válido 
            return calculo == digito;
        }
        private int findRegion(int inValue, int newValue, int noDataValue, System.Array inArr, System.Array outArr, List<string> columnrow, List<int>[] nextArray)
        {
            int permEdges = 0;
            string ccr = columnrow[0];
            string[] ccrArr = ccr.Split(new char[]{':'});
            int clm = System.Convert.ToInt32(ccrArr[0]);
            int rw = System.Convert.ToInt32(ccrArr[1]);
            int maxC = outArr.GetUpperBound(0);
            int maxR = outArr.GetUpperBound(1);
            int minCR = 0;
            for (int i = 0; i < 4; i++)
            {
                int cPlus = clm;
                int rPlus = rw;
                switch (i)
                {
                    case 0:
                        cPlus += 1;
                        break;
                    case 1:
                        rPlus += 1;
                        break;
                    case 2:
                        cPlus -= 1;
                        break;
                    default:
                        rPlus -= 1;
                        break;
                }
                int pVl = System.Convert.ToInt32(inArr.GetValue(cPlus + 1, rPlus + 1));
                bool inValueCheck = (pVl==inValue);
                bool rPlusMinCheck = (rPlus < minCR);
                bool rPlusMaxCheck = (rPlus > maxR);
                bool cPlusMinCheck = (cPlus < minCR);
                bool cPlusMaxCheck = (cPlus > maxC);
                if ((rPlusMinCheck || rPlusMaxCheck || cPlusMinCheck || cPlusMaxCheck))
                {
                    if (inValueCheck)
                    {
                        if (rPlusMinCheck)
                        {
                            nextArray[0].Add(cPlus);
                        }
                        else if (rPlusMaxCheck)
                        {
                            nextArray[1].Add(cPlus);
                        }
                        if (cPlusMinCheck)
                        {
                            nextArray[2].Add(rPlus);
                        }
                        if (cPlusMaxCheck)
                        {
                            nextArray[3].Add(rPlus);
                        }
                    }
                }
                else
                {
                    //try
                    //{
                        string cr = cPlus.ToString()+":"+rPlus.ToString();
                        //Console.WriteLine(cr);
                        int cVl = System.Convert.ToInt32(outArr.GetValue(cPlus, rPlus));
                        if (cVl == noDataValue)
                        {

                            if (inValueCheck)
                            {
                                try
                                {
                                    outArr.SetValue(newValue, cPlus, rPlus);
                                    if(!columnrow.Contains(cr))
                                    {
                                        columnrow.Add(cr);
                                    }
                                }
                                catch
                                {
                                }
                            }
                            else
                            {
                                permEdges++;
                            }
                        }
                        else
                        {
                        }
                    //}
                    //catch (Exception e)
                    //{
                    //    Console.WriteLine(e.ToString());
                    //}

                }
                //try
                //{
                    columnrow.Remove(ccr);
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine(e.ToString());
                //    columnrow.Clear();
                //}
            }
            return permEdges;
        }
Example #5
0
        public static System.Drawing.Bitmap ColorsToBitMap(System.Drawing.Color[][] pic)
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pic.GetUpperBound(0)+1, pic[0].GetUpperBound(0)+1);
             for (int w = 0; w < bmp.Width; w++)
             for (int h = 0; h < bmp.Height; h++)
             {
                 bmp.SetPixel(w, h, pic[w][h]);
             }

             return bmp;
        }
        public void Performance()
        {
            var manager = this.CreateManager();
            var uris = new[] { "http://www.a.com", "http://www.b.com", "http://www.c.com", "http://www.d.com", "http://www.e.com", "http://www.f.com", "http://www.g.com", "http://www.h.com" };
            var prefixes = new[] { "a", "b", "c", "d", "e", "f", "g", "h" };
            var count = uris.GetUpperBound(0);

            for (var i = 0; i < count; i++)
            {
                manager.RegisterNamespace(prefixes[i], uris[i]);
            }

            var rnd = new Random();
            var sw = new Stopwatch();

            sw.Start();
            for (var i = 0; i < 1000000; i++)
            {
                var j = rnd.Next(count);

                var pf = manager.LookupPrefix(uris[j]);
                var ns = manager.LookupNamespace(prefixes[j]);
                var nsq = manager.LookupNamespace(prefixes[j], true);
            }

            sw.Stop();
            var result = sw.ElapsedMilliseconds;
        }
        //Identifies the size of each dimension in the array
        private string GetArraySize(System.Array arr)
        {
            string _Size = System.String.Empty;

            for (int _Index = 0; _Index < arr.Rank; _Index++)
            {
                _Size += "," + System.Convert.ToString(arr.GetUpperBound(_Index) - arr.GetLowerBound(_Index) + 1);
            }

            if (_Size.Length == 0)
            {
                _Size = ",";
            }

            return _Size.Substring(1);
        }
        private void WriteArray(System.Array arr, System.Xml.XmlWriter writer, int rank, int[] Indices)
        {
            int _Index;

            //C# Is 0 Based While VB Is 1 Based By Default
            int[] _Indexes = new int[arr.Rank];

            if (Indices != null)
            {
                System.Array.Copy(Indices, _Indexes, Indices.Length - 1);
            }

            for (_Index = arr.GetLowerBound(rank); _Index <= arr.GetUpperBound(rank); _Index++)
            {
                //C# Is 0 Based While VB Is 1 Based By Default
                _Indexes.SetValue(_Index, rank);

                if (arr.GetValue(_Indexes) != null)
                {
                    writer.WriteStartElement("System.Array.Item");
                    writer.WriteAttributeString("point", null, GetArrayPoint(_Indexes));
                    WriteXml(arr.GetValue(_Indexes), writer);
                    writer.WriteEndElement();
                }

                if (arr.Rank - 1 > rank)
                {
                    WriteArray(arr, writer, rank + 1, _Indexes);
                }
            }
        }
        static string[,] ConvertToStringArray2Dimensional(System.Array values)
        {
            try
            {
                // create a new string array
                string[,] theArray = new string[values.GetUpperBound(0), values.GetUpperBound(1) - 1];
                //string[,] test = new string[11, 2];

                // loop through the 2-D System.Array and populate the 1-D String Array
                for (int i = 1; i <= values.GetUpperBound(0); i++)
                {
                    for (int j = 1; j < values.GetUpperBound(1); j++)
                    {
                        if (values.GetValue(i, j) == null)
                            theArray[i - 1, j - 1] = "";
                        else
                            theArray[i - 1, j - 1] = (string)values.GetValue(i, j).ToString();

                        //if (MainForm.StopGracefully)
                        //    return null;
                    }
                }
                return theArray;

            }
            catch (Exception Arrayexp)
            {

                throw Arrayexp;
            }
        }
Example #10
0
        /// <summary>
        /// Check cpf is valid
        /// </summary>
        /// <param name="cpf">Cpf</param>
        /// <returns>String is cpf</returns>
        public static bool IsCpf(this string cpf)
        {
            cpf = cpf.Replace(".", "").Replace("-", "");

            var reg = new Regex(@"(^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$)");

            if (!reg.IsMatch(cpf))
                return false;

            int d1;
            int d2;
            var soma = 0;

            var peso1 = new[] { 10, 9, 8, 7, 6, 5, 4, 3, 2 };
            var peso2 = new[] { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 };

            //Digitos
            var n = new int[11];

            // Se o tamanho for < 11 entao retorna como inválido
            if (cpf.Length != 11)
                return false;

            // Caso coloque todos os numeros iguais
            switch (cpf)
            {
                case "00000000000":
                    return false;
                case "11111111111":
                    return false;
                case "2222222222":
                    return false;
                case "33333333333":
                    return false;
                case "44444444444":
                    return false;
                case "55555555555":
                    return false;
                case "66666666666":
                    return false;
                case "77777777777":
                    return false;
                case "88888888888":
                    return false;
                case "99999999999":
                    return false;
            }

            try
            {
                n[0] = Convert.ToInt32(cpf.Substring(0, 1));
                n[1] = Convert.ToInt32(cpf.Substring(1, 1));
                n[2] = Convert.ToInt32(cpf.Substring(2, 1));
                n[3] = Convert.ToInt32(cpf.Substring(3, 1));
                n[4] = Convert.ToInt32(cpf.Substring(4, 1));
                n[5] = Convert.ToInt32(cpf.Substring(5, 1));
                n[6] = Convert.ToInt32(cpf.Substring(6, 1));
                n[7] = Convert.ToInt32(cpf.Substring(7, 1));
                n[8] = Convert.ToInt32(cpf.Substring(8, 1));
                n[9] = Convert.ToInt32(cpf.Substring(9, 1));
                n[10] = Convert.ToInt32(cpf.Substring(10, 1));
            }
            catch
            {
                return false;
            }

            for (int i = 0; i <= peso1.GetUpperBound(0); i++)
                soma += (peso1[i] * Convert.ToInt32(n[i]));

            int resto = soma % 11;

            if (resto == 1 || resto == 0)
                d1 = 0;
            else
                d1 = 11 - resto;

            soma = 0;

            for (var i = 0; i <= peso2.GetUpperBound(0); i++)
                soma += (peso2[i] * Convert.ToInt32(n[i]));

            resto = soma % 11;

            if (resto == 1 || resto == 0)
                d2 = 0;
            else
                d2 = 11 - resto;

            var calculado = d1 + d2.ToString(CultureInfo.InvariantCulture);
            var digitado = n[9] + n[10].ToString(CultureInfo.InvariantCulture);

            return calculado == digitado;
        }
        public void JScriptEngine_MarshalArraysByValue()
        {
            var foo = new[] { DayOfWeek.Saturday, DayOfWeek.Friday, DayOfWeek.Thursday };

            engine.Script.foo = foo;
            Assert.AreSame(foo, engine.Evaluate("foo"));

            engine.Dispose();
            engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.MarshalArraysByValue);

            engine.Script.foo = foo;
            Assert.AreNotSame(foo, engine.Evaluate("foo"));
            engine.Execute("foo = new VBArray(foo)");

            Assert.AreEqual(foo.GetUpperBound(0), engine.Evaluate("foo.ubound(1)"));
            for (var index = 0; index < foo.Length; index++)
            {
                Assert.AreEqual(foo[index], engine.Evaluate("foo.getItem(" + index + ")"));
            }
        }
 /// <summary>
 /// Converting the data values retrieved from the rangecells to string values.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private string[][] ToStringArray(System.Array data)
 {
     try
     {
         string[][] sArray = new string[data.GetUpperBound(0)][];
         for (int i = data.GetLowerBound(0); i <= data.GetUpperBound(0); ++i)
         {
             sArray[i - 1] = new string[data.GetUpperBound(1)];
             for (int j = data.GetLowerBound(1); j <= data.GetUpperBound(1); ++j)
             {
                 if (data.GetValue(i, j) == null)
                 {
                     sArray[i - 1][j - 1] = "-----";
                 }
                 else
                 {
                     sArray[i - 1][j - 1] = data.GetValue(i, j).ToString();
                 }
             }
         }
         return sArray;
     }
     catch 
     {
         throw (new Exception("Exception: Conversion to string array"));
     }
 }
Example #13
0
        private string[] ConvertToStringArray(System.Array values)
        {
            string[] newArray = new string[values.Length];

            int index = 0;
            for (int i = values.GetLowerBound(0);
                  i <= values.GetUpperBound(0); i++)
            {
                for (int j = values.GetLowerBound(1);
                          j <= values.GetUpperBound(1); j++)
                {
                    if (values.GetValue(i, j) == null)
                    {
                        newArray[index] = "";
                    }
                    else
                    {
                        newArray[index] = (string)values.GetValue(i, j).ToString();
                    }
                    index++;
                }
            }
            return newArray;
        }
			/// <summary />
			public void CopyTo(System.Int32[] array, int start) {
				if (m_count > array.GetUpperBound(0)+1-start)
					throw new System.ArgumentException("Destination array was not long enough.");

				// for (int i=0; i < m_count; ++i) array[start+i] = m_array[i];
				System.Array.Copy(m_array, 0, array, start, m_count); 
			}
Example #15
0
 private bool LoadArray(ref System.Array AnArray, short CanonDT, ref string wrTxt)
 {
     int ii;
     int loc;
     int Wlen;
     int start;
     try
     {
         start = 1;
         Wlen = wrTxt.Length;
         for (ii = AnArray.GetLowerBound(0); (ii <= AnArray.GetUpperBound(0)); ii++)
         {
             loc = (wrTxt.IndexOf(",", (start - 1)) + 1);
             if ((ii < AnArray.GetUpperBound(0)))
             {
                 if ((loc == 0))
                 {
                     MessageBox.Show("Write Value: Incorrect Number of Items for Array Size?", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     return false;
                 }
             }
             else
             {
                 loc = (Wlen + 1);
             }
             switch ((CanonicalDataTypes)CanonDT)
             {
                 case CanonicalDataTypes.CanonDtByte:
                     AnArray.SetValue(Convert.ToByte(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtChar:
                     AnArray.SetValue(Convert.ToSByte(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtWord:
                     AnArray.SetValue(Convert.ToUInt16(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtShort:
                     AnArray.SetValue(Convert.ToInt16(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtDWord:
                     AnArray.SetValue(Convert.ToUInt32(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtLong:
                     AnArray.SetValue(Convert.ToInt32(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtFloat:
                     AnArray.SetValue(Convert.ToSingle(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtDouble:
                     AnArray.SetValue(Convert.ToDouble(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtBool:
                     AnArray.SetValue(Convert.ToBoolean(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 case CanonicalDataTypes.CanonDtString:
                     AnArray.SetValue(Convert.ToString(wrTxt.Substring((start - 1), (loc - start))), ii);
                     //  End case
                     break;
                 default:
                     MessageBox.Show("Write Value Unknown data type", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                     return false;
                     break;
             }
             start = (loc + 1);
         }
         return true;
     }
     catch (Exception ex)
     {
         MessageBox.Show(("Write Value generated Exception: " + ex.Message), "SimpleOPCInterface Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return false;
     }
 }