Exemple #1
0
        private void MoveSelection(int offset, Keys modifiers)
        {
            if (SelectedAddress == null)
            {
                return;
            }
            ulong linAddr = (ulong)((long)SelectedAddress.ToLinear() + offset);

            if (!mem.IsValidLinearAddress(linAddr))
            {
                return;
            }
            Address addr = segmentMap.MapLinearAddressToAddress(linAddr);

            if (!IsVisible(SelectedAddress))
            {
                Address newTopAddress = TopAddress + offset;
                if (mem.IsValidAddress(newTopAddress))
                {
                    TopAddress = newTopAddress;
                }
            }
            if ((modifiers & Keys.Shift) != Keys.Shift)
            {
                addrAnchor = addr;
            }
            addrSelected = addr;
            Invalidate();
            OnSelectionChanged();
        }
        private void OnSaveNewAddress()
        {
            Model.Validate();
            if (Model.HasErrors)
            {
                return;
            }

            SelectedAddress.Validate();
            if (SelectedAddress.HasErrors)
            {
                return;
            }

            ShowAddressPopup = Visibility.Collapsed;

            if (Model.Addresses == null)
            {
                Model.Addresses = new List <MedicalPracticeAddress>();
            }

            if (IsEditingAddress)
            {
                IsEditingAddress = false;
                return;
            }

            Model.Addresses.Add(SelectedAddress);

            var tempAddresses = Model.Addresses;

            Model.Addresses = new List <MedicalPracticeAddress>();
            Model.Addresses = tempAddresses;
        }
Exemple #3
0
        private void SearchAddress()
        {
            _search = true;

            string searchText = this.txtSearch.Text.Trim();

            if (!string.IsNullOrWhiteSpace(searchText))
            {
                var data = new List <PcGroupAddress>();

                var filterAddress = from i in MyCache.GroupAddressTable where i.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) != -1 select i;

                foreach (var it in filterAddress)
                {
                    var temp = new PcGroupAddress(it);

                    if (SelectedAddress != null && SelectedAddress.ContainsKey(temp.Id))
                    {
                        temp.Selected = true;
                    }

                    data.Add(temp);
                }

                RefreashTable(data);
            }
        }
Exemple #4
0
        private void SetSelectIDs()
        {
            if (_search == false)
            {
                // 清空之前选择的
                SelectedAddress.Clear();
            }

            int count = dgvData.Rows.Count;

            for (int i = 0; i < count; i++)
            {
                var groupAddress = dgvData.Rows[i].DataBoundItem as PcGroupAddress;
                if (groupAddress != null)
                {
                    if (groupAddress.Selected == true)
                    {
                        SelectedAddress[groupAddress.Id] = new KNXSelectedAddress()
                        {
                            Id           = groupAddress.Id,
                            Name         = groupAddress.Name,
                            Type         = (int)Enum.Parse(typeof(KNXDataType), groupAddress.Type),
                            DefaultValue = groupAddress.DefaultValue
                        };
                    }
                }
            }
        }
        public void PasteRowCommand()
        {
            try
            {
                AddressColumnMetaDataList.Sort(delegate(ColumnMetaData c1, ColumnMetaData c2)
                                               { return(c1.Order.CompareTo(c2.Order)); });

                char[] rowSplitter    = { '\r', '\n' };
                char[] columnSplitter = { '\t' };
                //get the text from clipboard
                IDataObject dataInClipboard   = Clipboard.GetDataObject();
                string      stringInClipboard = (string)dataInClipboard.GetData(DataFormats.Text);
                //split it into rows...
                string[] rowsInClipboard = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries);

                foreach (string row in rowsInClipboard)
                {
                    NewAddressCommand(""); //this will generate a new item and set it as the selected item...
                    //split row into cell values
                    string[] valuesInRow = row.Split(columnSplitter);
                    int      i           = 0;
                    foreach (string columnValue in valuesInRow)
                    {
                        SelectedAddress.SetPropertyValue(AddressColumnMetaDataList[i].Name, columnValue);
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                NotifyMessage(ex.InnerException.ToString());
            }
        }
Exemple #6
0
        private void LoadAllAddress()
        {
            _search = false;

            var data = new List <PcGroupAddress>();

            foreach (var it in MyCache.GroupAddressTable)
            {
                //if (((AddressType.Read == this.PickType) && (it.IsCommunication && it.IsRead)) ||
                //    ((AddressType.Write == this.PickType) && (it.IsCommunication && it.IsWrite)))
                //{
                if (this.NeedActions && ((null == it.Actions) || (it.Actions.Count <= 0)))
                {
                    continue;
                }

                var temp = new PcGroupAddress(it);

                if (SelectedAddress != null && SelectedAddress.ContainsKey(temp.Id))
                {
                    temp.Selected     = true;
                    temp.DefaultValue = SelectedAddress[temp.Id].DefaultValue;
                }

                data.Add(temp);
                //}
            }

            RefreashTable(data);
        }
Exemple #7
0
        private void FrmGroupAddressPick_Load(object sender, EventArgs e)
        {
            foreach (EdGroupAddress address in MyCache.GroupAddressTable)
            {
                var temp = new MgGroupAddress(address);
                this.MgAddressList.Add(temp);

                if ((null != SelectedAddress) && (SelectedAddress.ContainsKey(address.Id)))
                {
                    temp.IsSelected   = true;
                    temp.DefaultValue = SelectedAddress[address.Id].DefaultValue;
                }
            }

            LoadAllAddress();
        }
        /// <summary>
        /// Called when [save new address].
        /// </summary>
        private void OnSaveNewAddress()
        {
            if (IsSearchingMedicalPractice)
            {
                PossibleMedicalPractices.OfType <db.MedicalPracticeAddress>().Where(x => x.IsSelected).ToList().ForEach(add =>
                {
                    // Get associated addresses for MedicalPractice.
                    var pmp = Model.PhysicianMedicalPractices.Where(pmpx => pmpx.MedicalPractice.Id == add.MedicalPractice.Id).FirstOrDefault();
                    if (pmp == null)
                    {
                        pmp = new db.PhysicianMedicalPractice()
                        {
                            Physician              = Model,
                            MedicalPractice        = add.MedicalPractice,
                            AssociatedPMPAddresses = new List <int>()
                        };
                        Model.PhysicianMedicalPractices.Add(pmp);
                    }

                    // Add the associated address if needed.
                    if (!pmp.AssociatedPMPAddresses.Contains(add.Id))
                    {
                        pmp.AssociatedPMPAddresses.Add(add.Id);
                    }
                });
            }
            else
            {
                if (SelectedAddress == null)
                {
                    return;
                }

                SelectedAddress.Validate();
                if (SelectedAddress.HasErrors)
                {
                    return;
                }

                Model.Addresses.Add(SelectedAddress);
            }
            ShowAddressPopup = Visibility.Collapsed;
            ProcessAddressForDisplay();
        }
        public ReceiveTabViewModel(WalletViewModel walletViewModel)
            : base("Receive", walletViewModel)
        {
            _addresses = new ObservableCollection <AddressViewModel>();
            Label      = "";

            InitializeAddresses();

            GenerateCommand = ReactiveCommand.Create(() =>
            {
                var label = new SmartLabel(Label);
                Label     = label.ToString();
                if (label.IsEmpty)
                {
                    LabelRequiredNotificationVisible = true;
                    LabelRequiredNotificationOpacity = 1;

                    Dispatcher.UIThread.PostLogException(async() =>
                    {
                        await Task.Delay(TimeSpan.FromSeconds(4));
                        LabelRequiredNotificationOpacity = 0;
                    });

                    return;
                }

                Dispatcher.UIThread.PostLogException(() =>
                {
                    HdPubKey newKey = Global.WalletService.GetReceiveKey(new SmartLabel(Label), Addresses.Select(x => x.Model).Take(7));                                     // Never touch the first 7 keys.

                    AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
                    if (found != default)
                    {
                        Addresses.Remove(found);
                    }

                    var newAddress = new AddressViewModel(newKey, Global);

                    Addresses.Insert(0, newAddress);

                    SelectedAddress = newAddress;

                    Label = "";
                });
            });

            this.WhenAnyValue(x => x.Label).Subscribe(UpdateSuggestions);

            this.WhenAnyValue(x => x.SelectedAddress).Subscribe(async address =>
            {
                if (Global.UiConfig?.Autocopy is false || address is null)
                {
                    return;
                }

                await address.TryCopyToClipboardAsync();
            });

            var isCoinListItemSelected = this.WhenAnyValue(x => x.SelectedAddress).Select(coin => coin != null);

            CopyAddress = ReactiveCommand.CreateFromTask(async() =>
            {
                if (SelectedAddress is null)
                {
                    return;
                }

                await SelectedAddress.TryCopyToClipboardAsync();
            },
                                                         isCoinListItemSelected);

            CopyLabel = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    await Application.Current.Clipboard.SetTextAsync(SelectedAddress.Label ?? string.Empty);
                }
                catch (Exception)
                { }
            },
                                                       isCoinListItemSelected);

            ToggleQrCode = ReactiveCommand.Create(() =>
            {
                try
                {
                    SelectedAddress.IsExpanded = !SelectedAddress.IsExpanded;
                }
                catch (Exception)
                { }
            },
                                                  isCoinListItemSelected);

#pragma warning disable IDE0053 // Use expression body for lambda expressions
            ChangeLabelCommand = ReactiveCommand.Create(() => { SelectedAddress.InEditMode = true; });
#pragma warning restore IDE0053 // Use expression body for lambda expressions

            DisplayAddressOnHwCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var client    = new HwiClient(Global.Network);
                using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
                try
                {
                    await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, SelectedAddress.Model.FullKeyPath, cts.Token);
                }
                catch (HwiException)
                {
                    await PinPadViewModel.UnlockAsync(Global);
                    await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, SelectedAddress.Model.FullKeyPath, cts.Token);
                }
            });

            _suggestions = new ObservableCollection <SuggestionViewModel>();
        }
        private void SelectedAddress_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {//these properties are not to be persisted we will igore them...
            if (e.PropertyName == "IsSelected" ||
                e.PropertyName == "IsExpanded" ||
                e.PropertyName == "IsValid" ||
                e.PropertyName == "NotValidMessage" ||
                e.PropertyName == "LastModifiedBy" ||
                e.PropertyName == "LastModifiedByDate")
            {
                return;
            }
            //Key ID Logic...
            if (e.PropertyName == "AddressID")
            {//make sure it is has changed...
                if (SelectedAddressMirror.AddressID != SelectedAddress.AddressID)
                {
                    //if their are no records it is a key change
                    if (AddressList != null && AddressList.Count == 0 &&
                        SelectedAddress != null && !string.IsNullOrEmpty(SelectedAddress.AddressID))
                    {
                        ChangeKeyLogic();
                        return;
                    }

                    EntityStates entityState = GetAddressState(SelectedAddress);

                    if (entityState == EntityStates.Unchanged ||
                        entityState == EntityStates.Modified)
                    {                             //once a key is added it can not be modified...
                        if (Dirty && AllowCommit) //dirty record exists ask if save is required...
                        {
                            NotifySaveRequired("Do you want to save changes?", _saveRequiredResultActions.ChangeKeyLogic);
                        }
                        else
                        {
                            ChangeKeyLogic();
                        }

                        return;
                    }
                }
            }//end KeyID logic...

            object propertyChangedValue = SelectedAddress.GetPropertyValue(e.PropertyName);
            object prevPropertyValue    = SelectedAddressMirror.GetPropertyValue(e.PropertyName);
            string propertyType         = SelectedAddress.GetPropertyType(e.PropertyName);
            //in some instances the value is not really changing but yet it still is tripping property change..
            //This will ensure that the field has physically been modified...
            //As well when we revert back it constitutes a property change but they will be = and it will bypass the logic...
            bool objectsAreEqual;

            if (propertyChangedValue == null)
            {
                if (prevPropertyValue == null)//both values are null
                {
                    objectsAreEqual = true;
                }
                else//only one value is null
                {
                    objectsAreEqual = false;
                }
            }
            else
            {
                if (prevPropertyValue == null)//only one value is null
                {
                    objectsAreEqual = false;
                }
                else //both values are not null use .Equals...
                {
                    objectsAreEqual = propertyChangedValue.Equals(prevPropertyValue);
                }
            }
            if (!objectsAreEqual)
            {
                //Here we do property change validation if false is returned we will reset the value
                //Back to its mirrored value and return out of the property change w/o updating the repository...
                if (AddressPropertyChangeIsValid(e.PropertyName, propertyChangedValue, prevPropertyValue, propertyType))
                {
                    Update(SelectedAddress);
                    //set the mirrored objects field...
                    SelectedAddressMirror.SetPropertyValue(e.PropertyName, propertyChangedValue);
                    SelectedAddressMirror.IsValid         = SelectedAddress.IsValid;
                    SelectedAddressMirror.IsExpanded      = SelectedAddress.IsExpanded;
                    SelectedAddressMirror.NotValidMessage = SelectedAddress.NotValidMessage;
                }
                else
                {
                    SelectedAddress.SetPropertyValue(e.PropertyName, prevPropertyValue);
                    SelectedAddress.IsValid         = SelectedAddressMirror.IsValid;
                    SelectedAddress.IsExpanded      = SelectedAddressMirror.IsExpanded;
                    SelectedAddress.NotValidMessage = SelectedAddressMirror.NotValidMessage;
                }
            }
        }
Exemple #11
0
        public ReceiveTabViewModel(WalletViewModel walletViewModel)
            : base("Receive", walletViewModel)
        {
            _addresses = new ObservableCollection <AddressViewModel>();
            Label      = "";

            InitializeAddresses();

            GenerateCommand = ReactiveCommand.Create(() =>
            {
                Label = Label.Trim(',', ' ').Trim();
                if (string.IsNullOrWhiteSpace(Label))
                {
                    LabelRequiredNotificationVisible = true;
                    LabelRequiredNotificationOpacity = 1;

                    Dispatcher.UIThread.PostLogException(async() =>
                    {
                        await Task.Delay(TimeSpan.FromSeconds(4));
                        LabelRequiredNotificationOpacity = 0;
                    });

                    return;
                }

                Dispatcher.UIThread.PostLogException(() =>
                {
                    var label       = Label;
                    HdPubKey newKey = Global.WalletService.GetReceiveKey(label, Addresses.Select(x => x.Model).Take(7));                     // Never touch the first 7 keys.

                    AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
                    if (found != default)
                    {
                        Addresses.Remove(found);
                    }

                    var newAddress = new AddressViewModel(newKey, Global);

                    Addresses.Insert(0, newAddress);

                    SelectedAddress = newAddress;

                    Label = "";
                });
            });

            this.WhenAnyValue(x => x.Label).Subscribe(UpdateSuggestions);

            this.WhenAnyValue(x => x.SelectedAddress).Subscribe(async address =>
            {
                if (Global.UiConfig?.Autocopy is false || address is null)
                {
                    return;
                }

                await address.TryCopyToClipboardAsync();
            });

            var isCoinListItemSelected = this.WhenAnyValue(x => x.SelectedAddress).Select(coin => coin != null);

            CopyAddress = ReactiveCommand.CreateFromTask(async() =>
            {
                if (SelectedAddress is null)
                {
                    return;
                }

                await SelectedAddress.TryCopyToClipboardAsync();
            }, isCoinListItemSelected);

            CopyLabel = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    await Application.Current.Clipboard.SetTextAsync(SelectedAddress.Label ?? string.Empty);
                }
                catch (Exception)
                { }
            }, isCoinListItemSelected);

            ShowQrCode = ReactiveCommand.Create(() =>
            {
                try
                {
                    SelectedAddress.IsExpanded = true;
                }
                catch (Exception)
                { }
            }, isCoinListItemSelected);

            ChangeLabelCommand = ReactiveCommand.Create(() =>
            {
                SelectedAddress.InEditMode = true;
            });

            _suggestions = new ObservableCollection <SuggestionViewModel>();
        }
Exemple #12
0
        public ComplexGraphViewModel()
        {
            var observer = MementoObserver.Monitor(service);

            UndoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanUndo)
                          .OnExecute(o => service.Undo())
                          .AddMonitor(observer);

            RedoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanRedo)
                          .OnExecute(o => service.Redo())
                          .AddMonitor(observer);

            CreateNewAddressCommand = DelegateCommand.Create()
                                      .OnExecute(o =>
            {
                var address     = Entity.Addresses.AddNew();
                SelectedAddress = address;
            });

            DeleteAddressCommand = DelegateCommand.Create()
                                   .OnCanExecute(o => SelectedAddress != null)
                                   .OnExecute(o =>
            {
                SelectedAddress.Delete();
                SelectedAddress = Entity.Addresses.FirstOrDefault();
            })
                                   .AddMonitor
                                   (
                PropertyObserver.For(this)
                .Observe(v => v.SelectedAddress)
                                   );

            var person = new Person()
            {
                FirstName = "Mauro",
                LastName  = "Servienti"
            };

            person.Addresses.Add(new Address(person)
            {
                City    = "Treviglio",
                Number  = "11",
                Street  = "Where I live",
                ZipCode = "20100"
            });

            person.Addresses.Add(new Address(person)
            {
                City    = "Daolasa",
                Number  = "2",
                Street  = "Pierino",
                ZipCode = "20100"
            });

            var entity = new PersonViewModel();

            entity.Initialize(person, false);

            service.Attach(entity);

            Entity = entity;
        }