Пример #1
0
            }             // proc Dispose

            public async Task <IOdetteFileWriter> CreateInFileAsync(IOdetteFile file, string userData)
            {
                var incomingFile = String.Format("In coming file {0} ", OdetteFileImmutable.FormatFileName(file, userData));

                if (!service.IsInFileAllowed(file))
                {
                    log.Info(incomingFile + "ignored");
                    return(null);
                }

                var fi = service.CreateInFileName(file, OdetteInFileState.Pending);

                // check if the file exists
                if (File.Exists(Path.ChangeExtension(fi.FullName, GetInFileExtention(OdetteInFileState.Received))) ||
                    File.Exists(Path.ChangeExtension(fi.FullName, GetInFileExtention(OdetteInFileState.PendingEndToEnd))) ||
                    File.Exists(Path.ChangeExtension(fi.FullName, GetInFileExtention(OdetteInFileState.Finished))))
                {
                    throw new OdetteFileServiceException(OdetteAnswerReason.DuplicateFile, "File already exists.", false);
                }

                // open the file to write
                var fileItem = await Task.Run(() => new FileItem(service, fi, file, true));

                fileItem.Log(log, incomingFile + "accepted");
                try
                {
                    return(await Task.Run(new Func <IOdetteFileWriter>(fileItem.OpenWrite)));
                }
                catch (IOException e)
                {
                    throw new OdetteFileServiceException(OdetteAnswerReason.UnspecifiedReason, e.Message, false, e);
                }
            }             // func CreateInFile
Пример #2
0
            }             // func GetOutFiles

            public async Task <bool> UpdateOutFileStateAsync(IOdetteFileEndToEndDescription description)
            {
                if (service.directoryOut == null)                 // do we have the directory
                {
                    return(false);
                }

                // check file exists
                var fi = service.CreateOutFileName(description.Name, OdetteOutFileState.WaitEndToEnd);

                if (!fi.Exists)
                {
                    return(false);
                }

                // mark file as finish
                await ChangeOutFileStateAsync(fi, OdetteOutFileState.ReceivedEndToEnd);

                // update file information
                var fileItem = await Task.Run(() => new FileItem(service, fi, description.Name, false));

                fileItem.Log(log, String.Format("Update file commit: {0} with [{1}] {2}", OdetteFileImmutable.FormatFileName(description.Name, description.UserData), description.ReasonCode, description.ReasonText));

                var xCommit = fileItem.Extensions.Root.Element("commit");

                if (xCommit == null)
                {
                    fileItem.Extensions.Root.Add(xCommit = new XElement("commit"));
                }

                xCommit.SetAttributeValue("reasonCode", description.ReasonCode);
                xCommit.SetAttributeValue("reasonText", description.ReasonText);
                xCommit.SetAttributeValue("userData", description.UserData);

                await fileItem.SaveExtensionsAsync();

                return(true);
            }             // proc UpdateOutFileState
Пример #3
0
            }             // func GetEndToEnd

            public IEnumerable <Func <IOdetteFileReader> > GetOutFiles()
            {
                if (service.directoryOut == null)                 // do we have the directory
                {
                    yield break;
                }

                // collect alle out files
                foreach (var fi in service.directoryOut.EnumerateFiles("*" + GetOutFileExtention(OdetteOutFileState.Sent)))
                {
                    var file = TrySplitFileName(fi.Name);
                    if (file != null)
                    {
                        yield return(new Func <IOdetteFileReader>(() =>
                        {
                            var fileItem = new FileItem(service, fi, file, false);
                            fileItem.Log(log, String.Format("Sent file to destination: {0}", OdetteFileImmutable.FormatFileName(file, fileItem.SendUserData)));

                            // file for sent
                            return fileItem.OpenRead();
                        }));
                    }
                }
            }             // func GetOutFiles
Пример #4
0
            }             // func CreateInFile

            public IEnumerable <IOdetteFileEndToEnd> GetEndToEnd()
            {
                if (service.directoryIn == null)                 // do we have the directory
                {
                    yield break;
                }

                // enumerator all files
                foreach (var fi in service.directoryIn.EnumerateFiles("*" + GetInFileExtention(OdetteInFileState.PendingEndToEnd), SearchOption.TopDirectoryOnly))
                {
                    var file = TrySplitFileName(fi.Name);
                    if (file != null)
                    {
                        var fileItem = new FileItem(service, fi, file, false);
                        var e2e      = new FileEndToEnd(fileItem);
                        fileItem.Log(log, String.Format("Sent {1} end to end for: {0}", OdetteFileImmutable.FormatFileName(file, e2e.UserData), e2e.ReasonCode == 0 ? "positive" : "negative"));
                        yield return(e2e);
                    }
                    else
                    {
                        log.Warn("GetEndToEnd: Can not parse file name '{0}'...", fi.Name);
                    }
                }
            }             // func GetEndToEnd