public void LogEventEntry(string desc, EventLogEntryType type) { // Write an informational entry to the event log. if (desc.Length > 32700) { evtLog.WriteEntry(desc.Substring(0, 32700), type, SequentialNumber.GetNextNumber()); } else { evtLog.WriteEntry(desc, type, SequentialNumber.GetNextNumber()); } }
protected override bool synchronizeDataBase(HostUrl hostUrl) { //called in sendJoinRequest() to get the latest appointments from the known host if (this.setDestinationHost(hostUrl)) { Date lmDate = new Date(); lmDate.resetTime(); if (calendar.getLastModified() != null) { lmDate = calendar.getLastModified(); } //Object[] params = new Object[]{dates}; host.MethodName = "Calendar.syncRequest"; host.Params.Clear(); host.Params.Add(lmDate.ToString()); try { Console.WriteLine("Appointments Syncronization has started ...."); response = host.Send(hostUrlAddress); String appointmentLists = (String)response.Value; if (appointmentLists == null) { Console.WriteLine("There is no appointment for synchronization."); } else { String[] lines = appointmentLists.Split("\n".ToCharArray()); Regex regex = null; Match matcher = null; //Set the main seqnum at the current machine! if (lines.Length > 0) { try { regex = new Regex("SequentialNum:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[0]); if (matcher.Success) { String mainSeqNumString = matcher.Groups[1].Value; SequentialNumber.setNextSequentialNumber(Integer.parseInt(mainSeqNumString)); Console.WriteLine("The sequential number has been synchronized successfully."); } else { Console.WriteLine("Couldn't synchronize the sequential number."); } } catch (Exception e) { Console.WriteLine("Couldn't synchronize the sequential number."); Console.WriteLine(e.Message); } } calendar.clearAllAppointments(); String seqNum, header, date, time, duration, comment; int counter = 0; int counterFailed = 0; for (int index = 1; index < lines.Length; index++) { try { seqNum = null; header = null; date = null; time = null; duration = null; comment = null; // regex = new Regex("SeqNum:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[index]); if (matcher.Success) { seqNum = matcher.Groups[1].Value; } // regex = new Regex("Header:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[index]); if (matcher.Success) { header = matcher.Groups[1].Value; } // regex = new Regex("Date:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[index]); if (matcher.Success) { date = matcher.Groups[1].Value; } // regex = new Regex("Time:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[index]); if (matcher.Success) { time = matcher.Groups[1].Value; } // regex = new Regex("Duration:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[index]); if (matcher.Success) { duration = matcher.Groups[1].Value; } // regex = new Regex("Comment:&@\\[(.*?)\\]#!"); matcher = regex.Match(lines[index]); if (matcher.Success) { comment = matcher.Groups[1].Value; } if (seqNum != null && header != null && date != null && time != null && duration != null && comment != null) { Integer seqNumber = new Integer(seqNum); Integer secDuration = new Integer(duration); Date dateTime = new Date(date + " " + time, DateString.Format); SequentialNumber sqn = new SequentialNumber(seqNumber.intValue()); Appointment appointment = new Appointment(sqn, dateTime, secDuration.intValue(), header, comment); calendar.addAppointment(appointment); counter++; } } catch (Exception) { counterFailed++; } }//end for if (counterFailed > 0) { Console.WriteLine(counterFailed + " numbers of the received appointment in synchronization has failed to add."); } if (counter == 1) { Console.WriteLine("The appointment list has been updated.\n" + counter + " appointment has been added or updated."); } else if (counter > 1) { Console.WriteLine("The appointment list has been updated.\n" + counter + " appointments have been added or updated."); } }//end if } catch (Exception e) { Console.WriteLine(e.Message); } } return(false); }