public WinFabricNameEnumerationResult(int identifier, NameEnumerationResult result)
        {
            ThrowIf.Null(result, "result");

            this.Identifier = identifier;
            this.Result     = result;
        }
예제 #2
0
파일: Utility.cs 프로젝트: zbrad/FabricLib
        /// <summary>
        /// enumerate all fabric names
        /// </summary>
        /// <param name="client">fabric client to use</param>
        /// <param name="subName">base namespace</param>
        /// <returns>list of Uri names</returns>
        public static List <Uri> EnumerateAndPrintSubNames(FabricClient client, Uri subName)
        {
            List <Uri> result = new List <Uri>();

            log.Info("Enumerating all fabric names which matches {0}:", subName);

            try
            {
                NameEnumerationResult nameResult = null;
                do
                {
                    Task <NameEnumerationResult> enumTask = client.PropertyManager.EnumerateSubNamesAsync(subName, nameResult, true);
                    enumTask.Wait();
                    nameResult = enumTask.Result;

                    // Each batch has two flags: HasMore and Consistent.
                    // Consistent indicates whether the relevant naming data in the cluster is currently being updated
                    // HasMore indicates whether there are othe batches that remain.
                    // If there are other batches, the user needs to recall the EnumerateSubNamesAsync and give the latest batch as the previousResult.
                    // PreviousResult makes sure that the subsequent batch is returned.
                    foreach (Uri name in nameResult)
                    {
                        log.Info("\t{0}", name);
                        result.Add(name);
                    }
                }while (nameResult.HasMoreData);
            }
            catch (AggregateException e)
            {
                if (e.InnerException is TimeoutException)
                {
                    log.Error(e, "EnumerateSubNamesAsync timed out");
                }
                else if (e.InnerException is FabricElementNotFoundException)
                {
                    // FabricElementNotFoundException indicates that the name in the argument did not exist in the Naming name tree.
                    log.Info("Name '{0}' does not exist", subName);
                }
                else
                {
                    log.Error(e, "Unexpected exception");
                }
            }
            catch (ArgumentException e)
            {
                // One of the common reasons for ArgumentException is that the specified URI is not a valid Windows Fabric name.
                log.Error(e, "Not a valid argument");
            }
            catch (Exception e)
            {
                log.Error(e, "Unexpected exception");
            }

            if (result.Count == 0)
            {
                log.Info("\t{0} does not have any child names.", subName);
            }

            return(result);
        }
예제 #3
0
파일: Utility.cs 프로젝트: zbrad/FabricLib
        /// <summary>
        /// get URI names
        /// </summary>
        /// <param name="fc">fabric client</param>
        /// <param name="baseUri">base uri</param>
        /// <returns>list of uri names</returns>
        public static List <Uri> GetNames(FabricClient fc, Uri baseUri)
        {
            List <Uri>                   names   = new List <Uri>();
            int                          limit   = Defaults.WaitRetryLimit;
            NameEnumerationResult        results = null;
            Task <NameEnumerationResult> t;

            while (limit-- > 0)
            {
                try
                {
                    while ((results =
                                (t = fc.PropertyManager.EnumerateSubNamesAsync(baseUri, results, true, Defaults.WaitDelay, CancellationToken.None)).Result).HasMoreData)
                    {
                        foreach (Uri name in results)
                        {
                            names.Add(name);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            if (limit < 0 || names.Count == 0)
            {
                return(null);
            }

            return(names);
        }
예제 #4
0
        public NameEnumerationResult Convert(WinFabricNameEnumerationResult previousResult)
        {
            NameEnumerationResult result = null;

            if (previousResult != null)
            {
                result = this.EnumerationHolder.RetrieveObject(previousResult.Identifier).RetrieveEnumeration <NameEnumerationResult>();
            }

            return(result);
        }
예제 #5
0
        public WinFabricNameEnumerationResult Convert(NameEnumerationResult result)
        {
            WinFabricNameEnumerationResult actualResult = null;

            if (result != null)
            {
                int id = this.EnumerationHolder.StoreObject(new EnumerationWrapper(result));
                actualResult = new WinFabricNameEnumerationResult(id, result);
            }

            return(actualResult);
        }
예제 #6
0
        private bool TryEnumNames(List <Uri> list, Uri uri, NameEnumerationResult result)
        {
            bool hasResult = false;

            try
            {
                this.fc.PropertyManager.EnumerateSubNamesAsync(uri, result, true).ContinueWith((t) =>
                {
                    if (t.Exception != null)
                    {
                        if (t.Exception is AggregateException)
                        {
                            log.Error("EnumerateSubNames failed, exception: {0}", t.Exception.InnerException.Message);
                        }
                        else
                        {
                            log.Error("EnumerateSubNames failed, exception: {0}", t.Exception.Message);
                        }
                    }
                    else
                    {
                        list.AddRange(t.Result);
                        if (t.Result.HasMoreData)
                        {
                            this.TryEnumNames(list, uri, t.Result);
                        }

                        hasResult = true;
                    }
                }).Wait();
            }
            catch (AggregateException ae)
            {
                log.Error("EnumerateSubNames failed, exception: {0}", ae.InnerException.Message);
            }
            catch (Exception e)
            {
                log.Error("EnumerateSubNames failed, exception: {0}", e.Message);
            }

            return(hasResult);
        }
예제 #7
0
        private bool TryEnumNames(List<Uri> list, Uri uri, NameEnumerationResult result)
        {
            bool hasResult = false;
            try
            {
                this.fc.PropertyManager.EnumerateSubNamesAsync(uri, result, true).ContinueWith((t) =>
                    {
                        if (t.Exception != null)
                        {
                            if (t.Exception is AggregateException)
                            {
                                log.Error("EnumerateSubNames failed, exception: {0}", t.Exception.InnerException.Message);
                            }
                            else
                            {
                                log.Error("EnumerateSubNames failed, exception: {0}", t.Exception.Message);
                            }
                        }
                        else
                        {
                            list.AddRange(t.Result);
                            if (t.Result.HasMoreData)
                            {
                                this.TryEnumNames(list, uri, t.Result);
                            }

                            hasResult = true;
                        }
                    }).Wait();
            }
            catch (AggregateException ae)
            {
                log.Error("EnumerateSubNames failed, exception: {0}", ae.InnerException.Message);
            }
            catch (Exception e)
            {
                log.Error("EnumerateSubNames failed, exception: {0}", e.Message);
            }

            return hasResult;
        }
예제 #8
0
 public EnumerationWrapper(NameEnumerationResult enumerationResult)
 {
     ThrowIf.Null(enumerationResult, "enumerationResult");
     this.enumerationResult = enumerationResult;
 }
예제 #9
0
        public OperationResult <WinFabricNameEnumerationResult> ConvertToWinFabricNameEnumerationResult(NameEnumerationResult enumerationResult, uint errorCode)
        {
            OperationResult <WinFabricNameEnumerationResult> actualResult = new OperationResult <WinFabricNameEnumerationResult>(errorCode);

            if (enumerationResult != null)
            {
                WinFabricNameEnumerationResult testProperty = this.Convert(enumerationResult);
                actualResult = FabricClientState.CreateOperationResultFromNativeErrorCode <WinFabricNameEnumerationResult>(testProperty);
            }

            return(actualResult);
        }