Beispiel #1
0
        // DEPRECATION WARNING!!! THIS WILL BE REMOVED IN A LATER VERSION
        #endregion

        #region _caseCreated
        // DEPRECATION WARNING!!! THIS WILL BE REMOVED IN A LATER VERSION
        private void _caseCompleted(object sender, EventArgs args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"_caseCompleted called ");
            //LogEvent(String.Format("_caseCompleted called"));
            //LogEvent(String.Format("_caseCompleted called inboundPath is : " + inboundPath));
            Case_Dto trigger  = (Case_Dto)sender;
            int      siteId   = trigger.SiteUId;
            string   caseType = trigger.CaseType;
            string   caseUid  = trigger.CaseUId;
            string   mUId     = trigger.MicrotingUId;
            string   checkUId = trigger.CheckUId;
            string   CaseId   = trigger.CaseId.ToString();

            LogEvent("_caseCompleted siteId is :'" + siteId + "'");
            LogEvent("_caseCompleted caseType is :'" + caseType + "'");
            LogEvent("_caseCompleted caseUid is :'" + caseUid + "'");
            LogEvent("_caseCompleted mUId is :'" + mUId + "'");
            LogEvent("_caseCompleted checkUId is :'" + checkUId + "'");
            LogEvent("_caseCompleted CaseId is :'" + CaseId + "'");

            try
            {
                outLook.MarkAppointmentCompleted(CaseId);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"_caseCompleted sufferend an exception : {ex.Message} ");
                LogException("outLook.MarkAppointmentCompleted threw the exception: " + ex.Message);
            }
        }
        public void CaseCompleted(object sender, EventArgs args)
        {
            Case_Dto trigger = (Case_Dto)sender;

            if (trigger.CheckUId != null && trigger.MicrotingUId != null)
            {
                _bus.SendLocal(new EformCompleted(trigger.CheckListId, trigger.CheckUId.Value, trigger.MicrotingUId.Value));
            }
        }
Beispiel #3
0
 public void EventCaseDeleted(object sender, EventArgs args)
 {
     //DOSOMETHING: changed to fit your wishes and needs
     Case_Dto temp     = (Case_Dto)sender;
     int      siteId   = temp.SiteUId;
     string   caseType = temp.CaseType;
     string   caseUid  = temp.CaseUId;
     string   mUId     = temp.MicrotingUId;
     string   checkUId = temp.CheckUId;
 }
        public bool CheckStatusUpdateIfNeeded(string microtingUId)
        {
            lock (_lockSending)
            {
                log.LogEverything("Not Specified", t.GetMethodName() + " called");
                log.LogVariable("Not Specified", nameof(microtingUId), microtingUId);

                string   correctStat = null;
                Case_Dto caseDto     = null;

                try
                {
                    caseDto     = sqlController.CaseReadByMUId(microtingUId);
                    correctStat = "Created"; //Sent

                    string status = CheckStatus(caseDto.MicrotingUId, caseDto.SiteUId);
                    if (!status.Contains("id=\"\"/>"))
                    {
                        correctStat = "Retrived";

                        string reply = Retrieve(caseDto.MicrotingUId, caseDto.SiteUId);

                        Response resp = new Response();
                        resp = resp.XmlToClassUsingXmlDocument(reply);
                        if (resp.Type == Response.ResponseTypes.Success)
                        {
                            if (resp.Checks.Count > 0)
                            {
                                correctStat = "Completed";
                            }
                        }

                        if (caseDto.Stat == "Deleted" || caseDto.Stat == correctStat)
                        {
                            return(true);
                        }
                    }
                }
                catch
                {
                }

                if (correctStat == "Retrived")
                {
                    sqlController.NotificationCreate("F:" + t.GetRandomInt(10), caseDto.MicrotingUId, "unit_fetch");
                }

                if (correctStat == "Completed")
                {
                    sqlController.NotificationCreate("F:" + t.GetRandomInt(10), caseDto.MicrotingUId, "check_status");
                }

                return(false);
            }
        }
Beispiel #5
0
        private static void Core_HandleCaseRetrived(object sender, EventArgs e)
        {
            Case_Dto caseDto = (Case_Dto)sender;

            Packer packer      = new Packer();
            String jsonCaseDto = packer.PackCaseDto(caseDto);

            IntPtr ptr = (IntPtr)caseRetrivedCallbackPointer;
            CaseRetrivedCallback caseRetrivedCallbackMethod = (CaseRetrivedCallback)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CaseRetrivedCallback));

            caseRetrivedCallbackMethod(jsonCaseDto);
        }
Beispiel #6
0
        public static int Core_CaseReadByCaseId(int caseId, [MarshalAs(UnmanagedType.BStr)] ref string jsonCaseDto)
        {
            int result = 0;

            try
            {
                Case_Dto caseDto = core.CaseReadByCaseId(caseId);
                jsonCaseDto = new Packer().PackCaseDto(caseDto);
            }
            catch (Exception ex)
            {
                LastError.Value = ex.Message;
                result          = 1;
            }
            return(result);
        }
Beispiel #7
0
#pragma warning disable 1998
        public async Task Handle(EformRetrieved message)
        {
            try
            {
                sqlController.CaseUpdateRetrived(message.MicrotringUUID);

                sqlController.NotificationUpdate(message.notificationUId, message.MicrotringUUID, Constants.WorkflowStates.Processed, "", "");

                Case_Dto cDto = sqlController.CaseReadByMUId(message.MicrotringUUID);
                log.LogStandard(t.GetMethodName("EformRetrievedHandler"), cDto.ToString() + " has been retrived");
                core.FireHandleCaseRetrived(cDto);
            }
            catch (Exception ex)
            {
                sqlController.NotificationUpdate(message.notificationUId, message.MicrotringUUID, Constants.WorkflowStates.NotFound, ex.Message, ex.StackTrace.ToString());
                Note_Dto note_Dto = new Note_Dto(message.notificationUId, message.MicrotringUUID, Constants.WorkflowStates.NotFound);
                core.FireHandleNotificationNotFound(note_Dto);
            }
        }
Beispiel #8
0
        // DEPRECATION WARNING!!! THIS WILL BE REMOVED IN A LATER VERSION
        #endregion

        #region _caseRetrived
        // DEPRECATION WARNING!!! THIS WILL BE REMOVED IN A LATER VERSION
        private void _caseRetrived(object sender, EventArgs args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"_caseRetrived called ");
            //LogEvent(String.Format("_caseCompleted called"));
            //LogEvent(String.Format("_caseCompleted called inboundPath is : " + inboundPath));
            Case_Dto trigger  = (Case_Dto)sender;
            int      siteId   = trigger.SiteUId;
            string   caseType = trigger.CaseType;
            string   caseUid  = trigger.CaseUId;
            string   mUId     = trigger.MicrotingUId;
            string   checkUId = trigger.CheckUId;
            string   CaseId   = trigger.CaseId.ToString();

            LogEvent("_caseRetrived siteId is :'" + siteId + "'");
            LogEvent("_caseRetrived caseType is :'" + caseType + "'");
            LogEvent("_caseRetrived caseUid is :'" + caseUid + "'");
            LogEvent("_caseRetrived mUId is :'" + mUId + "'");
            LogEvent("_caseRetrived checkUId is :'" + checkUId + "'");
            LogEvent("_caseRetrived CaseId is :'" + CaseId + "'");


            try
            {
                outLook.MarkAppointmentRetrived(CaseId);
            }
            catch (Exception ex)
            {
                LogException("outLook.MarkAppointmentRetrived threw the exception: " + ex.Message);
            }


            //string nav_id = trigger.Custom;

            //string oldPath = inboundPath.Replace("inbound", "parsed") + "\\" + siteId.ToString() + "_" + nav_id + "_" + mUId + ".xml";
            //string newPath = inboundPath.Replace("inbound", "outbound") + "\\" + siteId.ToString() + "_" + nav_id + "_" + mUId + ".xml";
            //LogEvent(String.Format("_caseCompleted called oldPath is : " + oldPath));

            //File.Move(oldPath, newPath);
            //LogEvent(String.Format("_caseCompleted completed for file " + oldPath));
        }
Beispiel #9
0
        public void Core_Case_CaseDeleteResult_DoesMarkCaseRemoved()
        {
            // Arrance
            sites site = new sites();

            site.name          = "SiteName";
            site.microting_uid = 1234;
            DbContext.sites.Add(site);
            DbContext.SaveChanges();

            check_lists cl = new check_lists();

            cl.label = "label";

            DbContext.check_lists.Add(cl);
            DbContext.SaveChanges();

            cases aCase = new cases();

            aCase.microting_uid       = "microting_uid";
            aCase.microting_check_uid = "microting_check_uid";
            aCase.workflow_state      = Constants.WorkflowStates.Created;
            aCase.check_list_id       = cl.id;
            aCase.site_id             = site.id;

            DbContext.cases.Add(aCase);
            DbContext.SaveChanges();

            // Act
            sut.CaseDeleteResult(aCase.id);
            Case_Dto theCase = sut.CaseLookupCaseId(aCase.id);

            // Assert
            Assert.NotNull(theCase);
            Assert.AreEqual(Constants.WorkflowStates.Removed, theCase.WorkflowState);
        }
        private bool CheckStatusByMicrotingUid(string microtingUid)
        {
            List <Case_Dto> lstCase     = new List <Case_Dto>();
            MainElement     mainElement = new MainElement();

            Case_Dto concreteCase = sqlController.CaseReadByMUId(microtingUid);

            log.LogEverything(t.GetMethodName("EformCompletedHandler"), concreteCase.ToString() + " has been matched");

            if (concreteCase.CaseUId == "" || concreteCase.CaseUId == "ReversedCase")
            {
                lstCase.Add(concreteCase);
            }
            else
            {
                lstCase = sqlController.CaseReadByCaseUId(concreteCase.CaseUId);
            }

            foreach (Case_Dto aCase in lstCase)
            {
                if (aCase.SiteUId == concreteCase.SiteUId)
                {
                    #region get response's data and update DB with data
                    string checkIdLastKnown = sqlController.CaseReadLastCheckIdByMicrotingUId(microtingUid); //null if NOT a checkListSite
                    log.LogVariable(t.GetMethodName("EformCompletedHandler"), nameof(checkIdLastKnown), checkIdLastKnown);

                    string respXml;
                    if (checkIdLastKnown == null)
                    {
                        respXml = communicator.Retrieve(microtingUid, concreteCase.SiteUId);
                    }
                    else
                    {
                        respXml = communicator.RetrieveFromId(microtingUid, concreteCase.SiteUId, checkIdLastKnown);
                    }
                    log.LogVariable(t.GetMethodName("EformCompletedHandler"), nameof(respXml), respXml);

                    Response resp = new Response();
                    resp = resp.XmlToClassUsingXmlDocument(respXml);

                    if (resp.Type == Response.ResponseTypes.Success)
                    {
                        log.LogEverything(t.GetMethodName("EformCompletedHandler"), "resp.Type == Response.ResponseTypes.Success (true)");
                        if (resp.Checks.Count > 0)
                        {
                            XmlDocument xDoc = new XmlDocument();

                            xDoc.LoadXml(respXml);
                            XmlNode checks = xDoc.DocumentElement.LastChild;
                            int     i      = 0;
                            foreach (Check check in resp.Checks)
                            {
                                int unitUId = sqlController.UnitRead(int.Parse(check.UnitId)).UnitUId;
                                log.LogVariable(t.GetMethodName("EformCompletedHandler"), nameof(unitUId), unitUId);
                                int workerUId = sqlController.WorkerRead(int.Parse(check.WorkerId)).WorkerUId;
                                log.LogVariable(t.GetMethodName("EformCompletedHandler"), nameof(workerUId), workerUId);

                                List <int> uploadedDataIds = sqlController.ChecksCreate(resp, checks.ChildNodes[i].OuterXml.ToString(), i);

                                foreach (int uploadedDataid in uploadedDataIds)
                                {
                                    if (core.downloadUploadedData(uploadedDataid))
                                    {
                                        core.TranscribeUploadedData(uploadedDataid);
                                    }
                                    else
                                    {
                                        log.LogEverything(t.GetMethodName("Core"), "downloadUploadedData failed for uploadedDataid :" + uploadedDataid.ToString());
                                    }
                                }

                                sqlController.CaseUpdateCompleted(microtingUid, check.Id, DateTime.Parse(check.Date), workerUId, unitUId);
                                log.LogEverything(t.GetMethodName("EformCompletedHandler"), "sqlController.CaseUpdateCompleted(...)");

                                #region IF needed retract case, thereby completing the process
                                if (checkIdLastKnown == null)
                                {
                                    string   responseRetractionXml = communicator.Delete(aCase.MicrotingUId, aCase.SiteUId);
                                    Response respRet = new Response();
                                    respRet = respRet.XmlToClass(respXml);

                                    if (respRet.Type == Response.ResponseTypes.Success)
                                    {
                                        log.LogEverything(t.GetMethodName("EformCompletedHandler"), aCase.ToString() + " has been retracted");
                                    }
                                    else
                                    {
                                        log.LogWarning(t.GetMethodName("EformCompletedHandler"), "Failed to retract eForm MicrotingUId:" + aCase.MicrotingUId + "/SideId:" + aCase.SiteUId + ". Not a critical issue, but needs to be fixed if repeated");
                                    }
                                }
                                #endregion

                                sqlController.CaseRetract(microtingUid, check.Id);
                                log.LogEverything(t.GetMethodName("EformCompletedHandler"), "sqlController.CaseRetract(...)");
                                // TODO add case.id
                                Case_Dto cDto = sqlController.CaseReadByMUId(microtingUid);
                                core.FireHandleCaseCompleted(cDto);
                                log.LogStandard(t.GetMethodName("EformCompletedHandler"), cDto.ToString() + " has been completed");
                                i++;
                            }
                        }
                    }
                    else
                    {
                        log.LogEverything(t.GetMethodName("EformCompletedHandler"), "resp.Type == Response.ResponseTypes.Success (false)");
                        throw new Exception("Failed to retrive eForm " + microtingUid + " from site " + aCase.SiteUId);
                    }
                    #endregion
                }
                else
                {
                    core.CaseDelete(aCase.MicrotingUId);
                }
            }
            return(true);
        }
 public string PackCaseDto(Case_Dto caseDto)
 {
     return(JObject.FromObject(caseDto).ToString());
 }
Beispiel #12
0
        public void EventCaseCompleted(object sender, EventArgs args)
        {
            lock (_lockLogic)
            {
                try
                {
                    Case_Dto trigger  = (Case_Dto)sender;
                    int      siteId   = trigger.SiteUId;
                    string   caseType = trigger.CaseType;
                    string   caseUid  = trigger.CaseUId;
                    string   mUId     = trigger.MicrotingUId;
                    string   checkUId = trigger.CheckUId;


                    //--------------------
                    Random rdn = new Random();

                    #region create offering
                    if (caseType == "Step one")
                    {
                        CoreElement reply = core.CaseRead(mUId, checkUId);

                        CheckListValue replyDataE = (CheckListValue)reply.ElementList[0];
                        FieldValue     answer     = (FieldValue)replyDataE.DataItemList[0];

                        MainElement mainElement = core.TemplateRead(step2tId);
                        DataElement dataE       = (DataElement)mainElement.ElementList[0];
                        None        none        = (None)dataE.DataItemList[0];


                        none.Label                  = "Container with stat:" + answer.Value + " is ready for collection";
                        none.Description            = new CDataValue();
                        none.Description.InderValue = DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString();


                        foreach (int siteIdTemp in siteIdsSA)
                        {
                            core.CaseCreate(mainElement, "", siteIdTemp);
                        }
                    }
                    #endregion

                    #region create replies (winner/others)
                    if (caseType == "Step two")
                    {
                        #region is the first?
                        bool isFirst = false;
                        int  found   = 0;
                        try
                        {
                            List <Case_Dto> lst = core.CaseLookupCaseUId(caseUid);

                            foreach (var item in lst)
                            {
                                if (item.Stat == "Completed")
                                {
                                    found++;
                                }
                            }

                            if (found == 1)
                            {
                                isFirst = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("isFirst failed", ex);
                        }
                        #endregion

                        if (isFirst)
                        {
                            #region send win eForm
                            CoreElement reply = core.CaseRead(mUId, checkUId);

                            DataElement replyDataE = (DataElement)reply.ElementList[0];
                            FieldValue  answer     = (FieldValue)replyDataE.DataItemList[0];

                            MainElement mainElement = core.TemplateRead(step3WtId);
                            DataElement dataE       = (DataElement)mainElement.ElementList[0];
                            Date        date        = (Date)dataE.DataItemList[0];

                            dataE.Description            = new CDataValue();
                            dataE.Description.InderValue = DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString();

                            date.MinValue     = DateTime.Now;
                            date.MaxValue     = DateTime.Now.AddDays(1);
                            date.DefaultValue = DateTime.Now.AddMinutes(1).ToString("u");


                            core.CaseCreate(mainElement, "", siteId);
                            #endregion
                        }
                        else
                        {
                            #region send loss eForm
                            CoreElement reply = core.CaseRead(mUId, checkUId);

                            DataElement replyDataE = (DataElement)reply.ElementList[0];
                            FieldValue  answer     = (FieldValue)replyDataE.DataItemList[0];

                            MainElement mainElement = core.TemplateRead(step3LtId);
                            DataElement dataE       = (DataElement)mainElement.ElementList[0];
                            None        none        = (None)dataE.DataItemList[0];

                            none.Description            = new CDataValue();
                            none.Description.InderValue = "Collection missed at:" + DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString();


                            core.CaseCreate(mainElement, "", siteId);
                            #endregion
                        }
                    }
                    #endregion

                    #region final step
                    if (caseType == "Step three")
                    {
                        CoreElement reply = core.CaseRead(mUId, checkUId);

                        DataElement replyDataE = (DataElement)reply.ElementList[0];
                        FieldValue  answer     = (FieldValue)replyDataE.DataItemList[0];

                        #region is the winner?
                        bool isWinner = false;
                        try
                        {
                            if (replyDataE.Label == "Won - Container collection")
                            {
                                isWinner = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("isWinner failed", ex);
                        }
                        #endregion

                        if (isWinner)
                        {
                            MainElement mainElement = core.TemplateRead(step4tId);
                            DataElement dataE       = (DataElement)mainElement.ElementList[0];
                            None        none        = (None)dataE.DataItemList[0];

                            none.Label = "Container collect at:" + answer.Value;

                            foreach (int siteIdTemp in siteIdsDW)
                            {
                                core.CaseCreate(mainElement, "", siteIdTemp);
                            }
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    EventMessage(ex.ToString(), EventArgs.Empty);
                }
            }
        }