public String[] ToArray()
 {
     String[] hiddenPaths = new String[List.Count];
     for (Int32 i = 0; i < List.Count; i++)
     {
         hiddenPaths.SetValue(List[i], i);
     }
     return hiddenPaths;
 }
Example #2
0
        /// <summary>
        /// получить список названий properties
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static String[] GetStringsProperties(Type type)
        {
            IList<PropertyInfo> listP = type.GetProperties();

            String[] listS = new String[listP.Count];

            foreach (PropertyInfo infoProperty in listP)
                listS.SetValue(infoProperty.Name, listP.IndexOf(infoProperty));

            Array.Sort(listS);

            return listS;
        }
Example #3
0
        public bool Write(String Key, String sFields, String sValues)
        {
            String Record = new string(' ', 1000);

            String[]     Fields    = sFields.Split(',');
            String[]     Values    = sValues.Split('|');
            System.Array arrValues = new System.String[Fields.GetLength(0) + 1];


            this.sKey = Key;


            int i = 0;

            foreach (String f in Fields)
            {
                arrValues.SetValue(Values.GetValue(i).ToString(), i);
                i++;
            }



            err = oFile.dsExtractRec(this.channel, this.sKey, 0, ref Record);
            if (err != -1)
            {
                if (err == 11)
                {
                    Record = "";
                }
                else
                {
                    this.Error = err.ToString();
                    return(false);
                }
            }

            err = oFile.dsWriteFld(this.channel, this.sKey, Record, sFields, ref arrValues);
            if (err != -1)
            {
                this.Error = "err=" + err.ToString() + "  Lenght: " + Record.Length.ToString();
                return(false);
            }

            return(true);
        }
Example #4
0
        public bool write_detail_order()
        {
            String Record = new string(' ', 200);

            System.Array arrDetail = new System.String[7];

            //Attach header fields template
            oCustomer.dsTmpl(channel, "teacher:c(30),student:c(30*),type:c(3*),item:c(10*),no_items:n(10*),tax:n(10*),no_invoiced:n(10)");

            arrDetail.SetValue(this.Detail.Teacher.PadRight(30, ' '), 0);
            arrDetail.SetValue(this.Detail.Student.PadRight(30, ' '), 1);
            arrDetail.SetValue(this.Detail.Seq, 2);
            arrDetail.SetValue(this.Detail.Item, 3);
            arrDetail.SetValue(this.Detail.No_Items, 4);
            arrDetail.SetValue(this.Detail.Tax, 5);
            arrDetail.SetValue(this.Detail.No_Invoiced, 6);

            this.sKey = arrDetail.GetValue(0).ToString() + arrDetail.GetValue(1).ToString() + arrDetail.GetValue(2).ToString();
            int err = oCustomer.dsExtractRec(channel, sKey, 0, ref Record);

            if (err != -1)
            {
                if (err == 11)
                {
                    Record = "";
                }
                else
                {
                    MessageBox.Show(err.ToString());
                    return(false);
                }
            }

            err = oCustomer.dsWriteFld(channel, sKey, Record, "teacher,student,type,item,no_items,tax,no_invoiced", ref arrDetail);
            if (err != -1)
            {
                MessageBox.Show("err=" + err.ToString() + "  Lenght: " + Record.Length.ToString());
                return(false);
            }


            return(true);
        }
        private static bool GetReplacement(String[] badwords, String[] filterwords, ref string find, ref string replacement)
        {
            if (find == "")
            {
                return false;
            }

            if (filterwords.Length == 2)
            {
                for (int m = 0; m < badwords.Length; m++)
                {
                    if (filterwords[1].ToString() != "")
                    {
                        replacement = filterwords[1].ToString();
                    }
                }
            }
            else if (filterwords.Length < 2)
            {
                for (int m = 0; m < badwords.Length; m++)
                {
                    replacement = "**";
                }
            }
            else
            {
                replacement = filterwords[filterwords.Length - 1];

                filterwords.SetValue("", filterwords.Length - 1);

                find = string.Join("=", filterwords);
                find = find.Remove(find.Length - 2);
            }

            if (replacement == string.Empty)
            {
                replacement = "**";
            }
            return true;
        }
Example #6
0
File: DAL.cs Project: GregXP/XP
        public bool PopulateDados(List<ACCC033.ContratoParcelaACCC033> listCon)
        {
            bool ret = false;
            try
            {
                using (OracleConnection connection = new OracleConnection(RetornoCIP.CNX_C3))
                {
                    String[] arrNU_CON = new String[listCon.Count];
                    String[] arrTP_EVT = new String[listCon.Count];
                    String[] arrSIT_EVT = new String[listCon.Count];
                    String[] arrNU_PAR = new String[listCon.Count];
                    String[] arrCODERR = new String[listCon.Count];

                    for (int i = 0; i < listCon.Count; i++)
                    {
                        arrNU_CON.SetValue(listCon[i].NU_CON, i);
                        arrTP_EVT.SetValue(listCon[i].TpMotvEvt, i);
                        arrSIT_EVT.SetValue(listCon[i].SitEvt, i);
                        arrNU_PAR.SetValue(listCon[i].NU_PAR, i);
                        arrCODERR.SetValue(listCon[i].CodErro, i);
                    }

                    OracleCommand command = new OracleCommand(@"insert into CCCTBL033 (NU_CONTRATO, TIPMOTVEVT, SITEVT, NU_PARCELA, CODERR)
                                                                values (:VER_CON_NU, :TP_EVT, :SIT_EVT, :VER_PAR_NU, :CODERR)", connection);
                    command.CommandType = CommandType.Text;
                    command.ArrayBindCount = listCon.Count;

                    // VER_CON_NU parameter
                    OracleParameter prmNUC = new OracleParameter("VER_CON_NU", OracleDbType.Varchar2);
                    prmNUC.Direction = System.Data.ParameterDirection.Input;
                    prmNUC.Value = arrNU_CON;
                    command.Parameters.Add(prmNUC);

                    // TP_EVT parameter
                    OracleParameter prmTPE = new OracleParameter("TP_EVT", OracleDbType.Varchar2);
                    prmTPE.Direction = System.Data.ParameterDirection.Input;
                    prmTPE.Value = arrTP_EVT;
                    command.Parameters.Add(prmTPE);

                    // SIT_EVT parameter
                    OracleParameter prmSIE = new OracleParameter("SIT_EVT", OracleDbType.Varchar2);
                    prmSIE.Direction = System.Data.ParameterDirection.Input;
                    prmSIE.Value = arrSIT_EVT;
                    command.Parameters.Add(prmSIE);

                    // VER_PAR_NU parameter
                    OracleParameter prmNUP = new OracleParameter("VER_PAR_NU", OracleDbType.Varchar2);
                    prmNUP.Direction = System.Data.ParameterDirection.Input;
                    prmNUP.Value = arrNU_PAR;
                    command.Parameters.Add(prmNUP);

                    // CODERR parameter
                    OracleParameter prmErr = new OracleParameter("CODERR", OracleDbType.Varchar2);
                    prmErr.Direction = System.Data.ParameterDirection.Input;
                    prmErr.Value = arrCODERR;
                    command.Parameters.Add(prmErr);

                    connection.Open();
                    command.ExecuteNonQuery();

                    if (Utils._logger != null)
                        Utils._logger.Info(command.ArrayBindCount + " registros inseridos");

                    connection.Close();

                    ret = true;
                }
            }
            catch (Exception ex)
            {
                if (Utils._logger != null)
                    Utils._logger.Error(ex.Message);
            }
            return ret;
        }
        /// <summary>
        /// Parse Joins and return new script
        /// </summary>
        public String[] ParseJoins(String Script)
        {
            MatchCollection col = Regex.Matches(Script, "join\\(\"(?<class>[A-Za-z0-9]*)\"\\);", RegexOptions.IgnoreCase);
            String NewScript = Regex.Replace(Script, "join\\(\"(?<class>[A-Za-z0-9]*)\"\\);", "", RegexOptions.IgnoreCase);
            String Serverside, Clientside;

            foreach (Match x in col)
            {
                ServerClass Class = this.FindClass(x.Groups["class"].Value);
                if (Class != null)
                    NewScript += "\n" + Class.Script;
            }

            int pos = NewScript.IndexOf("//#CLIENTSIDE");
            if (pos >= 0)
            {
                Serverside = NewScript.Substring(0, pos);
                Clientside = NewScript.Substring(pos + 13);
            }
            else
            {
                Serverside = NewScript;
                Clientside = "";
            }

            //Console.WriteLine(NewScript);
            NewScript = Regex.Replace(NewScript, "function\\s*([a-z0-9]+)\\s*\\((.*)\\)(\t|\r|\\s)*\\{(.*)\\}", delegate(Match match)
            {
                string v = match.ToString();
                return char.ToUpper(v[0]) + v.Substring(1);//"public void $1 ($2)\n{\n}\n"
            }, RegexOptions.IgnoreCase);

            //Console.WriteLine("after regexp: " + NewScript);
            String[] scripts = new String[2];
            scripts.SetValue(Serverside, 0);
            scripts.SetValue(Clientside, 1);
            return scripts;
        }
Example #8
0
        //Utilizes WebHDFS API to download files from HDFS, writing to the root directory specified in the command line arguments
        private static void DownloadFiles(string basePath, string localPath)
        {
            try
            {
                using (var client = new WebClient())
                {
                    //Get the result of the WebHDFS call
                    string result = client.DownloadString(basePath + listArgs);
                    JObject o = JObject.Parse(result);

                    int dirCount = o["FileStatuses"]["FileStatus"].Count();
                    if (dirCount > 0)
                    {
                        //for each directory, list the type, suffix, and size of the file
                        for (int i = 0; i < dirCount; i++)
                        {
                            string dirType = (string)o["FileStatuses"]["FileStatus"][i]["type"];
                            string pathSuffix = (string)o["FileStatuses"]["FileStatus"][i]["pathSuffix"];
                            string fileSize = (string)o["FileStatuses"]["FileStatus"][i]["length"];
                            string newBasePath = null;
                            string newLocalPath = null;
                            if (basePath.EndsWith("/"))
                            {
                                newBasePath = basePath + pathSuffix;
                                newLocalPath = localPath + pathSuffix;
                            }
                            else
                            {
                                newBasePath = basePath + "/" + pathSuffix;
                                newLocalPath = localPath + "\\" + pathSuffix;
                            }

                            //if current file status is a file, download the file
                            if (dirType.Equals("FILE"))
                            {
                                String[] fileProperties = new String[6];
                                DateTime fileStart = DateTime.UtcNow;
                                string downloadString = newBasePath + openArgs;
                                Directory.CreateDirectory(localPath);
                                Console.WriteLine("Downloading file {0}\nDounload started: {1}", newBasePath, fileStart);

                                //download the file to the newly created directory
                                client.DownloadFile(downloadString, newLocalPath);
                                var fileEnd = DateTime.UtcNow;
                                var fileDuration = fileEnd - fileStart;

                                //add file properties to an array for output logs/logging to sql server
                                fileProperties.SetValue(DateTime.UtcNow.ToShortDateString(), 0);
                                fileProperties.SetValue(basePath.Replace(baseURL, ""), 1);
                                fileProperties.SetValue(pathSuffix, 2);
                                fileProperties.SetValue(fileStart.ToString(), 3);
                                fileProperties.SetValue(fileEnd.ToString(), 4);
                                fileProperties.SetValue(fileSize, 5);
                                Console.WriteLine("Download ended: {0}\nDuration: {1}\n\n", fileProperties[4], fileDuration);
                                string fileLog = null;
                                for (int index = 0; index < fileProperties.Length; index++)
                                {
                                    if (index == fileProperties.Length - 1)
                                    {
                                        fileLog += fileProperties[index] + "\n\r";
                                    }
                                    else
                                    {
                                        fileLog += fileProperties[index] + "|";
                                    }
                                }
                                logFileOutput.Write(fileLog);
                                logFileOutput.Flush();
                                Console.WriteLine("Uploading file {0}\n\n", newBasePath);
                                try
                                {
                                    UploadToBlobAsync(newLocalPath, newBasePath);
                                }
                                catch(Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                    continue;
                                }
                                
                                if (logToSql.Equals("true"))
                                {
                                    LogToDatabase(fileProperties);
                                }
                            }

                            //if current file status is a directory, recursively call DownloadFiles on the sub directory
                            else if (dirType.Equals("DIRECTORY"))
                            {
                                try
                                {
                                    DownloadFiles(newBasePath, newLocalPath);
                                }
                                catch (Exception e)
                                {
                                    errorWriter.WriteLine("There was an error accessing directory {0}\n\t{1}", newBasePath, e.Message);
                                    errorWriter.Flush();
                                    Console.WriteLine("There was an error accessing directory {0}\n\t{1}", newBasePath, e.Message);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains("404"))
                {
                    throw e;
                }
                else
                {
                    Console.WriteLine(e.Message);
                    DownloadFiles(basePath, localPath);
                }
            }
        }
Example #9
0
 /// <summary>
 /// Skilar Röð úr WinningCombination[][]
 /// </summary>
 /// <param name="i">i er númer raðar</param>
 /// <returns>
 /// Streng sem er 3 á lengd og inniheldur röð úr WinningCombination[][]
 /// </returns>
 public String[] GetWinningCombinationRow(int i)
 {
     var output = new String[3];
     for (var j = 0; j < 3; j++)
     {
         output.SetValue(WinningCombinations[i][j], j);
     }
     return output;
 }
Example #10
0
 /// <summary>
 /// Skilar hornréttri línu úr WinningCombination[][]
 /// </summary>
 /// <param name="i">i er númer hornréttrar línu ( 1 = 1,5,9 og 2 = 3,5,7 )</param>
 /// <returns>
 /// Streng sem er 3 á lengd og inniheldur diagonal úr WinningCombination[][]
 /// </returns>
 public String[] GetWinningCombinationDiagonal(int i)
 {
     i = i + 6;
     var output = new String[3];
     for (int j = 0; j < 3; j++)
     {
         output.SetValue(WinningCombinations[i][j], j);
     }
     return output;
 }
Example #11
0
 // --------------------------------------------------------------------------------
 /// <summary>
 /// Concatenates a specified separator String between each element of a specified 
 /// String array, yielding a single concatenated string. Parameters specify the 
 /// first array element and number of elements to use.
 /// </summary>
 /// <param name="separator">Separator string</param>
 /// <param name="value">String vlues to join</param>
 /// <param name="startIndex">Index of first element</param>
 /// <param name="count">Number of elements to join</param>
 /// <returns>Joined value</returns>
 // --------------------------------------------------------------------------------
 public static DBString Join(DBString separator, DBString [] value, int startIndex, int count)
 {
     String [] elements = new String [value.GetLength (0)];
       int index = 0;
       foreach (DBString element in value)
       {
     elements.SetValue (element, index ++);
       }
       return String.Join (separator.m_Value, elements, startIndex, count);
 }
Example #12
0
        static void Main(string[] args)
        {
            /*
             * The object of this program is to ask the user to enter 7 grades for tests
             * and then the program will sum those grades and average them.
             */

            //Declare and initialize variables
            Double dSum = 0.0;
            Double dAvg = 0.0;
            Double[] dGrades;
            String[] sNames;
            String sUserResp = String.Empty;
            Int32 iStudentCount = 0;

            //Determine number of students to have test scores
            Console.Write("How many students in the class? ");
            sUserResp = Console.ReadLine();
            try
            {
                iStudentCount = Convert.ToInt32(sUserResp);
            }
            catch(Exception ex)
            {
                Console.WriteLine("I beg your pardon, fool. You have entered invalid data.");
                Console.WriteLine(ex.Message);
                Pause("Program will now exit.");
                return;
            }

            dGrades = new Double[iStudentCount];
            sNames = new String[iStudentCount];

            Type arrayType = dGrades.GetType();
            if (arrayType.IsArray)
            {
                Pause("dGrades is an array of " + arrayType.ToString());
            }
            else
            {
                Pause("dGrades is NOT an array.");
            }
            //Start loop for data entry
            for (Int32 i = 0; i < iStudentCount; i++)
            {
                //Obtain a student name
                Console.Write("Enter a name for student #" + (i + 1).ToString() + ": ");
                sNames.SetValue(Console.ReadLine(), i);

                //Obtain that student's grade
                Console.Write("Enter a grade for student #" + (i + 1).ToString() + ": ");
                sUserResp = Console.ReadLine();
                try
                {
                    dGrades.SetValue(Convert.ToDouble(sUserResp), i);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("I beg your pardon, fool. You have entered invalid data.");
                    Console.WriteLine(ex.Message);
                    Pause("Program will now exit.");
                    return;
                }

                //Add this grade to the running sum
                dSum += dGrades[i];

            }
            //Average the grades
            dAvg = dSum / (Double)iStudentCount;

            Console.WriteLine("\nHere is the breakdown of our student grades:");
            for (Int32 i = 0; i < iStudentCount; i++)
            {
                Console.Write(sNames.GetValue(i) + ": ");
                Console.WriteLine(dGrades.GetValue(i).ToString());
            }

            //Output the average
            Pause("The average score is: " + dAvg.ToString() +
                ".\nProgram will now exit.");
        }
Example #13
0
 private void addTextLine(String s)
 {
     String[] temp = null;
     temp = new String[richTextBoxInfo.Lines.Length + 1];
     richTextBoxInfo.Lines.CopyTo(temp, 0);
     temp.SetValue(s, richTextBoxInfo.Lines.Length);
     richTextBoxInfo.Lines = temp;
 }
        private Tuple<Solver.Status, string> ChooseNum(int posToChoose_i, int posToChoose_j, String[,] tableToSolve, List<Tuple<int, int>> fixedPositions)
        {
            List<string> existNums = null;

            if (stepsStack.Count > 0)
            {
                Tuple<Tuple<int, int>, List<string>> lastStep = stepsStack.Peek();
                if ((lastStep.Item1.Item1 == posToChoose_i) && (lastStep.Item1.Item2 == posToChoose_j))
                {
                    existNums = lastStep.Item2;

                    stepsStack.Pop();
                }
                else
                    existNums = TableWorker.GetExistentNums(tableToSolve, TABLEWIDTH, TABLEHEIGHT, posToChoose_i, posToChoose_j);
            }
            else
                existNums = TableWorker.GetExistentNums(tableToSolve, TABLEWIDTH, TABLEHEIGHT, posToChoose_i, posToChoose_j);

            for (int k = 0; k <= MAXVALUE - 1; k++)
            {
                string value = TableWorker.CellsValue[k];

                if (!existNums.Contains(value))
                {
                    existNums.Add(value);
                    existNums.TrimExcess();

                    stepsStack.Push(new Tuple<Tuple<int, int>, List<string>>(
                        new Tuple<int, int>(posToChoose_i, posToChoose_j), existNums));

                    return new Tuple<Solver.Status ,string>(Solver.Status.ValueChoosed, value);
                }
            }

            if (stepsStack.Count > 0)
            {
                tableToSolve.SetValue(String.Empty, posToChoose_i, posToChoose_j);
                return new Tuple<Solver.Status ,string>(Solver.Status.stackRollback, String.Empty);
            }
            else
                return new Tuple<Solver.Status ,string>(Solver.Status.Error, String.Empty);
        }
        private Solver.Status InsertNum(int start_i, int start_j, String[,] tableToSolve, List<Tuple<int, int>> fixedPositions)
        {
            bool setStart_i = true;
            bool setStart_j = true;

            for (int i = 0; i < TABLEWIDTH; i++)
            {
                if (setStart_i)
                    if (i != start_i) { continue; }
                    else setStart_i = false;

                for (int j = 0; j < TABLEHEIGHT; j++)
                {
                    if (setStart_j)
                        if (j != start_j) { continue; ; }
                        else setStart_j = false;

                    if (!TableWorker.IsFixed(i, j, fixedPositions))
                        if ((string)tableToSolve.GetValue(i, j) == String.Empty)
                        {
                            Tuple<Solver.Status, string> chooseResult = ChooseNum(i, j, tableToSolve, fixedPositions);

                            switch (chooseResult.Item1)
                            {
                                case (Solver.Status.stackRollback):
                                    return Solver.Status.stackRollback;

                                case (Solver.Status.Error):
                                    return Solver.Status.Error;

                                case (Solver.Status.ValueChoosed):
                                    tableToSolve.SetValue(chooseResult.Item2, i, j);
                                    break;
                            }
                        }
                }
            }
            return Solver.Status.Solved;
        }
Example #16
0
File: DAL.cs Project: GregXP/XP
        public bool PopulateDados(List<ACCC015.ContratoParcelaACCC015> listCon, String filename)
        {
            bool ret = false;
            try
            {
                using (OracleConnection connection = new OracleConnection(RetornoCIP.CNX_C3))
                {
                    String[] arrNU_CON = new String[listCon.Count];
                    String[] arrTP_EVT = new String[listCon.Count];
                    String[] arrNU_PAR = new String[listCon.Count];
                    String[] arrCODERR = new String[listCon.Count];

                    for (int i = 0; i < listCon.Count; i++)
                    {
                        arrNU_CON.SetValue(listCon[i].NU_CON, i);
                        arrTP_EVT.SetValue(listCon[i].TpMotvEvt, i);
                        arrNU_PAR.SetValue(listCon[i].NU_PAR, i);
                        arrCODERR.SetValue(listCon[i].CodErro, i);
                    }
                    String sql = String.Format(@"insert into CCCTBLBRE (HDRDATHOR, HDRCODUSU, HDRCODPGR, BREDATREG, BREDESREG, BREARQREG, BRESEQREG, BRENUMUNICOCON, BRETIPMOTVEVT, BRENUMUNICOPAR, BRECODERR)
                                   values (TO_CHAR(SYSDATE, 'dd/mm/yyyy HH24:MI:SS'), 'BCSul', 'SvcMonitorarRetorno', SYSDATE, 'Grupo_Evt_Recsdo', '{0}', 1, :VER_CON_NU, :TP_EVT, :VER_PAR_NU, :CODERR)", filename);
                    OracleCommand command = new OracleCommand(sql, connection);
                    command.CommandType = CommandType.Text;
                    command.ArrayBindCount = listCon.Count;

                    // VER_CON_NU parameter
                    OracleParameter prmNUC = new OracleParameter("VER_CON_NU", OracleDbType.Varchar2);
                    prmNUC.Direction = System.Data.ParameterDirection.Input;
                    prmNUC.Value = arrNU_CON;
                    command.Parameters.Add(prmNUC);

                    // TP_EVT parameter
                    OracleParameter prmTPE = new OracleParameter("TP_EVT", OracleDbType.Varchar2);
                    prmTPE.Direction = System.Data.ParameterDirection.Input;
                    prmTPE.Value = arrTP_EVT;
                    command.Parameters.Add(prmTPE);

                    // VER_PAR_NU parameter
                    OracleParameter prmNUP = new OracleParameter("VER_PAR_NU", OracleDbType.Varchar2);
                    prmNUP.Direction = System.Data.ParameterDirection.Input;
                    prmNUP.Value = arrNU_PAR;
                    command.Parameters.Add(prmNUP);

                    // CODERR parameter
                    OracleParameter prmErr = new OracleParameter("CODERR", OracleDbType.Varchar2);
                    prmErr.Direction = System.Data.ParameterDirection.Input;
                    prmErr.Value = arrCODERR;
                    command.Parameters.Add(prmErr);

                    connection.Open();
                    command.ExecuteNonQuery();

                    if (Utils._logger != null)
                        Utils._logger.Info(command.ArrayBindCount + " registros inseridos");

                    connection.Close();

                    ret = true;
                }
            }
            catch (Exception ex)
            {
                if (Utils._logger != null)
                    Utils._logger.Error(ex.Message);
            }
            return ret;
        }
	public void TestSetValue4() {
		{
			int[] c1 = { 1, 2, 3 };
			long[] c2 = new long [3];

			for (int i = 0; i < c1.Length; i++)
				c2.SetValue (c1 [i], i);

			for (int i = 0; i < c1.Length; i++) {
				Assert ("#M81(" + i + ")", c1[i] == c2[i]);
				AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());
			}
		}
		{
			long[] c1 = { 1, 2, 3 };
			int[] c2 = new int [3];
			bool errorThrown = false;
			try {
				c2.SetValue (c1 [0], 0);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("#M83", errorThrown);
		}
		{
			int[] c1 = { 1, 2, 3 };
			Object[] c2 = new Object [3];

			for (int i = 0; i < c1.Length; i++)
				c2.SetValue (c1 [i], i);

			for (int i = 0; i < c1.Length; i++)
				AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
		}
		{
			Object[] c1 = new Object [3];
			Object[] c2 = new Object [3];
			c1[0] = new Object ();

			for (int i = 0; i < c1.Length; i++)
				c2.SetValue (c1 [i], i);

			for (int i = 0; i < c1.Length; i++)
				AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
		}
		{
			Object[] c1 = new Object [3];
			string[] c2 = new String [3];
			string test = "hello";
			c1[0] = test;

			c2.SetValue (c1 [0], 0);
			AssertEquals ("#M86", c1[0], c2[0]);
			AssertEquals ("#M87", "hello", c2[0]);
		}
		{
			char[] c1 = { 'a', 'b', 'c' };
			string[] c2 = new string [3];
			try {
				c2.SetValue (c1 [0], 0);
				Fail ("#M88");
			} catch (InvalidCastException) {}
		}
		{
			Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
			long[] c2 = new long [3];
			try {
				c2.SetValue (c1 [0], 0);
				Fail ("#M89");
			} catch (ArgumentException) {}
		}
		{
			Type[] types = {
				typeof (Boolean),
				typeof (Byte),
				typeof (Char),
				typeof (Double),
				typeof (Int16),
				typeof (Int32),
				typeof (Int64),
				typeof (SByte),
				typeof (Single),
				typeof (UInt16),
				typeof (UInt32),
				typeof (UInt64)
			};

			bool v1 = true;
			Byte v2 = 1;
			Char v3 = 'a';
			Double v4 = -1.2;
			Int16 v5 = -32;
			Int32 v6 = -234;
			Int64 v7 = -34523;
			SByte v8 = -1;
			Single v9 = -4.8F;
			UInt16 v10 = 24234;
			UInt32 v11 = 235354;
			UInt64 v12 = 234552;

			Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
			Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
					 "-4.8F", "24234", "235354", "234552" };

			Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };

			int[] arg_ex = {
				0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
				1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
				1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
				1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
				1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
				1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
				1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
				1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
				1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
				1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
			};

			// SetValue

			for (int i = 0; i < types.Length; i++) {
				for (int j = 0; j < types.Length; j++) {
					Array array = Array.CreateInstance (types [j], 2);

					Object value = vt[j][i];

					bool errorThrown = false;
					try {
						array.SetValue (value, 0);
					} catch (ArgumentException) {
						errorThrown = true;
					}

					int ex_index = (i * types.Length) + j;

					AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
						      errorThrown, arg_ex [ex_index] == 1);
				}
			}

			for (int i = 0; i < types.Length; i++) {
				String[] array = new String [2];

				Object value = va1 [i];

				bool errorThrown = false;
				try {
					array.SetValue (value, 0);
				} catch (InvalidCastException) {
					errorThrown = true;
				}

				Assert ("#M91(" + types [i] + ")", errorThrown);
			}

			for (int i = 0; i < types.Length; i++) {
				Array array = Array.CreateInstance (types [i], 2);

				Object value = va2 [i];

				bool errorThrown = false;
				try {
					array.SetValue (value, 0);
				} catch (InvalidCastException) {
					errorThrown = true;
				}

				Assert ("#M92(" + types [i] + ")", errorThrown);
			}

			for (int i = 0; i < types.Length; i++) {
				Array array = Array.CreateInstance (types [i], 2);

				Object value = null;

				bool errorThrown = false;
				try {
					array.SetValue (value, 0);
				} catch (InvalidCastException) {
					errorThrown = true;
				}

				Assert ("#M93(" + types [i] + ")", !errorThrown);
			}

			// Copy

			for (int i = 0; i < types.Length; i++) {
				for (int j = 0; j < types.Length; j++) {
					Array source = Array.CreateInstance (types [i], 2);
					Array array = Array.CreateInstance (types [j], 2);

					source.SetValue (vt[j][i], 0);
					source.SetValue (vt[j][i], 1);

					bool errorThrown = false;
					try {
						Array.Copy (source, array, 2);
					} catch (ArrayTypeMismatchException) {
						errorThrown = true;
					}

					int ex_index = (i * types.Length) + j;

					AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
						      errorThrown, arg_ex [ex_index] == 1);
				}
			}

			for (int i = 0; i < types.Length; i++) {
				Array source = Array.CreateInstance (types [i], 2);
				String[] array = new String [2];

				source.SetValue (va1 [i], 0);
				source.SetValue (va1 [i], 1);

				bool errorThrown = false;
				try {
					Array.Copy (source, array, 2);
				} catch (ArrayTypeMismatchException) {
					errorThrown = true;
				}

				Assert ("#M95(" + types [i] + ")", errorThrown);
			}

			for (int i = 0; i < types.Length; i++) {
				String[] source = new String [2];
				Array array = Array.CreateInstance (types [i], 2);

				source.SetValue (va2 [i], 0);
				source.SetValue (va2 [i], 1);

				bool errorThrown = false;
				try {
					Array.Copy (source, array, 2);
				} catch (ArrayTypeMismatchException) {
					errorThrown = true;
				}

				Assert ("#M96(" + types [i] + ")", errorThrown);
			}
		}
	}
        private static Tuple<String[, ], List<Tuple<int, int>>> PrepareToSolve()
        {
            String[,] tableToSolve = new String[Program.TABLEWIDTH, Program.TABLEHEIGHT];
            List<Tuple<int, int>> fixedPositions = new List<Tuple<int, int>>(0);

            for (int i = 0; i < Program.TABLEWIDTH; i++)
                for (int j = 0; j < Program.TABLEHEIGHT; j++)
                {
                    if (cells[i, j].Text != String.Empty)
                    {
                        fixedPositions.Add(new Tuple<int, int>(i, j));
                    }

                    tableToSolve.SetValue(cells[i, j].Text, i, j);
                }

            fixedPositions.TrimExcess();

            return new Tuple<string[,], List<Tuple<int, int>>>(tableToSolve, fixedPositions);
        }
Example #19
0
        public bool write_header_order()
        {
            int    err    = 0;
            String Record = new string(' ', 200);

            System.Array arrDetail = new System.String[13];

            oCustomer.dsTmpl(channel, "teacher:c(30),student:c(30*),type:c(3*),prize:c(10*),no_items:n(10*),retail:n(10*),collected:n(10*),tax:n(10*),printed:n(1*),disc_printed:n(1*),box:c(10*),entry_date:n(10*):date=jul:,phone:c(10)"); //final field ascterisc relevant

            this.Header.CustomerID = this.sCustomerID;
            this.Header.CompanyID  = this.sCompanyID;

            arrDetail.SetValue(this.Header.Teacher.PadRight(30, ' '), 0);
            arrDetail.SetValue(this.Header.Student.PadRight(30, ' '), 1);
            arrDetail.SetValue(this.Header.Type, 2);
            arrDetail.SetValue(this.Header.Prize, 3);
            arrDetail.SetValue(this.Header.No_Items, 4);
            arrDetail.SetValue(this.Header.Retail, 5);
            arrDetail.SetValue(this.Header.Collected, 6);
            arrDetail.SetValue(this.Header.Tax, 7);
            arrDetail.SetValue(this.Header.Printed, 8);
            arrDetail.SetValue(this.Header.Disc_Printed, 9);
            arrDetail.SetValue(this.Header.Box, 10);
            arrDetail.SetValue(this.Header.Date, 11);
            arrDetail.SetValue(this.Header.Phone, 12);

            this.sKey = arrDetail.GetValue(0).ToString() + arrDetail.GetValue(1).ToString() + "000";
            err       = oCustomer.dsExtractRec(this.channel, this.sKey, 0, ref Record);
            if (err != -1)
            {
                if (err == 11)
                {
                    Record = "";
                }
                else
                {
                    MessageBox.Show(err.ToString());
                    return(false);
                }
            }

            err = oCustomer.dsWriteFld(this.channel, this.sKey, Record, "teacher,student,type,prize,no_items,retail,collected,tax,printed,disc_printed,box,entry_date,phone", ref arrDetail);
            if (err != -1)
            {
                MessageBox.Show("err=" + err.ToString() + "  Lenght: " + Record.Length.ToString());
                return(false);
            }
            return(true);
        }
Example #20
0
        /// <summary>
        /// Load filters to find in event log
        /// </summary>
        /// <param name="node">specific XML including filter parameters</param>
        static void LoadFilters(XmlNode node)
        {
            String patternSyslogLevel = "Emergency|Alert|Critical|Error|Warning|Notice|Informational|Debug";
            Regex rSyslogLevel = new Regex(patternSyslogLevel, RegexOptions.IgnoreCase);

            String patternSyslogFacility = "Kern|User|Mail|Daemon|Auth|Syslog|LPR|News|UUCP|Cron|AuthPriv|FTP|NTP|Audit|Audit2|CRON2|Local0|Local1|Local2|Local3|Local4|Local5|Local6|Local7";
            Regex rSyslogFacility = new Regex(patternSyslogFacility, RegexOptions.IgnoreCase);

            String[] eventLogName = null;
            Filter iFilter = null;
            Filter eFilter = null;

            foreach (XmlNode childnode in node.ChildNodes)
            {
                eventLogName = null;
                iFilter = new Filter();
                eFilter = new Filter();

                foreach (XmlNode cnode in childnode.ChildNodes)
                {
                    if (cnode.Name.ToLower().CompareTo("event") == 0)
                    {
                        foreach (XmlNode paramNode in cnode.ChildNodes)
                        {
                            if (paramNode.Name.ToLower().CompareTo("eventlogname") == 0)
                            {
                                ArrayList temp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("#comment") < 0)
                                    {
                                        temp.Add(element.InnerText);
                                    }
                                }
                                eventLogName = new String[temp.Count];
                                int i = 0;
                                foreach (String item in temp)
                                {
                                    eventLogName.SetValue(item, i);
                                    i++;
                                }
                            }
                            else if (paramNode.Name.ToLower().CompareTo("sources") == 0)
                            {
                                ArrayList itemp = new ArrayList();
                                ArrayList etemp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("include") >= 0)
                                    {
                                        itemp.Add(element.InnerText);
                                    }
                                    else if (element.Name.IndexOf("exclude") >= 0)
                                    {
                                        etemp.Add(element.InnerText);
                                    }
                                }

                                if (itemp.Count > 0)
                                {
                                    String[] strTemp = new String[itemp.Count];
                                    int i = 0;
                                    foreach (String item in itemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    iFilter.EventLogSources = strTemp;
                                }

                                if (etemp.Count > 0)
                                {
                                    String[] strTemp = new String[etemp.Count];
                                    int i = 0;
                                    foreach (String item in etemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    eFilter.EventLogSources = strTemp;
                                }

                            }
                            else if (paramNode.Name.ToLower().CompareTo("id") == 0)
                            {
                                ArrayList itemp = new ArrayList();
                                ArrayList etemp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("include") >= 0)
                                    {
                                        itemp.Add(element.InnerText);
                                    }
                                    else if (element.Name.IndexOf("exclude") >= 0)
                                    {
                                        etemp.Add(element.InnerText);
                                    }
                                }

                                if (itemp.Count > 0)
                                {
                                    String[] strTemp = new String[itemp.Count];
                                    int i = 0;
                                    foreach (String item in itemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    iFilter.EventLogID = strTemp;
                                }

                                if (etemp.Count > 0)
                                {
                                    String[] strTemp = new String[etemp.Count];
                                    int i = 0;
                                    foreach (String item in etemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    eFilter.EventLogID = strTemp;
                                }
                            }
                            else if (paramNode.Name.ToLower().CompareTo("users") == 0)
                            {
                                ArrayList itemp = new ArrayList();
                                ArrayList etemp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("include") >= 0)
                                    {
                                        itemp.Add(element.InnerText);
                                    }
                                    else if (element.Name.IndexOf("exclude") >= 0)
                                    {
                                        etemp.Add(element.InnerText);
                                    }
                                }

                                if (itemp.Count > 0)
                                {
                                    String[] strTemp = new String[itemp.Count];
                                    int i = 0;
                                    foreach (String item in itemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    iFilter.User = strTemp;
                                }

                                if (etemp.Count > 0)
                                {
                                    String[] strTemp = new String[etemp.Count];
                                    int i = 0;
                                    foreach (String item in etemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    eFilter.User = strTemp;
                                }
                            }
                            else if (paramNode.Name.ToLower().CompareTo("computers") == 0)
                            {
                                ArrayList itemp = new ArrayList();
                                ArrayList etemp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("include") >= 0)
                                    {
                                        itemp.Add(element.InnerText);
                                    }
                                    else if (element.Name.IndexOf("exclude") >= 0)
                                    {
                                        etemp.Add(element.InnerText);
                                    }
                                }

                                if (itemp.Count > 0)
                                {
                                    String[] strTemp = new String[itemp.Count];
                                    int i = 0;
                                    foreach (String item in itemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    iFilter.Computer = strTemp;
                                }

                                if (etemp.Count > 0)
                                {
                                    String[] strTemp = new String[etemp.Count];
                                    int i = 0;
                                    foreach (String item in etemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    eFilter.Computer = strTemp;
                                }
                            }
                            else if (paramNode.Name.ToLower().CompareTo("type") == 0)
                            {
                                ArrayList itemp = new ArrayList();
                                ArrayList etemp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("include") >= 0)
                                    {
                                        itemp.Add(element.InnerText);
                                    }
                                    else if (element.Name.IndexOf("exclude") >= 0)
                                    {
                                        etemp.Add(element.InnerText);
                                    }
                                }

                                if (itemp.Count > 0)
                                {
                                    String[] strTemp = new String[itemp.Count];
                                    int i = 0;
                                    foreach (String item in itemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    iFilter.EventLogType = strTemp;
                                }

                                if (etemp.Count > 0)
                                {
                                    String[] strTemp = new String[etemp.Count];
                                    int i = 0;
                                    foreach (String item in etemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    eFilter.EventLogType = strTemp;
                                }
                            }
                            else if (paramNode.Name.ToLower().CompareTo("descriptions") == 0)
                            {
                                ArrayList itemp = new ArrayList();
                                ArrayList etemp = new ArrayList();
                                foreach (XmlNode element in paramNode.ChildNodes)
                                {
                                    if (element.Name.IndexOf("include") >= 0)
                                    {
                                        itemp.Add(element.InnerText);
                                    }
                                    else if (element.Name.IndexOf("exclude") >= 0)
                                    {
                                        etemp.Add(element.InnerText);
                                    }
                                }

                                if (itemp.Count > 0)
                                {
                                    String[] strTemp = new String[itemp.Count];
                                    int i = 0;
                                    foreach (String item in itemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    iFilter.EventLogDescriptions = strTemp;
                                }

                                if (etemp.Count > 0)
                                {
                                    String[] strTemp = new String[etemp.Count];
                                    int i = 0;
                                    foreach (String item in etemp)
                                    {
                                        strTemp.SetValue(item, i);
                                        i++;
                                    }
                                    eFilter.EventLogDescriptions = strTemp;
                                }
                            }
                        }
                    }
                    else if (cnode.Name.ToLower().CompareTo("syslog") == 0)
                    {
                        foreach (XmlNode paramNode in cnode.ChildNodes)
                        {
                            if (paramNode.Name.ToLower().CompareTo("level") == 0)
                            {
                                if (rSyslogLevel.IsMatch(paramNode.InnerText))
                                {
                                    iFilter.SyslogLevel = paramNode.InnerText;
                                    eFilter.SyslogLevel = paramNode.InnerText;
                                }
                                else
                                {
                                    deb.Write("Load filters configuration", "301 - Uncorrect syslog level : \"" + paramNode.InnerText + "\"", DateTime.Now, 1);
                                }
                            }
                            else if (paramNode.Name.ToLower().CompareTo("facility") == 0)
                            {
                                if (rSyslogFacility.IsMatch(paramNode.InnerText))
                                {
                                    iFilter.SyslogFacility = paramNode.InnerText;
                                    eFilter.SyslogFacility = paramNode.InnerText;
                                }
                                else
                                {
                                    deb.Write("Load filters configuration", "301 - Uncorrect syslog facility : \"" + paramNode.InnerText + "\"", DateTime.Now, 1);
                                }
                            }
                        }
                    }
                }

                if (eventLogName != null)
                {
                    foreach (String element in eventLogName)
                    {
                        ArrayList itemp = null;
                        itemp = (ArrayList)iFilters[element];
                        ArrayList etemp = null;
                        etemp = (ArrayList)eFilters[element];

                        if ((itemp != null) && !iFilter.IsEmpty())
                        {
                            itemp.Add(iFilter);
                            deb.Write("Load filters configuration", "Add to filter list for event log " + element + " evement " + iFilter.ToString(), DateTime.Now, 2);
                            iFilters[element] = itemp;
                        }
                        else if ((itemp == null) && !iFilter.IsEmpty())
                        {
                            itemp = new ArrayList();
                            itemp.Add(iFilter);
                            deb.Write("Load filters configuration", "Add to filter list for event log " + element + " evement " + iFilter.ToString(), DateTime.Now, 2);
                            iFilters[element] = itemp;
                        }

                        if ((etemp != null) && !eFilter.IsEmpty())
                        {
                            etemp.Add(eFilter);
                            deb.Write("Load filters configuration", "Add to exclude filter list for event log " + element + " evement " + iFilter.ToString(), DateTime.Now, 2);
                            eFilters[element] = etemp;
                        }
                        else if ((etemp == null) && !eFilter.IsEmpty())
                        {
                            etemp = new ArrayList();
                            etemp.Add(eFilter);
                            deb.Write("Load filters configuration", "Add to exclude filter list for event log " + element + " evement " + iFilter.ToString(), DateTime.Now, 2);
                            eFilters[element] = etemp;
                        }
                    }
                }
            }
        }
Example #21
0
        //We want a command which will go through and list all the relevant employee data.
        private static void ListEmployee(ObjectId employeeId, ref string[] saEmployeeList)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            // Start the transaction
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                int nEmployeeDataCount = 0;
                Entity ent = (Entity)trans.GetObject(employeeId, OpenMode.ForRead, false); // Use it to open the current object!
                if (ent.GetType() == typeof(BlockReference)) // We use .NET's RTTI to establish type.
                {
                    // Not all BlockReferences will have our employee data, so we must make sure we can handle failure
                    bool bHasOurDict = true;
                    Xrecord EmployeeXRec = null;
                    try
                    {
                        BlockReference br = (BlockReference)ent;
                        DBDictionary extDict = (DBDictionary)trans.GetObject(br.ExtensionDictionary, OpenMode.ForRead, false);
                        EmployeeXRec = (Xrecord)trans.GetObject(extDict.GetAt("EmployeeData"), OpenMode.ForRead, false);
                    }
                    catch
                    {
                        // something bad happened...our dictionary and/or XRecord is not accessible for some reason
                        bHasOurDict = false;
                    }

                    // If obtaining the Extension Dictionary, and our XRecord is successful...
                    if (bHasOurDict)
                    {
                        // allocate memory for the list
                        saEmployeeList = new String[4];

                        TypedValue resBuf = EmployeeXRec.Data.AsArray()[0];
                        saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), nEmployeeDataCount);
                        nEmployeeDataCount += 1;
                        resBuf = EmployeeXRec.Data.AsArray()[1];
                        saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), nEmployeeDataCount);
                        nEmployeeDataCount += 1;
                        resBuf = EmployeeXRec.Data.AsArray()[2];
                        string str = (string)resBuf.Value;
                        saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), nEmployeeDataCount);
                        nEmployeeDataCount += 1;
                        DBDictionary NOD = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, false);
                        DBDictionary acmeDict = (DBDictionary)trans.GetObject(NOD.GetAt("ACME_DIVISION"), OpenMode.ForRead);
                        DBDictionary salesDict = (DBDictionary)trans.GetObject(acmeDict.GetAt((string)EmployeeXRec.Data.AsArray()[2].Value), OpenMode.ForRead);
                        Xrecord salesXRec = (Xrecord)trans.GetObject(salesDict.GetAt("Department Manager"), OpenMode.ForRead);
                        resBuf = salesXRec.Data.AsArray()[0];
                        saEmployeeList.SetValue(string.Format("{0}\n", resBuf.Value), nEmployeeDataCount);
                        nEmployeeDataCount += 1;
                    }
                }
                trans.Commit();
            }
        }
        /// <summary>
        /// Get all tag names for a specified group
        /// </summary>
        /// <param name="groupID">Group ID to get tag names from</param>
        /// <returns>Returns an array of tag names</returns>
        public System.Array getTagNames(int groupID)
        {
            System.Array tagNames = null;
            if ((isConnected()) && (RSLinxOPCGroups.Count == groupID + 1))
            {
                tagNames = new String[RSLinxOPCGroups.ElementAt(groupID).OPCItems.Count];

                for (int i = 0; i < RSLinxOPCGroups.ElementAt(groupID).OPCItems.Count; i++)
                {
                    tagNames.SetValue(RSLinxOPCGroups.ElementAt(groupID).OPCItems.Item(i + 1).ItemID.ToString(), i);
                }
            }

            return tagNames;
        }