// Currently used in TensorFlowTransform to protect temporary folders used when working with TensorFlow's SavedModel format. // Models are considered executable code, so we need to ACL tthe temp folders for high-rights process (so low-rights process can’t access it). /// <summary> /// Given a folder path, create it with proper ACL if it doesn't exist. /// Fails if the folder name is empty, or can't create the folder. /// </summary> internal static void CreateFolderWithAclIfNotExists(IHostEnvironment env, string folder) { Contracts.Check(env != null, nameof(env)); env.CheckNonWhiteSpace(folder, nameof(folder)); //if directory exists, do nothing. if (Directory.Exists(folder)) { return; } WindowsIdentity currentIdentity = null; try { currentIdentity = WindowsIdentity.GetCurrent(); } catch (PlatformNotSupportedException) { } if (currentIdentity != null && new WindowsPrincipal(currentIdentity).IsInRole(WindowsBuiltInRole.Administrator)) { // Create high integrity dir and set no delete policy for all files under the directory. // In case of failure, throw exception. CreateTempDirectoryWithAcl(folder, currentIdentity.User.ToString()); } else { try { Directory.CreateDirectory(folder); } catch (Exception exc) { throw Contracts.ExceptParam(nameof(folder), $"Failed to create folder for the provided path: {folder}. \nException: {exc.Message}"); } } }
internal static IEvaluator CreateEvaluator(this IHostEnvironment env, string settings) { Contracts.CheckValue(env, nameof(env)); env.CheckNonWhiteSpace(settings, nameof(settings)); return(CreateCore <IEvaluator>(env, typeof(SignatureEvaluator), settings)); }
public BaseAverager(IHostEnvironment env, string name) { Contracts.CheckValue(env, nameof(env)); env.CheckNonWhiteSpace(name, nameof(name)); Host = env.Register(name); }
private static byte[] CheckFileAndRead(IHostEnvironment env, string modelFile) { env.CheckNonWhiteSpace(modelFile, nameof(modelFile)); env.CheckUserArg(File.Exists(modelFile), nameof(modelFile)); return(File.ReadAllBytes(modelFile)); }
protected PredictorBase(IHostEnvironment env, string name) { Contracts.CheckValue(env, nameof(env)); env.CheckNonWhiteSpace(name, nameof(name)); Host = env.Register(name); }
private protected ModelParametersBase(IHostEnvironment env, string name) { Contracts.CheckValue(env, nameof(env)); env.CheckNonWhiteSpace(name, nameof(name)); Host = env.Register(name); }