/// <summary>
        /// Edit a referenced model.
        /// </summary>
        protected virtual void EditReferencedModel()
        {
            IOpenFileService openFileService = this.GlobalServiceProvider.Resolve <IOpenFileService>();

            openFileService.Filter = FileDialogFilter;
            if (openFileService.ShowDialog(null) == true)
            {
                if (!EnsureClosing())
                {
                    return;
                }

                bool bEnsureOpening;
                using (new Tum.PDE.ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
                {
                    bEnsureOpening = EnsureOpening(openFileService.FileName);
                }
                if (!bEnsureOpening)
                {
                    return;
                }

                SetReferencedModel(openFileService.FileName);
            }

            OnPropertyChanged("IsReferencedModelSet");
            OnPropertyChanged("PropertyValue");
        }
Example #2
0
        public void OpenFile()
        {
            _foundEntities = new List <T>();
            _exceptions    = new List <Exception>();


            if (_openFileService.ShowDialog(this) != true)
            {
                return;
            }

            FilePath = _openFileService.FileName;
            // 获取有效的Sheet表
            Dictionary <string, DataTable> foundSheets = ColumnNameMapping.GetValidExcelSheats(FilePath);

            _sheets = new Dictionary <string, DataTable>(_nameOfSheets.Count);

            foreach (var sheet in _nameOfSheets)
            {
                if (foundSheets.ContainsKey(sheet.Key))
                {
                    _sheets[sheet.Key]           = foundSheets[sheet.Key];
                    _sheets[sheet.Key].TableName = sheet.Key;
                    _sheets[sheet.Key].CheckColumnExist(sheet.Value); //检查sheet表中列是否存在
                    _sheets[sheet.Key].BlankRowsRemove();             //除去数据都为空的行
                    _sheets[sheet.Key].AsEnumerable().DuplicateCheckAndExtract(Validation, ValidationRow, DuplicateRow,
                                                                               CatchException);
                }
                if (foundSheets.Count == 0)
                {
                    _exceptions.Add(new Exception("档案格式有误!"));
                }
            }
            ReadingCompleted(_foundEntities);
        }
        /// <summary>
        /// Executes the AddNewAssemblyCommand
        /// </summary>
        private void ExecuteAddNewAssemblyCommand()
        {
            //Ask the user where they want to open the file from, and open it
            try
            {
                openFileService.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                openFileService.FileName         = String.Empty;
                openFileService.Filter           = "Dll files (*.dll)|*.dll";
                bool?result = openFileService.ShowDialog(null);

                if (result.HasValue && result.Value)
                {
                    FileInfo file = new FileInfo(openFileService.FileName);
                    if (file.Extension.ToLower().Equals(".dll"))
                    {
                        this.referencedAssemblies.Add(file);
                    }
                    else
                    {
                        messageBoxService.ShowError(String.Format("The file {0} is not a Dll", file.Name));
                    }
                }
            }
            catch (Exception ex)
            {
                messageBoxService.ShowError("An error occurred trying to Open the file\r\n" +
                                            ex.Message);
            }
        }
 private void OnOpen()
 {
     _openFileService.Filter = "Excel 2010 sheet|*.xlsx";
     if (_openFileService.ShowDialog() == true)
     {
         OpenExcelSheet(_openFileService.FileName);
     }
 }
Example #5
0
        private async Task <object> ExecutePickInputJarFileCommandAsync(object param)
        {
            IsBusy = true;

            try
            {
                _openFileService.Filter           = "Jar Files (*.jar)|*.jar";
                _openFileService.InitialDirectory = @"c:\";
                _openFileService.FileName         = "";
                var dialogResult = _openFileService.ShowDialog(null);
                if (dialogResult.Value)
                {
                    if (!_openFileService.FileName.ToLower().EndsWith(".jar"))
                    {
                        _messageBoxService.ShowError($"{_openFileService.FileName} is not a JAR file");
                        return(Task.FromResult <object>(null));
                    }
                    _jarFile    = new FileInfo(_openFileService.FileName);
                    JarFilePath = _jarFile.Name;
                    var rawBytesLength = File.ReadAllBytes(_jarFile.FullName).Length;
                    await _dataBricksFileUploadService.UploadFileAsync(_jarFile, rawBytesLength,
                                                                       (newStatus) => this.Status = newStatus);

                    bool uploadedOk = await IsDbfsFileUploadedAndAvailableAsync(_jarFile, rawBytesLength);

                    if (uploadedOk)
                    {
                        //2.0/jobs/runs/submit
                        //poll for success using jobs/runs/get, store that in the JSON
                        var runId = await SubmitJarJobAsync(_jarFile);

                        if (!runId.HasValue)
                        {
                            IsBusy = false;
                            _messageBoxService.ShowError(this.Status = $"Looks like there was a problem with calling Spark API '2.0/jobs/runs/submit'");
                        }
                        else
                        {
                            await PollForRunIdAsync(runId.Value);
                        }
                    }
                    else
                    {
                        IsBusy = false;
                        _messageBoxService.ShowError("Looks like the Jar file did not upload ok....Boo");
                    }
                }
            }
            catch (Exception ex)
            {
                _messageBoxService.ShowError(ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
            return(Task.FromResult <object>(null));
        }
Example #6
0
        /// <summary>
        /// Creates a new InMemoryViewModel by reading the persisted XML file from disk
        /// </summary>
        private void HydrateViewModelFromXml()
        {
            //Ask the user where they want to open the file from, and open it
            try
            {
                openFileService.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                openFileService.FileName         = String.Empty;
                openFileService.Filter           = "Xml files (*.xml)|*.xml";
                bool?result = openFileService.ShowDialog(null);

                if (result.HasValue && result.Value)
                {
                    //open to XML
                    PesistentVM pesistentVM =
                        ViewModelPersistence.HydratePersistedViewModel(openFileService.FileName);
                    //check we got something, and recreate the full weight InMemoryViewModel from
                    //the lighter weight XML read PesistentVM
                    if (pesistentVM != null)
                    {
                        CurrentVM = new InMemoryViewModel();

                        //Start out with PropertiesViewModel shown
                        PropertiesViewModel propertiesViewModel =
                            new PropertiesViewModel();
                        propertiesViewModel.IsCloseable = false;
                        CurrentVM.PropertiesVM          = propertiesViewModel;
                        //and now read in other data
                        CurrentVM.ViewModelName        = pesistentVM.VMName;
                        CurrentVM.CurrentViewModelType = pesistentVM.VMType;
                        CurrentVM.ViewModelNamespace   = pesistentVM.VMNamespace;
                        //and add in the individual properties
                        foreach (var prop in pesistentVM.VMProperties)
                        {
                            CurrentVM.PropertiesVM.PropertyVMs.Add(new
                                                                   SinglePropertyViewModel
                            {
                                PropertyType   = prop.PropertyType,
                                PropName       = prop.PropName,
                                UseDataWrapper = prop.UseDataWrapper
                            });
                        }

                        HasContent = true;
                    }
                    else
                    {
                        messageBoxService.ShowError(String.Format("Could not open the ViewModel {0}",
                                                                  openFileService.FileName));
                    }
                }
            }
            catch (Exception ex)
            {
                messageBoxService.ShowError("An error occurred trying to Opening the ViewModel\r\n" +
                                            ex.Message);
            }
        }
Example #7
0
        private void OpenFromFile()
        {
            var dialogResult = openFileService.ShowDialog(null);

            if (dialogResult == true)
            {
                var path = openFileService.FileName;
                files.OnNext(path);
            }
        }
Example #8
0
 private void Load()
 {
     if (OpenFileService.ShowDialog(Application.Current.MainWindow) == true)
     {
         using (var fileStream = new FileStream(OpenFileService.FileName, FileMode.Open))
         {
             var modelSaver = new XmlModelSerializer(fileStream);
             this.Document = modelSaver.Deserialize();
         }
     }
 }
        private void ExecuteUploadUserImageCommand(Object args)
        {
            //User File open service to get the file
            openFileService.InitialDirectory = @"C:\";
            openFileService.Filter           = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";

            var result = openFileService.ShowDialog(null);

            if (result.HasValue && result.Value == true)
            {
                var fileName = openFileService.FileName;
                NewUser.PhotoPath.DataValue = fileName;
            }
        }
Example #10
0
        /// <summary>
        /// Browse command executed.
        /// </summary>
        private void BrowseCommand_Executed()
        {
            IMessageBoxService messageBox      = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
            IOpenFileService   openFileService = this.GlobalServiceProvider.Resolve <IOpenFileService>();

            openFileService.Filter = "Image files (png, jpeg, gif)|*.png;*.jpg;*.jpeg;*.gif";
            if (openFileService.ShowDialog(null) == true)
            {
                // copy to images folder
                try
                {
                    string targetImagesDirectory = this.referencePath + "\\" + ImageDirectory;

                    // see if images directory exists
                    if (!Directory.Exists(targetImagesDirectory))
                    {
                        Directory.CreateDirectory(targetImagesDirectory);
                    }

                    // see if image is already in directory
                    FileInfo info = new FileInfo(openFileService.FileName);
                    if (info.DirectoryName == targetImagesDirectory)
                    {
                        // no need to do anything...
                    }
                    else
                    {
                        // see if file with the same name already exists
                        if (File.Exists(targetImagesDirectory + "\\" + info.Name))
                        {
                            if (messageBox.ShowYesNo("File " + info.Name + " already exists in " + targetImagesDirectory + ". Inserting the image would override the existing file. Do you want to continue?", CustomDialogIcons.Question) == CustomDialogResults.No)
                            {
                                return;
                            }
                        }
                    }

                    SourcePath   = openFileService.FileName;
                    RelativePath = "images/" + info.Name;

                    this.IsInsertionValid = true;
                }
                catch (Exception ex)
                {
                    messageBox.ShowError("Error while inserting image: " + ex.Message);
                }
            }
        }
Example #11
0
        /// <summary>
        /// Open command executed.
        /// </summary>
        protected virtual void OpenModelCommandExecuted()
        {
            if (this.SelectedModelContextViewModel == null)
            {
                return;
            }
            if (this.SelectedModelContextViewModel.ModelContext == null)
            {
                return;
            }

            IOpenFileService openFileService = this.GlobalServiceProvider.Resolve <IOpenFileService>();

            //openFileService.InitialDirectory = System.Windows.Application.Current.StartupUri.AbsolutePath;
            openFileService.Filter = this.SelectedModelContextViewModel.EditorTitle + " files|*.xml|All files|*.*";
            if (openFileService.ShowDialog(null) == true)
            {
                OpenModel(openFileService.FileName);
            }
        }
Example #12
0
        /// <summary>
        /// Create a new List<ImageViewModel> by reading a XML file using XLINQ
        /// </summary>
        private void ExecuteOpenExistingFileCommand(Object args)
        {
            openFileService.InitialDirectory = @"C:\";
            openFileService.Filter           = ".xml | XML Files";

            var result = openFileService.ShowDialog(null);

            if (result.HasValue && result.Value == true)
            {
                try
                {
                    List <ImageViewModel> xmlReadViewModels = imageDiskOperations.Open(openFileService.FileName);
                    if (xmlReadViewModels != null)
                    {
                        loadedImages   = xmlReadViewModels;
                        LoadedImagesCV = CollectionViewSource.GetDefaultView(loadedImages);
                        if (loadedImages != null)
                        {
                            LoadedImagesCV.MoveCurrentTo(loadedImages.First());
                        }

                        messageBoxService.ShowInformation(string.Format("Successfully retreived images from file\r\n{0}",
                                                                        saveFileService.FileName));
                    }
                    else
                    {
                        messageBoxService.ShowError(string.Format("Couldn't load any images from file\r\n{0}",
                                                                  saveFileService.FileName));
                    }
                }
                catch (Exception ex)
                {
                    messageBoxService.ShowError(
                        string.Format("An error occurred opening file\r\n{0}", ex.Message));
                }
            }
        }
Example #13
0
        private void ExecuteOpenFileCommand(Object parameter)
        {
            isGenerallyBusy = true;
            try
            {
                openFileService.InitialDirectory = @"C:\";
                openFileService.Filter           = "Assemblies (*.dll)|*.dll|Executables (*.exe)|*.exe";
                openFileService.FileName         = "";

                bool?result = openFileService.ShowDialog(null);
                if (result.HasValue && result.Value)
                {
                    if (!openFileService.FileName.Equals(string.Empty))
                    {
                        ProcessAssemblyFile(openFileService.FileName);
                    }
                }
            }
            catch (AggregateException AggEx)
            {
                MainAsyncState    = AsyncType.Content;
                HasActiveAssembly = false;
                messageBoxService.ShowError(AggEx.InnerException.Message);
            }
            catch (Exception ex)
            {
                MainAsyncState    = AsyncType.Content;
                HasActiveAssembly = false;
                messageBoxService.ShowError(ex.Message);
            }
            finally
            {
                isGenerallyBusy = false;
                MainAsyncState  = AsyncType.Content;
                ApplicationHelper.DoEvents();
            }
        }
Example #14
0
        public void OpenFile()
        {
            if (_importingThread.If(t => t.IsAlive) == true)
            {
                _importingThread.Abort();
                Status = null;
                return;
            }

            if (_openFileService.ShowDialog(this) != true)
            {
                return;
            }


            FilePath = _openFileService.FileName;

            Preparing();

            _importingThread = new Thread(Reading)
            {
                IsBackground = true
            }.Self(t => t.Start());
        }