예제 #1
0
        public ICommand IssueApplyChangesCommand()
        {
            var selected      = (String)_cbType.SelectedItem;
            var isNotSelected = selected == Resources.ValueType_NotSelected;
            var isBinary      = selected == Resources.ValueType_Binary;

            if (isNotSelected)
            {
                return(null);
            }
            else
            {
                if (isBinary)
                {
                    var bival = _tbValueBinary.Text;
                    if (bival == Resources.BinaryType_ContentNotEditedYet)
                    {
                        return(null);
                    }
                    else if (bival == Resources.BinaryType_ContentCleared)
                    {
                        return(new ValueEditBinaryFinishCommand(DataVaultUIContext, String.Empty.AsStream()));
                    }
                    else
                    {
                        try
                        {
                            using (var fs = File.OpenRead(_tbValueBinary.Text))
                            {
                                return(new ValueEditBinaryFinishCommand(DataVaultUIContext, fs.CacheInMemory()));
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(Resources.BinaryType_ErrorOpeningContentFile, Resources.Validation_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return(null);
                        }
                    }
                }
                else
                {
                    if (Wrapper != null && Wrapper.CType.LocTypeName == (String)_cbType.SelectedItem)
                    {
                        Wrapper.AssertNotNull();
                        Wrapper.AsLocalizedString = _tbValueTyped.Text;
                        return(Wrapper.IssueApplyChangesCommand(DataVaultUIContext));
                    }
                    else
                    {
                        // we're checking this case to make sure that binary -> w/e works fine
                        var wrapper_t    = ContentTypes.All.Single(t => t.LocTypeName == (String)_cbType.SelectedItem);
                        var typedWrapper = wrapper_t.Apply(Value);
                        typedWrapper.AsLocalizedString = _tbValueTyped.Text;
                        return(typedWrapper.IssueApplyChangesCommand(DataVaultUIContext));
                    }
                }
            }
        }
예제 #2
0
        protected override void OnClosing(CancelEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                var selected      = (String)_cbType.SelectedItem;
                var isNotSelected = selected == Resources.ValueType_NotSelected;
                var isBinary      = selected == Resources.ValueType_Binary;

                if (isNotSelected)
                {
                    MessageBox.Show(Resources.Validation_ValueTypeNotSelected, Resources.Validation_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                }
                else
                {
                    if (isBinary)
                    {
                        if (_tbValueBinary.Text == Resources.BinaryType_ContentNotEditedYet ||
                            _tbValueBinary.Text == Resources.BinaryType_ContentCleared)
                        {
                            // valid
                        }
                        else
                        {
                            try
                            {
                                using (File.OpenRead(_tbValueBinary.Text)){}
                            }
                            catch (Exception)
                            {
                                MessageBox.Show(Resources.BinaryType_ErrorOpeningContentFile, Resources.Validation_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                e.Cancel = true;
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            // need to reuse the Wrapper because it might represent an unknown ctype
                            // in that case ContentTypes.All won't contain it and we won't be able to succeed
                            if (Wrapper != null && Wrapper.CType.LocTypeName == (String)_cbType.SelectedItem)
                            {
                                Wrapper.AssertNotNull();
                                Wrapper.AsLocalizedString = _tbValueTyped.Text;
                            }
                            else
                            {
                                // we're checking this case to make sure that changing ctypes works fine
                                var wrapper_t    = ContentTypes.All.Single(t => t.LocTypeName == (String)_cbType.SelectedItem);
                                var typedWrapper = wrapper_t.Apply(Value);
                                typedWrapper.AsLocalizedString = _tbValueTyped.Text;
                            }
                        }
                        catch (ValidationException vex)
                        {
                            MessageBox.Show(vex.Message, Resources.Validation_Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            e.Cancel = true;
                        }
                    }
                }
            }

            base.OnClosing(e);
        }