예제 #1
0
        public static void DefaultSetDestinationsProc(LogServerReceivedData data, LogServerOptions options)
        {
            FileSystem  fs       = options.DestFileSystem;
            PathParser  parser   = fs.PathParser;
            string      root     = options.DestRootDirName;
            LogPriority priority = data.JsonData !.Priority._ParseEnum(LogPriority.None);
            LogJsonData d        = data.JsonData;

            if (d.Kind._IsSamei(LogKind.Default))
            {
                if (priority >= LogPriority.Debug)
                {
                    Add($"{d.AppName}/{d.MachineName}/Debug");
                }

                if (priority >= LogPriority.Info)
                {
                    Add($"{d.AppName}/{d.MachineName}/Info");
                }

                if (priority >= LogPriority.Error)
                {
                    Add($"{d.AppName}/{d.MachineName}/Error");
                }
            }
            else
            {
                Add($"{d.AppName}/{d.MachineName}/{d.Kind}");
            }

            void Add(string filename)
            {
                data.AddDestinationFileName(parser.NormalizeDirectorySeparator(parser.Combine(root, filename + ".log")));
            }
        }
예제 #2
0
    public static void DefaultSetDestinationsProc(DataVaultServerReceivedData data, DataVaultServerOptions options)
    {
        FileSystem    fs     = options.DestFileSystem;
        PathParser    parser = fs.PathParser;
        string        root   = options.DestRootDirName;
        DataVaultData d      = data.JsonData !;

        string timeStampStr;

        if (d.WithTime == false)
        {
            timeStampStr = Str.DateToStrShort(d.TimeStamp.LocalDateTime.Date);
        }
        else
        {
            timeStampStr = Str.DateTimeToStrShortWithMilliSecs(d.TimeStamp.LocalDateTime);
        }

        string relativePath = Str.CombineStringArray("/", d.SystemName, d.LogName, d.KeyType, d.KeyShortValue, d.KeyFullValue,
                                                     $"{timeStampStr}-{d.SystemName}-{d.LogName}-{d.KeyType}-{d.KeyFullValue}.json");

        if (d.WriteCompleteFlag ?? false)
        {
            relativePath += ".completed";
        }

        data.AddDestinationFileName(parser.NormalizeDirectorySeparator(parser.Combine(root, relativePath)));
    }
예제 #3
0
    public static void DefaultSetDestinationsProc(LogServerReceivedData data, LogServerOptions options)
    {
        FileSystem  fs       = options.DestFileSystem;
        PathParser  parser   = fs.PathParser;
        string      root     = options.DestRootDirName;
        LogPriority priority = data.JsonData !.Priority._ParseEnum(LogPriority.None);
        LogJsonData d        = data.JsonData;
        DateTime    date;

        if (d.TimeStamp.HasValue == false)
        {
            date = Util.ZeroDateTimeValue;
        }
        else
        {
            date = d.TimeStamp.Value.LocalDateTime.Date;
        }

        if (d.Kind._IsSamei(LogKind.Default))
        {
            if (priority >= LogPriority.Debug)
            {
                Add($"{d.AppName}/{d.MachineName}/Debug", d.AppName !, "Debug", date);
            }

            if (priority >= LogPriority.Info)
            {
                Add($"{d.AppName}/{d.MachineName}/Info", d.AppName !, "Info", date);
            }

            if (priority >= LogPriority.Error)
            {
                Add($"{d.AppName}/{d.MachineName}/Error", d.AppName !, "Error", date);
            }
        }
        else
        {
            Add($"{d.AppName}/{d.MachineName}/{d.Kind}", d.AppName !, d.Kind !, date);
        }

        void Add(string subDirName, string token0, string token1, DateTime date)
        {
            string yyyymmdd = Str.DateToStrShort(date);

            string tmp = parser.Combine(root, subDirName, $"{yyyymmdd}-{token0}-{token1}.log");

            data.AddDestinationFileName(parser.NormalizeDirectorySeparator(tmp));
        }
    }
예제 #4
0
        public FileSystemBasedProvider[] CreateEmbeddedAndPhysicalFileProviders(string rootDirectoryOnResourceRootDir, ResFileReadFrom flags = ResFileReadFrom.Both)
        {
            List <FileSystemBasedProvider> ret = new List <FileSystemBasedProvider>();

            string relativeRoot = rootDirectoryOnResourceRootDir;

            if (this.PathParser.IsAbsolutePath(relativeRoot))
            {
                relativeRoot = this.PathParser.NormalizeUnixStylePathWithRemovingRelativeDirectoryElements(relativeRoot);

                relativeRoot = this.PathParser.GetRelativeDirectoryName(relativeRoot, "/");
            }

            if (this.PathParser.IsAbsolutePath(relativeRoot))
            {
                throw new ApplicationException($"relativeRoot '{relativeRoot}' is absolute.");
            }

            if (relativeRoot._IsFilled())
            {
                if (flags.Bit(ResFileReadFrom.Physical))
                {
                    foreach (DirectoryPath srcRoot in this.ResourceRootSourceDirectoryList)
                    {
                        DirectoryPath resourceRoot = srcRoot.GetSubDirectory(relativeRoot, true);

                        if (resourceRoot.IsDirectoryExists())
                        {
                            ret.Add(resourceRoot.FileSystem.CreateFileProvider(resourceRoot));
                        }
                    }
                }

                if (flags.Bit(ResFileReadFrom.EmbeddedResource))
                {
                    string rootDirectoryInResourceAbsolute = PathParser.Combine(Consts.FileNames.ResourceRootAbsoluteDirName, relativeRoot);

                    ret.Add(this.CreateFileProvider(rootDirectoryInResourceAbsolute));
                }
            }

            return(ret.ToArray());
        }
        public DirectoryPath ConfigPathStringToPhysicalDirectoryPath(string pathString)
        {
            pathString = pathString._NonNullTrim();

            if (pathString._IsEmpty())
            {
                throw new ArgumentNullException(nameof(pathString));
            }

            pathString = PathParser.NormalizeDirectorySeparator(pathString, true);

            if (PathParser.IsAbsolutePath(pathString))
            {
                return(pathString);
            }
            else
            {
                pathString = "/" + PathParser.Linux.NormalizeDirectorySeparator(pathString, true);

                string[] elements = PathParser.Linux.SplitAbsolutePathToElementsUnixStyle(pathString);

                string tmp = PathParser.Linux.BuildAbsolutePathStringFromElements(elements);

                tmp = PathParser.Linux.NormalizeDirectorySeparator(tmp, true);

                if (tmp[0] != '/')
                {
                    throw new ApplicationException("tmp[0] != '/'");
                }

                tmp = tmp.Substring(1);

                tmp = PathParser.Combine(Env.AppRootDir, tmp, true);

                return(tmp);
            }
        }
예제 #6
0
    protected override async Task <FileSystemEntity[]> EnumDirectoryImplAsync(string directoryPath, EnumDirectoryFlags flags, CancellationToken cancel = default)
    {
        using (VfsPathParserContext ctx = await ParsePathInternalAsync(directoryPath, cancel))
        {
            if (ctx.Exception != null)
            {
                throw ctx.Exception;
            }

            if (ctx.LastEntity is VfsDirectory thisDirObject)
            {
                var entities = await thisDirObject.EnumEntitiesAsync(flags, cancel);

                List <FileSystemEntity> ret = new List <FileSystemEntity>();

                FileSystemEntity thisDir = new FileSystemEntity(
                    fullPath: ctx.NormalizedPath,
                    name: ".",
                    attributes: thisDirObject.Attributes,
                    creationTime: thisDirObject.CreationTime,
                    lastWriteTime: thisDirObject.LastWriteTime,
                    lastAccessTime: thisDirObject.LastAccessTime
                    );

                ret.Add(thisDir);

                foreach (var entity in entities)
                {
                    if (entity is VfsDirectory dirObject)
                    {
                        FileMetadata meta = await dirObject.GetMetadataAsync(cancel);

                        FileSystemEntity dir = new FileSystemEntity(
                            fullPath: PathParser.Combine(ctx.NormalizedPath, entity.Name),
                            name: entity.Name,
                            attributes: meta.Attributes ?? FileAttributes.Directory,
                            creationTime: meta.CreationTime ?? Util.ZeroDateTimeOffsetValue,
                            lastWriteTime: meta.LastWriteTime ?? Util.ZeroDateTimeOffsetValue,
                            lastAccessTime: meta.LastAccessTime ?? Util.ZeroDateTimeOffsetValue
                            );

                        ret.Add(dir);
                    }
                    else if (entity is VfsFile fileObject)
                    {
                        FileMetadata meta = await fileObject.GetMetadataAsync(cancel);

                        FileSystemEntity file = new FileSystemEntity(
                            fullPath: PathParser.Combine(ctx.NormalizedPath, entity.Name),
                            name: entity.Name,
                            size: meta.Size,
                            physicalSize: meta.PhysicalSize,
                            attributes: meta.Attributes ?? FileAttributes.Directory,
                            creationTime: meta.CreationTime ?? Util.ZeroDateTimeOffsetValue,
                            lastWriteTime: meta.LastWriteTime ?? Util.ZeroDateTimeOffsetValue,
                            lastAccessTime: meta.LastAccessTime ?? Util.ZeroDateTimeOffsetValue
                            );
                        ret.Add(file);
                    }
                }

                return(ret.ToArray());
            }
            else
            {
                throw new VfsNotFoundException(directoryPath, "Directory not found.");
            }
        }
    }
예제 #7
0
    protected async Task <FileObject> AddFileAsync(FileParameters option, CreateFileCallback createFileCallback, CancellationToken cancel = default, bool noOpen = false)
    {
        using (VfsPathParserContext ctx = await ParsePathInternalAsync(option.Path, cancel))
        {
            if (ctx.Exception == null)
            {
                if (ctx.LastEntity is VfsFile file)
                {
                    // Already exists
                    if (option.Mode == FileMode.CreateNew)
                    {
                        throw new VfsException(option.Path, $"The file already exists.");
                    }

                    if (noOpen == false)
                    {
                        return(await file.OpenAsync(option, ctx.NormalizedPath, cancel));
                    }
                    else
                    {
                        return(null !);
                    }
                }
                else
                {
                    // There is existing another type object
                    throw new VfsException(option.Path, $"There are existing object at the speficied path.");
                }
            }

            if (ctx.Exception is VfsNotFoundException && ctx.RemainingPathElements.Count == 1 && ctx.LastEntity is VfsDirectory && option.Mode != FileMode.Open)
            {
                // Create new RAM file
                VfsDirectory lastDir = (VfsDirectory)ctx.LastEntity;

                string fileName = ctx.RemainingPathElements.Peek();

                var newFile = await createFileCallback(fileName, option, cancel);

                string fullPath = PathParser.Combine(ctx.NormalizedPath, fileName);

                try
                {
                    await lastDir.AddFileAsync(newFile);
                }
                catch
                {
                    await newFile.ReleaseLinkAsync(true);

                    throw;
                }

                if (noOpen == false)
                {
                    return(await newFile.OpenAsync(option, fullPath, cancel));
                }
                else
                {
                    return(null !);
                }
            }
            else
            {
                throw ctx.Exception;
            }
        }
    }