/// <summary> /// Enqueues the specified job. /// </summary> /// <param name="job">The job.</param> /// <returns>True if successfully enqueued; otherwise false.</returns> bool EnqueueJob(IFtpFileUploaderJob job) { lock (_jobsSync) { // Check if this job already exists if (_jobsQueue.Any(x => x.AreJobsSame(job)) || _jobsActive.Any(x => x.AreJobsSame(job))) { if (log.IsDebugEnabled) log.DebugFormat("Enqueueing job `{0}` failed: job already in queue.", job); return false; } // Add the job _jobsQueue.Enqueue(job); if (log.IsDebugEnabled) log.DebugFormat("Enqueueing job `{0}` successful.", job); } return true; }
/// <summary> /// Gets if this <see cref="IFtpFileUploaderJob"/> is considered the same as another <see cref="IFtpFileUploaderJob"/>. /// The implementation depends on the context, but generally it means that they are of the same type and that the /// <paramref name="otherJob"/> operates on the same remote path as this job. /// </summary> /// <param name="otherJob">The <see cref="IFtpFileUploaderJob"/> to compare against.</param> /// <returns>True if the jobs are the same; otherwise false.</returns> public bool AreJobsSame(IFtpFileUploaderJob otherJob) { var o = otherJob as JobUploadFile; if (o == null) return false; return StringComparer.Ordinal.Equals(RemoteFile, o.RemoteFile); }
/// <summary> /// Gets if this <see cref="IFtpFileUploaderJob"/> is considered the same as another <see cref="IFtpFileUploaderJob"/>. /// The implementation depends on the context, but generally it means that they are of the same type and that the /// <paramref name="otherJob"/> operates on the same remote path as this job. /// </summary> /// <param name="otherJob">The <see cref="IFtpFileUploaderJob"/> to compare against.</param> /// <returns>True if the jobs are the same; otherwise false.</returns> public bool AreJobsSame(IFtpFileUploaderJob otherJob) { var o = otherJob as JobDeleteDir; if (o == null) return false; return StringComparer.Ordinal.Equals(RemotePath, o.RemotePath); }