Example #1
0
        ///<summary>Does not save to DB. Return null if listName does not exist.
        ///Pass in the userod.UserNum of the user that is making the change.  Typically Security.CurUser.UserNum.
        ///Security.CurUser cannot be used within this method due to the server side of middle tier.</summary>
        public static WikiListHist GenerateFromName(string listName, long userNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <WikiListHist>(MethodBase.GetCurrentMethod(), listName, userNum));
            }
            if (!WikiLists.CheckExists(listName))
            {
                return(null);
            }
            WikiListHist retVal = new WikiListHist();

            retVal.UserNum       = userNum;
            retVal.ListName      = listName;
            retVal.DateTimeSaved = DateTime.Now;
            DataTable table = WikiLists.GetByName(listName);

            table.TableName = listName;          //required for xmlwriter
            using (var writer = new StringWriter()) {
                table.WriteXml(writer, XmlWriteMode.WriteSchema);
                retVal.ListContent = writer.ToString();
            }
            List <WikiListHeaderWidth> listHeaders = WikiListHeaderWidths.GetForList(listName);

            if (listHeaders.Count > 0)
            {
                retVal.ListHeaders = string.Join(";", listHeaders.Select(x => x.ColName + "," + x.ColWidth));
            }
            return(retVal);
        }
Example #2
0
        ///<summary>Drops table in DB.  Recreates Table, then fills with Data.
        ///Pass in the userod.UserNum of the user that is making the change.  Typically Security.CurUser.UserNum.</summary>
        public static void RevertFrom(WikiListHist wikiListHist, long userNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), wikiListHist, userNum);
                return;
            }
            if (!WikiLists.CheckExists(wikiListHist.ListName))
            {
                return;                //should never happen.
            }
            DataTable tableRevertedContent = new DataTable();

            using (XmlReader xmlReader = XmlReader.Create(new StringReader(wikiListHist.ListContent))){
                tableRevertedContent.ReadXml(xmlReader);
            }
            //Begin the process of deleting old table and creating new one.
            //Save current wiki list content to the history
            WikiListHists.Insert(GenerateFromName(wikiListHist.ListName, userNum));
            //Delete current wiki list
            WikiLists.DeleteList(wikiListHist.ListName);
            //Create a new empty wiki list, except for the PK column
            WikiLists.CreateNewWikiList(wikiListHist.ListName);
            //Load header data
            List <WikiListHeaderWidth> listHeaders = WikiListHeaderWidths.GetFromListHist(wikiListHist);

            //Add one column per header, skipping the Pk column
            for (int i = 1; i < listHeaders.Count; i++)       //skip the first one, because the first one is the primary key
            {
                WikiLists.AddColumn(listHeaders[i].ListName);
            }
            //Update db with current names and current widths of columns in the WikiListHeaderWidth table to the reverted values
            WikiListHeaderWidths.UpdateNamesAndWidths(wikiListHist.ListName, listHeaders);
            //Fill db table with the reverted values.
            for (int i = 0; i < tableRevertedContent.Rows.Count; i++)
            {
                DataRow row = tableRevertedContent.Rows[i];
                row[0] = WikiLists.AddItem(wikiListHist.ListName);              //setPK and add new row
                DataTable tableOneItem = tableRevertedContent.Clone();
                tableOneItem.Rows.Add(tableOneItem.NewRow());
                tableOneItem.Rows[0].ItemArray = row.ItemArray;
                WikiLists.UpdateItem(wikiListHist.ListName, tableOneItem);
            }
        }
Example #3
0
        ///<summary>Drops table in DB.  Recreates Table, then fills with Data.
        ///Pass in the userod.UserNum of the user that is making the change.  Typically Security.CurUser.UserNum.</summary>
        public static void RevertFrom(WikiListHist wikiListHist, long userNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), wikiListHist, userNum);
                return;
            }
            if (!WikiLists.CheckExists(wikiListHist.ListName))
            {
                return;                                                                                  //should never happen.
            }
            Insert(GenerateFromName(wikiListHist.ListName, userNum));                                    //Save current wiki list content to the history
            List <WikiListHeaderWidth> listHeaders = WikiListHeaderWidths.GetFromListHist(wikiListHist); //Load header data

            WikiLists.CreateNewWikiList(wikiListHist.ListName, listHeaders, true);                       //dropTableIfExists=true, so the existing table and HeaderWidth rows will be dropped
            DataTable tableRevertedContent = new DataTable();

            using (StringReader sr = new StringReader(wikiListHist.ListContent))
                using (XmlReader xmlReader = XmlReader.Create(sr)) {
                    tableRevertedContent.ReadXml(xmlReader);
                }
            string        commandStart = $@"INSERT INTO wikilist_{POut.String(wikiListHist.ListName)} ({string.Join(",",listHeaders.Select(x => POut.String(x.ColName)))})
				VALUES "                ;
            StringBuilder sb           = new StringBuilder(commandStart);
            string        commaStr     = "";

            for (int i = 0; i < tableRevertedContent.Rows.Count; i++)
            {
                string rowStr = "(" + string.Join(",", tableRevertedContent.Rows[i].ItemArray.Select(x => "'" + POut.String(x.ToString()) + "'")) + ")";
                if (sb.Length + rowStr.Length + 1 > TableBase.MaxAllowedPacketCount)
                {
                    Db.NonQ(sb.ToString());
                    sb       = new StringBuilder(commandStart);
                    commaStr = "";
                }
                sb.Append(commaStr + rowStr);
                commaStr = ",";
                if (i == tableRevertedContent.Rows.Count - 1)
                {
                    Db.NonQ(sb.ToString());
                }
            }
        }
Example #4
0
        ///<summary>Does not save to DB. Return null if listName does not exist.
        ///Pass in the userod.UserNum of the user that is making the change.  Typically Security.CurUser.UserNum.
        ///Security.CurUser cannot be used within this method due to the server side of middle tier.</summary>
        public static WikiListHist GenerateFromName(string listName, long userNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <WikiListHist>(MethodBase.GetCurrentMethod(), listName, userNum));
            }
            if (!WikiLists.CheckExists(listName))
            {
                return(null);
            }
            WikiListHist retVal = new WikiListHist();

            retVal.UserNum       = userNum;
            retVal.ListName      = listName;
            retVal.DateTimeSaved = DateTime.Now;
            DataTable table = WikiLists.GetByName(listName);

            table.TableName = listName;          //required for xmlwriter
            using (var writer = new System.IO.StringWriter()) {
                table.WriteXml(writer);
                retVal.ListContent = writer.ToString();
            }
            List <WikiListHeaderWidth> listHeaders = WikiListHeaderWidths.GetForList(listName);
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < listHeaders.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(";");
                }
                sb.Append(listHeaders[i].ColName + "," + listHeaders[i].ColWidth);
            }
            retVal.ListHeaders = sb.ToString();
            using (var writer = new StringWriter()) {
                table.WriteXml(writer, XmlWriteMode.WriteSchema);
                retVal.ListContent = writer.ToString();
            }
            return(retVal);
        }