Esempio n. 1
0
        protected override FileTransferInfo DetailedProc(FileTransferInfo fileTransferInfo)
        {
            try
            {
                var json = Encoding.UTF8.GetString(fileTransferInfo.Data);
                var bl   = BlankList.GetList(
                    json,
                    ex => _console?.AddException(ex));
                var parsedAct = bl.ToModelFormat(ex => _console?.AddException(ex));
                // HandingValidation(parsedAct);

                _context.Acts.Add(parsedAct);
                var cnt = _context.SaveChanges();
                _console.AddEvent($"{fileTransferInfo} added. {cnt}.");

                GetPpvkFileInfo(fileTransferInfo);

                return(fileTransferInfo);
            }
            catch (DbEntityValidationException ve)
            {
                _console.AddException(ve);
                ve.EntityValidationErrors
                .SelectMany(sm => sm.ValidationErrors)
                .ForEach(e => _console.AddEvent(e.ErrorMessage, ConsoleMessageType.Exception));
                ErrorFileCopy(fileTransferInfo);

                return(fileTransferInfo);
            }
            catch (Exception e)
            {
                _console.AddException(e);
                ErrorFileCopy(fileTransferInfo);
                return(fileTransferInfo);
            }
        }
        public void Work()
        {
            var form = (ActEditForm)_container.Resolve <Form>("ActEditForm");
            var act  = _settings.GetKeys().Contains(ArgsKeyList.Mode) &&
                       _settings[ArgsKeyList.Mode].Equals("Act")
                ? new Act().LoadFromJson(LoadJsonFile())
                : BlankList.GetList(LoadJsonFile(), ex =>
                                    _console?.AddException(ex)).ToModelFormat(e => _console?.AddException(e));

            if (ActEditForm.ShowModal(_container, act) == null)
            {
                return;
            }

            _context.Acts.Add(act);
            _context.SaveChanges();

            var item          = listBox1.Items[listBox1.SelectedIndex].ToString();
            var storeFileName = $"{_settings[ArgsKeyList.StorePath]}\\{_items[item].Id}";

            File.Delete(storeFileName);
            _items.Remove(item);
            listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }