Exemple #1
0
        private static string BuildOutput(DeleteContext context)
        {
            MarkdownBuilder builder = new MarkdownBuilder();
            bool            empty   = true;

            if (context.DeletedFiles.Count > 0)
            {
                builder.Header("Deleted files");
                builder.WriteRawPathList(context.DeletedFiles);
                empty = false;
            }

            if (context.DeletedFolders.Count > 0)
            {
                builder.Header("Deleted directories");
                builder.WriteRawPathList(context.DeletedFolders);
                empty = false;
            }

            if (empty)
            {
                builder.Italic("Nothing deleted.");
            }

            return(builder.ToString());
        }
Exemple #2
0
        public async Task DeleteContextValidator_ThrowsWhenInputIdsIsEmpty()
        {
            var context = new DeleteContext <TestEntity>(EndpointName.Tests, new List <int>());

            await this.pipelineElement.ProcessAsync(context, MockLogger.Object, default)
            .ConfigureAwait(false);
        }
        public async Task RestClientDeleteHandler_RestClientIsInvokedWithExpectedInputsAsync()
        {
            var idsToDelete = new List <long> {
                1, 2, 3
            };

            // rest client Delete() method is called with 3 parameters:
            // the request id, the endpoint, and the list of id's to delete
            this.mockRestClient
            .Setup(p => p.DeleteAsync(
                       It.Is <EndpointName>(t => t.Equals(EndpointName.Tests)),
                       It.Is <IEnumerable <long> >(s => s.IsEqualTo(idsToDelete)),
                       It.IsAny <LogContext>(),
                       It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(Response));

            var context = new DeleteContext <BasicTestEntity>(EndpointName.Tests, idsToDelete)
            {
                RestClient = this.mockRestClient.Object
            };

            await this.pipelineElement.ProcessAsync(context, NullLogger.Instance, default).ConfigureAwait(false);

            this.mockRestClient.VerifyAll();
        }
        /// <summary>
        /// Asynchronously Delete Jobcode Assignments, with support for cancellation.
        /// </summary>
        /// <remarks>
        /// Delete one or more <see cref="JobcodeAssignment"/> assignments, by id.
        /// </remarks>
        /// <param name="ids">
        /// The set of ids for the <see cref="JobcodeAssignment"/> assignment objects to be deleted.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The asynchronous task.</returns>
        public async Task DeleteJobcodeAssignmentsAsync(
            IEnumerable <long> ids,
            CancellationToken cancellationToken)
        {
            var context = new DeleteContext <JobcodeAssignment>(EndpointName.JobcodeAssignments, ids);

            await ExecuteOperationAsync(context, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Asynchronously Delete Timesheets, with support for cancellation.
        /// </summary>
        /// <remarks>
        /// Delete one or more <see cref="Timesheet"/> objects, by id.
        /// </remarks>
        /// <param name="ids">
        /// The set of ids for the <see cref="Timesheet"/> objects to be deleted.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The asynchronous task.</returns>
        public async Task DeleteTimesheetsAsync(
            IEnumerable <int> ids,
            CancellationToken cancellationToken)
        {
            var context = new DeleteContext <Timesheet>(EndpointName.Timesheets, ids);

            await ExecuteOperationAsync(context, cancellationToken).ConfigureAwait(false);
        }
Exemple #6
0
 protected override bool OnDeleting(DeleteContext deleteContext)
 {
     if (OnDeletingFun != null)
     {
         var flag = OnDeletingFun(deleteContext);
     }
     return(base.OnDeleting(deleteContext));
 }
Exemple #7
0
        /// <summary>
        /// Asynchronously Delete Notifications, with support for cancellation.
        /// </summary>
        /// <remarks>
        /// Delete one or more <see cref="Notification"/> objects, by id.
        /// </remarks>
        /// <param name="ids">
        /// The set of ids for the <see cref="Notification"/> objects to be deleted.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The asynchronous task.</returns>
        public async Task DeleteNotificationsAsync(
            IEnumerable <long> ids,
            CancellationToken cancellationToken)
        {
            var context = new DeleteContext <Notification>(EndpointName.Notifications, ids);

            await ExecuteOperationAsync(context, cancellationToken).ConfigureAwait(false);
        }
        public async Task DeleteResultsSerializer_CorrectlyDeserializesResponseWithErrorResultsAsync()
        {
            DeleteContext <TestEntity> context = GetDeleteContextWithErrorItems <TestEntity>();

            await this.pipelineElement.ProcessAsync(context, NullLogger.Instance, default).ConfigureAwait(false);

            const int expectedCount = 2;

            Assert.AreEqual(expectedCount, context.Results.ErrorItems.Count, $"Expected {expectedCount} error results.");
        }
Exemple #9
0
        private void DeleteFile(string filePath, DeleteContext context)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            context.DeletedFiles.Add(filePath.GetFriendlyPath(context.SourceLobby));
            ProcessFileDelete(filePath, context);
        }
        public async Task ExecuteAsync(DeleteContext context, DeleteResult result, CancellationToken cancellationToken)
        {
            try
            {
                await _repository.DeleteByIdAsync(context.Id, context.ETag, cancellationToken);

                result.ResourceWasDeleted = true;
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }
        }
Exemple #11
0
        private void ProcessFileDelete(string filePath, DeleteContext context)
        {
            if (context.Preview)
            {
                return;
            }

            try
            {
                File.Delete(filePath);
            }
            catch (Exception exception)
            {
                logger.Error("File delete: " + filePath, exception);
            }
        }
Exemple #12
0
        private void DeleteDirectory(string directoryPath, DeleteContext context)
        {
            foreach (string filePath in TexoDirectory.GetFiles(directoryPath))
            {
                DeleteFile(filePath, context);
            }

            if (context.Preview ||
                !TexoDirectory.IsEmpty(directoryPath))
            {
                return;
            }

            context.DeletedFolders.Add(directoryPath.GetFriendlyPath(context.SourceLobby));
            ProcessDirectoryDelete(directoryPath);
        }
Exemple #13
0
        private ICommandResult Delete(DeleteContext context)
        {
            foreach (string path in context.Items)
            {
                switch (path.GetPathType())
                {
                case PathTypeEnum.File:
                    DeleteFile(path, context);
                    break;

                case PathTypeEnum.Directory:
                    DeleteDirectory(path, context);
                    break;
                }
            }

            return(new ItemsResult(Item.AsMarkdown(BuildOutput(context))));
        }
Exemple #14
0
 /// <summary>
 /// 数据库操作类
 /// </summary>
 /// <param name="ConnectionString">链接串 不传入默认为 ConnectionString </param>
 public DBContext(string ConnectionString = null)
 {
     if (string.IsNullOrEmpty(ConnectionString))
     {
         _ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
     }
     else
     {
         _ConnectionString = ConnectionString;
     }
     add      = new AddContext(_ConnectionString);
     edit     = new EditContext(_ConnectionString);
     delete   = new DeleteContext(_ConnectionString);
     find     = new FindContext(_ConnectionString);
     dbhelper = new DbHelper(_ConnectionString);
     check    = new CheckContext <BaseEntity>(_ConnectionString);
     jss      = new JavaScriptSerializer();
 }
        public void PipelineFactory_GivenDeleteContext_BuildsExpectedPipeline()
        {
            var context = new DeleteContext <TestEntity>(
                EndpointName.Tests,
                new[] { 1, 2, 3 });

            var pipeline = (RequestPipeline)this.pipelineFactory.GetPipeline(context);

            Type[] expectedElementTypes =
            {
                typeof(DeleteContextValidator),
                typeof(RestClientDeleteHandler),
                typeof(DeleteResultsDeserializer),
                typeof(MultiStatusHandler)
            };

            IPipelineElement[] actualElements = pipeline.PipelineElements.ToArray();

            AssertElements(expectedElementTypes, actualElements);
        }
        public async Task RestClientDeleteHandler_RestClientSetsResponseContentPropertyOfContextObjectAsync()
        {
            this.mockRestClient
            .Setup(p => p.DeleteAsync(
                       It.IsAny <EndpointName>(),
                       It.IsAny <IEnumerable <long> >(),
                       It.IsAny <LogContext>(),
                       It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(Response));

            var context = new DeleteContext <BasicTestEntity>(EndpointName.Tests, new long[] { 1 })
            {
                RestClient = this.mockRestClient.Object
            };

            await this.pipelineElement.ProcessAsync(context, NullLogger.Instance, default);

            Assert.AreEqual(Response, context.ResponseContent, "Expected response content to be set.");

            this.mockRestClient.VerifyAll();
        }
Exemple #17
0
        private async Task DeleteAsync(MusicDb db, PathData pd)
        {
            db.ChangeTracker.AutoDetectChangesEnabled = false;
            taskItem = await db.TaskItems.FindAsync(taskId);

            IEnumerable <MusicFile> musicFileList = null;
            string path = "";

            if (pd.GetFullOpusPath() != null)
            {
                path          = pd.IsCollections ? pd.OpusPath : $"{pd.ArtistPath}\\{pd.OpusPath}";
                musicFileList = db.MusicFiles
                                .Where(f => (f.DiskRoot.ToLower() == pd.DiskRoot.ToLower()) &&
                                       (f.StylePath.ToLower() == pd.StylePath.ToLower()) &&
                                       (f.OpusPath.ToLower() == path.ToLower()))
                                .OrderBy(f => f.File)
                ;
            }
            else
            {
                if (pd.IsCollections)
                {
                    musicFileList = db.MusicFiles
                                    .Where(f => (f.DiskRoot.ToLower() == pd.DiskRoot.ToLower()) &&
                                           (f.StylePath.ToLower() == pd.StylePath.ToLower()) &&
                                           f.Musician.ToLower() == "collections")
                                    .OrderBy(f => f.File)
                    ;
                }
                else
                {
                    musicFileList = db.MusicFiles
                                    .Where(f => (f.DiskRoot.ToLower() == pd.DiskRoot.ToLower()) &&
                                           (f.StylePath.ToLower() == pd.StylePath.ToLower()) &&
                                           f.OpusPath.StartsWith(pd.ArtistPath))
                                    .OrderBy(f => f.File)
                    ;
                }
            }

            log.Information($"Deleting {musicFileList.Count()} music files");
            var dc = new DeleteContext(taskItem);

            foreach (var mf in musicFileList)
            {
                db.Delete(mf, dc);
            }
            taskItem.Status     = Music.Core.TaskStatus.Finished;
            taskItem.FinishedAt = DateTimeOffset.Now;
            await db.SaveChangesAsync();

            if (dc.DeletedArtistId.HasValue)
            {
                await this.playManager.SendArtistDeleted(dc.DeletedArtistId.Value);
            }
            else if (dc.ModifiedArtistId.HasValue)
            {
                var shouldSend = true;
                var artist     = await db.Artists.FindAsync(dc.ModifiedArtistId.Value);

                if (artist != null)
                {
                    shouldSend = artist.Type != ArtistType.Various;
                }
                if (shouldSend)
                {
                    await this.playManager.SendArtistNewOrModified(dc.ModifiedArtistId.Value);
                }
            }
            //if (dc.DeletedArtistId.HasValue || dc.ModifiedArtistId.HasValue)
            //{
            //    var shouldSend = true;
            //    var id = dc.ModifiedArtistId ?? 0;
            //    if (id > 0)
            //    {
            //        var artist = await db.Artists.FindAsync(id);
            //        shouldSend = artist.Type != ArtistType.Various;
            //    }
            //    if (shouldSend)
            //    {
            //        if (dc.DeletedArtistId.HasValue)
            //        {
            //            await this.playManager.SendArtistDeleted(dc.DeletedArtistId.Value);
            //        }
            //        else if (dc.ModifiedArtistId.HasValue)
            //        {
            //            await this.playManager.SendArtistNewOrModified(dc.ModifiedArtistId.Value);
            //        }
            //    }
            //}
            // send artist modified/deleted - info is in dc
        }
Exemple #18
0
        public bool OnDeleting(IDatabase database, DeleteContext deleteContext)
        {
            var context = deleteContext;

            return(true);
        }