public Dictionary <string, string> GetLogs(string top, string userID, string logTypeID)
        {
            Authorize();

            List <LogItem> dbLogs = new List <LogItem>();

            try
            {
                string sql = "";
                string where = " WHERE 1=1 ";

                string userIDsql = "";
                if (userID != "")
                {
                    userIDsql = " AND userId=" + Convert.ToInt32(userID);
                }

                string logTypeSql = "";
                if (logTypeID != "")
                {
                    string logType = System.Enum.GetName(typeof(LogTypes), Convert.ToInt32(logTypeID));
                    logTypeSql = " AND logHeader='" + logType + "'";
                }

                sql = "SELECT TOP " + Convert.ToInt32(top) + " * FROM umbracoLog " + where + userIDsql + logTypeSql + " ORDER BY id DESC";
                //umbraco.BusinessLogic.Log.Add(LogTypes.Debug, 0, sql);

                IRecordsReader reader = SqlHelper.ExecuteReader(sql);
                dbLogs = LogItem.ConvertIRecordsReader(reader);

                SqlHelper.Dispose();
            }
            catch (Exception e)
            {
                returnValue.Add("status", jsonSerializer.Serialize(status.ERROR.ToString()));
                returnValue.Add("error", jsonSerializer.Serialize(e.Message));
            }

            List <uToolsLogItem> finalLogs = new List <uToolsLogItem>();

            foreach (LogItem thisItem in dbLogs)
            {
                finalLogs.Add(new uToolsLogItem()
                {
                    userID = thisItem.UserId, nodeID = thisItem.NodeId, name = new User(thisItem.UserId).Name, logType = thisItem.LogType.ToString(), comment = thisItem.Comment, dateTime = thisItem.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff")
                });
            }

            returnValue.Add("status", status.SUCCESS.ToString());
            returnValue.Add("logs", jsonSerializer.Serialize(finalLogs));

            return(returnValue);
        }
Example #2
0
        public IEnumerable <LogItem> GetLatestLogItems(int take, int skip)
        {
            string sqlQuery;

            string connectionString = ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString;

            if (connectionString.Contains(".sdf"))
            {
                // SQL Server Compact does not support subquery, use OFFSET instead
                sqlQuery = string.Format("{0} ORDER BY DateStamp DESC OFFSET (@skip) ROWS FETCH NEXT (@take) ROWS ONLY", GetInnerSelect(false));
            }
            else
            {
                // SQL Server 2005/2008/2008 R2 does not support OFFSET, but subquery
                sqlQuery = string.Format(";WITH [logResult] AS ({0}) SELECT * FROM [logResult] {1}", GetInnerSelect(), GetWhere());
            }

            return(LogItem.ConvertIRecordsReader(SqlHelper.ExecuteReader(sqlQuery,
                                                                         SqlHelper.CreateParameter("@dateStamp", _getLogSince),
                                                                         SqlHelper.CreateParameter("@skip", GetSkip(skip)),
                                                                         SqlHelper.CreateParameter("@take", GetTake(take, skip)))));
        }