Ejemplo n.º 1
0
        public async Task <string> FindMedicineNameByBarcode(long barcode)
        {
            ScanFilter   scanFilter = new ScanFilter();
            ScanOperator ope        = ScanOperator.Equal;
            string       att        = "Barcode";

            scanFilter.AddCondition(att, ope, barcode);

            Table table = Table.LoadTable(DynamoClient, "Medicine");

            List <Document> medicine = await(table.Scan(scanFilter)).GetRemainingAsync();
            int             id       = medicine.Count;
            string          val      = "";

            foreach (Document item in medicine)
            {
                foreach (string key in item.Keys)
                {
                    if (key == "Name")
                    {
                        DynamoDBEntry dbEntry = item[key];
                        val = dbEntry.ToString();
                    }
                }
            }
            return(val);
        }
Ejemplo n.º 2
0
        public async static Task <string> QueryByClientGuid(string key)
        {
            // Function  returns a client "secret" using the ClientGuid as a search
            Table      QTable     = Table.LoadTable(dbClient, clientTableName);
            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("ClientGuid", ScanOperator.Equal, key);
            ScanOperationConfig config = new ScanOperationConfig()
            {
                Filter    = scanFilter,
                IndexName = "ClientGuid-index"
            };

            Search search = QTable.Scan(scanFilter);

            List <Document> allItems = await search.GetRemainingAsync();

            string secret = null;

            foreach (Document doc in allItems)
            {
                foreach (string itemkey in doc.Keys)
                {
                    DynamoDBEntry dbEntry = doc[itemkey];
                    string        val     = dbEntry.ToString();
                    if (itemkey == "secret")
                    {
                        secret = val;
                    }
                }
            }
            return(secret);
        }
        public object FromEntry(DynamoDBEntry entry)
        {
            if (!DateTime.TryParse(entry.ToString(), out var value))
            {
                throw new ArgumentException("entry must be a valid DateTime value.", nameof(entry));
            }

            return(value);
        }
        private Dictionary <CurrencyPair, decimal> ToExchangeRates(List <Document> allItems)
        {
            var exchangeRates = new Dictionary <CurrencyPair, decimal>();

            foreach (Document item in allItems)
            {
                var sourceCurrency     = string.Empty;
                var targetCurrencyJSON = string.Empty;

                foreach (string key in item.Keys)
                {
                    DynamoDBEntry dbEntry = item[key];
                    string        val     = dbEntry.ToString();

                    if (string.Equals(key, "source", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sourceCurrency = val;
                    }
                    if (string.Equals(key, "target", StringComparison.InvariantCultureIgnoreCase))
                    {
                        targetCurrencyJSON = val;
                    }
                }

                var perCurrencyRates = ToModel(sourceCurrency, JsonConvert.DeserializeObject <List <KeyValue> >(targetCurrencyJSON));



                if (perCurrencyRates != null)
                {
                    exchangeRates = Merge <CurrencyPair, decimal>(new List <Dictionary <CurrencyPair, decimal> >()
                    {
                        exchangeRates, perCurrencyRates
                    });
                }
            }

            return(exchangeRates);
        }
Ejemplo n.º 5
0
        //public async void FindMedicineWithBarcode(long barcode, string table)
        //{
        //    GetItemOperationConfig config = new GetItemOperationConfig()
        //    {
        //        AttributesToGet = new List<string>() { "Barcode" },
        //    };

        //    //  Primitive key = Medicine
        //    Table tablename = Table.LoadTable(DynamoClient, table);
        //    //  tablename.GetItemAsync(Primitive Medicine.MedicineID, Primitive sortKey, GetItemOperationConfig config)
        //    ScanFilter scanFilter = new ScanFilter();
        //    scanFilter.AddCondition("Barcode", ScanOperator.Equal, barcode);
        //    ScanOperationConfig ScanConfig = new ScanOperationConfig()
        //    {
        //        AttributesToGet = new List<string> { "MedicineID", "Barcode" },
        //        Filter = scanFilter
        //    };
        //    Search getMedicine = tablename.Scan(ScanConfig);
        //    List<Document> result = await getMedicine.GetRemainingAsync();
        //    foreach (Document item in result)
        //    {
        //        foreach (string key in item.Keys)
        //        {
        //            DynamoDBEntry dbEntry = item[key];
        //            string val = dbEntry.ToString();
        //            if (key.ToLower() == "Barcode")
        //            {
        //                List<string> barcodes = dbEntry.AsListOfString();
        //                StringBuilder valueBuilder = new StringBuilder();
        //                foreach (string code in barcodes)
        //                {
        //                    valueBuilder.Append(code).Append(", ");
        //                }
        //                val = valueBuilder.ToString();
        //            }
        //            Console.WriteLine(string.Format("Property: {0}, value: {1}", key, val));
        //        }
        //    }
        //}

        public async Task <string> FindPrescriptionForCurrentDate(string date)
        {
            ScanFilter   filter   = new ScanFilter();
            ScanOperator op       = ScanOperator.Equal;
            string       attrName = "StartDate";

            filter.AddCondition(attrName, op, date);

            Table tablename = Table.LoadTable(DynamoClient, "Prescription");

            List <Document> prescriptions = await(tablename.Scan(filter)).GetRemainingAsync();
            int             newID         = prescriptions.Count;
            string          medicineName  = "";
            string          numberOfTime  = "";
            string          returnValue   = "";

            foreach (Document item in prescriptions)
            {
                foreach (string key in item.Keys)
                {
                    if (key == "Barcode")
                    {
                        DynamoDBEntry dbEntry      = item[key];
                        string        val          = dbEntry.ToString();
                        long          barcodeValue = Convert.ToInt64(val);
                        //find medicine name
                        medicineName = await FindMedicineNameByBarcode(barcodeValue);
                    }

                    if (key == "NumberOfTime")
                    {
                        DynamoDBEntry dbEntry = item[key];
                        numberOfTime = dbEntry.ToString();
                    }
                    returnValue = medicineName + " & " + numberOfTime;
                }
            }
            return(returnValue);
        }
 public object FromEntry(DynamoDBEntry entry)
 {
     return(entry == null || entry == "" ? new DateTime() : DateTime.Parse(entry.ToString()));
 }
Ejemplo n.º 7
0
        public async static Task <List <RequestQ> > FetchQItem(string Key)
        {
            // Functions returns all requestQ items
            string tableName   = requestQTableName;
            Table  ThreadTable = Table.LoadTable(dbClient, tableName);

            List <RequestQ> requests = new List <RequestQ>();

            //get the RequestQ items for the ClientGuid
            ScanFilter scanFilter = new ScanFilter();

            scanFilter.AddCondition("ClientGuid", ScanOperator.Equal, Key);
            Search search = ThreadTable.Scan(scanFilter);

            try
            {
                //get the request. MobilitySkillsRequestQ has a sort key so we may get more than one
                List <Document> allItems = await search.GetRemainingAsync();

                Document doc = allItems.Last();
                //create a RequestQ object for this request
                RequestQ request = new RequestQ();
                foreach (string key in doc.Keys)
                {
                    DynamoDBEntry dbEntry = doc[key];
                    string        val     = dbEntry.ToString();
                    if (key == "ClientGuid")
                    {
                        request.ClientGuid = val;
                    }
                    if (key == "MessageId")
                    {
                        request.MessageId = val;
                    }
                    if (key == "corelationToken")
                    {
                        request.corelationToken = val;
                    }
                    if (key == "directive")
                    {
                        request.directive = val;
                    }
                    if (key == "endpointId")
                    {
                        request.endpointId = val;
                    }
                    if (key == "time")
                    {
                        request.time = val;
                    }
                    if (key == "secret")
                    {
                        request.secret = val;
                    }
                } //end for loop
                requests.Add(request);

                return(requests);
            } //end try
            catch
            {
                Globals.logger.LogCritical("Exception reading: " + requestQTableName);
                return(requests);
            } //end catch
        }
Ejemplo n.º 8
0
        public async static Task <bool> DeleteQbyClientGuid(string KeyItem)
        {
            //  The requestQ for the ESP8266 may have more than one unhandled request.  When we get a requestQ object to present to the
            //  8266 we only retrieve the latest.  This procedure is called when the 8266 responds after a requestQ item is processed successfully.
            //  We then delete any unhandled request in the queue.

            string tableName = requestQTableName;

            try
            {
                Table QTable = Table.LoadTable(dbClient, tableName);
                //get the RequestQ items for the ClientGuid
                ScanFilter scanFilter = new ScanFilter();
                scanFilter.AddCondition("ClientGuid", ScanOperator.Equal, KeyItem);
                ScanOperationConfig config = new ScanOperationConfig()
                {
                    Filter    = scanFilter,
                    IndexName = "ClientGuid-index"
                };

                Search          search   = QTable.Scan(scanFilter);
                List <Document> allItems = await search.GetRemainingAsync();

                foreach (Document doc in allItems)
                {
                    string KeytoDelete  = "";
                    string TimetoDelete = "";
                    foreach (string itemkey in doc.Keys)
                    {
                        DynamoDBEntry dbEntry = doc[itemkey];
                        string        val     = dbEntry.ToString();
                        if (itemkey == "ClientGuid")
                        {
                            KeytoDelete = val;
                        }
                        if (itemkey == "time")
                        {
                            TimetoDelete = val;
                        }
                    } // end foreach key

                    Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>
                    {
                        { "ClientGuid", new AttributeValue {
                              S = KeytoDelete
                          } },
                        { "time", new AttributeValue {
                              S = TimetoDelete
                          } }
                    };

                    // Create DeleteItem request
                    DeleteItemRequest request = new DeleteItemRequest
                    {
                        TableName = tableName,
                        Key       = key
                    };

                    // Issue request
                    var response = await dbClient.DeleteItemAsync(request);
                } //end foreach document

                return(true);
            }

            catch { return(false); }
        }