예제 #1
0
파일: Schedule.cs 프로젝트: afrog33k/eAd
 private void xmds2_ScheduleCompleted(object sender, ScheduleCompletedEventArgs e)
 {
     this._xmdsProcessing = false;
     if (e.Error != null)
     {
         Trace.WriteLine(e.Error.Message);
     }
     else
     {
         lock (ScheduleWriteLock)
         {
             string str = "";
             Settings.Default.XmdsLastConnection = DateTime.Now;
             XmlSerializer serializer = new XmlSerializer(typeof(ScheduleModel));
             MemoryStream  stream     = new MemoryStream();
             serializer.Serialize((Stream)stream, e.Result);
             string str2 = Hashes.MD5(Encoding.UTF8.GetString(stream.ToArray()));
             try
             {
                 StreamReader reader =
                     new StreamReader(File.Open(this._scheduleLocation, FileMode.Open, FileAccess.ReadWrite,
                                                FileShare.ReadWrite));
                 str = Hashes.MD5(reader.ReadToEnd());
                 reader.Close();
                 if (str == str2)
                 {
                     return;
                 }
             }
             catch (Exception)
             {
             }
             FileStream stream2 = File.OpenWrite(this._scheduleLocation);
             byte[]     buffer  = stream.ToArray();
             stream2.Write(buffer, 0, buffer.Length);
             stream2.Close();
             stream.Close();
             this._scheduleManager.RefreshSchedule = true;
         }
     }
 }
예제 #2
0
파일: Schedule.cs 프로젝트: afrog33k/eAd
 private void xmds2_ScheduleCompleted(object sender, ScheduleCompletedEventArgs e)
 {
     this._xmdsProcessing = false;
     if (e.Error != null)
     {
         Trace.WriteLine(e.Error.Message);
     }
     else
     {
         lock (ScheduleWriteLock)
         {
             string str = "";
             Settings.Default.XmdsLastConnection = DateTime.Now;
             XmlSerializer serializer = new XmlSerializer(typeof (ScheduleModel));
             MemoryStream stream = new MemoryStream();
             serializer.Serialize((Stream) stream, e.Result);
             string str2 = Hashes.MD5(Encoding.UTF8.GetString(stream.ToArray()));
             try
             {
                 StreamReader reader =
                     new StreamReader(File.Open(this._scheduleLocation, FileMode.Open, FileAccess.ReadWrite,
                                                FileShare.ReadWrite));
                 str = Hashes.MD5(reader.ReadToEnd());
                 reader.Close();
                 if (str == str2)
                 {
                     return;
                 }
             }
             catch (Exception)
             {
             }
             FileStream stream2 = File.OpenWrite(this._scheduleLocation);
             byte[] buffer = stream.ToArray();
             stream2.Write(buffer, 0, buffer.Length);
             stream2.Close();
             stream.Close();
             this._scheduleManager.RefreshSchedule = true;
         }
     }
 }
예제 #3
0
파일: Schedule.cs 프로젝트: afrog33k/eAd
        /// <summary>
        /// Schedule XMDS call completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void xmds2_ScheduleCompleted(object sender, ScheduleCompletedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Schedule Retrival Complete.");

            // Set XMDS to no longer be processing
            _xmdsProcessing = false;

            // Expect new schedule XML
            if (e.Error != null)
            {
                // There was an error - what do we do?
                System.Diagnostics.Trace.WriteLine(e.Error.Message);
            }
            else
            {
                // Only update the schedule if its changed.
                String md5CurrentSchedule = "";

                // Set the flag to indicate we have a connection to XMDS
                Settings.Default.XmdsLastConnection = DateTime.Now;

                XmlSerializer serializer     = new XmlSerializer(typeof(ScheduleModel));
                MemoryStream  scheduleStream = new MemoryStream();
                serializer.Serialize(scheduleStream, e.Result);
                // Hash of the result
                String md5NewSchedule = Hashes.MD5(Encoding.UTF8.GetString(scheduleStream.ToArray()));

                try
                {
                    StreamReader sr = new StreamReader(File.Open(_scheduleLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));

                    // Yes - get the MD5 of it, and compare to the MD5 of the file in the XML
                    md5CurrentSchedule = Hashes.MD5(sr.ReadToEnd());

                    sr.Close();

                    // Compare the existing to the new
                    if (md5CurrentSchedule == md5NewSchedule)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    // Failed to get the MD5 of the existing schedule - just continue and overwrite it
                    Debug.WriteLine(ex.Message);
                }

                System.Diagnostics.Debug.WriteLine("Different Schedules Detected, writing new schedule.", "Schedule - ScheduleCompleted");

                // Write the result to the schedule xml location



                // ms is your memoryStream
                FileStream fs = File.OpenWrite(_scheduleLocation);

                byte[] data = scheduleStream.ToArray();

                /* could replace with GetBuffer() if you don't mind the padding, or you
                 * could set Capacity of ms to Position to crop the padding out of the
                 * buffer.*/


                fs.Write(data, 0, data.Length);

                fs.Close();


                scheduleStream.Close();
                Debug.WriteLine("New Schedule Recieved", "xmds_ScheduleCompleted");

                // Indicate to the schedule manager that it should read the XML file
                _scheduleManager.RefreshSchedule = true;
            }
        }
예제 #4
0
파일: Schedule.cs 프로젝트: afrog33k/eAd
    /// <summary>
    /// Schedule XMDS call completed
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void xmds2_ScheduleCompleted(object sender, ScheduleCompletedEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Schedule Retrival Complete.");

        // Set XMDS to no longer be processing
        _xmdsProcessing = false;

        // Expect new schedule XML
        if (e.Error != null)
        {
            // There was an error - what do we do?
            System.Diagnostics.Trace.WriteLine(e.Error.Message);
        }
        else
        {
            // Only update the schedule if its changed.
            String md5CurrentSchedule = "";

            // Set the flag to indicate we have a connection to XMDS
            Settings.Default.XmdsLastConnection = DateTime.Now;

            XmlSerializer serializer = new XmlSerializer(typeof(ScheduleModel));
            MemoryStream scheduleStream = new MemoryStream();
            serializer.Serialize(scheduleStream, e.Result);
            // Hash of the result
            String md5NewSchedule = Hashes.MD5(Encoding.UTF8.GetString(scheduleStream.ToArray()));

            try
            {
                StreamReader sr = new StreamReader(File.Open(_scheduleLocation, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));

                // Yes - get the MD5 of it, and compare to the MD5 of the file in the XML
                md5CurrentSchedule = Hashes.MD5(sr.ReadToEnd());

                sr.Close();

                // Compare the existing to the new
                if (md5CurrentSchedule == md5NewSchedule)
                    return;
            }
            catch (Exception ex)
            {
                // Failed to get the MD5 of the existing schedule - just continue and overwrite it
                Debug.WriteLine(ex.Message);
            }

            System.Diagnostics.Debug.WriteLine("Different Schedules Detected, writing new schedule.", "Schedule - ScheduleCompleted");

            // Write the result to the schedule xml location



            // ms is your memoryStream
            FileStream fs = File.OpenWrite(_scheduleLocation);

            byte[] data = scheduleStream.ToArray();
            /* could replace with GetBuffer() if you don't mind the padding, or you
            could set Capacity of ms to Position to crop the padding out of the
            buffer.*/


            fs.Write(data, 0, data.Length);

            fs.Close();


            scheduleStream.Close();
            Debug.WriteLine("New Schedule Recieved", "xmds_ScheduleCompleted");

            // Indicate to the schedule manager that it should read the XML file
            _scheduleManager.RefreshSchedule = true;
        }
    }