Пример #1
0
        private FileInfo GetExternalFile(string relFilePath)
        {
            if (string.IsNullOrEmpty(relFilePath))
            {
                MessageBox.Show(
                    string.Format("No external file is referenced in {0}.", _controlLocationName)
                    , Resources.ExternalNodeReference_ExternalFileNotFoundTitle, MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return(null);
            }
            FileInfo fi = EnvironmentFileHandler.GetFile();

            if (fi != null)
            {
                FileInfo extFile = new FileInfo(Path.Combine(fi.DirectoryName, relFilePath));
                if (extFile.Exists)
                {
                    return(extFile);
                }
                MessageBox.Show(
                    string.Format("The external file {1} referenced in {0} does not exist.", _controlLocationName,
                                  extFile.FullName)
                    , Resources.ExternalNodeReference_ExternalFileNotFoundTitle, MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }

            return(null);
        }
Пример #2
0
        private void BrowseButton_Click(object sender, EventArgs e)
        {
            if (EnvironmentFileHandler.IsSingletonNew)
            {
                MessageBox.Show(
                    Resources.ExternalNodeReference_FileUnsavedWarningText,
                    Resources.ExternalNodeReference_FileUnsavedWarningTitle, MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }
            FileInfo fi = EnvironmentFileHandler.GetFile();

            if (fi != null)
            {
                openFileDialog.InitialDirectory = fi.DirectoryName;
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        FileInfo extFile = new FileInfo(openFileDialog.FileName);
                        if (extFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            MessageBox.Show(
                                Resources.ExternalNodeReference_SelfReferenceMessage,
                                Resources.ExternalNodeReference_BrowseErrorTitle, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                            return;
                        }
                        string relPath = fi.RelativePathTo(extFile);
                        //Model.SPSD file = EnvironmentFileHandler.LoadFile(openFileDialog.FileName);
                        //if (file != null)
                        //{
                        if (LoadExternalNodeIds(relPath))
                        {
                            textBox_ExtNodeFile.Text = relPath;
                            EnvironmentFileHandler.MakeSingletonDirty();
                        }
                        //}
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            ex.Message,
                            Resources.ExternalNodeReference_BrowseErrorTitle, MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                        return;
                    }
                }
            }
        }