#pragma warning disable 1998
        public async Task Handle(EformCompleted message)
        {
            Appointment appo = sqlController.AppointmentFindByCaseId(message.caseId);

            outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, ProcessingStateOptions.Completed, appo.Body);
            sqlController.AppointmentsUpdate(appo.GlobalId, ProcessingStateOptions.Completed, appo.Body, "", "", true, appo.Start, appo.End, appo.Duration);
            sqlController.AppointmentSiteUpdate((int)appo.AppointmentSites.First().Id, message.caseId, ProcessingStateOptions.Completed);
        }
#pragma warning disable 1998
        public async Task Handle(EformCompleted message)
        {
            Appointment appo = Appointment.AppointmentFindByCaseId(_dbContext, message.caseId);

            outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, Appointment.ProcessingStateOptions.Completed, appo.Body);
            Appointment.AppointmentsUpdate(_dbContext, appo.GlobalId, Appointment.ProcessingStateOptions.Completed, appo.Body, "", "", true, appo.Start, appo.End, appo.Duration);
            AppointmentSite appointmentSite = new AppointmentSite()
            {
                Id              = (int)appo.AppointmentSites.First().Id,
                SdkCaseId       = message.caseId,
                ProcessingState = Constants.ProcessingState.Completed
            };

            await appointmentSite.Update(_dbContext);
        }
예제 #3
0
#pragma warning disable 1998
        public async Task Handle(ParseOutlookItem message)
        {
            //#region processingState "planned"?
            string processingState = null;

            try
            {
                processingState = message.Item.Location.DisplayName;
            }
            catch { }


            if (string.IsNullOrEmpty(processingState))
            {
                if (includeBlankLocations)
                {
                    processingState = "planned";
                }
                else
                {
                    processingState = "";
                }
            }

            processingState = processingState.ToLower();
            //#endregion

            //if (processingState.ToLower() == "planned")
            //#region planned
            //{
            log.LogVariable("Not Specified", nameof(processingState), processingState);

            if (message.Item.BodyPreview != null)
            {
                if (message.Item.BodyPreview.Contains("<<< "))
                {
                    if (message.Item.BodyPreview.Contains("End >>>"))
                    {
                        message.Item.BodyPreview = t.ReplaceAtLocationAll(message.Item.BodyPreview, "<<< ", "End >>>", "", true);
                        message.Item.BodyPreview = message.Item.BodyPreview.Replace("<<< End >>>", "");
                        message.Item.BodyPreview = message.Item.BodyPreview.Trim();
                    }
                }
            }

            log.LogStandard("Not Specified", "Trying to do UpdateEvent on item.Id:" + message.Item.Id + " to have new location location : " + processingState);
            Event updatedItem = outlookExchangeOnlineAPIClient.UpdateEvent(userEmailAddess, message.Item.Id, "{\"Location\": {\"DisplayName\": \"" + processingState + "\"},\"Body\": {\"ContentType\": \"HTML\",\"Content\": \"" + ReplaceLinesInBody(message.Item.BodyPreview) + "\"}}");

            //if (updatedItem == null)
            //{
            //    return false;
            //}

            log.LogStandard("Not Specified", "Trying create new appointment for item.Id : " + message.Item.Id + " and the UpdateEvent returned Updateditem: " + updatedItem.ToString());

            Appointment appo;
            int         appoId = 0;

            appo = sqlController.AppointmentsFind(message.Item.Id);
            if (appo == null)
            {
                appo = new Appointment(message.Item.Id, message.Item.Start.DateTime, (message.Item.End.DateTime - message.Item.Start.DateTime).Minutes, message.Item.Subject, "planned", updatedItem.BodyPreview, t.Bool(sqlController.SettingRead(Settings.colorsRule)), null);
                appo.ParseBodyContent(sdkCore);
                appoId = sqlController.AppointmentsCreate(appo);
            }

            //log.LogStandard("Not Specified", "Before calling CalendarItemIntrepret.AppointmentsCreate");
            //log.LogStandard("Not Specified", "After calling CalendarItemIntrepret.AppointmentsCreate");

            if (appoId > 0)
            {
                log.LogStandard("Not Specified", "Appointment created successfully for item.Id : " + message.Item.Id);
                outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, ProcessingStateOptions.Processed, appo.Body);
                bus.SendLocal(new AppointmentCreatedInOutlook(appo)).Wait();
            }
            else
            {
                if (appoId == 0)
                {
                    outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, ProcessingStateOptions.Exception, appo.Body);
                }
                if (appoId == -1)
                {
                    log.LogStandard("Not Specified", "Appointment not created successfully for item.Id : " + message.Item.Id);

                    #region appo.Body = 'text'
                    appo.Body = "<<< Parsing error: Start >>>" +
                                Environment.NewLine + "Global ID already exists in the database." +
                                Environment.NewLine + "Indicating that this appointment has already been created." +
                                Environment.NewLine + "Likely course, is that you set the Appointment’s location to 'planned'/[blank] again." +
                                Environment.NewLine + "" +
                                Environment.NewLine + "If you wanted to a create a new appointment in the calendar:" +
                                Environment.NewLine + "- Create a new appointment in the calendar" +
                                Environment.NewLine + "- Create or copy the wanted details to the new appointment" +
                                Environment.NewLine + "" +
                                Environment.NewLine + "Item.Id :" + message.Item.Id +
                                Environment.NewLine + "<<< Parsing error: End >>>" +
                                Environment.NewLine + "" +
                                Environment.NewLine + appo.Body;
                    #endregion
                    outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, ProcessingStateOptions.ParsingFailed, appo.Body);
                }
            }

            //AllParsed = true;
            //}
            //#endregion

            //if (processingState.ToLower() == "cancel")
            //#region cancel
            //{
            //    log.LogVariable("Not Specified", nameof(processingState), processingState);

            //    Appointment appo = new Appointment(message.Item.Id, message.Item.Start.DateTime, (message.Item.End.DateTime - message.Item.Start.DateTime).Minutes, message.Item.Subject, message.Item.Location.DisplayName, ReplaceLinesInBody(message.Item.BodyPreview), t.Bool(sqlController.SettingRead(Settings.colorsRule)), true, null);

            //    if (sqlController.AppointmentsCancel(appo.GlobalId))
            //        outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, ProcessingStateOptions.Canceled, appo.Body);
            //    else
            //        outlookOnlineController.CalendarItemUpdate(appo.GlobalId, appo.Start, ProcessingStateOptions.ParsingFailed, appo.Body);

            //    //AllParsed = true;
            //}
            //#endregion

            //if (processingState.ToLower() == "processed")
            //#region processed
            //{
            //    Appointment appo = sqlController.AppointmentsFind(message.Item.Id);

            //    log.LogStandard("Not Specified", "ParseCalendarItems appo start is : " + appo.Start.ToString());
            //    log.LogStandard("Not Specified", "ParseCalendarItems item start is : " + message.Item.Start.DateTime.ToString());
            //    log.LogStandard("Not Specified", "ParseCalendarItems appo end is : " + appo.End.ToString());
            //    log.LogStandard("Not Specified", "ParseCalendarItems item end is : " + message.Item.End.DateTime.ToString());
            //    if (appo.Start != message.Item.Start.DateTime)
            //    {
            //        log.LogStandard("Not Specified", "ParseCalendarItems updating calendar entry with globalId : " + appo.GlobalId);
            //        sqlController.AppointmentsUpdate(appo.GlobalId, ProcessingStateOptions.Processed, appo.Body, "", "", appo.Completed, message.Item.Start.DateTime, message.Item.End.DateTime, (message.Item.End.DateTime - message.Item.Start.DateTime).Minutes);
            //    }
            //}
            //#endregion
        }
#pragma warning disable 1998
        public async Task Handle(AppointmentCreatedInOutlook message)
        {
            try
            {
                Appointment Appo = sqlController.AppointmentsFind(message.Appo.GlobalId);

                if (Appo.ProcessingState == ProcessingStateOptions.Processed.ToString())
                {
                    bool sqlUpdate = sqlController.AppointmentsUpdate(Appo.GlobalId, ProcessingStateOptions.Created, Appo.Body, "", "", Appo.Completed, Appo.Start, Appo.End, Appo.Duration);
                    if (sqlUpdate)
                    {
                        bool updateStatus = outlookOnlineController.CalendarItemUpdate(Appo.GlobalId, (DateTime)Appo.Start, ProcessingStateOptions.Created, Appo.Body);
                    }
                    else
                    {
                        throw new Exception("Unable to update Appointment in AppointmentCreatedInOutlookHandler");
                    }
                    //log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L623");
                }

                eFormData.MainElement mainElement = sdkCore.TemplateRead((int)Appo.TemplateId);
                if (mainElement == null)
                {
                    log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L625 mainElement is NULL!!!");
                }

                mainElement.Repeated = 1;
                DateTime startDt = new DateTime(Appo.Start.Year, Appo.Start.Month, Appo.Start.Day, 0, 0, 0);
                DateTime endDt   = new DateTime(Appo.End.AddDays(1).Year, Appo.End.AddDays(1).Month, Appo.End.AddDays(1).Day, 23, 59, 59);
                //mainElement.StartDate = ((DateTime)appo.Start).ToUniversalTime();
                mainElement.StartDate = startDt;
                //mainElement.EndDate = ((DateTime)appo.End.AddDays(1)).ToUniversalTime();
                mainElement.EndDate = endDt;
                //log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L629");

                #region fill eForm
                if (Appo.AppointmentPrefillFieldValues.Count > 0)
                {
                    SetDefaultValue(mainElement.ElementList, Appo.AppointmentPrefillFieldValues);
                    string description = "";
                    foreach (AppointmentPrefillFieldValue pfv in Appo.AppointmentPrefillFieldValues)
                    {
                        eFormData.Field field      = sdkCore.Advanced_FieldRead(pfv.FieldId);
                        string          fieldValue = pfv.FieldValue;
                        if (field.FieldType == eFormShared.Constants.FieldTypes.EntitySelect)
                        {
                            fieldValue = sdkCore.EntityItemReadByMicrotingUUID(pfv.FieldValue).Name;
                        }
                        description = description + "<b>" + field.Label + ":</b> " + fieldValue + "<br>";
                    }
                    eFormShared.CDataValue cDataValue = new eFormShared.CDataValue();
                    cDataValue.InderValue = description;
                    mainElement.ElementList[0].Description = cDataValue;
                }
                #endregion


                log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() StartDate is " + mainElement.StartDate);
                log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() EndDate is " + mainElement.EndDate);
                bool allGood = false;
                List <AppoinntmentSite> appoSites = Appo.AppointmentSites;
                if (appoSites == null)
                {
                    log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L635 appoSites is NULL!!! for appo.GlobalId" + Appo.GlobalId);
                }
                else
                {
                    foreach (AppoinntmentSite appo_site in appoSites)
                    {
                        log.LogEverything("Not Specified", "outlookController.foreach AppoinntmentSite appo_site is : " + appo_site.MicrotingSiteUid);
                        string resultId;
                        if (appo_site.MicrotingUuId == null)
                        {
                            resultId = sdkCore.CaseCreate(mainElement, "", appo_site.MicrotingSiteUid);
                            log.LogEverything("Not Specified", "outlookController.foreach resultId is : " + resultId);
                        }
                        else
                        {
                            resultId = appo_site.MicrotingUuId;
                        }

                        if (!string.IsNullOrEmpty(resultId))
                        {
                            int localCaseId = (int)sdkCore.CaseLookupMUId(resultId).CaseId;
                            //appo_site.MicrotingUuId = resultId;
                            sqlController.AppointmentSiteUpdate((int)appo_site.Id, localCaseId.ToString(), ProcessingStateOptions.Sent);
                            allGood = true;
                        }
                        else
                        {
                            log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L656");
                            allGood = false;
                        }
                    }

                    if (allGood)
                    {
                        //log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L663");
                        bool updateStatus = outlookOnlineController.CalendarItemUpdate(Appo.GlobalId, (DateTime)Appo.Start, ProcessingStateOptions.Sent, Appo.Body);
                        if (updateStatus)
                        {
                            //log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L667");
                            sqlController.AppointmentsUpdate(Appo.GlobalId, ProcessingStateOptions.Sent, Appo.Body, "", "", Appo.Completed, Appo.Start, Appo.End, Appo.Duration);
                        }
                    }
                    else
                    {
                        //log.LogEverything("Not Specified", "outlookController.SyncAppointmentsToSdk() L673");
                        //syncAppointmentsToSdkRunning = false;
                    }
                }
                //}
            }
            catch (Exception ex)
            {
                log.LogEverything("Exception", "Got the following exception : " + ex.Message + " and stacktrace is : " + ex.StackTrace);
                throw ex;
            }
        }