private async Task <IHosting> GetHostingWithFile(UPath path) { var workedHostings = hostings.ToList(); var tasks = hostings.Select(h => h.IsFileAsync(path).WithTimeOut(Timeout)).ToList(); IHosting withFile = null; while (tasks.Count > 0) { var completed = await Task.WhenAny(tasks); var hosting = workedHostings[tasks.IndexOf(completed)]; if (!completed.IsFaulted && completed.Result) { if (withFile != null) { throw new HostingException("More one hosting contains file!"); } withFile = hosting; } workedHostings.Remove(hosting); tasks.Remove(completed); } if (withFile != null) { return(withFile); } throw new ItemNotFound($"File '{path}' not founded"); }
public App() { DispatcherHelper.Initialize(); appHosting = new AppHosting(); DispatcherUnhandledException += App_DispatcherUnhandledException; AppHelper.ProgramVerify(); }
public static async Task DownloadDirectoryAsync(this IHosting hosting, UPath source, DirectoryInfo destination, IProgress <UPath> failures = null, IProgress <UPath> successes = null) { if (File.Exists(destination.FullName)) { throw new UnexpectedItemType("Destination should be a directory"); } if (destination.Parent == null || File.Exists(destination.Parent.FullName) || !destination.Parent.Exists) { throw new UnexpectedItemType("Problem with destination parent"); } if (!destination.Exists) { Directory.CreateDirectory(destination.FullName); } var tasks = new List <Task>(); var items = await hosting.GetDirectoryListAsync(source); foreach (var item in items) { var destFile = destination.GetSubFile(item.Name); var destDir = destination.GetSubDirectory(item.Name); var task = item.IsFile ? hosting.DownloadFileAsync(item.Path, destFile) : hosting.DownloadDirectoryAsync(item.Path, destDir, failures, successes); task = task.ContinueWith(t => (t.IsFaulted ? failures : successes).Report(item.Path)); tasks.Add(task); } await Task.WhenAll(tasks); }
public void SetUp() { var a = new List <ItemInfo>() .AddFile("afile") .AddDirectory("adir") .AddFile("abfile") .AddDirectory("abdir") .AddFile("filedir") .ToHosting(); var b = new List <ItemInfo>() .AddFile("bfile") .AddDirectory("bdir") .AddFile("abfile") .AddDirectory("abdir") .AddDirectory("filedir") .ToHosting(); var c = new List <ItemInfo>().AddFile("cfile").ToHosting(); var d = A.Fake <IHosting>(); A.CallTo(() => d.GetItemInfoAsync("ifs")).Returns(TaskWithThrows(new InconsistentFileSystemState(""))); merged = new MergedHostingManager().GetFileHostingFor(new[] { a, b, c, d }); abHostings = new[] { a, b }; }
public static async Task DownloadFileAsync(this IHosting hosting, UPath source, FileInfo destination, IProgress <double> progress = null) { using (var stream = destination.OpenWrite()) { await hosting.DownloadFileAsync(stream, source, progress); } }
public static async Task UploadFileAsync(this IHosting hosting, FileInfo source, UPath destination, IProgress <double> progress = null) { using (var stream = source.OpenRead()) { await hosting.UploadFileAsync(stream, destination, progress); } }
public App() { DispatcherHelper.Initialize(); DispatcherUnhandledException += App_DispatcherUnhandledException; Exit += App_Exit; appHosting = new AppHosting(); }
public static async Task <bool> IsFileAsync(this IHosting hosting, UPath path) { var result = (await hosting.TryGetItemInfoAsync(path))?.IsFile; if (result != null) { return(result.Value); } throw new ItemNotFound(path); }
/// <summary> /// /// </summary> /// <param name="hosting"></param> /// <param name="path"></param> /// <returns>ItemInfo if item exist or null if item is not founded</returns> public static async Task <ItemInfo> TryGetItemInfoAsync(this IHosting hosting, UPath path) { try { return(await hosting.GetItemInfoAsync(path)); } catch (ItemNotFound) { return(null); } }
public static async Task <Node <ItemInfo> > GetItemsTreeAsync(this IHosting hosting, UPath path) { if (!await hosting.IsExistAsync(path)) { throw new ItemNotFound(); } if (await hosting.IsFileAsync(path)) { return(new Node <ItemInfo>(await hosting.GetItemInfoAsync(path))); } return(await hosting.GetDirectoryItemsTreeAsync(path)); }
public async Task Topology() { var result = await TopologyEditor.ShowNew(topology, services); if (result.HasBeenCanceled) { return; } topology = result; Hosting = treeBuilder.FromCredentials(topology); SaveToFile(); }
public static async Task <ItemType> GetItemType(this IHosting hosting, UPath path) { try { var info = await hosting.GetItemInfoAsync(path); return(info.Type); } catch (ItemNotFound) { return(ItemType.Unexist); } }
private static async Task <Node <ItemInfo> > GetDirectoryItemsTreeAsync(this IHosting hosting, UPath path) { var nested = (await hosting.GetDirectoryListAsync(path)) .Select(async i => { return(i.IsDirectory ? await hosting.GetDirectoryItemsTreeAsync(i.Path) : new Node <ItemInfo>(await hosting.GetItemInfoAsync(i.Path))); }).ToList(); await Task.WhenAll(nested); var node = new Node <ItemInfo>(await hosting.GetItemInfoAsync(path)); node.Nested.AddRange(nested.Select(n => n.Result)); return(node); }
public static async Task UploadDirectoryAsync(this IHosting hosting, DirectoryInfo source, UPath destination, IProgress <UPath> failures = null, IProgress <UPath> successes = null, Action <UPath, Exception> logger = null) { if (!await hosting.IsDirectoryAsync(destination.Parent)) { throw new UnexpectedItemType("Parent of destination should be directory"); } if (await hosting.IsFileAsync(destination)) { throw new UnexpectedItemType("Destination should be a directory"); } await hosting.MakeDirectoryAsync(destination); var tasks = new List <Task>(); foreach (var directory in source.GetDirectories()) { var d = destination.SubPath(directory.Name); var task = hosting.UploadDirectoryAsync(directory, d, failures, successes, logger); tasks.Add(task.ContinueWith(t => { (t.IsFaulted ? failures : successes).Report(d); if (t.IsFaulted) { logger(d, t.Exception.InnerException); } })); } foreach (var file in source.GetFiles()) { var f = destination.SubPath(file.Name); var task = hosting.UploadFileAsync(file, f); tasks.Add(task.ContinueWith(t => { (t.IsFaulted ? failures : successes).Report(f); if (t.IsFaulted) { logger(f, t.Exception.InnerException); } })); } await Task.WhenAll(tasks); }
private void LoadFromFile() { if (!File.Exists(TopologyFileName)) { return; } using (var text = File.OpenText(TopologyFileName)) { topology = formatter.ParseNodes(text); } if (topology != null) { Hosting = treeBuilder.FromCredentials(topology); } else { Hosting = null; } }
private static void start_services(VcallConfiguration vconfig) { if (_core != null) return; var core = Helpers.TryCatch(_log, () => VcallSubsystem.New(vconfig), ex => Helpers.ThrowNew<VcallException>(ex, _log, "Failed to create Vcall subsystem")); Helpers.TryCatch(_log, () => core.Start(), ex => Helpers.ThrowNew<VcallException>(ex, _log, "Failed to start Vcall subsystem")); _core = core; _defaultHosting = null; _defaultProxy = null; _log.Info("Vcall services are started"); }
public static bool IsPublicCloudComplete(this IHosting hosting) => !string.IsNullOrWhiteSpace(hosting?.PublicCloud?.Summary) || !string.IsNullOrWhiteSpace(hosting?.PublicCloud?.Link) || !string.IsNullOrWhiteSpace(hosting?.PublicCloud?.RequiresHscn);
public static async Task <bool> IsFileOrUnexistAsync(this IHosting hosting, UPath path) { return((await hosting.TryGetItemInfoAsync(path))?.IsFile ?? true); }
internal HybridHostingTypeSection(IHosting hosting) =>
public static bool IsHybridHostingTypeComplete(this IHosting hosting) => !string.IsNullOrWhiteSpace(hosting?.HybridHostingType?.Summary) || !string.IsNullOrWhiteSpace(hosting?.HybridHostingType?.Link) || !string.IsNullOrWhiteSpace(hosting?.HybridHostingType?.HostingModel) || !string.IsNullOrWhiteSpace(hosting?.HybridHostingType?.RequiresHscn);
public virtual void SetUp() { Hosting = HostingManager.GetFileHostingFor(new OAuthCredentials { Token = Token, Service = HostingManager.Name }); }
public void ManyToMany_should_get_self_notifications() { var vcall = VcallSubsystem.New(); vcall.Start(); const int count = 7; var random = new Random(); var hosts = new IHosting[count]; var vproxy = new IProxy[count]; for (int i = 0; i < count; i++) { Thread.Sleep(random.Next(100)); hosts[i] = vcall.NewHosting(); vproxy[i] = vcall.NewProxy(); } UnitTestingHelpers.RunUpdateLoop(120 * 1000, () => vcall.Counters); vcall.Stop(); Console.WriteLine(vcall.Counters.Format("Vcall is stopped")); }
internal OnPremiseSection(IHosting hosting) => Answers = new OnPremiseSectionAnswers(hosting?.OnPremise);
internal OnPremiseSection(IHosting hosting) =>
public static void SetUpClass() { controller = GetClient().Hosting; applyConfiguration(); }
internal PrivateCloudSection(IHosting hosting) { Answers = new PrivateCloudSectionAnswers(hosting?.PrivateCloud); }
internal PublicCloudSection(IHosting hosting) { Answers = new PublicCloudSectionAnswers(hosting?.PublicCloud); }
public static bool IsOnPremiseComplete(this IHosting hosting) => !string.IsNullOrWhiteSpace(hosting?.OnPremise?.Summary) || !string.IsNullOrWhiteSpace(hosting?.OnPremise?.Link) || !string.IsNullOrWhiteSpace(hosting?.OnPremise?.HostingModel) || !string.IsNullOrWhiteSpace(hosting?.OnPremise?.RequiresHSCN);
public static bool IsPrivateCloudComplete(this IHosting hosting) => !string.IsNullOrWhiteSpace(hosting?.PrivateCloud?.Summary) || !string.IsNullOrWhiteSpace(hosting?.PrivateCloud?.Link) || !string.IsNullOrWhiteSpace(hosting?.PrivateCloud?.HostingModel) || !string.IsNullOrWhiteSpace(hosting?.PrivateCloud?.RequiresHSCN);
private static void stop_services() { if (_core == null) return; var defaultHosting = _defaultHosting; var defaultProxy = _defaultProxy; var core = _core; _defaultHosting = null; _defaultProxy = null; _core = null; try { if (defaultHosting != null) defaultHosting.Close(); if (defaultProxy != null) defaultProxy.Close(); Helpers.TryCatch(_log, () => core.Stop(), ex => Helpers.ThrowNew<VcallException>(ex, _log, "Failed to stop default Vcall endpoint services")); } catch (Exception ex) { _log.Error(ex.GetDetailedMessage()); } _log.Info("Vcall services are stopped"); }
private static IHosting get_default_hosting() { if (_defaultHosting != null) return _defaultHosting; _defaultHosting = new_hosting(new HostingConfiguration()); return _defaultHosting; }