// Call with a single API

        /*
         * private string FindCase()
         * {
         *  Tyler.Odyssey.API.JobTemplate.FindCaseByCaseNumberEntity entity = new Tyler.Odyssey.API.JobTemplate.FindCaseByCaseNumberEntity();
         *  entity.SetStandardAttributes(800, "FindCase", Context.UserID, "FindCase", Context.SiteID);
         *  entity.CaseNumber = Context.Parameters.CaseNumber;
         *
         *  OdysseyMessage msg = new OdysseyMessage(entity.ToOdysseyMessageXml(), Context.SiteID);
         *  string test = entity.ToOdysseyMessageXml();
         *  MessageHandlerFactory.Instance.ProcessMessage(msg);
         *
         *  StringReader reader = new StringReader(msg.ResponseDocument.OuterXml);
         *  XmlSerializer serializer = new XmlSerializer(typeof(Tyler.Odyssey.API.JobTemplate.FindCaseByCaseNumberResultEntity));
         *  Tyler.Odyssey.API.JobTemplate.FindCaseByCaseNumberResultEntity result = (Tyler.Odyssey.API.JobTemplate.FindCaseByCaseNumberResultEntity)serializer.Deserialize(reader);
         *
         *  return result.CaseID;
         * }
         */
        // Call with API Transaction
        private bool AddCaseEvent(string caseID, string eventCode)
        {
            Tyler.Odyssey.API.JobTemplate.AddCaseEventEntity entity = new Tyler.Odyssey.API.JobTemplate.AddCaseEventEntity();
            entity.SetStandardAttributes(800, "AddEvent", Context.UserID, "AddEvent", Context.SiteID);
            entity.CaseID        = caseID;
            entity.CaseEventType = eventCode;
            entity.Date          = DateTime.Today.ToShortDateString();

            TransactionEntity txn = new TransactionEntity();

            txn.TransactionType = "TylerAPIJobAddCaseEvent";
            txn.Messages.Add(entity);

            string responseXML = ProcessTransaction(txn.ToOdysseyTransactionXML());

            if (responseXML != "ERROR")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool ScheduleHearing(DataRow row, string startDate, string endDate, string hearingType, string sessionID)
        {
            // Row Results
            // CaseID, CaseNbr, DtFile, NodeID, CurrCaseStatusCode, CalendarCode, CaseTypeCode, CaseSequence
            string caseID          = row[0].ToString();
            string caseNbr         = row[1].ToString();
            string judicialOfficer = row[5].ToString();
            string nodeID          = row[3].ToString();

            TransactionEntity txn = new TransactionEntity();

            txn.TransactionType = "ILCookLawDivisionCallJob";
            txn.ReferenceNumber = "ILCookLawDivisionCallJob";
            txn.Source          = "ILCookLawDivisionCallJob";

            // Data Propagation
            txn.DataPropagation.AddIntraTxnDataPropagationEntry("#|CourtSessionBlockID|#"
                                                                , "/TxnResponse/Result[@MessageType='LoadCourtSession']/SessionBlocks/SessionBlock/SessionBlockID");


            // **** Load Court Session **** //
            Entities.LoadCourtSessionEntity loadCourtSessionEntity = new Entities.LoadCourtSessionEntity();
            loadCourtSessionEntity.SetStandardAttributes(1, "LoadCourtSession", Context.UserID, "LoadCourtSession", Context.SiteID);
            loadCourtSessionEntity.NodeID          = nodeID;
            loadCourtSessionEntity.ReferenceNumber = "LoadCourtSession";
            loadCourtSessionEntity.UserID          = "1";
            loadCourtSessionEntity.Source          = "ILCookLawDivisionCallJob";
            loadCourtSessionEntity.SessionID       = sessionID;
            txn.Messages.Add(loadCourtSessionEntity);


            // **** Add Hearing **** //
            Entities.AddHearingEntity addHearingEntity = new Entities.AddHearingEntity();
            addHearingEntity.SetStandardAttributes(1, "LoadCourtSession", Context.UserID, "LoadCourtSession", Context.SiteID);
            addHearingEntity.NodeID          = nodeID;
            addHearingEntity.ReferenceNumber = "LoadCourtSession";
            addHearingEntity.UserID          = "1";
            addHearingEntity.Source          = "ILCookLawDivisionCallJob";

            addHearingEntity.CaseID = caseID;
            addHearingEntity.CourtSessionBlockID = "#|CourtSessionBlockID|#";
            addHearingEntity.HearingType         = hearingType;
            addHearingEntity.OffSetMinutes       = "0";
            addHearingEntity.HearingDuration     = "30";
            addHearingEntity.HearingPriority     = "1";

            Entities.JusticeCaseHearingInterpreterRequired interpreterRequired = new Entities.JusticeCaseHearingInterpreterRequired();
            addHearingEntity.InterpreterNeeded = new Entities.JusticeCaseHearingInterpreter();
            object notRequired = new object();

            addHearingEntity.InterpreterNeeded.Item = notRequired;

            txn.Messages.Add(addHearingEntity);

            string test = txn.ToOdysseyTransactionXML();

            Logger.WriteToLog("Schedule Hearing Transaction Request: " + txn.ToOdysseyTransactionXML(), LogLevel.Verbose);
            string result = "";

            try
            {
                result = ProcessTransaction(txn.ToOdysseyTransactionXML());
                if (result != "ERROR")
                {
                    return(true);
                }
                else
                {
                    Logger.WriteToLog("Cannot schedule a hearing.", LogLevel.Verbose);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Logger.WriteToLog("Cannot find a hearing. Exception: " + e, LogLevel.Verbose);
                return(false);
            }
        }
        private string FindHearing(DataRow row, string startDate, string endDate, string hearingType)
        {
            // Row Results
            // CaseID, CaseNbr, DtFile, NodeID, CurrCaseStatusCode, CalendarCode, CaseTypeCode, CaseSequence
            string caseID          = row[0].ToString();
            string caseNbr         = row[1].ToString();
            string judicialOfficer = row[5].ToString();
            string nodeID          = row[3].ToString();

            TransactionEntity txn = new TransactionEntity();

            txn.TransactionType = "ILCookLawDivisionCallJob";
            txn.ReferenceNumber = "ILCookLawDivisionCallJob";
            txn.Source          = "ILCookLawDivisionCallJob";

            // **** Find Court Session **** //
            Entities.FindCourtSessionEntity findCourtSessionEntity = new Entities.FindCourtSessionEntity();
            // Message Attributes
            findCourtSessionEntity.SetStandardAttributes(1, "FindCourtSession", Context.UserID, "FindCourtSession", Context.SiteID);
            findCourtSessionEntity.ReferenceNumber = "ILCookLawDivisionCallJob";
            findCourtSessionEntity.Source          = "ILCookLawDivisionCallJob";
            findCourtSessionEntity.NodeID          = "0";
            findCourtSessionEntity.UserID          = "1";

            /* Options */
            findCourtSessionEntity.Options = new Entities.FINDCOURTSESSIONOPTIONS();
            findCourtSessionEntity.Options.MaxNumberOfResults   = "20";
            findCourtSessionEntity.Options.IncludeAdHocHearings = "false";

            // Search Nodes
            findCourtSessionEntity.Options.Nodes = new Entities.FINDCOURTSESSIONOPTIONSNODES();
            Entities.FINDCOURTSESSIONOPTIONSNODESLIST nodeList = new Entities.FINDCOURTSESSIONOPTIONSNODESLIST();
            nodeList.SearchNodeID    = new string[1];
            nodeList.SearchNodeID[0] = nodeID;
            findCourtSessionEntity.Options.Nodes.Item = nodeList;

            /* Search Criteria */
            findCourtSessionEntity.SearchCriteria = new Entities.FINDCOURTSESSIONSEARCHCRITERIA();
            // Hearing Type
            findCourtSessionEntity.SearchCriteria.HearingTypes    = new string[1];
            findCourtSessionEntity.SearchCriteria.HearingTypes[0] = hearingType;

            // Judge Resource
            findCourtSessionEntity.SearchCriteria.Resources = new Entities.FINDCOURTSESSIONSEARCHCRITERIARESOURCES();
            Entities.FINDCOURTSESSIONSEARCHCRITERIARESOURCEGROUPRESOURCE judicialOfficerEntity = new Entities.FINDCOURTSESSIONSEARCHCRITERIARESOURCEGROUPRESOURCE();
            judicialOfficerEntity.Resource = judicialOfficer;
            findCourtSessionEntity.SearchCriteria.Resources.JudicialOfficer    = new Entities.FINDCOURTSESSIONSEARCHCRITERIARESOURCEGROUPRESOURCE[1];
            findCourtSessionEntity.SearchCriteria.Resources.JudicialOfficer[0] = judicialOfficerEntity;

            // Date Window
            findCourtSessionEntity.SearchCriteria.StartDate = startDate;
            findCourtSessionEntity.SearchCriteria.EndDate   = endDate;

            txn.Messages.Add(findCourtSessionEntity);

            Logger.WriteToLog("Schedule Hearing Transaction Request: " + txn.ToOdysseyTransactionXML(), LogLevel.Verbose);
            string result = "";

            try
            {
                result = ProcessTransaction(txn.ToOdysseyTransactionXML());
                if (result != "ERROR")
                {
                    return(result);
                }
                else
                {
                    Logger.WriteToLog("Cannot schedule a hearing.", LogLevel.Verbose);
                    return("ERROR");
                }
            }
            catch (Exception e)
            {
                Logger.WriteToLog("Cannot find a hearing. Exception: " + e, LogLevel.Verbose);
                return("ERROR");
            }
        }