コード例 #1
0
        private OperationResult WriteAll(DataEntity dataEntity, string entityName)
        {
            var operationResult = new OperationResult();
            var output          = new DataEntity(entityName);

            dataEntity.Properties.TryGetValue("TargetFullPath", out var TargetFullPath);

            try
            {
                switch (entityName)
                {
                case EntityNames.WriteBytes:
                    var Bytes = dataEntity.Properties["Bytes"] as Byte[];
                    File.WriteAllBytes(TargetFullPath.ToString(), Bytes);
                    break;

                case EntityNames.WriteText:
                    dataEntity.Properties.TryGetValue("Text", out var Text);
                    File.WriteAllText(TargetFullPath.ToString(), Text.ToString());
                    break;

                case EntityNames.AppendText:
                case EntityNames.AppendText2:
                    dataEntity.Properties.TryGetValue("Text", out var appText);
                    File.AppendAllText(TargetFullPath.ToString(), appText.ToString());
                    break;
                }

                return(new OperationResult
                {
                    ErrorInfo = new ErrorResult[] { null },
                    ObjectsAffected = new[] { 1 },
                    Output = new[] { output },
                    Success = new[] { true }
                });
            }
            catch (IOException ioEx)
            {
                var errorResult = new ErrorResult();
                errorResult.Description = ioEx.Message;

                return(new OperationResult
                {
                    ErrorInfo = new ErrorResult[] { errorResult },
                    ObjectsAffected = new[] { 0 },
                    Success = new[] { false }
                });
            }
        }
コード例 #2
0
        private OperationResult MoveOrRename(DataEntity dataEntity, string entityName)
        {
            var operationResult = new OperationResult();
            var output          = new DataEntity(entityName);

            dataEntity.Properties.TryGetValue("SearchFullPath", out var SearchFullPath);
            try
            {
                switch (entityName)
                {
                case EntityNames.MoveOrRename:
                    dataEntity.Properties.TryGetValue("TargetFullPath", out var TargetFullPath);
                    File.Move(SearchFullPath.ToString(), TargetFullPath.ToString());
                    break;
                }
                return(new OperationResult
                {
                    ErrorInfo = new ErrorResult[] { null },
                    ObjectsAffected = new[] { 1 },
                    Output = new[] { output },
                    Success = new[] { true }
                });
            }
            catch (IOException ioEx)
            {
                var errorResult = new ErrorResult();
                errorResult.Description = ioEx.Message;

                return(new OperationResult
                {
                    ErrorInfo = new ErrorResult[] { errorResult },
                    ObjectsAffected = new[] { 0 },
                    Success = new[] { false }
                });
            }
        }