private Dictionary<decimal, GenericCommand> PopulateCommands(CommandSelectionOptions options, OracleConnection con, OracleTransaction tx)
        {


                #region Get next command

                Dictionary<decimal, GenericCommand> commands = new Dictionary<decimal, GenericCommand>();

                Dictionary<decimal, MarketingPackage> mps = new Dictionary<decimal, MarketingPackage>();


                // create the command object and set attributes
                using (OracleCommand cmd = new OracleCommand(readerSPName, con, tx))
                {
                    //cmd.
                    cmd.CommandType = CommandType.StoredProcedure;
                    
                    #region test parameters

                    OracleCommandBuilder.DeriveParameters(cmd);

                    //foreach (OracleParameter p in cmd.Parameters)
                    //{
                    //    Console.WriteLine(String.Format("Name: {0}, OracleType: {1}", p.ParameterName, p.OracleType));
                    //}

                    //return null;

                    #endregion


                    //OracleParameter pRefCursor = cmd.Parameters["P_COMMANDS"]; //new OracleParameter("P_COMMANDS", OracleType.Cursor);


                    OracleHelper.AssignOracleParameter2String("P_PARTITIONNAME", options.PartitionName, cmd);
                    OracleHelper.AssignOracleParameter2String("P_BATCHID", options.BatchId, cmd);

                    cmd.Parameters["P_COMMANDTYPE"].Value = options.CommandTypeId;

                    OracleHelper.AssignOracleParameter2String("P_MACHINENAME", options.MachineName, cmd);
                    OracleHelper.AssignOracleParameter2String("P_USERNAME", Environment.UserName, cmd);
                    OracleHelper.AssignOracleParameter2String("P_ACTIVITYID", options.ActivityId, cmd);

                    try
                    {

                        using (IDataReader dr = cmd.ExecuteReader())
                        {

                            while (dr.Read())
                            {
                                //Console.WriteLine(Convert.ToDecimal(dr["REQ_ID"]) + ":" + dr["Status"]);

                                GenericCommand gCmd = new GenericCommand();

                                gCmd.ReqId = GetDefaultDecimal(dr, "REQ_ID", true, 0);

                                Trace.CorrelationManager.ActivityId = Guid.NewGuid();

                                gCmd.CommandType = GetDefaultDecimal(dr, "COMMAND_TYPE", true, 0);
                                gCmd.Priority = GetDefaultDecimal(dr, "PRIORITY", false, 0);

                                Log.TraceData(Log.Source, System.Diagnostics.TraceEventType.Start, CommandMessages.CommandDispatchedFromTheDatabase, String.Format("Command [{0}:{1}](p{2})", gCmd.CommandType, gCmd.ReqId, gCmd.Priority));
                                gCmd.ReqTime = GetDefaultDate(dr, "REQ_TIME", true, DateTime.Now);
                                gCmd.TisCustomerId = GetDefaultString(dr, "TIS_CUSTOMER_ID", false, String.Empty);

                                gCmd.TisWalletId = GetDefaultString(dr, "TIS_WALLET_ID", false, String.Empty);
                                gCmd.TisTDId = GetDefaultDecimal(dr, "TIS_TD_ID", false, 0);
                                gCmd.CustomerType = GetDefaultString(dr, "CUSTOMER_TYPE", false, String.Empty);
                                gCmd.Name = GetDefaultString(dr, "NAME", false, String.Empty);
                                gCmd.BillingCycle = GetNullableDecimal(dr, "BILLING_CYCLE", false, null);

                                gCmd.TaxGroup = GetDefaultString(dr, "TAX_GROUP", false, String.Empty);
                                gCmd.TDType = GetDefaultDecimal(dr, "TD_TYPE", false, 0);

                                gCmd.MonthlyLimit = GetNullableDecimal(dr, "MONTHLY_LIMIT", false, null);

                                gCmd.IccId = GetDefaultString(dr, "ICCID", false, String.Empty);
                                gCmd.PhoneNumber = GetDefaultString(dr, "PHONE_NUMBER", false, String.Empty);
                                gCmd.BlockReason = GetDefaultString(dr, "BLOCK_REASON", false, null);
                                gCmd.BlockStatus = GetNullableDecimal(dr, "BLOCK_STATUS", false, null);

                                gCmd.VpnProfile = GetDefaultDecimal(dr, "VPN_PROFILE", false, 0);
                                gCmd.ShortNumber = GetDefaultString(dr, "SHORT_NUMBER", false, String.Empty);
                                gCmd.NewPhoneNumber = GetDefaultString(dr, "NEW_PHONE_NUMBER", false, String.Empty);
                                gCmd.NewIccId = GetDefaultString(dr, "NEW_ICCID", false, String.Empty);
                                gCmd.ContractEndDate = GetNullableDate(dr, "CONTRACT_END_DATE", false, null);
                                gCmd.ValidFrom = GetDefaultDate(dr, "VALID_FROM", false, DateTime.MinValue);
                                gCmd.P2P = GetDefaultString(dr, "P2P", false, String.Empty);
                                gCmd.OnetimeLimitAmount = GetDefaultDecimal(dr, "ONETIME_LIMIT_AMOUNT", false, 0);
                                gCmd.Status = GetDefaultString(dr, "STATUS", false, String.Empty);
                                gCmd.TisPosAOId = GetDefaultString(dr, "TIS_POSAO_ID", false, String.Empty);

                                gCmd.ActivityId = options.ActivityId;

                                commands.Add(gCmd.ReqId, gCmd);

                            }
                            // Next result is marketing package instances
                            if (dr.NextResult())
                            {
                                while (dr.Read())
                                {
                                    //Console.WriteLine(Convert.ToDecimal(dr["REQ_ID"]) + ":mpid:" + Convert.ToDecimal(dr["MP_INSTANCE_ID"]));

                                    MarketingPackage mp = new MarketingPackage
                                    {
                                        ReqId = GetDefaultDecimal(dr, "REQ_ID", true, 0),
                                        MPInstanceId = GetDefaultDecimal(dr, "MP_INSTANCE_ID", true, 0),
                                        MPId = GetNullableDecimal(dr, "MP_ID", false, null),
                                        MPType = GetDefaultString(dr, "MP_TYPE", true, String.Empty)
                                    };

                                    commands[mp.ReqId].MarketingPackages.Add(mp);
                                    mps.Add(mp.MPInstanceId, mp);
                                }
                                //}

                                // Next result is marketing package parameters
                                if (dr.NextResult())
                                {
                                    while (dr.Read())
                                    {
                                        //Console.WriteLine("mpid: " + Convert.ToDecimal(dr["MP_INSTANCE_ID"]) + ":" + dr["PARAM_CODE"]);

                                        PackageParameter p = new PackageParameter
                                        {
                                            ReqId = GetDefaultDecimal(dr, "REQ_ID", true, 0),
                                            MPInstanceId = GetDefaultDecimal(dr, "MP_INSTANCE_ID", true, 0),
                                            ParamCode = GetDefaultString(dr, "PARAM_CODE", true, String.Empty),
                                            ProductCode = GetDefaultString(dr, "PRODUCT_CODE", true, String.Empty),
                                            Value = GetDefaultString(dr, "VALUE", false, String.Empty)
                                        };

                                        mps[p.MPInstanceId].Parameters.Add(p);

                                    }
                                }
                            }

                            stats.Append(String.Format("[{0}/P. {1}/HPP]", GetCommandParameterDecimalValue(cmd, "p_countOfProcessing", 0), GetCommandParameterDecimalValue(cmd, "p_countOfProcessingHP", 0)));

                            return commands;
                        }
                    }
                    finally
                    {
                        //if (pMpsCursor != null) pMpsCursor.Dispose();
                        //if (pParamsCursor != null) pParamsCursor.Dispose();
                    }
                }

                return commands;
                #endregion
        }
        internal static void CopyParametersToMarketingPackage(MarketingPackage mp, List<@params> parameters)
        {
            foreach (PackageParameter pp in mp.Parameters)
            {
                // Skip parameters with product code of N/A. That is taken from Milorad's code.
                if (pp.ProductCode.ToUpper() == "N/A")
                    continue;

                parameters.Add(new @params
                {
                    code = (pp.ParamCode == "N/A") ? String.Empty : pp.ParamCode,
                    productCode = pp.ProductCode,
                    value = pp.Value
                });
            }
        }