コード例 #1
0
 internal ModelOperationsCatalog(IHostEnvironment env)
 {
     Contracts.AssertValue(env);
     _env = env;
 }
コード例 #2
0
 /// <summary>
 /// Create an output "file" and return a handle to it.
 /// </summary>
 public static IFileHandle CreateOutputFile(this IHostEnvironment env, string path)
 {
     Contracts.AssertValue(env);
     Contracts.CheckNonWhiteSpace(path, nameof(path));
     return(new SimpleFileHandle(env, path, needsWrite: true, autoDelete: false));
 }
コード例 #3
0
 internal DataOperations(IHostEnvironment env)
 {
     Contracts.AssertValue(env);
     Environment = env;
 }
コード例 #4
0
 public TelemetryException(Exception exception)
 {
     Contracts.AssertValue(exception);
     Exception = exception;
 }
コード例 #5
0
        /// <summary>
        /// Make sure the given assemblies are loaded and that their loadable classes have been catalogued.
        /// </summary>
        public static void LoadAndRegister(IHostEnvironment env, string[] assemblies)
        {
            Contracts.AssertValue(env);

            if (Utils.Size(assemblies) > 0)
            {
                foreach (string path in assemblies)
                {
                    Exception ex = null;
                    try
                    {
                        // REVIEW: Will LoadFrom ever return null?
                        Contracts.CheckNonEmpty(path, nameof(path));
                        var assem = LoadAssembly(env, path);
                        if (assem != null)
                        {
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        ex = e;
                    }

                    // If it is a zip file, load it that way.
                    ZipArchive zip;
                    try
                    {
                        zip = ZipFile.OpenRead(path);
                    }
                    catch (Exception e)
                    {
                        // Couldn't load as an assembly and not a zip, so warn the user.
                        ex = ex ?? e;
                        Console.Error.WriteLine("Warning: Could not load '{0}': {1}", path, ex.Message);
                        continue;
                    }

                    string dir;
                    try
                    {
                        dir = CreateTempDirectory();
                    }
                    catch (Exception e)
                    {
                        throw Contracts.ExceptIO(e, "Creating temp directory for extra assembly zip extraction failed: '{0}'", path);
                    }

                    try
                    {
                        zip.ExtractToDirectory(dir);
                    }
                    catch (Exception e)
                    {
                        throw Contracts.ExceptIO(e, "Extracting extra assembly zip failed: '{0}'", path);
                    }

                    LoadAssembliesInDir(env, dir, false);
                }
            }
        }