public static void IdentityII(SqlInt32 accoutId, SqlString deliveryTablePrefix, SqlDateTime identity1Timestamp, SqlString identityConfig)
    {
        using (var objectsConnection = new SqlConnection("context connection=true"))
        {
            objectsConnection.Open();
            var identityMng = new IdentityManager(objectsConnection);

            // pass all delivery parameters as parameters to SP
            identityMng.AccountId          = Convert.ToInt32(accoutId.ToString());
            identityMng.TablePrefix        = deliveryTablePrefix.ToString();
            identityMng.ConfigXml          = identityConfig.ToString();
            identityMng.TransformTimestamp = Convert.ToDateTime(identity1Timestamp.ToString());

            identityMng.Log(string.Format("Starting Identity II, parameters: accountId={0}, delivery table prefix='{1}', identity I timestamp={2}, identity config={3}",
                                          accoutId, deliveryTablePrefix, identityMng.TransformTimestamp.ToString("dd/MM/yyyy HH:mm:ss"), identityMng.ConfigXml));
            try
            {
                identityMng.UpdateEdgeObjects();
            }
            catch (System.Exception ex)
            {
                // TODO: write to log in DB
                throw;
            }
        }
    }
Beispiel #2
0
    private void SetSearchCriteria()
    {
        DateTime    fromDate  = DateTime.Parse(txtFromDate.Text);
        DateTime    toDate    = DateTime.Parse(txtToDate.Text);
        SqlDateTime sFromDate = Utility.GetSqlDateTimeFromDateTime(fromDate);
        SqlDateTime sToDate   = Utility.GetSqlDateTimeFromDateTime(toDate);

        SqlInt32 numAdults = SqlInt32.Parse(drpNumberOfAdults.SelectedValue);
        SqlInt32 numKids   = SqlInt32.Parse(drpNumberOfChildren.SelectedValue);

        this.FromDate          = sFromDate;
        this.hidFromDate.Value = sFromDate.ToString();
        this.ToDate            = sToDate;
        this.hidToDate.Value   = sToDate.ToString();

        this.NumAdults = numAdults;
        this.hidNumberOfAdults.Value = numAdults.ToString();
        this.NumKids = numKids;
        this.hidNumberOfChildren.Value = numKids.ToString();
        SqlInt32 numRooms = SqlInt32.Parse(this.hidNumberOfAdults.Value) + SqlInt32.Parse(this.hidNumberOfChildren.Value);

        this.NumRooms = numRooms;
        Session.Add("FromDate", sFromDate);
        Session.Add("ToDate", sToDate);
        Session.Add("NumAdults", numAdults);
        Session.Add("NumKids", numKids);
        Session.Add("NumRooms", numRooms);
    }
Beispiel #3
0
        public static void GetSkyline(SqlString strQuery, SqlString strOperators, SqlInt32 numberOfRecords, SqlInt32 sortType, SqlInt32 upToLevel)
        {
            SPMultipleSkylineBNLLevel skyline = new SPMultipleSkylineBNLLevel();

            string[] additionalParameters = new string[5];
            additionalParameters[4] = upToLevel.ToString();
            skyline.GetSkylineTable(strQuery.ToString(), strOperators.ToString(), numberOfRecords.Value, false, Helper.CnnStringSqlclr, Helper.ProviderClr, additionalParameters, sortType.Value, true);
        }
        public CustomerWiseProductENT SelectByPK(SqlInt32 CustomerWiseProductID)
        {
            using (SqlConnection objConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand objcmd = objConnection.CreateCommand())
                {
                    try
                    {
                        objConnection.Open();

                        #region Prepare Command
                        objcmd.CommandType = CommandType.StoredProcedure;
                        objcmd.CommandText = "PR_CustomerWiseProduct_SelectByPK";
                        objcmd.Parameters.AddWithValue("@CustomerWiseProductID", CustomerWiseProductID.ToString());
                        #endregion Prepare Command

                        #region ReadData And SetData
                        CustomerWiseProductENT entCustomerWiseProduct = new CustomerWiseProductENT();
                        using (SqlDataReader objSDR = objcmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["CustomerID"].Equals(DBNull.Value))
                                {
                                    entCustomerWiseProduct.CustomerID = Convert.ToInt32(objSDR["CustomerID"]);
                                }
                                if (!objSDR["ProductID"].Equals(DBNull.Value))
                                {
                                    entCustomerWiseProduct.ProductID = Convert.ToInt32(objSDR["ProductID"]);
                                }
                            }
                        }

                        return(entCustomerWiseProduct);

                        #endregion ReadData And SetData
                    }
                    catch (SqlException Sqlex)
                    {
                        Message = Sqlex.Message.ToString();
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.Message.ToString();
                        return(null);
                    }
                    finally
                    {
                        if (objConnection.State == ConnectionState.Open)
                        {
                            objConnection.Close();
                        }
                    }
                }
            }
        }
Beispiel #5
0
 public static void MD_MetricsViewer(SqlInt32 account, SqlString deliveryTableName, out SqlChars metricsSelect)
 {
     using (var objectsConnection = new SqlConnection("context connection=true"))
     {
         objectsConnection.Open();
         int accountId = Convert.ToInt32(account.ToString());
         metricsSelect = new SqlChars(EdgeViewer.GetMetricsView(accountId, deliveryTableName.ToString(), objectsConnection));
     }
 }
Beispiel #6
0
    public static void MD_ObjectsViewer(SqlInt32 account, SqlString stagingTableName)
    {
        using (var objectsConnection = new SqlConnection("context connection=true"))
        {
            objectsConnection.Open();

            int accountId = Convert.ToInt32(account.ToString());
            EdgeViewer.GetObjectsView(accountId, stagingTableName.ToString(), objectsConnection, SqlContext.Pipe);
        }
    }
        public static SqlString RegExReplacex(SqlString pattern, SqlString input, SqlString replacement, SqlInt32 Options)
        {
            if ((input.IsNull || pattern.IsNull))
            {
                return(SqlString.Null);
            }

            System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions();
            //RegexOption = Options;
            RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString());
            return(new SqlString(Regex.Replace(input.Value, pattern.Value, replacement.Value, RegexOption)));
        }
        public static IEnumerable RegExMatches(SqlString pattern, SqlString input, SqlInt32 Options)
        {
            if ((input.IsNull || pattern.IsNull))
            {
                return(null);
            }

            System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions();
            //RegexOption = Options;
            RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString());
            return(Regex.Matches(input.Value, pattern.Value, RegexOption));
        }
Beispiel #9
0
    private void BindNewGuest(SqlInt32 newGuestId)
    {
        BindGuests();
        Guests guest = new Guests();

        guest.Guest_ID = newGuestId;
        DataTable table = guest.SelectOne();

        grid.DataSource = table;
        grid.DataBind();
        hidNewGuestId.Value = newGuestId.ToString();
    }
        public static SqlString RegExMatch(SqlString pattern, SqlString input, SqlInt32 Options)
        {
            if ((input.IsNull || pattern.IsNull))
            {
                return(String.Empty);
            }

            System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions();
            //RegexOption = (int)Options;
            RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString());
            return(Regex.Match(input.Value, pattern.Value, RegexOption).Value);
        }
Beispiel #11
0
    public static SqlDateTime GetDateByYearID(SqlInt32 YearID)
    {
        if (YearID.IsNull || YearID.Value <= 0)
        {
            return(SqlDateTime.Null);
        }

        string s    = YearID.ToString();
        int    year = int.Parse(s.Substring(0, 4));

        return(new SqlDateTime(year,
                               1,
                               1));
    }
Beispiel #12
0
    public static SqlDateTime GetDateByMonthID(SqlInt32 MonthID)
    {
        if (MonthID.IsNull || MonthID.Value <= 0)
        {
            return(SqlDateTime.Null);
        }

        string s     = MonthID.ToString();
        int    year  = int.Parse(s.Substring(0, 4));
        int    month = int.Parse(s.Substring(4, 2));

        return(new SqlDateTime(year,
                               month,
                               1));
    }
        public DataTable SelectDropDownList(SqlInt32 CustomerID, SqlInt32 UserID)
        {
            using (SqlConnection objConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand objcmd = objConnection.CreateCommand())
                {
                    try
                    {
                        objConnection.Open();

                        #region Prepare Command
                        objcmd.CommandType = CommandType.StoredProcedure;
                        objcmd.CommandText = "[PR_CustomerWiseProduct_DropDownList]";
                        objcmd.Parameters.AddWithValue("@CustomerID", CustomerID.ToString());
                        objcmd.Parameters.AddWithValue("@UserID", UserID.ToString());
                        #endregion Prepare Command

                        #region ReadData And SetData
                        DataTable dt = new DataTable();
                        using (SqlDataReader objSDR = objcmd.ExecuteReader())
                        {
                            dt.Load(objSDR);
                        }
                        return(dt);

                        #endregion ReadData And SetData
                    }
                    catch (SqlException Sqlex)
                    {
                        Message = Sqlex.Message.ToString();
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.Message.ToString();
                        return(null);
                    }
                    finally
                    {
                        if (objConnection.State == ConnectionState.Open)
                        {
                            objConnection.Close();
                        }
                    }
                }
            }
        }
Beispiel #14
0
    public static SqlBoolean SaveToFolderByZoomXY(SqlBinary image, SqlString rootFolderPath, SqlInt32 Zoom, SqlInt32 X, SqlInt32 Y)
    {
        SqlBoolean result = false;

        using (MemoryStream ms = new MemoryStream())
        {
            ms.Write(image.Value, 0, image.Length);
            SetBeginPosition(ms);

            using (Icon2TileRendering bitmap = new Icon2TileRendering(ms))
            {
                bitmap.SaveToPngFile((string)rootFolderPath, Zoom.ToString(), X.ToString(), Y.ToString());
                result = true;
            }
        }
        // Put your code here
        return(result);
    }
Beispiel #15
0
    public static void MakeError(SqlInt32 severity, SqlInt32 state, SqlString message)
    {
        if (severity.IsNull || state.IsNull || message.IsNull)
        {
            return;
        }
        var error = String.Format("RAISERROR (N'A Phony Error %s', {0}, {1}, @message)",
                                  severity.Value.ToString(), state.ToString());

        using (SqlConnection conn = new SqlConnection("context connection=true"))
            using (SqlCommand cmd = new SqlCommand(
                       error,
                       conn))
            {
                conn.Open();
                cmd.Parameters.AddWithValue("@message", message);
                SqlContext.Pipe.ExecuteAndSend(cmd);
            }
    }
    public static void MetricsStaging(SqlInt32 accoutId, SqlString deliveryTable, SqlString stagingTable, out SqlChars stagingSql)
    {
        using (var connection = new SqlConnection("context connection=true"))
        {
            connection.Open();

            // pass all delivery parameters as parameters to SP
            var account           = Convert.ToInt32(accoutId.ToString());
            var deliveryTableName = deliveryTable.ToString();
            var stagingTableName  = stagingTable.ToString();

            try
            {
                stagingSql = new SqlChars(EdgeViewer.StageMetrics(account, deliveryTableName, stagingTableName, connection));
            }
            catch (System.Exception ex)
            {
                // TODO: write to log in DB
                throw;
            }
        }
    }
Beispiel #17
0
    public static void IdentityI(SqlInt32 accoutId, SqlString deliveryTablePrefix, SqlDateTime identity1Timestamp, SqlBoolean createNewEdgeObjects)
    {
        using (var objectsConnection = new SqlConnection("context connection=true"))
        {
            objectsConnection.Open();
            var identityMng = new IdentityManager(objectsConnection);

            // pass all delivery parameters as parameters to SP
            identityMng.AccountId   = Convert.ToInt32(accoutId.ToString());
            identityMng.TablePrefix = deliveryTablePrefix.ToString();

            identityMng.Log(string.Format("Starting Identity I, parameters: accountId={0}, delivery table prefix='{1}'", accoutId, deliveryTablePrefix));
            try
            {
                identityMng.IdentifyDeliveryObjects();
            }
            catch (System.Exception)
            {
                // TODO: write to log in DB
                throw;
            }
        }
    }
        public static SqlString RegExMatchGroups(SqlString pattern, SqlString input, SqlInt32 Options)
        {
            if ((input.IsNull || pattern.IsNull))
            {
                return(String.Empty);
            }

            System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions();
            //RegexOption = (int)Options;
            RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString());


            string myOutput = "";

            int i = 0;

            foreach (Group group in Regex.Match(input.Value, pattern.Value, RegexOption).Groups)
            {
                if (!(i == 0))
                {
                    //Console.WriteLine(group.Value);
                    myOutput += group.Value + " ";
                }

                i++;
            }

            if (myOutput.Length > 0)
            {
                myOutput = myOutput.Substring(0, myOutput.Length - 1);
            }



            //return Regex.Match(input.Value, pattern.Value, RegexOption).Value;
            return(myOutput);
        }
Beispiel #19
0
        public static void GeographyAStar(SqlInt32 StartID, SqlInt32 GoalID)
        {
            /**
             * INITIALISATION
             */
            // The "Open List" contains the nodes that have yet to be assessed
            List <AStarNode> OpenList = new List <AStarNode>();

            // The "Closed List" contains the nodes that have already been assessed
            // Implemented as a Dictionary<> to enable quick lookup of nodes
            Dictionary <int, AStarNode> ClosedList = new Dictionary <int, AStarNode>();

            using (SqlConnection conn = new SqlConnection("context connection=true;"))
            {
                conn.Open();

                // Retrieve the location of the StartID
                SqlCommand   cmdGetStartNode = new SqlCommand("SELECT geog4326 FROM Nodes WHERE NodeID = @id", conn);
                SqlParameter param           = new SqlParameter("@id", SqlDbType.Int);
                param.Value = StartID;
                cmdGetStartNode.Parameters.Add(param);
                object       startNode = cmdGetStartNode.ExecuteScalar();
                SqlGeography startGeom;
                if (startNode != null)
                {
                    startGeom = (SqlGeography)(startNode);
                }
                else
                {
                    throw new Exception("Couldn't find start node with ID " + StartID.ToString());
                }
                cmdGetStartNode.Dispose();

                // Retrieve the location of the GoalID;
                SqlCommand   cmdGetEndNode = new SqlCommand("SELECT geog4326 FROM Nodes WHERE NodeID = @id", conn);
                SqlParameter endparam      = new SqlParameter("@id", SqlDbType.Int);
                endparam.Value = GoalID;
                cmdGetEndNode.Parameters.Add(endparam);
                object       endNode = cmdGetEndNode.ExecuteScalar();
                SqlGeography endGeom;
                if (endNode != null)
                {
                    endGeom = (SqlGeography)(endNode);
                }
                else
                {
                    throw new Exception("Couldn't find end node with ID " + GoalID.ToString());
                }
                cmdGetEndNode.Dispose();
                conn.Close();

                // To start with, the only point we know about is the start node
                AStarNode StartNode = new AStarNode(
                    (int)StartID,                         // ID of this node
                    -1,                                   // Start node has no parent
                    0,                                    // g - the distance travelled so far to get to this node
                    (double)startGeom.STDistance(endGeom) // h - the estimated remaining distance to the goal
                    );

                // Add the start node to the open list
                OpenList.Add(StartNode);

                /**
                 * TRAVERSAL THROUGH THE NETWORK
                 */

                // So long as there are open nodes to assess
                while (OpenList.Count > 0)
                {
                    // Sort the list of open nodes by ascending f score
                    OpenList.Sort(delegate(AStarNode p1, AStarNode p2)
                                  { return(p1.f.CompareTo(p2.f)); });

                    // Consider the open node with lowest f score
                    AStarNode NodeCurrent = OpenList[0];

                    /**
                     * GOAL FOUND
                     */
                    if (NodeCurrent.NodeID == GoalID)
                    {
                        // Reconstruct the route to get here
                        List <SqlGeography> route = new List <SqlGeography>();
                        int parentID = NodeCurrent.ParentID;

                        // Keep looking back through nodes until we get to the start (parent -1)
                        while (parentID != -1)
                        {
                            conn.Open();

                            SqlCommand cmdSelectEdge = new SqlCommand("GetEdgeBetweenNodes", conn);
                            cmdSelectEdge.CommandType = CommandType.StoredProcedure;
                            SqlParameter fromOSODRparam = new SqlParameter("@NodeID1", SqlDbType.Int);
                            SqlParameter toOSODRparam   = new SqlParameter("@NodeID2", SqlDbType.Int);
                            fromOSODRparam.Value = NodeCurrent.ParentID;
                            toOSODRparam.Value   = NodeCurrent.NodeID;
                            cmdSelectEdge.Parameters.Add(fromOSODRparam);
                            cmdSelectEdge.Parameters.Add(toOSODRparam);

                            object       edge = cmdSelectEdge.ExecuteScalar();
                            SqlGeography edgeGeom;
                            if (edge != null)
                            {
                                edgeGeom = (SqlGeography)(edge);
                                route.Add(edgeGeom);
                            }
                            conn.Close();

                            NodeCurrent = ClosedList[parentID];
                            parentID    = NodeCurrent.ParentID;
                        }

                        // Send the results back to the client
                        SqlMetaData   ResultMetaData = new SqlMetaData("Route", SqlDbType.Udt, typeof(SqlGeography));
                        SqlDataRecord Record         = new SqlDataRecord(ResultMetaData);
                        SqlContext.Pipe.SendResultsStart(Record);
                        // Loop through route segments in reverse order
                        for (int k = route.Count - 1; k >= 0; k--)
                        {
                            Record.SetValue(0, route[k]);
                            SqlContext.Pipe.SendResultsRow(Record);
                        }
                        SqlContext.Pipe.SendResultsEnd();

                        return;
                    } // End if (NodeCurrent.NodeID == GoalID)

                    /**
                     * GOAL NOT YET FOUND - IDENTIFY ALL NODES ACCESSIBLE FROM CURRENT NODE
                     */
                    List <AStarNode> Successors = new List <AStarNode>();
                    conn.Open();
                    SqlCommand cmdSelectSuccessors = new SqlCommand("GetNodesAccessibleFromNode", conn);
                    cmdSelectSuccessors.CommandType = CommandType.StoredProcedure;
                    SqlParameter CurrentNodeOSODRparam = new SqlParameter("@NodeID", SqlDbType.Int);
                    CurrentNodeOSODRparam.Value = NodeCurrent.NodeID;
                    cmdSelectSuccessors.Parameters.Add(CurrentNodeOSODRparam);

                    using (SqlDataReader dr = cmdSelectSuccessors.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            // Create a node for this potential successor
                            AStarNode SuccessorNode = new AStarNode(
                                dr.GetInt32(0),                  // NodeID
                                NodeCurrent.NodeID,              // Successor node is a child of the current node
                                NodeCurrent.g + dr.GetDouble(1), // Additional distance from current node to successor
                                (double)(((SqlGeography)dr.GetValue(2)).STDistance(endGeom))
                                );
                            // Add the end of the list of successors
                            Successors.Add(SuccessorNode);
                        }
                    }
                    cmdSelectSuccessors.Dispose();
                    conn.Close();

                    /**
                     * Examine list of possible nodes to go next
                     */
                    SqlContext.Pipe.Send("Possible nodes to visit from " + NodeCurrent.NodeID.ToString());
                    foreach (AStarNode NodeSuccessor in Successors)
                    {
                        // Keep track of whether we have already found this node
                        bool found = false;

                        // If this node is already on the closed list, it doesn't need to be examined further
                        if (ClosedList.ContainsKey(NodeSuccessor.NodeID))
                        {
                            found = true;
                            SqlContext.Pipe.Send(NodeSuccessor.NodeID.ToString() + "(" + NodeSuccessor.f.ToString() + ") (already visited)");
                        }

                        // If we didn't find the node on the closed list, look for it on the open list
                        if (!found)
                        {
                            for (int j = 0; j < OpenList.Count; j++)
                            {
                                if (OpenList[j].NodeID == NodeSuccessor.NodeID)
                                {
                                    found = true;
                                    SqlContext.Pipe.Send(NodeSuccessor.NodeID.ToString() + "(" + NodeSuccessor.f.ToString() + ") (already on list to consider)");
                                    // If this is a cheaper way to get there
                                    if (OpenList[j].h > NodeSuccessor.h)
                                    {
                                        // Update the route on the open list
                                        OpenList[j] = NodeSuccessor;
                                    }
                                    break;
                                }
                            }
                        }

                        // If not on either list, add to the open list
                        if (!found)
                        {
                            OpenList.Add(NodeSuccessor);
                            SqlContext.Pipe.Send(NodeSuccessor.NodeID.ToString() + "(" + NodeSuccessor.f.ToString() + ") (new)");
                        }
                    }
                    // SqlContext.Pipe.Send("---");

                    // Once all successors have been examined, we've finished with the current node
                    // so move it to the closed list
                    OpenList.Remove(NodeCurrent);
                    ClosedList.Add(NodeCurrent.NodeID, NodeCurrent);
                } // end while (OpenList.Count > 0)

                SqlContext.Pipe.Send("No route could be found!");
                return;
            }
        }
Beispiel #20
0
 public override string ToString() => _sql.ToString();
Beispiel #21
0
        public JobworkOrderENT SelectByPK(SqlInt32 JobworkOrderID)
        {
            using (SqlConnection objConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand objcmd = objConnection.CreateCommand())
                {
                    try
                    {
                        objConnection.Open();

                        #region Prepare Command
                        objcmd.CommandType = CommandType.StoredProcedure;
                        objcmd.CommandText = "PR_JobworkOrder_SelectByPK";
                        objcmd.Parameters.AddWithValue("@JobworkOrderID", JobworkOrderID.ToString());
                        #endregion Prepare Command

                        #region ReadData And SetData
                        JobworkOrderENT entJobworkOrder = new JobworkOrderENT();
                        using (SqlDataReader objSDR = objcmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["CustomerID"].Equals(DBNull.Value))
                                {
                                    entJobworkOrder.CustomerID = Convert.ToInt32(objSDR["CustomerID"]);
                                }
                                if (!objSDR["ProductID"].Equals(DBNull.Value))
                                {
                                    entJobworkOrder.ProductID = Convert.ToInt32(objSDR["ProductID"]);
                                }
                                if (!objSDR["Gross"].Equals(DBNull.Value))
                                {
                                    entJobworkOrder.Gross = Convert.ToInt32(objSDR["Gross"]);
                                }
                                if (!objSDR["Rate"].Equals(DBNull.Value))
                                {
                                    entJobworkOrder.Rate = Convert.ToInt32(objSDR["Rate"]);
                                }
                                if (!objSDR["IssueDate"].Equals(DBNull.Value))
                                {
                                    entJobworkOrder.IssueDate = Convert.ToDateTime(objSDR["IssueDate"]);
                                }
                                if (!objSDR["ReturnDate"].Equals(DBNull.Value))
                                {
                                    entJobworkOrder.ReturnDate = Convert.ToDateTime(objSDR["ReturnDate"]);
                                }
                            }
                        }

                        return(entJobworkOrder);

                        #endregion ReadData And SetData
                    }
                    catch (SqlException Sqlex)
                    {
                        Message = Sqlex.Message.ToString();
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.Message.ToString();
                        return(null);
                    }
                    finally
                    {
                        if (objConnection.State == ConnectionState.Open)
                        {
                            objConnection.Close();
                        }
                    }
                }
            }
        }
Beispiel #22
0
 private void validateResultSetNumber(SqlInt32 resultsetNo)
 {
     if (resultsetNo < 0 || resultsetNo.IsNull)
     {
         throw new InvalidResultSetException("ResultSet index begins at 1. ResultSet index [" + resultsetNo.ToString() + "] is invalid.");
     }
 }
Beispiel #23
0
        public void sendSelectedResultSetToSqlContext(SqlInt32 resultsetNo, SqlString command)
        {
            validateResultSetNumber(resultsetNo);

            SqlDataReader dataReader = testDatabaseFacade.executeCommand(command);

            int ResultsetCount = 0;

            if (dataReader.FieldCount > 0)
            {
                do
                {
                    ResultsetCount++;
                    if (ResultsetCount == resultsetNo)
                    {
                        sendResultsetRecords(dataReader);
                        break;
                    }
                } while (dataReader.NextResult());
            }
            dataReader.Close();

            if (ResultsetCount < resultsetNo)
            {
                throw new InvalidResultSetException("Execution returned only " + ResultsetCount.ToString() + " ResultSets. ResultSet [" + resultsetNo.ToString() + "] does not exist.");
            }
        }
Beispiel #24
0
 public override string ToString()
 {
     return(number.ToString());
 }
Beispiel #25
0
        public static bool Process(ServerVersion version,
                                   string targetConnection,
                                   string repositoryConnection,
                                   int snapshotid,
                                   string server)
        {
            Debug.Assert(version != ServerVersion.Unsupported);
            Debug.Assert(!string.IsNullOrEmpty(targetConnection));
            Debug.Assert(!string.IsNullOrEmpty(repositoryConnection));

            bool isOk = true;

            targetConnection = Sql.SqlHelper.AppendDatabaseToConnectionString(targetConnection, "msdb");
            Program.ImpersonationContext wi = Program.SetLocalImpersonationContext();
            using (SqlConnection target = new SqlConnection(targetConnection),
                   repository = new SqlConnection(repositoryConnection))
            {
                try
                {
                    // Open repository and target connections.
                    repository.Open();
                    Program.SetTargetSQLServerImpersonationContext();
                    target.Open();

                    // Use bulk copy object to write to repository.
                    using (SqlBulkCopy bcp = new SqlBulkCopy(repository))
                    {
                        // Set the destination table.
                        bcp.DestinationTableName = SqlJobDataTable.RepositoryTable;
                        bcp.BulkCopyTimeout      = SQLCommandTimeout.GetSQLCommandTimeoutFromRegistry();
                        // Create the datatable to write to the repository.
                        using (DataTable dataTable = SqlJobDataTable.Create())
                        {
                            // Process each rule to collect the table objects.

                            string query = string.Format(SqlJob.GetJobsQuery, server);
                            if (version == ServerVersion.SQL2000)
                            {
                                query = SqlJob.GetJobsQuerySQL2000;
                            }

                            Debug.Assert(!string.IsNullOrEmpty(query));

                            // Query to get the table objects.
                            using (SqlDataReader rdr = Sql.SqlHelper.ExecuteReader(target, null, CommandType.Text, query, null))
                            {
                                while (rdr.Read())
                                {
                                    // Retrieve the object information.

                                    SqlString name    = rdr.GetSqlString(ColName);
                                    SqlBinary owner   = rdr.GetSqlBinary(ColOwnerSid);
                                    SqlInt16  enabled = rdr.GetByte(ColEnabled);

                                    SqlString   desc       = rdr.GetSqlString(ColDescription);
                                    SqlInt32    lastRunInt = rdr.GetInt32(ColLastRunDate);
                                    SqlDateTime lastRun    = SqlDateTime.MinValue;
                                    if (lastRunInt != 0)
                                    {
                                        lastRun = DateTime.ParseExact(lastRunInt.ToString(), "yyyyMMdd", null);
                                    }
                                    SqlString command   = rdr.GetSqlString(ColCommand);
                                    SqlString stepname  = rdr.GetSqlString(ColStepName);
                                    SqlString subsystem = rdr.GetSqlString(ColSubSystem);

                                    SqlInt32 proxyId = rdr.IsDBNull(ColProxyId)? SqlInt32.Null : rdr.GetInt32(ColProxyId);

                                    DataRow dr = dataTable.NewRow();
                                    dr[SqlJobDataTable.ParamSnapshotId]  = snapshotid;
                                    dr[SqlJobDataTable.ParamName]        = name;
                                    dr[SqlJobDataTable.ParamDescription] = desc;
                                    dr[SqlJobDataTable.ParamStepName]    = stepname;
                                    dr[SqlJobDataTable.ParamLastRunDate] = lastRun;
                                    dr[SqlJobDataTable.ParamCommand]     = command;
                                    dr[SqlJobDataTable.ParamSubSystem]   = subsystem;
                                    dr[SqlJobDataTable.ParamOwnerSid]    = owner;
                                    dr[SqlJobDataTable.ParamEnabled]     = enabled;
                                    dr[SqlJobDataTable.Paramproxyid]     = proxyId;

                                    dataTable.Rows.Add(dr);
                                    if (dataTable.Rows.Count > Constants.RowBatchSize)
                                    {
                                        try
                                        {
                                            bcp.WriteToServer(dataTable);
                                            dataTable.Clear();
                                        }
                                        catch (SqlException ex)
                                        {
                                            string strMessage = "Writing to Repository sql server jobs faild";

                                            logX.loggerX.Error("ERROR - " + strMessage, ex);
                                            throw;
                                        }
                                    }
                                }

                                // Write any items still in the data table.
                                if (dataTable.Rows.Count > 0)
                                {
                                    try
                                    {
                                        bcp.WriteToServer(dataTable);
                                        dataTable.Clear();
                                    }
                                    catch (SqlException ex)
                                    {
                                        string strMessage = "Writing to Repository sql server jobs failed";
                                        logX.loggerX.Error("ERROR - " + strMessage, ex);
                                        throw;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (SqlException ex)
                {
                    string strMessage = "Processing sql server jobs failed";
                    logX.loggerX.Error("ERROR - " + strMessage, ex);
                    Sql.Database.CreateApplicationActivityEventInRepository(repositoryConnection,
                                                                            snapshotid,
                                                                            Collector.Constants.ActivityType_Error,
                                                                            Collector.Constants.ActivityEvent_Error,
                                                                            strMessage + ex.Message);
                    AppLog.WriteAppEventError(SQLsecureEvent.ExErrExceptionRaised, SQLsecureCat.DlDataLoadCat,
                                              " SQL Server = " + new SqlConnectionStringBuilder(targetConnection).DataSource +
                                              strMessage, ex.Message);
                    isOk = false;
                }
                finally
                {
                    Program.RestoreImpersonationContext(wi);
                }
            }

            return(isOk);
        }
Beispiel #26
0
 public override string ToString()
 {
     return(_value.ToString());
 }
Beispiel #27
0
    private static void writeOutput(SqlInt32 style_color_id, SalesAndReceiptPlan salesAndReceiptPlan, SqlBoolean verbose, bool debug = false)
    {
        string[] storedProcs = verbose.IsTrue ?
                               new string[] { "Save_Consolidated_Receipts", "Save_Consolidated_Node_Receipts", "Save_Node_Receipt_Needs_Debug" } :
        new string[] { "Save_Consolidated_Receipts", "Save_Consolidated_Node_Receipts" };
        int     numStoredProcs = verbose ? 3 : 2;
        SqlPipe sqlP           = SqlContext.Pipe;

        for (int i = 0; i < numStoredProcs; i++)
        {
            using (SqlConnection connection = new SqlConnection("context connection=true"))
            {
                using (SqlCommand cmd = new SqlCommand(storedProcs[i], connection))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    if (debug)
                    {
                        sqlP.Send(storedProcs[i] + " started");
                    }

                    DataTable dt = null;
                    switch (i)
                    {
                    case 0:
                        if (debug)
                        {
                            sqlP.Send("Style_Color_Id, Receipt Type, Week");
                            foreach (Receipt receipt in salesAndReceiptPlan.Receipts)
                            {
                                sqlP.Send(style_color_id.ToString() + "," + receipt.ReceiptType + "," + receipt.Week);
                            }
                        }
                        dt = salesAndReceiptPlan.GetConsolidatedReceiptsDataTable();
                        break;

                    case 1:
                        dt = salesAndReceiptPlan.GetConsolidatedNodeReceiptsDataTable();
                        break;

                    case 2:
                        dt = salesAndReceiptPlan.GetReceiptNeedsDebugDataTable();
                        break;
                    }
                    cmd.Parameters.AddRange(new SqlParameter[]
                    {
                        new SqlParameter
                        {
                            ParameterName = "@style_color_id",
                            SqlDbType     = System.Data.SqlDbType.Int,
                            Direction     = System.Data.ParameterDirection.Input,
                            Value         = style_color_id
                        },
                        new SqlParameter
                        {
                            ParameterName = "@data",
                            SqlDbType     = System.Data.SqlDbType.Structured,
                            TypeName      = dt.TableName,
                            Direction     = System.Data.ParameterDirection.Input,
                            Value         = dt
                        }
                    });
                    connection.Open();
                    cmd.ExecuteNonQuery();

                    if (debug)
                    {
                        sqlP.Send(storedProcs[i] + " completed");
                    }
                }
            }
        }
        if (debug)
        {
            sqlP.Send(style_color_id.ToString() + " processed.");
        }
    }
Beispiel #28
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(_sql.ToString());
 }
 public SqlString Terminate()
 {
     return(countOfVowels.ToString());
 }