Unofficial Content

// Sample by fórum 

using System.Text;
using Artech.Architecture.Common.Objects;
using Artech.Architecture.Common.Services;
using Artech.Genexus.Common.Objects;
using Artech.Genexus.Common.Parts;
using Artech.Genexus.Common.Wiki;

namespace Artech.Samples.Forum
{
   public class TransactionsDoc
   {
      private static string TransactionsDocSection = "Transactions Document update";
      private static string TransactionsDocName = "TransactionsDocument";

      public static bool Execute(KBModel model)
      {
         if (model == null)
            return false;
 
         IOutputService output = CommonServices.Output;
         output.Show("General");
         output.StartSection(TransactionsDocSection);
         bool success = false;

         try
         {
            WikiPageKBObject docKBObject = GetDocumentKBObject(model, TransactionsDocName);
            docKBObject.Part.Page = new WikiPage(model, TransactionsDocName, "");
            docKBObject.Part.Page.EditableContent = GetDocumentContent(model);
            docKBObject.Save();
            success = true;
         }
         catch (System.Exception exception)
         {
            output.AddLine(exception.Message);
         }
         finally
         {
            output.EndSection(TransactionsDocSection, success);
         }
         return success;
      }

      private static string GetDocumentContent(KBModel model)
      {
         StringBuilder builder = new StringBuilder();
         builder.AppendLine("<h2>Transactions</h2>");
         builder.Append("<p>");
         foreach (Transaction trn in Transaction.GetAll(model))
         {
            builder.AppendFormat("[[ToDelete234]]<br/>\r\n", trn.Name);
         }
         builder.Append("</p>");
         return builder.ToString();
      }

      private static WikiPageKBObject GetDocumentKBObject(KBModel model, string documentName)
      {
         System.Guid wikiType = typeof(WikiPageKBObject).GUID;
         WikiPageKBObject docKBObject = KBObject.Get(model, wikiType, documentName)
            as WikiPageKBObject;

         if (docKBObject == null)
         {
            docKBObject = (WikiPageKBObject)KBObject.Create(model, wikiType);
            docKBObject.Name = documentName;
         }
         return docKBObject;
      }
   }
}
Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant