コード例 #1
0
        public override void DoWork()
        {
            try
            {
                //TODO: do some clean-up for very old import/export jobs/logs

                var job = EntitiesController.Instance.GetFirstActiveJob();
                if (job == null)
                {
                    ScheduleHistoryItem.Succeeded = true;
                    ScheduleHistoryItem.AddLogNote("<br/>No Site Export/Import jobs queued for processing.");
                }
                else if (job.IsCancelled)
                {
                    job.JobStatus = JobStatus.Cancelled;
                    EntitiesController.Instance.UpdateJobStatus(job);
                    ScheduleHistoryItem.Succeeded = true;
                    ScheduleHistoryItem.AddLogNote("<br/>Site Export/Import jobs was previously cancelled.");
                }
                else
                {
                    job.JobStatus = JobStatus.InProgress;
                    EntitiesController.Instance.UpdateJobStatus(job);
                    var result = new ExportImportResult
                    {
                        JobId = job.JobId,
                    };
                    var engine    = new ExportImportEngine();
                    var succeeded = true;

                    switch (job.JobType)
                    {
                    case JobType.Export:
                        try
                        {
                            engine.Export(job, result, ScheduleHistoryItem);
                        }
                        catch (Exception ex)
                        {
                            result.AddLogEntry("EXCEPTION exporting job #" + job.JobId, ex.Message, ReportLevel.Error);
                            engine.AddLogsToDatabase(job.JobId, result.CompleteLog);
                            throw;
                        }
                        EntitiesController.Instance.UpdateJobStatus(job);
                        break;

                    case JobType.Import:
                        try
                        {
                            engine.Import(job, result, ScheduleHistoryItem);
                        }
                        catch (ThreadAbortException)
                        {
                            ScheduleHistoryItem.TimeLapse                 = EmergencyScheduleFrequency;
                            ScheduleHistoryItem.TimeLapseMeasurement      = EmergencyScheduleFrequencyUnit;
                            ScheduleHistoryItem.RetryTimeLapse            = EmergencyScheduleRetry;
                            ScheduleHistoryItem.RetryTimeLapseMeasurement = EmergencyScheduleRetryUnit;
                            ScheduleHistoryItem.RetainHistoryNum          = EmergencyHistoryNumber;

                            SchedulingController.UpdateSchedule(ScheduleHistoryItem);

                            SchedulingController.PurgeScheduleHistory();

                            Logger.Error("The Schduler item stopped because main thread stopped, set schedule into emergency mode so it will start after app restart.");
                            succeeded = false;
                        }
                        catch (Exception ex)
                        {
                            result.AddLogEntry("EXCEPTION importing job #" + job.JobId, ex.Message, ReportLevel.Error);
                            engine.AddLogsToDatabase(job.JobId, result.CompleteLog);
                            throw;
                        }
                        EntitiesController.Instance.UpdateJobStatus(job);
                        if (job.JobStatus == JobStatus.Successful || job.JobStatus == JobStatus.Cancelled)
                        {
                            // clear everything to be sure imported items take effect
                            DataCache.ClearCache();
                        }
                        break;

                    default:
                        throw new Exception("Unknown job type: " + job.JobType);
                    }

                    ScheduleHistoryItem.Succeeded = true;

                    //restore schedule item running timelapse to default.
                    if (succeeded &&
                        ScheduleHistoryItem.TimeLapse == EmergencyScheduleFrequency &&
                        ScheduleHistoryItem.TimeLapseMeasurement == EmergencyScheduleFrequencyUnit)
                    {
                        ScheduleHistoryItem.TimeLapse                 = DefaultScheduleFrequency;
                        ScheduleHistoryItem.TimeLapseMeasurement      = DefaultScheduleFrequencyUnit;
                        ScheduleHistoryItem.RetryTimeLapse            = DefaultScheduleRetry;
                        ScheduleHistoryItem.RetryTimeLapseMeasurement = DefaultScheduleRetryUnit;
                        ScheduleHistoryItem.RetainHistoryNum          = DefaultHistoryNumber;

                        SchedulingController.UpdateSchedule(ScheduleHistoryItem);
                    }

                    var sb        = new StringBuilder();
                    var jobType   = Localization.GetString("JobType_" + job.JobType, Constants.SharedResources);
                    var jobStatus = Localization.GetString("JobStatus_" + job.JobStatus, Constants.SharedResources);
                    sb.AppendFormat("<br/><b>{0} {1}</b>", jobType, jobStatus);
                    var summary = result.Summary;
                    if (summary.Count > 0)
                    {
                        sb.Append("<br/><b>Summary:</b><ul>");
                        foreach (var entry in summary)
                        {
                            sb.Append($"<li>{entry.Name}: {entry.Value}</li>");
                        }
                        sb.Append("</ul>");
                    }

                    ScheduleHistoryItem.AddLogNote(sb.ToString());
                    engine.AddLogsToDatabase(job.JobId, result.CompleteLog);

                    Logger.Trace("Site Export/Import: Job Finished");
                }
                //SetLastSuccessfulIndexingDateTime(ScheduleHistoryItem.ScheduleID, ScheduleHistoryItem.StartDate);
            }
            catch (Exception ex)
            {
                ScheduleHistoryItem.Succeeded = false;
                ScheduleHistoryItem.AddLogNote("<br/>Export/Import EXCEPTION: " + ex.Message);
                Errored(ref ex);
                // this duplicates the logging
                //if (ScheduleHistoryItem.ScheduleSource != ScheduleSource.STARTED_FROM_BEGIN_REQUEST)
                //{
                //    Exceptions.LogException(ex);
                //}
            }
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ClearHeaders();
            context.Response.ClearContent();
            context.Response.Clear();
            context.Response.ContentType = "text/calendar";
            int eventId   = Int32.Parse(context.Request.QueryString["EventId"]);
            int companyId = Int32.Parse(context.Request.QueryString["CompanyId"]);

            SchedulingController controller = new SchedulingController();
            SchedulingEntity     scheduling = controller.GetSchedulingCompany(companyId, eventId).FirstOrDefault();

            if (scheduling != null)
            {
                string description = "Informações: " + scheduling.Comments + Environment.NewLine + Environment.NewLine;
                description += description += "Pet: " + scheduling.Pet + Environment.NewLine;
                description += "Sexo: " + (scheduling.Pet.Sex == EnumSex.Male ? "M" : "F") + Environment.NewLine;
                description += "Tamanho: " + scheduling.Pet.Size + Environment.NewLine;
                description += "Raça: " + scheduling.Pet.Breed != null
                    ? scheduling.Pet.Breed.SubSpecies + " | " + scheduling.Pet.Breed.Name
                    : scheduling.Pet.SubSpecies.ToString();
                if (scheduling.Pet.Breed != null || scheduling.Pet.Breed.UrlReference != null)
                {
                    description += Environment.NewLine + "Informações da Raça: " + scheduling.Pet.Breed.UrlReference;
                }
                description += Environment.NewLine + Environment.NewLine;

                description += "Endereço: " + scheduling.Address + Environment.NewLine;
                if (scheduling.Service != null)
                {
                    description += "Serviço: " + scheduling.Service.Name + Environment.NewLine;
                }
                else
                {
                    description += "Serviço: Nenhum selecionado" + Environment.NewLine;
                }
                if (scheduling.Employee != null)
                {
                    description += "Funcionário: " + scheduling.Employee.User.Name + Environment.NewLine;
                }
                else
                {
                    description += "Funcionário: Nenhum Funcionário de preferencia" + Environment.NewLine;
                }



                //http://stackoverflow.com/questions/30661839/generate-and-send-ical-event-to-outlook
                Calendar iCal = new Calendar
                {
                    Method  = "PUBLISH",
                    Version = "2.0"
                };
                Event calendarEvent = iCal.Create <Event>();
                calendarEvent.Summary     = scheduling.Company.Name + " (" + scheduling.Pet.Name + ")";
                calendarEvent.Start       = new CalDateTime(scheduling.DateStart);
                calendarEvent.End         = new CalDateTime(scheduling.DateEnd);
                calendarEvent.Status      = EventStatus.Confirmed;
                calendarEvent.Description = description;
                calendarEvent.Location    = scheduling.Address.ToString();
                calendarEvent.IsAllDay    = false;
                calendarEvent.Uid         = Guid.NewGuid().ToString();
                calendarEvent.Organizer   = scheduling.Company.Email != null
                    ? new Organizer(scheduling.Company.Email)
                    : new Organizer("*****@*****.**");
                calendarEvent.Url = new Uri("http://pet.afonsoft.com.br");
                calendarEvent.Categories.Add("PetShop");

                foreach (var companyPhone in scheduling.Company.Phones)
                {
                    calendarEvent.Contacts.Add(companyPhone.ToString());
                }
                calendarEvent.Comments.Add("Calendário gerado automátio pelo sistema.");
                calendarEvent.Comments.Add("Favor não alteraro ou responde-lo.");

                CalendarSerializer serializer = new CalendarSerializer(iCal);
                string             eventCode  = serializer.SerializeToString(iCal);
                context.Response.Write(eventCode);
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            TalkController       talkController       = new TalkController();
            SchedulingController schedulingController = new SchedulingController();
            int numberSelected = 0;

            Console.WriteLine("Welcome to CONFERENCE TRACK MANAGEMENT");
            Console.WriteLine("");
            while (numberSelected != 9)
            {
                Console.WriteLine("");
                Console.WriteLine("------------------------------------------------------------------------------");
                Console.WriteLine("Select an option:");
                Console.WriteLine("1 - Create default talks");
                Console.WriteLine("2 - Scheduling talks");
                Console.WriteLine("3 - Add talk");
                Console.WriteLine("4 - List all Talks");
                Console.WriteLine("9 - Exit");
                Console.WriteLine("------------------------------------------------------------------------------");
                string optionSelected = Console.ReadLine();
                if (int.TryParse(optionSelected, out numberSelected))
                {
                    switch (numberSelected)
                    {
                    case 1:
                        Console.Clear();
                        talkController.CreateDefaultTalks();
                        Console.WriteLine("Default talk were created successfully.");
                        break;

                    case 2:
                        try
                        {
                            Console.Clear();
                            Console.WriteLine("Which date start the conference? (YYYY/MM/DD)");
                            string   firstDayConferenceString = Console.ReadLine();
                            DateTime firstDayConference       = new DateTime();
                            //validate date format
                            if (DateTime.TryParse(firstDayConferenceString, out firstDayConference))
                            {
                                Console.WriteLine("Building Scheduling...");
                                //get the best scheduling
                                List <Track> bestTrackList = schedulingController.ScheduleTalks(firstDayConference);
                                Console.Clear();
                                Console.WriteLine("This is the best scheduling of talks.");
                                Console.WriteLine("");
                                foreach (Track track in bestTrackList)
                                {
                                    Console.WriteLine("--------------" + track.Title + "--------------");
                                    Console.WriteLine("");
                                    foreach (Session session in track.SessionList)
                                    {
                                        Console.WriteLine("--------------" + session.Title + "--------------");
                                        Console.WriteLine("");
                                        foreach (Scheduling scheduling in session.SchedulingList)
                                        {
                                            Console.WriteLine(scheduling.StartHour.ToString("HH:mm") + "-" + scheduling.EndHour.ToString("HH:mm") + " > " + scheduling.Talk.Title + ", " + scheduling.Talk.Duration + " MIN");
                                        }
                                        Console.WriteLine("");
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Invalid date! Please write a date in format YYYY/MM/DD");
                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.Message);
                            Console.WriteLine("");
                            Console.WriteLine("Please try again.");
                        }
                        break;

                    case 3:
                        Talk talk = new Talk();
                        Console.Clear();
                        Console.WriteLine("Add a talk");
                        Console.WriteLine("Add a title to your talk: ");
                        talk.Title = Console.ReadLine();

                        Console.WriteLine("Is lightining talk? (1-Yes, 2-No) ");
                        string isLightiningString = Console.ReadLine();
                        while (!(isLightiningString == "1" || isLightiningString == "2"))
                        {
                            Console.WriteLine("Invalid value! Please write 1 to YES or 2 to NO.");
                            Console.WriteLine("Is lightining talk? (1-Yes, 2-No) ");
                            isLightiningString = Console.ReadLine();
                        }

                        if (isLightiningString == "1" ? true : false)
                        {
                            talk.IsLightning = true;
                            talk.Duration    = 5;
                        }
                        else
                        {
                            Console.WriteLine("Add a time, in minutes, to your talk: ");
                            string time = Console.ReadLine();
                            int    timeInt;
                            while (!int.TryParse(time, out timeInt) || (timeInt > 180))
                            {
                                Console.WriteLine("Invalid time! Please write a time only with numbers and lenght max 180 minutes.");
                                Console.WriteLine("Add in minutes a time to your talk: ");
                                time = Console.ReadLine();
                            }
                            talk.IsLightning = false;
                            talk.Duration    = timeInt;
                        }
                        try
                        {
                            if (talkController.AddTalk(talk))
                            {
                                Console.Clear();
                                Console.WriteLine("Talk add successfuly.");
                            }
                        }
                        catch (Exception talkException)
                        {
                            Console.Clear();
                            Console.WriteLine(talkException.Message);
                        }
                        break;

                    case 4:
                        List <Talk> talkList = talkController.ListAllTalks();
                        Console.Clear();
                        Console.WriteLine("List of talks");
                        Console.WriteLine("");
                        foreach (Talk talkObject in talkList)
                        {
                            Console.WriteLine(talkObject.Title + " - " + talkObject.Duration);
                        }
                        Console.WriteLine("----------------------------------------------------------------------");
                        Console.WriteLine(talkList.Count + " talks listed.");
                        Console.WriteLine("");
                        break;

                    default:
                        Console.WriteLine("Command not found.");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You need write a valid number.");
                }
            }
        }