Ejemplo n.º 1
0
        private void DownloadFiles()
        {
            var client = new WebClient();

            foreach (var url in URLs)
            {
                var fileName  = url.Substring(url.LastIndexOf('/') + 1);
                var localPath = Path.GetFullPath(Path.Combine(ComponentManager.BasePath ?? "", ComponentManager.PATH_COMPONENTS, fileName));

                try
                {
                    client.DownloadFile(new Uri(url), localPath);
                    if (url != URLs.First())
                    {
                        var factory = ComponentManager.LoadFactory(localPath);
                        if (factory != null)
                        {
                            ComponentManager.ComponentFactories.Add(fileName, factory);
                        }
                    }
                }
                catch (WebException)
                {
                    Log.Error("Error downloading file from " + url);
                }
            }

            if (Type == AutoSplitterType.Component)
            {
                var factory = ComponentManager.LoadFactory(LocalPath);
                ComponentManager.ComponentFactories.Add(Path.GetFileName(LocalPath), factory);
            }
        }
Ejemplo n.º 2
0
        private void DownloadFiles()
        {
            var client = new WebClient();

            foreach (var url in URLs)
            {
                var fileName      = url.Substring(url.LastIndexOf('/') + 1);
                var tempFileName  = fileName + "-temp";
                var localPath     = Path.GetFullPath(Path.Combine(ComponentManager.BasePath ?? "", ComponentManager.PATH_COMPONENTS, fileName));
                var tempLocalPath = Path.GetFullPath(Path.Combine(ComponentManager.BasePath ?? "", ComponentManager.PATH_COMPONENTS, tempFileName));

                try
                {
                    // Download to temp file so the original file is kept if it fails downloading
                    client.DownloadFile(new Uri(url), tempLocalPath);
                    File.Copy(tempLocalPath, localPath, true);

                    if (url != URLs.First() && localPath.EndsWith(".dll"))
                    {
                        var factory = ComponentManager.LoadFactory <IComponentFactory>(localPath);
                        if (factory != null)
                        {
                            ComponentManager.ComponentFactories.Add(fileName, factory);
                        }
                    }
                }
                catch (WebException)
                {
                    Log.Error("Error downloading file from " + url);
                }
                catch (Exception ex)
                {
                    // Catch errors of File.Copy() if necessary
                    Log.Error(ex);
                }
                finally
                {
                    try
                    {
                        // This is not required to run the AutoSplitter, but should still try to clean up
                        File.Delete(tempLocalPath);
                    }
                    catch (Exception)
                    {
                        Log.Error($"Failed to delete temp file: {tempLocalPath}");
                    }
                }
            }

            if (Type == AutoSplitterType.Component)
            {
                var factory = ComponentManager.LoadFactory <IComponentFactory>(LocalPath);
                ComponentManager.ComponentFactories.Add(Path.GetFileName(LocalPath), factory);
            }
        }