Esempio n. 1
0
        /// <summary>
        ///
        /// <para>ScanTable</para>
        ///
        /// <para>Scans the table for attribute specified by _Key</para>
        ///
        /// <para>Check <seealso cref="IBDatabaseServiceInterface.ScanTable"/> for detailed documentation</para>
        ///
        /// </summary>
        public bool ScanTable(string _Table, out List <JObject> _ReturnItem, Action <string> _ErrorMessageAction = null)
        {
            _ReturnItem = null;

            var Table = GetTable(_Table);

            if (Table == null)
            {
                return(false);
            }

            List <JObject> Results = new List <JObject>();

            var Filter = Builders <BsonDocument> .Filter.Empty;

            IFindFluent <BsonDocument, BsonDocument> ReturnedSearch;

            try
            {
                ReturnedSearch = Table.Find(Filter);
            }
            catch (Exception e)
            {
                _ErrorMessageAction?.Invoke("BDatabaseServiceMongoDB->ScanTable: " + e.Message + ", Trace: " + e.StackTrace);
                return(false);
            }

            if (ReturnedSearch != null)
            {
                List <JObject> TempResults = new List <JObject>();
                try
                {
                    foreach (var Document in ReturnedSearch.ToList())
                    {
                        var CreatedJson = BsonToJObject(Document);
                        BUtility.SortJObject(CreatedJson, true);
                        TempResults.Add(CreatedJson);
                    }

                    _ReturnItem = TempResults;
                }
                catch (Newtonsoft.Json.JsonReaderException e)
                {
                    _ErrorMessageAction?.Invoke("BDatabaseServiceAWS->ScanTable: JsonReaderException: " + e.Message + ", Trace: " + e.StackTrace);
                    return(false);
                }
                return(true);
            }
            else
            {
                _ErrorMessageAction?.Invoke("BDatabaseServiceAWS->ScanTable: TableObject.ScanTable returned null.");
            }

            return(false);
        }