Пример #1
0
        string WriteToRemoteTempStorage(IActivityIOOperationsEndPoint dst, IDev2PutRawOperationTO args, string result, string tmp)
        {
            switch (args.WriteType)
            {
            case WriteType.AppendBottom:
                var fileContent = Encoding.ASCII.GetBytes(args.FileContents);
                var putResult   = PerformPut(fileContent, dst, false);
                result = putResult ? ResultOk : ResultBad;
                break;

            case WriteType.AppendTop:
                using (var s = dst.Get(dst.IOPath, _filesToDelete))
                {
                    _fileWrapper.WriteAllText(tmp, args.FileContents);
                    _common.AppendToTemp(s, tmp);
                    result = MoveTmpFileToDestination(dst, tmp, result);
                }
                break;

            case WriteType.Overwrite:
            default:
                var res = WriteDataToFile(args, dst);
                result = res ? ResultOk : ResultBad;
                break;
            }

            return(result);
        }
Пример #2
0
        public string PutRaw(IActivityIOOperationsEndPoint dst, IDev2PutRawOperationTO args)
        {
            var result = ResultOk;

            try
            {
                FileLock.EnterWriteLock();
                if (dst.RequiresLocalTmpStorage())
                {
                    var tmp = CreateTmpFile();
                    switch (args.WriteType)
                    {
                    case WriteType.AppendBottom:
                        using (var s = dst.Get(dst.IOPath, _filesToDelete))
                        {
                            _fileWrapper.WriteAllBytes(tmp, s.ToByteArray());
                            _fileWrapper.AppendAllText(tmp, args.FileContents);
                        }
                        break;

                    case WriteType.AppendTop:
                        using (var s = dst.Get(dst.IOPath, _filesToDelete))
                        {
                            _fileWrapper.WriteAllText(tmp, args.FileContents);
                            _common.AppendToTemp(s, tmp);
                        }
                        break;

                    default:
                        WriteDataToFile(args, tmp);
                        break;
                    }
                    result = MoveTmpFileToDestination(dst, tmp, result);
                }
                else
                {
                    if (_fileWrapper.Exists(dst.IOPath.Path))
                    {
                        var tmp = CreateTmpFile();
                        switch (args.WriteType)
                        {
                        case WriteType.AppendBottom:
                            _fileWrapper.AppendAllText(dst.IOPath.Path, args.FileContents);
                            result = ResultOk;
                            break;

                        case WriteType.AppendTop:
                            using (var s = dst.Get(dst.IOPath, _filesToDelete))
                            {
                                _fileWrapper.WriteAllText(tmp, args.FileContents);
                                _common.AppendToTemp(s, tmp);
                                result = MoveTmpFileToDestination(dst, tmp, result);
                                RemoveTmpFile(tmp);
                            }
                            break;

                        default:
                            WriteDataToFile(args, tmp);
                            result = MoveTmpFileToDestination(dst, tmp, result);
                            RemoveTmpFile(tmp);
                            break;
                        }
                    }
                    else
                    {
                        Dev2CRUDOperationTO newArgs = new Dev2CRUDOperationTO(true);
                        CreateEndPoint(dst, newArgs, true);
                        var path = dst.IOPath.Path;
                        WriteDataToFile(args, path);
                    }
                }
            }
            finally
            {
                FileLock.ExitWriteLock();
                for (var index = _filesToDelete.Count - 1; index > 0; index--)
                {
                    var name = _filesToDelete[index];
                    RemoveTmpFile(name);
                }
            }
            return(result);
        }