public ProfileItemPage(EditProfilePage editProfilePage, ProfileItemJson profileItem) : base("ProfileItemPage")
        {
            _editProfilePage = editProfilePage;
            _profileItem     = profileItem;

            AddTitleRow("Title");

            AddHeaderRow();

            _key = AddEntryRow(profileItem.k, "Key");
            _key.SetDetailViewIcon(Icons.Pencil);
            _value = AddEntryRow(profileItem.v ?? (profileItem.IsWebSite() ? "https://" : ""), profileItem.IsWebSite() ? "WebsiteValue" : "MailValue");
            _value.SetDetailViewIcon(profileItem.IsWebSite() ? Icons.RowLink : Icons.At);

            Status.Add(_key.Edit, T("KeyStatus"), (sv, edit, newText, oldText) =>
            {
                return(!string.IsNullOrWhiteSpace(newText));
            }).Add(_value.Edit, profileItem.IsWebSite() ? T("WebsiteStatus") : T("MailStatus"), (sv, edit, newText, oldText) =>
            {
                if (profileItem.IsWebSite())
                {
                    return(newText.IsValdiUrl(false));
                }
                if (profileItem.IsMail())
                {
                    return(newText.IsValidMail(false));
                }

                return(false);
            });

            AddFooterRow();

            AddSubmitRow("Common.Submit", Submit);
        }
        public EditInboxPage(MessageNode node, InboxNameRecordInfo inboxItem) : base("EditInboxPage")
        {
            Subscribe <InboxRenameEvent>(InboxRenamed);

            _node      = node;
            _inboxItem = inboxItem;
            _title     = inboxItem.Title;

            AddTitleRow("Title");

            AddHeaderRow("RenameHeader");

            _titleRow = AddEntryRow(_title, "RenameEntry");

            Status.Add(_titleRow.Edit, T("RenameStatus"), (sv, edit, newText, oldText) =>
            {
                if (!string.IsNullOrEmpty(newText) && newText.Length <= MessageServiceInfo.MaxInboxNameLength && newText != _title)
                {
                    return(true);
                }

                return(false);
            });

            AddSubmitRow("RenameButton", Rename);

            AddFooterRow();
        }
        public TransferPage(long receiverId = 0, long amount = 0, string reason = null) : base("TransferPage")
        {
            _receiverId = receiverId;

            Subscribe <CoreAccountTransferEvent>(TransferEvent);

            AddTitleRow("Title");

            AddHeaderRow("TransferDetail");

            _receiver = AddEntryRow(null, "Receiver");
            _receiver.SetDetailViewIcon(Icons.Coins);

            if (receiverId > 0)
            {
                _receiver.Edit.Text      = receiverId.ToString();
                _receiver.Edit.IsEnabled = false;
            }

            var showreceiver = AddButtonRow("ReceiverButton", ShowReceiver);

            showreceiver.IsEnabled = false;

            _amount = AddEntryRow(null, "Amount");
            _amount.SetDetailViewIcon(Icons.CreditCardFront);
            if (amount > 0)
            {
                _amount.Edit.Text = Currency.ToString(amount, false);
            }

            _reason = AddEntryRow(null, "Reason");
            _reason.SetDetailViewIcon(Icons.Pencil);
            _reason.Edit.Text = reason;

            _reason.Edit.TextChanged += (sender, e) =>
            {
                var txt = e.NewTextValue;
                if (!string.IsNullOrEmpty(txt) && txt.Length > AccountUpdateOperation.MaxReasonLength)
                {
                    _reason.Edit.Text = txt.Substring(0, AccountUpdateOperation.MaxReasonLength);
                }
            };

            AddFooterRow();

            Status.Add(_receiver.Edit, T("ReceiverStatus"), (sv, edit, newText, oldText) =>
            {
                return(showreceiver.IsEnabled = StatusValidators.PositiveNumberValidator(sv, edit, newText, oldText));
            }).
            Add(_amount.Edit, T("AmountStatus"), StatusValidators.HeleusCoinValidator).
            AddBusyView(showreceiver).
            AddBusyView(_reason.Edit);

            AddIndex       = AddSubmitRow("Submit", Submit);
            AddIndexBefore = true;

            _password = AddPasswordRow(null, "Password");

            Status.Add(_password.Edit, T("PasswordStatus"), StatusValidators.HeleusPasswordValidator);
        }
Exemple #4
0
        void SetupPage()
        {
            _balanceView    = null;
            _unlockButton   = null;
            _unlockPassword = null;

            StackLayout.Children.Clear();

            AddTitleRow("Title");

            if (!WalletApp.HasCoreAccount)
            {
                AddRegisterSection();
            }
            else if (!WalletApp.IsCoreAccountUnlocked)
            {
                AddUnlockSection();
            }
            else
            {
                AddAccountSection();
            }

            UpdateSuspendedLayout();
        }
        public VerifyPage(VerificationResult result) : base("VerifyPage")
        {
            Subscribe <ServiceNodesLoadedEvent>(ServiceNodesLoaded);

            var viewResult = result != null;

            AddTitleRow("Title");

            if (!viewResult)
            {
                AddHeaderRow("Search");

                _transactionId = AddEntryRow(null, "TransactionId");
                _transactionId.SetDetailViewIcon(Icons.ShieldCheck);
                _transactionId.Edit.TextChanged += (sender, e) =>
                {
                    StatusValidators.PositiveNumberValidator(null, _transactionId.Edit, e.NewTextValue, e.OldTextValue);
                };

                AddSubmitRow("SearchButton", Search, false);
                AddInfoRow("SearchInfo");
                AddFooterRow();
            }

            _verifyButton           = AddButtonRow("VerifyFile", VerifyFile);
            _verifyButton.RowStyle  = Theme.SubmitButton;
            _verifyButton.IsEnabled = false;

            _verifyView = new VerifyView();
            AddViewRow(_verifyView);

            _viewFiles           = AddButtonRow("ViewFiles", ViewFiles);
            _viewFiles.IsEnabled = false;

            _link                     = AddLinkRow("Link", "");
            _link.IsEnabled           = false;
            _verifyLink               = AddLinkRow("VerifyLink", "");
            _verifyLink.IsEnabled     = false;
            _copyVerifyLink           = AddButtonRow("CopyVerifyLink", Copy);
            _copyVerifyLink.IsEnabled = false;
            _account                  = AddButtonRow("Account", Account);
            _account.IsEnabled        = false;

            AddFooterRow();

            if (!viewResult)
            {
                AddHeaderRow("Common.ServiceNode");
                _serviceNode = AddRow(new ServiceNodeButtonRow(VerifyApp.Current.GetLastUsedServiceNode(), this, SelectServiceNode));
                AddInfoRow("Common.ServiceNodeInfo");
                AddFooterRow();
            }

            if (viewResult)
            {
                Update(result);
            }
        }
Exemple #6
0
        //DeleteObject method just in case if it can be used to remove entry when object is removed.
        private void DeleteObject(EntryRow entry, NpgsqlConnection conn, ILambdaContext context)
        {
            NpgsqlCommand command = new NpgsqlCommand("DELETE FROM health.\"healthTable\" WHERE id == " + entry.id + ";", conn);

            context.Logger.LogLine(command.Statements[0].SQL);
            command.ExecuteNonQuery();
            conn.Close();
            context.Logger.LogLine("DELETE command sent. Connection is now closed. ");
        }
Exemple #7
0
        public RestorePage() : base("RestorePage")
        {
            EnableStatus();

            AddTitleRow("Title");

            AddHeaderRow("Account");

            _accountId = AddEntryRow(null, "AccountId");
            _accountId.SetDetailViewIcon(Icons.Coins);

            AddSeparatorRow();

            _name = AddEntryRow("", "RegisterPage.Name");
            _name.SetDetailViewIcon(Icons.Pencil);
            _password1 = AddPasswordRow("", "RegisterPage.Password1");
            var password2 = AddPasswordRow("", "RegisterPage.Password2");

            Status.AddBusyView(_accountId);
            Status.Add(_accountId.Edit, T("AccountStatus"), StatusValidators.PositiveNumberValidator);

            Status.Add(_password1.Edit, T("RegisterPage.PasswordStatus", WalletApp.MinPasswordLength), (sv, entry, newText, oldText) =>
            {
                var pw1 = _password1.Edit.Text;
                var pw2 = password2.Edit.Text;

                return(WalletApp.IsValidPassword(pw1) && WalletApp.IsValidPassword(pw2) && pw1 == pw2);
            }).
            AddBusyView(password2);

            AddFooterRow();


            AddHeaderRow("AuthorizeAccountPage.SignatureKey");

            _passphrase = AddEntryRow(null, "AuthorizeAccountPage.Passphrase", ServiceNodeManager.MinimumServiceAccountPassphraseLength);
            var button = AddButtonRow("AuthorizeAccountPage.NewPassphrase", Generate);

            Status.AddBusyView(button);

            _key = AddEditorRow(null, "AuthorizeAccountPage.SignatureKey");
            _key.SetDetailViewIcon(Icons.Key);
            Status.Add(_key.Edit, T("RestoreAccountPage.KeyStatus"), (sv, edit, newText, oldText) =>
            {
                return(StatusValidators.HexValidator(64, sv, edit, newText, oldText));
            });

            AddFooterRow();


            password2.Edit.TextChanged += (sender, e) =>
            {
                Status.ReValidate();
            };

            AddSubmitRow("Restore", Restore);
        }
 private static void AssertEntry(EntryRow expected, Entry actual, int index)
 {
   Assert.AreEqual(expected.Account, actual.Account, "Row {0} Account", index);
   Assert.AreEqual(expected.BookingDate, actual.BookingDate, "Row {0} BookingDate", index);
   Assert.AreEqual(expected.Description, actual.Description, "Row {0} Description", index);
   Assert.AreEqual(expected.Payee, actual.Payee, "Row {0} Payee", index);
   Assert.AreEqual(expected.ValueDate, actual.ValueDate, "Row {0} Value Date", index);
   Assert.AreEqual(expected.AmountIn, actual.AmountIn, "Row {0} Amount In", index);
   Assert.AreEqual(expected.AmountOut, actual.AmountOut, "Row {0} Amount Out", index);
   Assert.AreEqual(expected.Currency, actual.Currency, "Row {0} Currency", index);
   Assert.AreEqual(expected.IsNew, actual.IsNew, "Row {0} Is New", index);
 }
Exemple #9
0
        private void populate_campaign()
        {
            this.save_opt.IsEnabled          = true;
            this.save_as_opt.IsEnabled       = true;
            this.calendar_cfg_opt.IsEnabled  = true;
            this.charsheet_cfg_opt.IsEnabled = true;
            this.item_library_opt.IsEnabled  = true;
            this.character_list.set_char_sheet(this.state.character_sheet);
            this.character_list.set_state(this.state.domain.state);
            this.inventory_list.set_state(this.state, this.state.domain.state);
            int valid_idx = this.state.domain.valid_entries - 1;

            if (valid_idx < 0)
            {
                valid_idx = this.state.domain.entries.Count - 1;
            }
            if (valid_idx >= 0)
            {
                this.current_timestamp       = this.state.domain.entries[valid_idx].timestamp;
                this.session_num_box.Content = (this.state.domain.entries[valid_idx].session ?? 0).ToString();
            }
            else
            {
                this.current_timestamp       = this.state.calendar.default_timestamp;
                this.session_num_box.Content = "1";
            }
            this.current_timestamp_box.Content = this.state.calendar.format_timestamp(this.current_timestamp, verbose: true);
            this.entry_rows.Clear();
            for (int i = this.state.domain.entries.Count - 1; i >= 0; i--)
            {
                Entry    ent = this.state.domain.entries[i];
                EntryRow row = new EntryRow(
                    this.state.calendar.format_timestamp(ent.timestamp, verbose: true),
                    i >= this.state.domain.valid_entries,
                    (ent.session ?? 0).ToString(),
                    ent.created.ToString("G"),
                    ent.description
                    );
                this.entry_rows.Add(row);
            }
            this.ent_add_but.IsEnabled         = true;
            this.calendar_event_list.show_past = this.state.show_past_events;
            this.calendar_event_list.set_calendar(this.state.calendar);
            this.calendar_event_list.set_state(this.state.domain.state, this.current_timestamp);
            this.task_list.show_inactive = this.state.show_inactive_tasks;
            this.task_list.set_calendar(this.state.calendar);
            this.task_list.set_state(this.state, this.state.domain.state, this.current_timestamp);
            this.topic_list.set_state(this.state, this.state.domain.state, this.current_timestamp);
        }
Exemple #10
0
        /// <summary>
        /// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used
        /// to respond to S3 notifications.
        /// </summary>
        /// <param name="evnt"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <string> FunctionHandler(S3Event evnt, ILambdaContext context)
        {
            var s3Event = evnt.Records?[0].S3;

            if (s3Event != null)
            {
                string bucketName = s3Event.Bucket.Name;
                string objectKey  = s3Event.Object.Key;
                string extension  = objectKey.Split(".").Last().ToLower().TrimEnd();
                context.Logger.LogLine(evnt.Records[0].EventName + " for " + extension + " file named " + objectKey + " in " + bucketName);

                try
                {
                    Stream stream = await S3Client.GetObjectStreamAsync(bucketName, objectKey, null);

                    using (StreamReader reader = new StreamReader(stream))
                    {
                        NpgsqlConnection connection = Function.OpenConnection(context);
                        string           output     = reader.ReadToEnd();
                        context.Logger.LogLine(output);

                        //if event detected an item is put/marked removed (not activated, testing) and the xml or json is valid, then add or remove
                        EntryRow content = null;
                        if (evnt.Records[0].EventName == EventType.ObjectCreatedPut && (content = CheckValidXmlorJson(output, extension, false, context)) != null)
                        {
                            AddObject(content, connection, context);
                        }
                        else if (evnt.Records[0].EventName == EventType.ObjectRemovedDeleteMarkerCreated && (content = CheckValidXmlorJson(output, extension, true, context)) != null)
                        {
                            DeleteObject(content, connection, context);
                        }
                        reader.Close();
                    }
                    //kept original requests/return here.
                    GetObjectMetadataResponse res = await this.S3Client.GetObjectMetadataAsync(bucketName, objectKey);

                    return(res.ResponseMetadata.Metadata.ToString());
                }
                catch (Exception e)
                {
                    context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function.");
                    context.Logger.LogLine(e.Message);
                    context.Logger.LogLine(e.StackTrace);
                    context.Logger.LogLine(e.HelpLink);
                    throw;
                }
            }
            return(null);
        }
Exemple #11
0
        VerificationFilePage(AddVerificationPage verificationPage, VerifyFileJson verifyItem, OpenFile file = null) : base("VerificationFilePage")
        {
            _verificationPage = verificationPage;
            _item             = verifyItem ?? new VerifyFileJson();

            AddTitleRow("Title");
            AddHeaderRow("File");
            Status.AddBusyView(AddButtonRow("Select", Select));

            _link = AddEntryRow(null, "Link");
            _link.SetDetailViewIcon(Icons.RowLink);

            _verifyView = new VerifyFileView(false);
            AddViewRow(_verifyView);

            if (verifyItem != null)
            {
                _link.Edit.Text = verifyItem.link;
                _fileName       = verifyItem.name;
                _fileHash       = verifyItem.GetHash();
                _length         = verifyItem.length;
                _verifyView.Update(verifyItem);
            }

            Status.Add(_link.Edit, T("LinkStatus"), (view, entry, newText, oldText) =>
            {
                if (string.IsNullOrEmpty(newText))
                {
                    return(true);
                }

                return(newText.IsValdiUrl(true));
            });

            Status.Add(T("FileStatus"), (sv) =>
            {
                return(!string.IsNullOrEmpty(_fileName) && _fileHash != null && _length > 0);
            });

            AddFooterRow();

            AddSubmitRow("Submit", Submit);

            if (file != null)
            {
                UIApp.Run(() => HashFile(file));
            }
        }
        public EndpointPage(ChainPage chainPage, List <ChainItem <string> > endPoints) : base("EndpointPage")
        {
            _chainPage = chainPage;
            _endPoints = endPoints;

            AddTitleRow("Title");

            AddHeaderRow("EndPoint");
            _endPoint = AddEntryRow("https://", "EndPoint");
            _endPoint.Edit.TextChanged += Entry_TextChanged;
            _endPoint.SetDetailViewIcon(Icons.RowLink);
            AddFooterRow("EndPointInfo");

            _submit           = AddSubmitRow("Submit", Submit);
            _submit.IsEnabled = false;
        }
Exemple #13
0
        protected void AddSubmitSection()
        {
            AddIndex       = AddSubmitRow("Submit", Submit);
            AddIndexBefore = true;

            if (!WalletApp.IsCoreAccountUnlocked)
            {
                _password = AddPasswordRow(null, "ChainInfoBasePage.Password");
                Status.Add(_password.Edit, T("ChainInfoBasePage.PasswordStatus"), StatusValidators.HeleusPasswordValidator);
            }

            if (_chainId > 0)
            {
                _ = QueryChainInfo(_chainId);
            }

            AddIndex = null;
        }
        public SignTextPage() : base("SignTextPage")
        {
            AddTitleRow("Title");

            AddHeaderRow("Sign");
            _text = AddEntryRow("", "TextToSign");
            _text.SetDetailViewIcon(Icons.Pencil);

            _signedText = AddEditorRow("", null);
            _signedText.SetDetailViewIcon(Icons.Signature);

            var submit = AddSubmitRow("SignButton", Submit);

            submit.IsEnabled        = false;
            _text.Edit.TextChanged += (sender, e) =>
            {
                submit.IsEnabled = !string.IsNullOrWhiteSpace(e.NewTextValue);
            };

            AddFooterRow();
        }
        public BuyPurchasePage(int chainId = 0, int purchaseId = 0) : base(chainId, "BuyPurchasePage")
		{
            if (chainId > 0 && purchaseId > 0)
                _purchaseId = purchaseId;

            Subscribe<PurchaseEvent>(Purchased);

            SetupPage();

            AddHeaderRow("PurchaseInfo");

            _selectPurchase = AddButtonRow("SelectPurchase", SelectPurchase);
            _selectPurchase.IsEnabled = false;

            _purchaseIdText = AddEntryRow(null, "PurchaseId");
            _purchaseView = new PurchaseInfoView();
            AddViewRow(_purchaseView);

            AddFooterRow();

            Status.Add(_purchaseIdText.Edit, T("PurchaseStatus"), (sv, edit, newText, oldText) =>
            {
                if(_chainInfo != null && StatusValidators.PositiveNumberValidator(sv, edit, newText, oldText))
                {
                    if(int.TryParse(newText, out var id))
                    {
                        var purchase = _chainInfo.GetPurchase(id);
                        if(purchase != null)
                        {
                            _purchaseView.Update(purchase);
                            return true;
                        }
                    }
                }
                _purchaseView.Reset();
                return false;
            });

            AddSubmitSection();
		}
Exemple #16
0
        void AddUnlockSection()
        {
            AddHeaderRow("Unlock");

            _unlockPassword = AddPasswordRow("", "UnlockPassword");
            _unlockPassword.Edit.TextChanged += UnlockPasswordChanged;

            _unlockButton           = AddSubmitRow("UnlockButton", Unlock, false);
            _unlockButton.IsEnabled = false;

            AddSeparatorRow();

            AddButtonRow("ProfilePage.Title", Profile).SetDetailViewIcon(Icons.UserCircle);
            AddButtonRow(HandleRequestPage.HandleRequestTranslation, HandleRequest).SetDetailViewIcon(HandleRequestPage.HandleRequestIcon);

            AddFooterRow();

            AddHeaderRow("Key");
            AddViewRow(new ClientAccountView(WalletApp.CurrentCoreAccount));

            AddFooterRow();
        }
        public ExplorePage() : base("ExplorePage")
        {
            Subscribe <ServiceNodesLoadedEvent>(Loaded);
            Subscribe <ServiceAccountAuthorizedEvent>(AccountAuth);
            Subscribe <ServiceAccountImportEvent>(AccountImport);

            IsSuspendedLayout = true;

            AddTitleRow("Title");

            AddHeaderRow("Search");

            _searchText = AddEntryRow("", "SearchTerm");
            _searchText.SetDetailViewIcon(Icons.Coins);

            _searchButton = AddSubmitButtonRow("SearchButton", Search);
            (_searchButton.DetailView as FontIcon).Icon = Icons.Search;
            _searchButton.IsEnabled = false;

            _searchText.Edit.TextChanged += (sender, e) =>
            {
                UpdateSearch();
            };

            AddFooterRow();

            AddHeaderRow("Common.ServiceNode");
            _serviceNode = AddRow(new ServiceNodeButtonRow(this, ServiceNodesPageSelectionFlags.ActiveRequired, "explore"));
            _serviceNode.SelectionChanged = ServiceNodeChanged;
            AddInfoRow("Common.ServiceNodeInfo");
            AddFooterRow();

            UpdateSuspendedLayout();

            UIApp.Run(Update);
        }
        public InvitationPage(ServiceNode serviceNode, long todoListId, long accountId = 0) : base("InvitationPage")
        {
            Subscribe <TodoListInvitationSentEvent>(InvitationResult);

            EnableStatus();

            AddTitleRow("Title");

            var todo = TodoApp.Current.GetTodo(serviceNode);

            if (todo.TodoLists.Count == 0)
            {
                AddInfoRow("NoLists");
                return;
            }

            AddHeaderRow("List");

            TodoList @default      = null;
            var      listSelection = new SelectionItemList <TodoList>();

            foreach (var list in todo.TodoLists)
            {
                listSelection.Add(new SelectionItem <TodoList>(list, TodoApp.GetTodoListName(list)));
                if (list.ListId == todoListId)
                {
                    @default = list;
                }
            }

            _listSelection = AddSelectionRows(listSelection, @default);
            _listSelection.SelectionChanged = SelectionChanged;

            Status.Add(T("ListStatus"), (sv) => {
                return(_listSelection.Selection != null);
            });

            AddFooterRow();

            AddHeaderRow("AccountId");

            _accountId = AddEntryRow(accountId > 0 ? accountId.ToString() : null, "AccountId");
            Status.Add(_accountId.Edit, T("AccountStatus"), (sv, edit, n, o) =>
            {
                var valid = StatusValidators.PositiveNumberValidator(sv, edit, n, o);
                if (_profile != null)
                {
                    _profile.IsEnabled = valid;
                    if (valid)
                    {
                        _profile.AccountId = long.Parse(n);
                    }
                    else
                    {
                        _profile.AccountId = 0;
                    }
                }
                return(valid);
            });

            _profile           = AddRow(new ProfileButtonRow(0, Profile));
            _profile.IsEnabled = accountId > 0;
            Status.AddBusyView(_profile);

            AddFooterRow();

            AddIndex       = AddSubmitRow("Submit", Submit);
            AddIndexBefore = true;

            _password = AddPasswordRow("", "Password");
            Status.Add(_password.Edit, T("PasswordStatus"), (sv, edit, newtext, oldtext) => true);

            AddIndex       = null;
            AddIndexBefore = false;

            AddHeaderRow("Common.SubmitAccount");
            _submitAccount = AddRow(new SubmitAccountButtonRow <GroupSubmitAccount>(null, this, SelectSubmitAccount));
            AddInfoRow("Common.SubmitAccountInfo");
            AddFooterRow();

            Status.Add(T("SubmitAccountStatus"), (sv) =>
            {
                return(_submitAccount.SubmitAccount != null);
            });

            SelectionChanged(@default);
        }
Exemple #19
0
 public EntryRow Entry <T>(T element)
 {
     _currententry = new EntryRow(element);
     return(_currententry);
 }
Exemple #20
0
        public TodoListPage(TodoList todoList, bool edit) : base("TodoListPage")
        {
            Subscribe <QueryTodoListEvent>(QueryTodoList);

            if (edit)
            {
                Subscribe <TodoListNameChangedEvent>(ListName);
                Subscribe <TodoListDeletetEvent>(GroupDeleted);
            }

            TodoList = todoList;
            _edit    = edit;


            var header = AddTitleRow(null);

            header.Identifier = "Title";
            var title = TodoApp.GetTodoListName(todoList);

            header.Label.Text = title;
            SetTitle(title);

            UpdateSecretKeyButton();

            var items = todoList.GetTasks(TodoTaskStatusTypes.Open, TodoListSortMethod.ByTimestampDesc);

            AddHeaderRow("OpenTasks");

            if (items.Count > 0)
            {
                foreach (var item in items)
                {
                    var b = AddTaskButtonRow(item);
                    _openTasks.Add(b);
                }
            }
            else
            {
                AddInfoRow("NoOpenTasks");
            }

            AddFooterRow();

            if (!_edit)
            {
                AddHeaderRow("More");

                var button = AddButtonRow("TodoListView.Add", NewTask);
                //add.Margin = new Thickness(40, 0, 0, 0);
                button.RowStyle           = Theme.SubmitButton;
                button.FontIcon.IsVisible = false;
                button.SetDetailViewIcon(Icons.Plus);
                //add.IsEnabled = !todoList.HasMissingSecretKeys;

                button = AddButtonRow("Edit", Edit);
                button.SetDetailViewIcon(Icons.Pencil);

                button = AddButtonRow("Reload", Reload);
                button.SetDetailViewIcon(Icons.Sync);
                AddFooterRow();
            }

            if (_edit)
            {
                items = todoList.GetTasks(TodoTaskStatusTypes.Closed, TodoListSortMethod.ByTimestampDesc);

                AddHeaderRow("ClosedTasks");
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        var b = AddTaskButtonRow(item);
                        _closedTasks.Add(b);
                    }
                }
                else
                {
                    AddInfoRow("NoClosedTasks");
                }
                AddFooterRow();

                AddHeaderRow("UsersSection");

                var button = AddButtonRow("ViewUsers", Users);
                button.SetDetailViewIcon(Icons.Users);
                button = AddButtonRow("Invite", Invite);
                button.SetDetailViewIcon(Icons.UserPlus);

                AddFooterRow();

                AddHeaderRow("NameHeader");

                _nameEntry = AddEntryRow(todoList.Name, "Name");
                _nameEntry.SetDetailViewIcon(Icons.Pencil);
                _nameButton          = AddSubmitButtonRow("NameButton", Name);
                _nameButton.RowStyle = Theme.SubmitButton;

                Status.AddBusyView(_nameEntry.Edit);
                Status.AddBusyView(_nameButton);
                AddFooterRow();

                AddHeaderRow("Common.SubmitAccount");
                _submitAccount = AddRow(new SubmitAccountButtonRow <GroupSubmitAccount>(this, () => todoList.ServiceNode.GetSubmitAccounts <GroupSubmitAccount>(todoList.Index), todoList.ListId.ToString()));
                AddInfoRow("Common.SubmitAccountInfo");
                AddFooterRow();

                AddHeaderRow("DeleteHeader");

                var del = AddButtonRow("DeleteButton", Delete);
                del.RowStyle = Theme.CancelButton;
                del.SetDetailViewIcon(Icons.TrashAlt);

                Status.AddBusyView(del);

                AddFooterRow();
            }
        }
        static void Main(string[] args)
        {
            string        input = File.ReadAllText(@"C:\Users\user\OneDrive - Bellevue College\Project1Cloud\patient9.json");
            EntryRow      entry = CheckValidXmlorJson(input, "json", false);
            StringBuilder sb    = new StringBuilder();

            sb.Append(entry.id + ",");
            if (entry.age != null)
            {
                sb.Append(entry.age + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.gender != null)
            {
                sb.Append("'" + entry.gender + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.maritalStatus != null)
            {
                sb.Append("'" + entry.maritalStatus + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.bmi != null)
            {
                sb.Append(entry.bmi + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.smoker != null)
            {
                sb.Append("'" + entry.smoker + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.alcoholConsumption != null)
            {
                sb.Append("'" + entry.alcoholConsumption + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.totalCholesterol != null)
            {
                sb.Append(entry.totalCholesterol + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.ldlCholesterol != null)
            {
                sb.Append(entry.ldlCholesterol + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.hdlCholesterol != null)
            {
                sb.Append(entry.hdlCholesterol + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.triglycerides != null)
            {
                sb.Append(entry.triglycerides + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.plasmaCeramides != null)
            {
                sb.Append(entry.plasmaCeramides + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.natriureticPeptide != null)
            {
                sb.Append(entry.natriureticPeptide + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.hasVascularDisease != null)
            {
                sb.Append("'" + entry.hasVascularDisease + "'");
            }
            else
            {
                sb.Append("NULL");
            }
            string input2 = "INSERT INTO health.\"healthTable\" (id, age, gender, \"maritalStatus\", bmi, smoker, \"alcoholConsumption\", \"totalCholesterol\", \"LDLCholesterol\", \"HDLCholesterol\", triglycerides, \"plasmaCeramides\", \"natriureticPeptide\", \"hasVascularDisease\") VALUES (" + sb.ToString() + ");";

            Console.WriteLine(input2);
            Console.Read();
        }
Exemple #22
0
        public JsonResult CreateExcel()
        {
            HttpPostedFileBase excelFile = Request.Files[0];

            if (excelFile != null && excelFile.ContentLength > 0)
            {
                string fileName = Path.GetFileName(excelFile.FileName);
                var    path     = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
                excelFile.SaveAs(path);

                using (ExcelPackage package = new ExcelPackage(new FileInfo(path)))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets[1];

                    ExcelCellAddress start = worksheet.Dimension.Start;
                    ExcelCellAddress end   = worksheet.Dimension.End;

                    int startCol = start.Column;
                    int startRow = start.Row;
                    int endCol   = end.Column;
                    int endRow   = end.Row;
                    int rowId    = 0;

                    List <EntryError> errorList = new List <EntryError>();

                    var entryList = new List <EntryRow>();
                    var columns   = new List <ExcelMap>();
                    Dictionary <string, string> map = null;

                    var convertDateTime = new Func <double, DateTime>(excelDate =>
                    {
                        if (excelDate < 1)
                        {
                            throw new ArgumentException("Excel dates cannot be smaller than 0.");
                        }

                        var dateOfReference = new DateTime(1900, 1, 1);

                        if (excelDate > 60d)
                        {
                            excelDate = excelDate - 2;
                        }
                        else
                        {
                            excelDate = excelDate - 1;
                        }
                        return(dateOfReference.AddDays(excelDate));
                    });

                    var props = typeof(EntryRow).GetProperties()
                                .Select(prop =>
                    {
                        var displayAttribute = (DisplayAttribute)prop.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault();
                        return(new
                        {
                            Name = prop.Name,
                            DisplayName = displayAttribute == null ? prop.Name : displayAttribute.Name,
                            Order = displayAttribute == null || !displayAttribute.GetOrder().HasValue ? 999 : displayAttribute.Order,
                            PropertyInfo = prop,
                            PropertyType = prop.PropertyType,
                            HasDisplayName = displayAttribute != null
                        });
                    })
                                .Where(prop => !string.IsNullOrWhiteSpace(prop.DisplayName) && prop.Name != "rowId")
                                .ToList();

                    //Based on Template provided, the first row in Excel spreadsheet contains column names
                    for (int column = startCol; column <= endCol; column++)
                    {
                        string cellValue = (worksheet.Cells[startRow, column].Value ?? string.Empty).ToString().Trim();

                        if (!string.IsNullOrWhiteSpace(cellValue))
                        {
                            columns.Add(new ExcelMap()
                            {
                                Name     = cellValue,
                                MappedTo = map == null || map.Count == 0 ?
                                           cellValue :
                                           map.ContainsKey(cellValue) ? map[cellValue] : string.Empty,
                                Index = column
                            });
                        }
                    }

                    //Loop through the remaining rows of the spreadsheet
                    for (int rowIndex = startRow + 1; rowIndex <= endRow; rowIndex++)
                    {
                        var item = new EntryRow();
                        columns.ForEach(column =>
                        {
                            var value    = worksheet.Cells[rowIndex, column.Index].Value;
                            var valueStr = value == null ? string.Empty : value.ToString().Trim();
                            var prop     = props.First(p => p.DisplayName.Contains(column.MappedTo));

                            //Excel stores all numbers as doubles, but we're relying on the object's property types
                            if (prop != null)
                            {
                                var propertyType   = prop.PropertyType;
                                object parsedValue = null;

                                if (propertyType == typeof(int?) || propertyType == typeof(int))
                                {
                                    int val;
                                    if (!int.TryParse(valueStr, out val))
                                    {
                                        val = default(int);
                                    }

                                    parsedValue = val;
                                }
                                else if (propertyType == typeof(short?) || propertyType == typeof(short))
                                {
                                    short val;
                                    if (!short.TryParse(valueStr, out val))
                                    {
                                        val = default(short);
                                    }
                                    parsedValue = val;
                                }
                                else if (propertyType == typeof(long?) || propertyType == typeof(long))
                                {
                                    long val;
                                    if (!long.TryParse(valueStr, out val))
                                    {
                                        val = default(long);
                                    }
                                    parsedValue = val;
                                }
                                else if (propertyType == typeof(decimal?) || propertyType == typeof(decimal))
                                {
                                    decimal val;
                                    if (!decimal.TryParse(valueStr, out val))
                                    {
                                        val = default(decimal);
                                    }
                                    parsedValue = val;
                                }
                                else if (propertyType == typeof(double?) || propertyType == typeof(double))
                                {
                                    double val;
                                    if (!double.TryParse(valueStr, out val))
                                    {
                                        val = default(double);

                                        EntryError doubleError = new EntryError()
                                        {
                                            errorMessage = "Input not valid",
                                            errorRow     = rowIndex,
                                            errorCol     = column.Index
                                        };

                                        errorList.Add(doubleError);
                                    }
                                    else
                                    {
                                        parsedValue = val;
                                    }
                                }
                                else if (propertyType == typeof(DateTime?) || propertyType == typeof(DateTime))
                                {
                                    parsedValue = convertDateTime((double)value);
                                }
                                else if (propertyType.IsEnum)
                                {
                                    try
                                    {
                                        parsedValue = Enum.ToObject(propertyType, int.Parse(valueStr));
                                    }
                                    catch
                                    {
                                        parsedValue = Enum.ToObject(propertyType, 0);
                                    }
                                }
                                else if (propertyType == typeof(string))
                                {
                                    parsedValue = valueStr;
                                }
                                else
                                {
                                    try
                                    {
                                        parsedValue = Convert.ChangeType(value, propertyType);
                                    }
                                    catch
                                    {
                                        parsedValue = valueStr;
                                    }
                                }

                                try
                                {
                                    prop.PropertyInfo.SetValue(item, parsedValue);
                                }
                                catch (Exception ex)
                                {
                                    logger.log("Excel upload error : " + ex.Message);
                                }
                            }
                        });

                        entryList.Add(item);
                    }

                    //Now that we've added all of the spreadsheet fields to the list of EntryRows, add in a unique rowId
                    //The rowId is used for the checkbox feature in the datatables editor and as the key value in the HTML table

                    foreach (var item in entryList)
                    {
                        item.DT_RowId = rowId;
                        rowId++;
                    }

                    var json = new JavaScriptSerializer().Serialize(entryList);
                    Console.WriteLine(json);

                    //json = json.Replace("[{", "{\"data\" :[{").Replace("}]", "}]}");

                    json = json.Replace("[{", "{\"data\" :[{").Replace("}]", "}],\"fieldErrors\" :[{\"name\" :\"journalNumber\",\"status\" :\"This field is required\"},{\"name\":\"Source\",\"status\": \"This field is required\"}]}");

                    return(Json(json, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(excelFile));
        }
Exemple #23
0
        public ChainKeyPage(ChainPage chainPage, List <ChainKeyItem> chainKeys) : base("ChainKeyPage")
        {
            _chainPage = chainPage;

            AddTitleRow("Title");

            AddHeaderRow("Key");

            _name = AddEntryRow(null, "Name");
            _name.SetDetailViewIcon(Icons.Pencil);

            _key = AddEditorRow(null, "Key");
            _key.SetDetailViewIcon(Icons.Key);

            AddButtonRow("KeyButton", NewKey);

            _keyIndex = AddEntryRow(string.Empty, "KeyIndex");
            _keyIndex.SetDetailViewIcon(Icons.Highlighter);

            AddFooterRow();

            AddHeaderRow("KeyOptions");

            _admin       = AddSwitchRow("Admin");
            _serviceKey  = AddSwitchRow("ServiceKey");
            _serviceVote = AddSwitchRow("ServiceVote");
            _dataKey     = AddSwitchRow("DataKey");
            _dataVote    = AddSwitchRow("DataVote");
            _chainIndex  = AddEntryRow(string.Empty, "ChainIndex");

            _admin.Switch.Toggled = (swt) =>
            {
                if (swt.IsToggled)
                {
                    _serviceKey.Switch.IsToggled  = false;
                    _serviceVote.Switch.IsToggled = false;
                    _dataKey.Switch.IsToggled     = false;
                    _dataVote.Switch.IsToggled    = false;
                    _chainIndex.Edit.Text         = null;
                }
                Status.ReValidate();
            };

            _serviceKey.Switch.Toggled = (swt) =>
            {
                if (swt.IsToggled)
                {
                    _admin.Switch.IsToggled    = false;
                    _dataKey.Switch.IsToggled  = false;
                    _dataVote.Switch.IsToggled = false;
                    _chainIndex.Edit.Text      = null;
                }
                else
                {
                    _serviceVote.Switch.IsToggled = false;
                }
                Status.ReValidate();
            };

            _serviceVote.Switch.Toggled = (swt) =>
            {
                if (swt.IsToggled)
                {
                    _serviceKey.Switch.IsToggled = true;
                }
            };

            _dataKey.Switch.Toggled = (swt) =>
            {
                if (swt.IsToggled)
                {
                    _admin.Switch.IsToggled       = false;
                    _serviceKey.Switch.IsToggled  = false;
                    _serviceVote.Switch.IsToggled = false;
                }
                else
                {
                    _dataVote.Switch.IsToggled = false;
                }
                Status.ReValidate();
            };

            _dataVote.Switch.Toggled = (swt) =>
            {
                if (swt.IsToggled)
                {
                    _dataKey.Switch.IsToggled = true;
                }
            };

            AddFooterRow();

            AddHeaderRow("Password");

            _pw1 = AddEntryRow(string.Empty, "Password");
            _pw1.SetDetailViewIcon(Icons.Unlock);
            _pw2 = AddEntryRow(string.Empty, "Password2");
            _pw2.SetDetailViewIcon(Icons.Unlock);
            _pw1.Edit.IsPassword = _pw2.Edit.IsPassword = true;

            AddFooterRow();

            Status.Add(_key.Edit, T("KeyStatus"), (view, entry, newText, oldtext) =>
            {
                try
                {
                    var key = Key.Restore(entry.Text);
                    return(key.KeyType == Protocol.TransactionKeyType);
                }
                catch { }
                return(false);
            }).
            Add(_keyIndex.Edit, T("KeyIndexStatus", short.MinValue, short.MaxValue), (view, entry, newText, oldText) =>
            {
                if (short.TryParse(newText, out var idx))
                {
                    foreach (var key in chainKeys)
                    {
                        if (key.Item.KeyIndex == idx)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                if (!newText.IsNullOrEmpty())
                {
                    entry.Text = oldText;
                }
                return(false);
            }).
            Add(_chainIndex.Edit, T("ChainIndexStatus"), (view, entry, newText, oldText) =>
            {
                if (_dataKey.Switch.IsToggled)
                {
                    return(StatusValidators.PositiveNumberValidatorWithZero(view, entry, newText, oldText));
                }

                if (!string.IsNullOrEmpty(newText))
                {
                    entry.Text = null;
                }

                return(true);
            }).
            Add(_name.Edit, T("NameStatus"), (view, entry, newText, oldtext) =>
            {
                return(!newText.IsNullOrWhiteSpace());
            }).
            Add(_pw1.Edit, T("PasswordStatus", WalletApp.MinPasswordLength), (view, entry, newText, oldtext) =>
            {
                var pw1 = _pw1.Edit.Text;
                var pw2 = _pw2.Edit.Text;

                return(WalletApp.IsValidPassword(pw1) && WalletApp.IsValidPassword(pw2) && pw1 == pw2);
            });

            _pw2.Edit.TextChanged += (sender, e) =>
            {
                Status.ReValidate();
            };

            AddSubmitRow("Submit", Submit);
        }
Exemple #24
0
        private void view_entry(object sender, RoutedEventArgs e)
        {
            int row_idx = this.entries_list.SelectedIndex, idx = this.state.domain.entries.Count - row_idx - 1;

            if ((idx < 0) || (idx >= this.state.domain.entries.Count))
            {
                return;
            }
            EntryWindow entry_window = new EntryWindow(this.state, idx)
            {
                Owner = this
            };

            entry_window.ShowDialog();
            if (!entry_window.valid)
            {
                return;
            }

            if (entry_window.topics is not null)
            {
                this.state.domain.topics = entry_window.topics;
            }
            if (entry_window.topic_refs is not null)
            {
                this.state.topic_refs = entry_window.topic_refs;
            }
            if (entry_window.notes is not null)
            {
                this.state.domain.notes = entry_window.notes;
            }

            decimal  timestamp       = entry_window.timestamp_box.calendar_value;
            DateTime created         = entry_window.get_created();
            string   description     = entry_window.description_box.Text;
            int      session         = (int)(entry_window.session_box.Value);
            Entry    ent             = this.state.domain.entries[idx];
            bool     changed         = (timestamp != ent.timestamp) || (created != ent.created) || (description != ent.description) || (session != ent.session);

            if ((!changed) && (entry_window.actions.Count != ent.actions.Count))
            {
                changed = true;
            }
            if (!changed)
            {
                for (int i = 0; i < entry_window.actions.Count; i++)
                {
                    if (entry_window.actions[i] != ent.actions[i])
                    {
                        changed = true;
                        break;
                    }
                }
            }
            if (!changed)
            {
                return;
            }
            this.state_dirty = true;
            this.state.domain.remove_entry(idx, true);
            this.entry_rows.RemoveAt(row_idx);
            this.state.remove_references(ent.actions);
            this.state.add_references(entry_window.actions);
            ent.timestamp   = timestamp;
            ent.created     = created;
            ent.description = description;
            ent.session     = session;
            ent.actions     = entry_window.actions;
            idx             = this.state.domain.add_entry(ent);
            int valid_idx = this.state.domain.valid_entries - 1;

            if (valid_idx < 0)
            {
                valid_idx = this.state.domain.entries.Count - 1;
            }
            this.session_num_box.Content       = (this.state.domain.entries[valid_idx].session ?? 0).ToString();
            this.current_timestamp             = this.state.domain.entries[valid_idx].timestamp;
            this.current_timestamp_box.Content = this.state.calendar.format_timestamp(this.current_timestamp, verbose: true);
            EntryRow row = new EntryRow(
                this.state.calendar.format_timestamp(ent.timestamp, verbose: true),
                idx >= this.state.domain.valid_entries,
                (ent.session ?? 0).ToString(),
                ent.created.ToString("G"),
                ent.description
                );

            this.entry_rows.Insert(this.entry_rows.Count - idx, row);
            for (int i = 0; i < this.entry_rows.Count; i++)
            {
                this.entry_rows[i].set_invalid(this.entry_rows.Count - i > this.state.domain.valid_entries);
            }
            this.refresh_lists();
        }
Exemple #25
0
        private void entry_action_callback(
            List <EntryAction> actions,
            Guid?entry_guid = null,
            Dictionary <Guid, Topic> topics       = null,
            Dictionary <Guid, int> topic_refs     = null,
            Dictionary <Guid, ExternalNote> notes = null
            )
        {
            if (topics is not null)
            {
                this.state.domain.topics = topics;
            }
            if (topic_refs is not null)
            {
                this.state.topic_refs = topic_refs;
            }
            if (notes is not null)
            {
                this.state.domain.notes = notes;
            }

            if (actions is not null)
            {
                EntryWindow entry_window = new EntryWindow(this.state, actions: actions)
                {
                    Owner = this
                };
                entry_window.ShowDialog();
                if (!entry_window.valid)
                {
                    return;
                }

                if (entry_window.topics is not null)
                {
                    this.state.domain.topics = entry_window.topics;
                }
                if (entry_window.topic_refs is not null)
                {
                    this.state.topic_refs = entry_window.topic_refs;
                }
                if (entry_window.notes is not null)
                {
                    this.state.domain.notes = entry_window.notes;
                }

                decimal  timestamp   = entry_window.timestamp_box.calendar_value;
                DateTime created     = entry_window.get_created();
                string   description = entry_window.description_box.Text;
                int      session     = (int)(entry_window.session_box.Value);
                Entry    ent         = new Entry(timestamp, created, description, session, new List <EntryAction>(entry_window.actions), entry_guid);
                this.state_dirty = true;
                int idx = this.state.domain.add_entry(ent);
                this.state.add_references(ent.actions);
                int valid_idx = this.state.domain.valid_entries - 1;
                if (valid_idx < 0)
                {
                    valid_idx = this.state.domain.entries.Count - 1;
                }
                this.session_num_box.Content       = (this.state.domain.entries[valid_idx].session ?? 0).ToString();
                this.current_timestamp             = this.state.domain.entries[valid_idx].timestamp;
                this.current_timestamp_box.Content = this.state.calendar.format_timestamp(this.current_timestamp, verbose: true);
                EntryRow row = new EntryRow(
                    this.state.calendar.format_timestamp(ent.timestamp, verbose: true),
                    idx >= this.state.domain.valid_entries,
                    (ent.session ?? 0).ToString(),
                    ent.created.ToString("G"),
                    ent.description
                    );
                this.entry_rows.Insert(this.entry_rows.Count - idx, row);
                for (int i = 0; i < this.entry_rows.Count; i++)
                {
                    this.entry_rows[i].set_invalid(this.entry_rows.Count - i > this.state.domain.valid_entries);
                }
            }

            this.refresh_lists();
        }
        internal static EntryRow CheckValidXmlorJson(string input, string extension, bool del)
        {
            EntryRow output = null;

            if (extension.Equals("xml"))
            {
                Console.WriteLine("Attempting to parse XML contents... ");
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(input);
                    XmlNode parent = xmlDoc.FirstChild;

                    if (parent.Name.Equals("patient") && parent["id"] != null)
                    {
                        output    = new EntryRow();
                        output.id = int.Parse(parent["id"].InnerText);
                        if (del)
                        {
                            return(output);
                        }
                        if (parent["age"] != null)
                        {
                            output.age = int.Parse(parent["age"].InnerText);
                        }
                        if (parent["gender"] != null)
                        {
                            output.gender = parent["gender"].InnerText;
                        }
                        if (parent["maritalStatus"] != null)
                        {
                            output.maritalStatus = parent["maritalStatus"].InnerText;
                        }
                        if (parent["bmi"] != null && double.TryParse(parent["bmi"].InnerText, out double temp))
                        {
                            output.bmi = double.Parse(parent["bmi"].InnerText);
                        }
                        if (parent["smoker"] != null)
                        {
                            output.smoker = parent["smoker"].InnerText;
                        }
                        if (parent["alcoholConsumption"] != null)
                        {
                            output.alcoholConsumption = parent["alcoholConsumption"].InnerText;
                        }
                        if (parent["hasVascularDisease"] != null)
                        {
                            output.hasVascularDisease = parent["hasVascularDisease"].InnerText;
                        }

                        XmlNode tests = parent["tests"];
                        if (tests != null)
                        {
                            foreach (XmlNode test in tests.ChildNodes)
                            {
                                switch (test.Attributes["name"].Value)
                                {
                                case "total-cholesterol":
                                    output.totalCholesterol = int.Parse(test.InnerText);
                                    break;

                                case "LDL-cholesterol":
                                    output.ldlCholesterol = int.Parse(test.InnerText);
                                    break;

                                case "HDL-cholesterol":
                                    output.hdlCholesterol = int.Parse(test.InnerText);
                                    break;

                                case "triglycerides":
                                    output.triglycerides = int.Parse(test.InnerText);
                                    break;

                                case "plasmaCeramides":
                                    output.plasmaCeramides = int.Parse(test.InnerText);
                                    break;

                                case "natriureticPeptide":
                                    output.natriureticPeptide = int.Parse(test.InnerText);
                                    break;

                                default:
                                    Console.WriteLine(test.Name + " does not exist for the health template. ");
                                    break;
                                }
                            }
                        }
                        Console.WriteLine("XML contents are prepped. ");
                    }
                    else
                    {
                        Console.WriteLine("XML contents are invalid... Lambda function will stop. ");
                    }
                }
                catch (XmlException e)
                {
                    Console.WriteLine("Contents did not create valid XML... Lambda function will stop. ");
                }
            }
            else if (extension.Equals("json"))
            {
                try
                {
                    Console.WriteLine("Attempting to parse JSON contents... ");
                    JObject jsonOut = JObject.Parse(input);
                    if (jsonOut["id"] != null)
                    {
                        output    = new EntryRow();
                        output.id = int.Parse((string)jsonOut["id"]);
                        if (del)
                        {
                            return(output);
                        }
                        if ((string)jsonOut["age"] != null && int.TryParse((string)jsonOut["age"], out int i))
                        {
                            output.age = int.Parse((string)jsonOut["age"]);
                        }
                        if (jsonOut["gender"] != null)
                        {
                            output.gender = (string)jsonOut["gender"];
                        }
                        if (jsonOut["maritalStatus"] != null)
                        {
                            output.maritalStatus = (string)jsonOut["maritalStatus"];
                        }
                        if ((string)jsonOut["bmi"] != null && double.TryParse((string)jsonOut["bmi"], out double j))
                        {
                            output.bmi = double.Parse((string)jsonOut["bmi"]);
                        }
                        if (jsonOut["smoker"] != null)
                        {
                            output.smoker = (string)jsonOut["smoker"];
                        }
                        if (jsonOut["alcoholConsumtion"] != null)
                        {
                            output.alcoholConsumption = (string)jsonOut["alcoholConsumtion"];
                        }
                        if (jsonOut["hasVascularDisease"] != null)
                        {
                            output.hasVascularDisease = (string)jsonOut["hasVascularDisease"];
                        }
                        if (jsonOut["tests"] != null)
                        {
                            JArray tests = jsonOut["tests"].Value <JArray>();
                            if (tests != null)
                            {
                                foreach (JToken test in tests)
                                {
                                    switch ((string)test["name"])
                                    {
                                    case "total-cholesterol":
                                        output.totalCholesterol = int.Parse((string)test["value"]);
                                        break;

                                    case "LDL-cholesterol":
                                        output.ldlCholesterol = int.Parse((string)test["value"]);
                                        break;

                                    case "HDL-cholesterol":
                                        output.hdlCholesterol = int.Parse((string)test["value"]);
                                        break;

                                    case "triglycerides":
                                        output.triglycerides = int.Parse((string)test["value"]);
                                        break;

                                    case "plasmaCeramides":
                                        output.plasmaCeramides = int.Parse((string)test["value"]);
                                        break;

                                    case "natriureticPeptide":
                                        output.natriureticPeptide = int.Parse((string)test["value"]);
                                        break;

                                    default:
                                        Console.WriteLine((string)test["name"] + " does not exist for the health template. ");
                                        break;
                                    }
                                }
                            }
                        }
                        Console.WriteLine("JSON contents are prepped. ");
                    }
                    else
                    {
                        Console.WriteLine("JSON contents are invalid... Lambda function will stop. ");
                    }
                }
                catch (Newtonsoft.Json.JsonReaderException e)
                {
                    Console.WriteLine("Contents did not create valid JSON... Lambda function will stop. ");
                }
            }
            else
            {
                Console.WriteLine(" extension is an invalid extension. Lambda function will stop. ");
            }
            return(output);
        }
        public PurchasePage(ChainPage chainPage, List <ChainItem <PurchaseInfo> > purchases) : base("PurchasePage")
        {
            _chainPage = chainPage;

            AddTitleRow("Title");

            AddHeaderRow("Type");

            _type = AddSelectionRows(new SelectionItem <PurchaseTypes>[] {
                new SelectionItem <PurchaseTypes>(PurchaseTypes.Feature, Tr.Get("PurchaseTypes.Feature")),
                new SelectionItem <PurchaseTypes>(PurchaseTypes.Subscription, Tr.Get("PurchaseTypes.Subscription"))
            }, PurchaseTypes.Feature);

            AddFooterRow();

            AddHeaderRow("Ids");

            _purchaseId = AddEntryRow(null, "PurchaseId");
            _purchaseId.SetDetailViewIcon(Icons.CreditCardFront);
            _groupId = AddEntryRow(null, "GroupId");
            _groupId.SetDetailViewIcon(Icons.LayerGroup);

            AddFooterRow("IdsInfo");

            AddHeaderRow("Info");

            _description = AddEntryRow(null, "Description");
            _description.SetDetailViewIcon(Icons.AlignLeft);
            _price = AddEntryRow(null, "Price");
            _price.SetDetailViewIcon(Icons.MoneyBillAlt, 22);

            _duration = AddEntryRow(null, "Duration");
            _duration.SetDetailViewIcon(Icons.Stopwatch);

            AddFooterRow();

            Status.Add(_purchaseId.Edit, T("PurchaseIdStatus"), (sv, entry, newText, oldText) =>
            {
                if (int.TryParse(newText, out var id))
                {
                    foreach (var p in purchases)
                    {
                        if (p.Item.PurchaseItemId == id)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }

                if (!newText.IsNullOrEmpty())
                {
                    entry.Text = oldText;
                }

                return(false);
            }).Add(_groupId.Edit, T("GroupIdStatus"), (sv, entry, newText, oldText) =>
            {
                if (short.TryParse(newText, out var id))
                {
                    foreach (var p in purchases)
                    {
                        if (p.Item.PurchaseGroupId == id && _type.Selection != p.Item.PurchaseType)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }

                if (!newText.IsNullOrEmpty())
                {
                    entry.Text = oldText;
                }

                return(false);
            }).Add(_description.Edit, T("DescriptionStatus"), (sv, entry, newText, oldText) =>
            {
                return(!string.IsNullOrWhiteSpace(newText));
            }).Add(_price.Edit, T("PriceStatus"), StatusValidators.HeleusCoinValidator).
            Add(_duration.Edit, T("DurationStatus"), (sv, entry, newText, oldText) =>
            {
                if (_type.Selection == PurchaseTypes.Feature)
                {
                    if (!newText.IsNullOrEmpty())
                    {
                        entry.Text = oldText;
                    }
                    return(true);
                }

                return(StatusValidators.PositiveNumberValidator(sv, entry, newText, oldText));
            });

            _type.SelectionChanged = (item) =>
            {
                Status.ReValidate();
                return(Task.CompletedTask);
            };

            AddSubmitRow("Submit", Submit);
        }
Exemple #28
0
        void SetupEdit(ProfileDataResult profileData)
        {
            _profileData = profileData;

            AddHeaderRow("ImageSection");
            _image = AddImageRow(1, "Image");
            if (profileData.Image != null)
            {
                _image.ImageView.Source = ImageSource.FromStream(() => new MemoryStream(profileData.Image));
            }
            else
            {
                _image.ImageView.Source = AccountDummyImage.ImageSource;
            }

            var sel = AddButtonRow("SelectImage", SelectImage);

            sel.SetDetailViewIcon(Icons.UserCircle);
            Status.AddBusyView(sel);
            AddFooterRow();

            AddHeaderRow("EditSection");

            _profileName = AddEntryRow(ProfileItemJson.GetItemValue(profileData.ProfileJsonItems, ProfileItemJson.ProfileNameItem), "ProfileName");
            _profileName.SetDetailViewIcon(Icons.FullName);

            _realName = AddEntryRow(ProfileItemJson.GetItemValue(profileData.ProfileJsonItems, ProfileItemJson.RealNameItem), "RealName");
            _realName.SetDetailViewIcon(Icons.UserAlt);

            _bio = AddEntryRow(ProfileItemJson.GetItemValue(profileData.ProfileJsonItems, ProfileItemJson.BioItem), "Bio");
            _bio.SetDetailViewIcon(Icons.Info);

            Status.Add(_profileName.Edit, T("ProfileNameStatus"), (sv, edit, newValue, oldVAlue) =>
            {
                var valid = ProfileServiceInfo.IsProfileNameValid(newValue);
                if (!valid)
                {
                    edit.Text = ProfileServiceInfo.ToValidProfileName(newValue);
                }
                return(valid);
            });
            Status.Add(_realName.Edit, T("RealNameStatus"), (sv, edit, newValue, oldVAlue) =>
            {
                return(ProfileServiceInfo.IsRealNameValid(newValue));
            });

            Status.Add(_bio.Edit, T("BioStatus"), StatusValidators.NoEmptyString);

            if (profileData.ProfileJsonItems != null)
            {
                foreach (var item in profileData.ProfileJsonItems)
                {
                    AddProfileButton(item);
                }
            }

            Status.AddBusyView(AddButtonRow("AddItemButton", AddItem));

            AddFooterRow();

            AddSubmitRow("Common.Submit", Submit);
        }
Exemple #29
0
        //Takes the file string input for further processing with the internal
        internal EntryRow CheckValidXmlorJson(string input, string extension, bool del, ILambdaContext context)
        {
            EntryRow output = null;

            if (extension.Equals("xml"))
            {
                context.Logger.LogLine("Attempting to parse XML contents... ");
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(input);
                    XmlNode parent = xmlDoc.FirstChild;

                    //Process only if the XML starts with patient and has an id on the first level
                    if (parent.Name.Equals("patient") && parent["id"] != null)
                    {
                        output    = new EntryRow();
                        output.id = int.Parse(parent["id"].InnerText);
                        //if delimiter is true for deleting, just get out of the method.
                        if (del)
                        {
                            return(output);
                        }

                        if (parent["age"] != null && int.TryParse(parent["age"].InnerText, out int i))
                        {
                            output.age = int.Parse(parent["age"].InnerText);
                        }
                        if (parent["gender"] != null)
                        {
                            output.gender = parent["gender"].InnerText;
                        }
                        if (parent["maritalStatus"] != null)
                        {
                            output.maritalStatus = parent["maritalStatus"].InnerText;
                        }
                        if (parent["bmi"] != null && double.TryParse(parent["bmi"].InnerText, out double temp))
                        {
                            output.bmi = double.Parse(parent["bmi"].InnerText);
                        }
                        if (parent["smoker"] != null)
                        {
                            output.smoker = parent["smoker"].InnerText;
                        }
                        if (parent["alcoholConsumption"] != null)
                        {
                            output.alcoholConsumption = parent["alcoholConsumption"].InnerText;
                        }
                        if (parent["hasVascularDisease"] != null)
                        {
                            output.hasVascularDisease = parent["hasVascularDisease"].InnerText;
                        }

                        XmlNode tests = parent["tests"];
                        if (tests != null)
                        {
                            //If tests node on xml is valid go through all of them and define them if valid;
                            foreach (XmlNode test in tests.ChildNodes)
                            {
                                switch (test.Attributes["name"].Value)
                                {
                                case "total-cholesterol":
                                    output.totalCholesterol = int.Parse(test.InnerText);
                                    break;

                                case "LDL-cholesterol":
                                    output.ldlCholesterol = int.Parse(test.InnerText);
                                    break;

                                case "HDL-cholesterol":
                                    output.hdlCholesterol = int.Parse(test.InnerText);
                                    break;

                                case "triglycerides":
                                    output.triglycerides = int.Parse(test.InnerText);
                                    break;

                                case "plasmaCeramides":
                                    output.plasmaCeramides = int.Parse(test.InnerText);
                                    break;

                                case "natriureticPeptide":
                                    output.natriureticPeptide = int.Parse(test.InnerText);
                                    break;

                                default:
                                    context.Logger.LogLine(test.Name + " does not exist for the health template. ");
                                    break;
                                }
                            }
                        }
                        context.Logger.LogLine("XML contents are prepped. ");
                    }
                    else
                    {
                        context.Logger.LogLine("XML contents are invalid... Lambda function will stop. ");
                    }
                }
                catch (XmlException e)
                {
                    context.Logger.LogLine("Contents did not create valid XML... Lambda function will stop. ");
                }
            }
            else if (extension.Equals("json"))
            {
                try
                {
                    context.Logger.LogLine("Attempting to parse JSON contents... ");
                    JObject jsonOut = JObject.Parse(input);
                    //if json has id then continue
                    if (jsonOut["id"] != null)
                    {
                        output    = new EntryRow();
                        output.id = int.Parse((string)jsonOut["id"]);
                        //if delimiter is true for deleting, just get out of the method.
                        if (del)
                        {
                            return(output);
                        }
                        if ((string)jsonOut["age"] != null && int.TryParse((string)jsonOut["age"], out int i))
                        {
                            output.age = int.Parse((string)jsonOut["age"]);
                        }
                        if (jsonOut["gender"] != null)
                        {
                            output.gender = (string)jsonOut["gender"];
                        }
                        if (jsonOut["maritalStatus"] != null)
                        {
                            output.maritalStatus = (string)jsonOut["maritalStatus"];
                        }
                        if ((string)jsonOut["bmi"] != null && double.TryParse((string)jsonOut["bmi"], out double j))
                        {
                            output.bmi = double.Parse((string)jsonOut["bmi"]);
                        }
                        if (jsonOut["smoker"] != null)
                        {
                            output.smoker = (string)jsonOut["smoker"];
                        }
                        if (jsonOut["alcoholConsumtion"] != null)
                        {
                            output.alcoholConsumption = (string)jsonOut["alcoholConsumtion"];
                        }
                        if (jsonOut["hasVascularDisease"] != null)
                        {
                            output.hasVascularDisease = (string)jsonOut["hasVascularDisease"];
                        }

                        //if jsonOut tests exists go through each json sub-element and add into the EntryRow data structure as applicable
                        if (jsonOut["tests"] != null)
                        {
                            JArray tests = jsonOut["tests"].Value <JArray>();
                            if (tests != null)
                            {
                                foreach (JToken test in tests)
                                {
                                    switch ((string)test["name"])
                                    {
                                    case "total-cholesterol":
                                        output.totalCholesterol = int.Parse((string)test["value"]);
                                        break;

                                    case "LDL-cholesterol":
                                        output.ldlCholesterol = int.Parse((string)test["value"]);
                                        break;

                                    case "HDL-cholesterol":
                                        output.hdlCholesterol = int.Parse((string)test["value"]);
                                        break;

                                    case "triglycerides":
                                        output.triglycerides = int.Parse((string)test["value"]);
                                        break;

                                    case "plasmaCeramides":
                                        output.plasmaCeramides = int.Parse((string)test["value"]);
                                        break;

                                    case "natriureticPeptide":
                                        output.natriureticPeptide = int.Parse((string)test["value"]);
                                        break;

                                    default:
                                        Console.WriteLine((string)test["name"] + " does not exist for the health template. ");
                                        break;
                                    }
                                }
                            }
                        }
                        context.Logger.LogLine("JSON contents are prepped. ");
                    }
                    else
                    {
                        context.Logger.LogLine("JSON contents are invalid... Lambda function will stop. ");
                    }
                }
                catch (Newtonsoft.Json.JsonReaderException e)
                {
                    context.Logger.LogLine("Contents did not create valid JSON... Lambda function will stop. ");
                }
            }
            else
            {
                context.Logger.LogLine(" extension is an invalid extension. Lambda function will stop. ");
            }
            return(output);
        }
Exemple #30
0
        //AddObject method will do INSERT code
        private void AddObject(EntryRow entry, NpgsqlConnection conn, ILambdaContext context)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(entry.id + ",");
            if (entry.age != null)
            {
                sb.Append(entry.age + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.gender != null)
            {
                sb.Append("'" + entry.gender + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.maritalStatus != null)
            {
                sb.Append("'" + entry.maritalStatus + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.bmi != null)
            {
                sb.Append(entry.bmi + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.smoker != null)
            {
                sb.Append("'" + entry.smoker + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.alcoholConsumption != null)
            {
                sb.Append("'" + entry.alcoholConsumption + "',");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.totalCholesterol != null)
            {
                sb.Append(entry.totalCholesterol + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.ldlCholesterol != null)
            {
                sb.Append(entry.ldlCholesterol + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.hdlCholesterol != null)
            {
                sb.Append(entry.hdlCholesterol + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.triglycerides != null)
            {
                sb.Append(entry.triglycerides + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.plasmaCeramides != null)
            {
                sb.Append(entry.plasmaCeramides + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.natriureticPeptide != null)
            {
                sb.Append(entry.natriureticPeptide + ",");
            }
            else
            {
                sb.Append("NULL,");
            }
            if (entry.hasVascularDisease != null)
            {
                sb.Append("'" + entry.hasVascularDisease + "'");
            }
            else
            {
                sb.Append("NULL");
            }
            string input = "INSERT INTO health.\"healthTable\" (id, age, gender, \"maritalStatus\", bmi, smoker, \"alcoholConsumption\", \"totalCholesterol\", \"LDLCholesterol\", \"HDLCholesterol\", triglycerides, \"plasmaCeramides\", \"natriureticPeptide\", \"hasVascularDisease\") VALUES (" + sb.ToString() + ");";

            NpgsqlCommand command = new NpgsqlCommand(input, conn);

            command.ExecuteNonQuery();
            conn.Close();
            context.Logger.LogLine("INSERT command sent. Connection is now closed. ");
        }