internal static void SaveFile(IFilePath fp) { using (new EntityCache(EntityCacheType.ForceNew)) { FileTypeAlgorithm alg = FileTypes.GetOrThrow(fp.FileType); if (alg.TakesOwnership) { string sufix = alg.CalculateSufix(fp); if (!sufix.HasText()) throw new InvalidOperationException("Sufix not set"); fp.SetPrefixPair(alg.GetPrefixPair(fp)); int i = 2; fp.Sufix = sufix; while (alg.RenameOnCollision && File.Exists(fp.FullPhysicalPath)) { fp.Sufix = alg.RenameAlgorithm(sufix, i); i++; } alg.SaveFileInDisk(fp); } } }
/// <summary> /// Initializes a new instance of the <see cref="RijndaelSymmetricCryptoSerialized"/> class. /// </summary> /// <param name="configurationFilePath">The configuration file path.</param> public RijndaelSymmetricCryptoSerialized(IFilePath configurationFilePath) { XmlSerializer serializer = new XmlSerializer(typeof(RijndaelSymmetricCryptoConfiguration)); using (Stream stream = configurationFilePath.GetFileStream()) using (XmlTextReader reader = new XmlTextReader(stream)) { RijndaelSymmetricCryptoConfiguration configuration = serializer.Deserialize(reader) as RijndaelSymmetricCryptoConfiguration; this.wrapped = new RijndaelSymmetricCrypto(configuration); } }
/// <summary> /// Initializes a new instance of the <see cref="AliasIpReader"/> class. /// </summary> /// <param name="configurationFilePath">The configuration file path.</param> public AliasIpReader(IFilePath configurationFilePath) { XmlSerializer serializer = new XmlSerializer(typeof(AliasIpReaderConfiguration)); using (Stream stream = configurationFilePath.GetFileStream()) { using (XmlTextReader reader = new XmlTextReader(stream)) { this.configuration = serializer.Deserialize(reader) as AliasIpReaderConfiguration; } } }
/// <summary> /// Initializes a new instance of the <see cref="Config" /> class. /// </summary> /// <param name="path">The path to the config file.</param> /// <param name="configSection">The name of the configuration section to load.</param> public Config(IFilePath path, string configSection) { this.config = null; var filepath = ((RelativeFilePath)path).FilePath; // It's ok for the config file to not be specified. // We will just use the default values for each request. if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath) && !string.IsNullOrEmpty(configSection)) { var json = File.ReadAllText(((RelativeFilePath)path).FilePath); var conf = JToken.Parse(json); this.config = conf.SelectToken(configSection, false); } }
/// <summary> /// Initialisiert eine neue Instanz der <see cref="T:System.Object" />-Klasse. /// </summary> /// <exception cref="ArgumentNullException"> /// <paramref name="filePath" /> is <see langword="null" />. /// <paramref name="app" /> is <see langword="null" />. /// </exception> public Worker(IFilePath filePath, App app) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } if (app == null) { throw new ArgumentNullException(nameof(app)); } _filePath = filePath; _app = app; _xmlPath = _app.XmlPath; }
internal static string UpdateExtension(IFilePath filePath, string newExtension) { Debug.Assert(filePath != null); // All these 3 assertions have been checked by contract! Debug.Assert(newExtension != null); Debug.Assert(newExtension.Length >= 2); Debug.Assert(newExtension[0] == '.'); var fileNameBefore = filePath.FileName; var fileNameAfter = filePath.FileNameWithoutExtension + newExtension; var filePathString = filePath.ToString(); Debug.Assert(filePathString.Length > fileNameBefore.Length); var filePathStringWithoutFileName = filePathString.Substring(0, filePathString.Length - fileNameBefore.Length); var filePathStringWithFileNameAfter = filePathStringWithoutFileName + fileNameAfter; return filePathStringWithFileNameAfter; }
internal static string UpdateExtension(IFilePath filePath, string extension) { Argument.IsNotNull(nameof(filePath), filePath); Argument.IsNotNull(nameof(extension), extension); Argument.IsValid(nameof(extension), extension, extension.Length >= 2 && extension[0] == '.'); var fileNameBefore = filePath.FileName; var fileNameAfter = filePath.FileNameWithoutExtension + extension; var filePathString = filePath.ToString(); //Debug.Assert(filePathString.Length > fileNameBefore.Length); var filePathStringWithoutFileName = filePathString.Substring(0, filePathString.Length - fileNameBefore.Length); return filePathStringWithoutFileName + fileNameAfter; }
/// <summary> /// Try get a new <see cref="IFilePath" /> object object from this string. /// </summary> /// <returns> /// <i>true</i> if <paramref name="path" /> is a valid file path and as a consequence, the returned <paramref name="filePath" /> is not /// null. /// </returns> /// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks> /// <param name="path">Represents the path.</param> /// <param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param> /// <param name="failureMessage">If this method returns <i>false</i>, this is the plain english description of the failure.</param> public static bool TryGetFilePath(this string path, out IFilePath filePath, out string failureMessage) { filePath = null; if (IsNullOrEmpty(() => path, out failureMessage)) { return false; } if (path.IsValidAbsoluteFilePath()) { filePath = path.ToAbsoluteFilePath(); return true; } if (path.IsValidRelativeFilePath()) { filePath = path.ToRelativeFilePath(); return true; } if (path.IsValidEnvVarFilePath()) { filePath = path.ToEnvVarFilePath(); return true; } if (path.IsValidVariableFilePath()) { filePath = path.ToVariableFilePath(); return true; } path.IsValidFilePath(out failureMessage); failureMessage = $@"The parameter pathString is not a valid file path.{Environment.NewLine}{failureMessage}"; return false; }
/// <summary> /// Try get a new <see cref="IFilePath" /> object object from this string. /// </summary> /// <returns> /// <i>true</i> if <paramref name="path" /> is a valid file path and as a consequence, the returned <paramref name="filePath" /> is not /// null. /// </returns> /// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks> /// <param name="path">Represents the path.</param> /// <param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param> public static bool TryGetFilePath(this string path, out IFilePath filePath) { string failureMessage; return path.TryGetFilePath(out filePath, out failureMessage); }
static bool IsNotExcluded(IFilePath x, IReadOnlyCollection<IAbsoluteDirectoryPath> excludedDirectories, IEnumerable<IAbsoluteFilePath> excludedFiles) { return IsNotDirectoryExcluded(x, excludedDirectories) && !excludedFiles.Contains(x); }
static bool IsNotDirectoryExcluded(IFilePath x, IReadOnlyCollection<IAbsoluteDirectoryPath> excludedDirectories) { IPath b = x; while (b.HasParentDirectory) { var parent = b.ParentDirectoryPath; if (excludedDirectories.Contains(parent)) return false; b = parent; } return true; }
public DoPutAction(Stream currentStream, IActivityIOPath destination, IDev2CRUDOperationTO crudArgument, string whereToPut, IDev2LogonProvider logOnProvider, IFile fileWrapper, IFileStreamFactory fileStreamFactory, IFilePath pathWrapper, IMemoryStreamFactory memoryStreamFactory, ImpersonationDelegate impersonationDelegate) : base(impersonationDelegate) { _logOnProvider = logOnProvider; _pathWrapper = pathWrapper; _fileWrapper = fileWrapper; _fileStreamFactory = fileStreamFactory; _memoryStreamFactory = memoryStreamFactory; _currentStream = currentStream; _destination = destination; _arguments = crudArgument; _impersonatedUser = _impersonationDelegate(_destination, _logOnProvider); _whereToPut = whereToPut; }
public void Test_Invalid_IsValidFile(string pathString) { Assert.IsFalse(pathString.IsValidFilePath()); Assert.Throws(typeof(ArgumentException), delegate { IFilePath filePath = pathString.ToRelativeFilePath(); }); }
public void Test_InvalidInputRelativePathNull() { Assert.IsFalse(PathHelpers.IsValidRelativeFilePath(null)); Assert.Throws(typeof(ArgumentNullException), delegate { IFilePath filePath = PathHelpers.ToRelativeFilePath(null); }); }
public static void SaveFileDefault(IFilePath fp) { string fullPhysicalPath = null; try { string path = Path.GetDirectoryName(fp.FullPhysicalPath); fullPhysicalPath = path; if (!Directory.Exists(path)) Directory.CreateDirectory(path); File.WriteAllBytes(fp.FullPhysicalPath, fp.BinaryFile); fp.BinaryFile = null; } catch (IOException ex) { ex.Data.Add("FullPhysicalPath", fullPhysicalPath); ex.Data.Add("CurrentPrincipal", System.Threading.Thread.CurrentPrincipal.Identity.Name); throw; } }
///<summary> ///Try get a new <see cref="IFilePath"/> object object from this string. ///</summary> ///<returns><i>true</i> if <paramref name="pathString"/> is a valid file path and as a consequence, the returned <paramref name="filePath"/> is not null.</returns> ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks> ///<param name="pathString">Represents the path.</param> ///<param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param> ///<param name="failureReason">If this method returns <i>false</i>, this is the plain english description of the failure.</param> public static bool TryGetFilePath(this string pathString, out IFilePath filePath, out string failureReason) { filePath = null; if (pathString.IsPathStringNullOrEmpty(out failureReason)) { return false; } if (pathString.IsValidAbsoluteFilePath()) { filePath = pathString.ToAbsoluteFilePath(); return true; } if (pathString.IsValidRelativeFilePath()) { filePath = pathString.ToRelativeFilePath(); return true; } if (pathString.IsValidEnvVarFilePath()) { filePath = pathString.ToEnvVarFilePath(); return true; } if (pathString.IsValidVariableFilePath()) { filePath = pathString.ToVariableFilePath(); return true; } var b = pathString.IsValidFilePath(out failureReason); Debug.Assert(!b); failureReason = @"The parameter pathString is not a valid file path. " + failureReason; return false; }
public IEnumerable<IDebugState> GetDebugStates(string serverWebUri, IDirectoryPath directory, IFilePath path) { yield break; }
public void Test_ValidFilePath(string pathString) { Assert.IsTrue(pathString.IsValidFilePath()); IFilePath path = pathString.ToFilePath(); }
public EmployeeDal(IFilePath filePath) { _filePath = filePath; }
public IEnumerable <IDebugState> GetDebugStates(string serverWebUri, IDirectoryPath directory, IFilePath path) { yield break; }
internal static bool IsSketchFilesFile(IFilePath path) { return(path.Name.HasExtension(SketchFilesExtension)); }
public FilePathCollection(IFilePath filePathMain, IFilePath filePathPdf, IFilePath filePathPrint) { FilePathMain = filePathMain; FilePathPdf = filePathPdf; FilePathPrint = filePathPrint; }
///<summary> ///Try get a new <see cref="IFilePath"/> object object from this string. ///</summary> ///<returns><i>true</i> if <paramref name="pathString"/> is a valid file path and as a consequence, the returned <paramref name="filePath"/> is not null.</returns> ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks> ///<param name="pathString">Represents the path.</param> ///<param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param> public static bool TryGetFilePath(this string pathString, out IFilePath filePath) { string failureReasonUnused; return pathString.TryGetFilePath(out filePath, out failureReasonUnused); }
protected override void LoadAssets(object argument) { var root = _filepath = (IFilePath)argument;
/// <summary> /// 从<see cref="IFilePath" />创建<see cref="DirectoryResource" /> /// </summary> /// <param name="path"></param> /// <param name="name"></param> public DirectoryResource(IFilePath path, string name = null) : base(Uuid.NewUuid(), name ?? path.GetFileName(), null, path) { }
static ServerVersionRepository CreateServerVersionRepository(IVersionStrategy strat, IResourceCatalog cat, IDirectory dir, string rootPath, IFile file, IFilePath filePath) { var serverVersionRepostory = new ServerVersionRepository(strat, cat, dir, rootPath, file, filePath); return(serverVersionRepostory); }