Exemplo n.º 1
0
        public int SendAppoinments()
        {
            // string[] rooms = ScheduleUpdateController.GetWatchingRooms();

            int        sentCount = 0;
            ITransport transport = TransportFactory.Transport;

            foreach (RoomConfig room in RoomConfigurations.Values)
            {
                try
                {
                    ScheduleData roomSchedule = ExchangeHelper.LoadResouceCallendar(room.Location);
                    if (roomSchedule != null && roomSchedule.Schedule != null)
                    {
                        transport.SendAppointments(roomSchedule, room);
                        sentCount += roomSchedule.Schedule.Length;
                        Console.Out.WriteLine("Sucessfully sent {0} appointments for the room {1}", new object[] { roomSchedule.Schedule.Length, room.Location });
                    }
                    else
                    {
                        Console.Out.WriteLine("Nothing sent for the room {0}", room.Location);
                    }
                }catch (Exception ex)
                {
                    Console.Out.WriteLine(String.Format("Error {0} sending data for room {1}", new object[] { ex.Message, room.Location }));
                }
            }

            return(sentCount);
        }
        static void WriteAppointments(XmlTextWriter xmlWriter)
        {
            string[] rooms = GetWatchingRooms();

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("Appointments");
            xmlWriter.WriteElementString("ImportTime", DateTime.Now.ToString());

            isError = false;

            foreach (string room in rooms)
            {
                try
                {
                    data.ScheduleData roomAppointments = ExchangeHelper.LoadResouceCallendar(room);
                    WriteRoomXml(roomAppointments, xmlWriter);
                }
                catch (Exception ex)
                {
                    isError = true; // Set error flag to prevent caching
                    Trace.TraceError("Error writing appointments for room {0} ErrMsg: {1}", room, ex.Message);
                    xmlWriter.WriteStartElement("Error");
                    xmlWriter.WriteAttributeString("Room", room);
                    xmlWriter.WriteStartElement("Message", ex.Message);
                    xmlWriter.WriteStartElement("Trace");
                    xmlWriter.WriteCData(ex.StackTrace);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                }
            }

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
        }