Пример #1
0
        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");
        }
Пример #2
0
 public App()
 {
     DispatcherHelper.Initialize();
     appHosting = new AppHosting();
     DispatcherUnhandledException += App_DispatcherUnhandledException;
     AppHelper.ProgramVerify();
 }
Пример #3
0
        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);
        }
Пример #4
0
        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 };
        }
Пример #5
0
 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);
     }
 }
Пример #6
0
 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);
     }
 }
Пример #7
0
        public App()
        {
            DispatcherHelper.Initialize();

            DispatcherUnhandledException += App_DispatcherUnhandledException;

            Exit += App_Exit;

            appHosting = new AppHosting();
        }
Пример #8
0
        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);
        }
Пример #9
0
 /// <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);
     }
 }
Пример #10
0
 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));
 }
Пример #11
0
        public async Task Topology()
        {
            var result = await TopologyEditor.ShowNew(topology, services);

            if (result.HasBeenCanceled)
            {
                return;
            }

            topology = result;
            Hosting  = treeBuilder.FromCredentials(topology);
            SaveToFile();
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
Пример #15
0
 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;
     }
 }
Пример #16
0
        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");
        }
Пример #17
0
 public static bool IsPublicCloudComplete(this IHosting hosting) =>
 !string.IsNullOrWhiteSpace(hosting?.PublicCloud?.Summary) ||
 !string.IsNullOrWhiteSpace(hosting?.PublicCloud?.Link) ||
 !string.IsNullOrWhiteSpace(hosting?.PublicCloud?.RequiresHscn);
Пример #18
0
 public static async Task <bool> IsFileOrUnexistAsync(this IHosting hosting, UPath path)
 {
     return((await hosting.TryGetItemInfoAsync(path))?.IsFile ?? true);
 }
 internal HybridHostingTypeSection(IHosting hosting) =>
Пример #20
0
 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);
Пример #21
0
 public virtual void SetUp()
 {
     Hosting = HostingManager.GetFileHostingFor(new OAuthCredentials {
         Token = Token, Service = HostingManager.Name
     });
 }
Пример #22
0
        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);
Пример #24
0
 internal OnPremiseSection(IHosting hosting) =>
Пример #25
0
 public static void SetUpClass()
 {
     controller = GetClient().Hosting;
     applyConfiguration();
 }
Пример #26
0
 internal PrivateCloudSection(IHosting hosting)
 {
     Answers = new PrivateCloudSectionAnswers(hosting?.PrivateCloud);
 }
Пример #27
0
 internal PublicCloudSection(IHosting hosting)
 {
     Answers = new PublicCloudSectionAnswers(hosting?.PublicCloud);
 }
Пример #28
0
 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);
Пример #29
0
 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);
Пример #30
0
        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");
        }
Пример #31
0
        private static IHosting get_default_hosting()
        {
            if (_defaultHosting != null)
                return _defaultHosting;

            _defaultHosting = new_hosting(new HostingConfiguration());

            return _defaultHosting;
        }