예제 #1
0
 private void TakeSnapshot(Camera camera)
 {
     try
     {
         var    now  = DateTime.Now;
         string path = string.Format(@"{0}\{1}", camera.Path, now.ToString("yyyyMMdd"));
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         string fileName = string.Format(@"{0}\{1}.jpg", path, now.ToString("yyyyMMdd_HHmmss"));
         using (var wc = new WebClientEx())
         {
             if (camera.Credentials.IsNotEmpty())
             {
                 var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(camera.Credentials));
                 wc.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
             }
             wc.DownloadFile(camera.Url, fileName);
             SnapshotReceived?.Invoke(camera, new SnapshotReceivedEventArgs(camera.Name, fileName, now));
         }
     }
     catch (Exception ex)
     {
         ex.LogException(EventId.ErrorTakingSnapshot);
     }
 }
예제 #2
0
        private void OnSnapshotHandler(MemoryStream stream)
        {
            var snapshot = Schemes.Snapshot.DeserializeWithLengthPrefix(stream);

            SnapshotReceived?.Invoke(this, new SnapshotEventArgs(snapshot));
        }