Ejemplo n.º 1
0
        private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (e.ChangeType != WatcherChangeTypes.Deleted)
            {
                try
                {
                    var attr = File.GetAttributes(e.FullPath);
                    if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        return; //Ignore directory change
                    }
                }
                catch (System.Exception ex)
                {
                    ServiceUtils.WriteLog(string.Format("ERROR getting file attributes -- {0}", ex.Message));
                    return;
                }
            }

            EnqueueItem(e.FullPath);

            //timer is used to wait 1 second before execute sync
            timer.Stop();
            timer.Start();
        }
Ejemplo n.º 2
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (e == null || e.ExceptionObject == null)
            {
                return;
            }

            var exception = (Exception)e.ExceptionObject;

            ServiceUtils.WriteLog(string.Format("ERROR -- CurrentDomain_UnhandledException -- {0}", exception.Message));
        }
Ejemplo n.º 3
0
        private void ProcessItem(string path)
        {
            string relativePath = ServiceUtils.GetRelativePath(path, basePath);
            bool   update       = System.IO.File.Exists(path);
            int    attempt      = 0;
            int    maxAttempts  = 3;

            while (true)
            {
                try
                {
                    attempt++;

                    if (update)
                    {
                        UploadFile(path, relativePath);
                    }
                    else
                    {
                        DeleteFile(path, relativePath);
                    }

                    break;
                }
                catch (System.Exception ex)
                {
                    ServiceUtils.WriteLog(string.Format("ERROR {0} file: \"{1}\" -- attempt:{2}/{3} -- {4}", (update ? "updating" : "deleting"), path, attempt, maxAttempts, ex.Message));
                    System.Diagnostics.Debugger.Break();

                    if (attempt >= maxAttempts)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void DeleteFile(string path, string relativePath)
 {
     awsS3Client.DeleteItem(syncConfiguration.ServerPath, relativePath);
     ServiceUtils.WriteLog(string.Format("File: {0} deleted from bucket: {1}, path: {2}", path, syncConfiguration.ServerPath, relativePath));
 }
Ejemplo n.º 5
0
 private void UploadFile(string path, string relativePath)
 {
     awsS3Client.UploadFile(syncConfiguration.ServerPath, path, relativePath);
     ServiceUtils.WriteLog(string.Format("File: {0} updated in bucket: {1}, path: {2}", path, syncConfiguration.ServerPath, relativePath));
 }