Beispiel #1
0
//        利用 文件路径 为 axMapControl1 添加图层

        private void addLayer(string path)
        {
            // GetDirectoryName 方法可以解析出目录名

            string directoryName = Path.GetDirectoryName(path);

            // GetFileNameWithoutExtension 方法可以解析出

            // 不包含扩展名的文件名称(不包含路径名)

            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);


            IWorkspaceFactory shapefileWorkspaceFactory = new ShapefileWorkspaceFactory();

            // 调用 OpenFromFile 通过目录名方法打开 Shapefile 数据库

            IWorkspace workspace = shapefileWorkspaceFactory.OpenFromFile(directoryName, 0);

            if (workspace != null)
            {
                // ESRI.ArcGIS.Geodatabase.IEnumDataset

                IEnumDataset enumDataset =
                    workspace.get_Datasets(esriDatasetType.esriDTFeatureClass);

                enumDataset.Reset();

                IDataset shpDataset = enumDataset.Next();

                while (shpDataset != null)
                {
                    if (shpDataset.Name == fileNameWithoutExtension)
                    {
                        // ESRI.ArcGIS.Carto.IFeatureLayer

                        IFeatureLayer newLayer = new FeatureLayerClass();

                        newLayer.FeatureClass = shpDataset as IFeatureClass;

                        newLayer.Name = fileNameWithoutExtension;

                        axMapControl1.Map.AddLayer(newLayer);

                        break;
                    }

                    shpDataset = enumDataset.Next();
                }
            }
        }
        public override bool Execute()
        {
            AppDomain domain = null;
            bool      success;

            if (!Path.IsPathRooted(ToolPath))
            {
                ToolPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), ToolPath);
            }

            if (!Path.IsPathRooted(BuildTaskPath))
            {
                BuildTaskPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), BuildTaskPath);
            }

            try
            {
                domain = GetAntlrTaskAppDomain();
                AntlrClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper(domain);
                success = wrapper.Execute();

                if (success)
                {
                    _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem) new TaskItem(file)));
                }

                foreach (BuildMessage message in wrapper.BuildMessages)
                {
                    ProcessBuildMessage(message);
                }
            }
            catch (Exception exception)
            {
                if (IsFatalException(exception))
                {
                    throw;
                }

                ProcessExceptionAsBuildMessage(exception);
                success = false;
            }
            finally
            {
                if (domain != null && domain != _sharedAppDomain)
                {
                    AppDomain.Unload(domain);
                }
            }

            return(success);
        }
Beispiel #3
0
        private void Save_Pdf_Button_Click(object sender, RoutedEventArgs e)
        {
            {
                Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                dlg.FileName   = Path.GetDirectoryName(SRC) + "\\" + Path.GetFileNameWithoutExtension(SRC) + " - Filled.pdf";
                dlg.DefaultExt = ".pdf";
                dlg.Filter     = "PDF Files (*.pdf)|*.pdf";

                // Show save file dialog box
                Nullable <bool> result = dlg.ShowDialog();

                // Process save file dialog box results
                if (result == true)
                {
                    // Save document
                    DEST = dlg.FileName;

                    PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
                    PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, false);

                    try
                    {
                        form.SetGenerateAppearance(true);

                        PdfFont font = PdfFontFactory.CreateFont();

                        IEnumerable <TextBox> elements = FindVisualChildren <TextBox>(lbFormFields).Where(x => x.Tag != null && x.Tag.ToString() == "textBox_FieldValue");
                        foreach (TextBox tb in elements)
                        {
                            String FieldName = ((Grid)tb.Parent).Tag.ToString();
                            IEnumerable <TextBox> fontSizeTextBoxElements = FindVisualChildren <TextBox>(tb.Parent).Where(x => x.Tag != null && x.Tag.ToString() == FieldName);
                            float fieldFontSize = 10f;
                            float.TryParse(fontSizeTextBoxElements.First().Text, out fieldFontSize);
                            form.GetField(FieldName).SetValue(tb.Text, font, fieldFontSize);
                        }

                        if (MessageBox.Show("PDF saved! \nPath: " + DEST + "\n\nDo you want to open the file?",
                                            "Successful", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            System.Diagnostics.Process.Start(DEST);
                        }
                    }
                    catch {
                        MessageBox.Show("An error occurred!");
                    }
                    finally {
                        pdfDoc.Close();
                    }
                }
            }
        }
Beispiel #4
0
        /** The format gets reset either from the Tool if the user supplied a command line option to that effect
         *  Otherwise we just use the default "antlr".
         */
        public virtual void SetFormat(string formatName)
        {
            this.formatName = formatName;
            string fileName = Path.Combine(FORMATS_DIR, formatName + TemplateGroup.GroupFileExtension);

            if (!File.Exists(fileName) && formatName != "antlr")
            {
                SetFormat("antlr");
                return;
            }

            //format.EnableCache = AntlrTool.EnableTemplateCache;
            if (!File.Exists(fileName))
            {
                RawError("ANTLR installation corrupted; cannot find ANTLR messages format file " + fileName);
                Panic();
            }
            //else if (url == null)
            //{
            //    RawError("no such message format file " + fileName + " retrying with default ANTLR format");
            //    SetFormat("antlr"); // recurse on this rule, trying the default message format
            //    return;
            //}

            format = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    fileName),
                Encoding.UTF8);
            format.Load();

            if (initSTListener.Errors.Count > 0)
            {
                RawError("ANTLR installation corrupted; can't load messages format file:\n" +
                         initSTListener.ToString());
                Panic();
            }

            bool formatOK = VerifyFormat();

            if (!formatOK && formatName.Equals("antlr"))
            {
                RawError("ANTLR installation corrupted; ANTLR messages format file " + formatName + ".stg incomplete");
                Panic();
            }
            else if (!formatOK)
            {
                SetFormat("antlr"); // recurse on this rule, trying the default message format
            }
        }
Beispiel #5
0
        protected virtual TemplateGroup LoadTemplates()
        {
            TemplateGroup result = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    Path.Combine(CodeGenerator.TEMPLATE_ROOT, GetLanguage(), GetLanguage() + TemplateGroup.GroupFileExtension)),
                Encoding.UTF8);

            result.RegisterRenderer(typeof(int), new NumberRenderer());
            result.RegisterRenderer(typeof(string), new StringRenderer());
            result.Listener = new ErrorListener(this);

            return(result);
        }
Beispiel #6
0
        /**
         * Convert an object of type T to JSON representation, and output to a file.
         * If filename is not an absolute path, it will be relative to the
         * Application's dataPath.
         */
        public void Persist(string filename, T settings)
        {
            string dstFilePath = filename;

            if (!Path.IsPathRooted(dstFilePath)) // If relative path, base at dataPath.
            {
                dstFilePath = Path.Combine(Application.dataPath, dstFilePath);
            }
            if (!Directory.Exists(Path.GetDirectoryName(dstFilePath))) // If directory doesnt exist create it.
            {
                Directory.CreateDirectory(Path.GetDirectoryName(dstFilePath));
            }
            File.WriteAllText(dstFilePath, JsonUtility.ToJson(settings));
        }
Beispiel #7
0
        static PSqlClient()
        {
            LoadPath
                = Path.GetDirectoryName(typeof(PSqlClient).Assembly.Location)
                  ?? Environment.CurrentDirectory;

            LoadContext            = new AssemblyLoadContext(nameof(PSqlClient));
            LoadContext.Resolving += OnResolving;

            LoadMicrosoftDataSqlClientAssembly();
            Assembly = LoadAssembly(AssemblyPath);

            Instance = CreateObject(nameof(PSqlClient));
        }
Beispiel #8
0
        private void Image_MouseDown_1(object sender, MouseButtonEventArgs e)
        {
            var directory = FilePath.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var player    = new SoundPlayer(FilePath.Combine(directory, "click.wav"));

            if (Option.isPlaying == false)
            {
                player.Play();
            }
            else
            {
                player.Stop();
            }
        }
        private void btnPickComponent_Click(object sender, RoutedEventArgs e)
        {
            string imgGalleryPath = PathIO.Combine(PathIO.GetDirectoryName(Assembly.GetAssembly(typeof(NewComponent)).Location), IMG_FOLDER, COMPONENT_FOLDER);
            var    picker         = new ComponentGalleryPicker();

            picker.ShowDialog();
            if (picker.DialogResult.Value)
            {
                this.CType            = picker.SelectedItem.CType;
                this.ImageIndex       = picker.SelectedItem.Index;
                this.miniature.Source = picker.SelectedItem.Index.LoadImage(imgGalleryPath, 32, true);
                this.UpdatePowerSelector();
            }
        }
Beispiel #10
0
        public void Persist()
        {
            _logger.Information($"Reflection settings folder: {_extraDataPathProvider.Path}");
            _logger.Information($"Reflection settings subpath: {SettingsSubPath}");
            var doc = new JObject();

            ObjVM.Persist(doc, _logger.Information);
            if (!_fileSystem.Directory.Exists(_extraDataPathProvider.Path))
            {
                _logger.Information($"Creating reflection settings directory");
                _fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(SettingsPath) !);
            }
            _logger.Information($"Writing reflection settings to: {SettingsPath}");
            _fileSystem.File.WriteAllText(SettingsPath, doc.ToString());
        }
        private void BrowseFolder()
        {
            var settings = new FolderBrowserDialogSettings
            {
                Description  = "Select folder with images",
                SelectedPath = IOPath.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
            };

            bool?success = dialogService.ShowFolderBrowserDialog(this, settings);

            if (success == true)
            {
                Path = settings.SelectedPath;
            }
        }
Beispiel #12
0
        public virtual void LoadDependencyTemplates()
        {
            if (templates != null)
            {
                return;
            }

            string fileName = Path.Combine("Tool", "Templates", "depend.stg");

            templates = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    fileName),
                Encoding.UTF8);
        }
Beispiel #13
0
        public void Test1()
        {
            const string fileName = "Resources/example.pptx";
            var          path     = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException(), fileName);

            using var doc = PresentationDocument.Open(path, false);
            var slide  = doc.PresentationPart.SlideParts.First();
            var reader = OpenXmlReader.Create(slide);

            reader.Read();
            var element = reader.LoadCurrentElement();
            var text    = element.Descendants <Text>().First();

            Assert.Equal(" ", text.Text);
        }
Beispiel #14
0
        /// <summary>
        /// Try to load the file.
        /// Possibly this might raise an exception. That exception is not caught here
        /// </summary>
        /// <param name="file">The file that needs to be loaded</param>
        public override void TryLoading(string file)
        {
            string subdirname = Path.GetFileName(Path.GetDirectoryName(file));

            if (subdirname.Equals("openrails", System.StringComparison.OrdinalIgnoreCase))
            {
                //todo Need good examples for this. Might not actually be found via SIMIS header
                //Also not clear if this needs a global tracksection or not
                _ = new TrackSectionsFile(file);
            }
            else
            {
                globalTsection.AddRouteTSectionDatFile(file);
            }
        }
Beispiel #15
0
        protected override TemplateGroup LoadTemplates()
        {
            // override the superclass behavior to put all C# templates in the same folder
            TemplateGroup result = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    Path.Combine(CodeGenerator.TEMPLATE_ROOT, "CSharp", GetLanguage() + TemplateGroup.GroupFileExtension)),
                Encoding.UTF8);

            result.RegisterRenderer(typeof(int), new NumberRenderer());
            result.RegisterRenderer(typeof(string), new StringRenderer());
            result.Listener = new ErrorListener(this);

            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// Try to load the file.
        /// Possibly this might raise an exception. That exception is not caught here
        /// </summary>
        /// <param name="file">The file that needs to be loaded</param>
        public override void TryLoading(string file)
        {
            var subdirname = Path.GetFileName(Path.GetDirectoryName(file)).ToLowerInvariant();

            if (subdirname == "openrails")
            {
                //todo Need good examples for this. Might not actually be found via SIMIS header
                //Also not clear if this needs a global tracksection or not
                var TSectionDat = new TrackSectionsFile(file);
            }
            else
            {
                _globalTsection.AddRouteTSectionDatFile(file);
            }
        }
 void loadGrupo_DoWork(object sender, DoWorkEventArgs e)
 {
     App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
     {
         Controller.SetController();
         List <Grupo> listGrupo = Controller.GetGrupos();
         foreach (var grupo in listGrupo)
         {
             custdata.Add(grupo);
         }
         textbox1.Text = Path.GetDirectoryName(Controller.pathToExcelFile) + @"\" + Path.GetFileNameWithoutExtension(Controller.pathToExcelFile) +
                         "-ErrorSalva-" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" +
                         DateTime.Now.Minute + Path.GetExtension(Controller.pathToExcelFile);
         ;
     });
 }
Beispiel #18
0
        /// <summary>
        /// Returns the directory information for the specified path string.
        /// </summary>
        /// <param name="path">The path of a file or directory.</param>
        /// <returns>
        /// A System.String containing directory information for path, or null if path
        /// denotes a root directory, is the empty string (""), or is null. Returns System.String.Empty
        /// if path does not contain directory information.
        /// </returns>
        public static string GetDirectoryName(string path)
        {
            string directoryName = SystemIoPath.GetDirectoryName(path);

            if (!string.IsNullOrWhiteSpace(directoryName))
            {
                if (directoryName[directoryName.Length - 1] == SystemIoPath.VolumeSeparatorChar)
                {
                    return(directoryName + SystemIoPath.DirectorySeparatorChar);
                }

                return(directoryName);
            }

            return(null);
        }
Beispiel #19
0
        private static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs e)
        {
            if (e.RequestingAssembly.FullName.StartsWith("Tvl."))
            {
                AssemblyName name         = new AssemblyName(e.Name);
                string       searchFolder = Path.GetDirectoryName(typeof(AgentExports).Assembly.Location);
                string       fileName     = name.Name + ".dll";
                string       path         = Path.Combine(searchFolder, fileName);
                if (File.Exists(path))
                {
                    return(Assembly.LoadFrom(path));
                }
            }

            return(null);
        }
Beispiel #20
0
        private void OpenFileDialg()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = FilePath.Text == string.Empty
                            ? "C:\\"
                            : Path.GetDirectoryName(FilePath.Text);
            openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == true)
            {
                FilePath.Text = openFileDialog.FileName;
            }
        }
 /**<summary>Checks if the path is valid.</summary>*/
 private bool ValidPathTest()
 {
     if (Patcher.ExePath == "")
     {
         TriggerMessageBox.Show(this, MessageIcon.Warning, "The Terraria path cannot be empty!", "Invalid Path");
         return(false);
     }
     try {
         Path.GetDirectoryName(Patcher.ExePath);
         return(true);
     }
     catch (ArgumentException) {
         TriggerMessageBox.Show(this, MessageIcon.Warning, "You must enter a valid Terraria path!", "Invalid Path");
         return(false);
     }
 }
Beispiel #22
0
        /// <summary> нахождение несуществующего имени файла </summary>
        private static string GeneratingFileName(string path)
        {
            var    i = 1;
            string newpath;

            //перебираем инкремент в названию файла пока не найдётся несуществующий
            do
            {
                newpath = Path.GetDirectoryName(path) + "\\" +
                          Path.GetFileNameWithoutExtension(path) + i +
                          ".mkv";
                i++;
            } while (File.Exists(newpath));

            return(newpath);
        }
Beispiel #23
0
        private void OpenFile()
        {
            var settings = new OpenFileDialogSettings
            {
                Title            = "This Is The Title",
                InitialDirectory = IOPath.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                Filter           = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
            };

            bool?success = dialogService.ShowOpenFileDialog(this, settings);

            if (success == true)
            {
                Path = settings.FileName;
            }
        }
        private string GetReferencePath(ITaskItem reference)
        {
            string path = reference.ItemSpec;

            if (File.Exists(reference.ItemSpec) && Path.GetExtension(reference.ItemSpec).Equals(".jar", StringComparison.OrdinalIgnoreCase))
            {
                return(path);
            }

            if (Directory.Exists(Path.GetDirectoryName(reference.ItemSpec)))
            {
                return(Path.GetDirectoryName(reference.ItemSpec));
            }

            return(null);
        }
Beispiel #25
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var openDlg = new OpenFileDialog();

            openDlg.Filter = "exe files (*.exe)|*.exe|All files (*.*)|*.*";

            if (openDlg.ShowDialog() == true)
            {
                zipFileName       = openDlg.FileName;
                edtFileName.Text  = openDlg.FileName;
                driverDirFullName = Path.Combine(Path.GetDirectoryName(openDlg.FileName),
                                                 Path.GetFileNameWithoutExtension(openDlg.FileName));
                edtLog.AppendText("Директория:\n");
                edtLog.AppendText(driverDirFullName + "\n");
                setupCfg = driverDirFullName + "\\" + setupCfg;
            }
        }
Beispiel #26
0
        static LrpLibrary()
        {
            var path = typeof(Native).Assembly.Location;

            path = IOPath.GetDirectoryName(path);
            path = IOPath.Combine(path, CppDllName);

#if DEBUG
            var value = Environment.GetEnvironmentVariable("FRE");
            if (null != value)
            {
                path = IOPath.Combine(value, CppDllName);
            }
#endif

            LrpLibrary.Path = path;
        }
Beispiel #27
0
        internal static List <string> GetModulePaths(string[] modulesFound, out List <ModuleInfo> modules)
        {
            List <string> modulePaths = new List <string>();

            List <ModuleInfo> findingModules = new List <ModuleInfo>();

            foreach (string moduleID in modulesFound)
            {
                try
                {
                    ModuleInfo moduleInfo = ModuleHelper.GetModules().FirstOrDefault(searchInfo => searchInfo.Id == moduleID);

                    if (moduleInfo != null && !moduleInfo.DependedModules.Exists(item => item.ModuleId == "zCaptivityEvents"))
                    {
                        continue;
                    }

                    try
                    {
                        if (moduleInfo == null)
                        {
                            continue;
                        }
                        CECustomHandler.ForceLogToFile("Added to ModuleLoader: " + moduleInfo.Name);
                        modulePaths.Insert(0, Path.GetDirectoryName(ModuleHelper.GetPath(moduleInfo.Id)));

                        findingModules.Add(moduleInfo);
                    }
                    catch (Exception)
                    {
                        if (moduleInfo != null)
                        {
                            CECustomHandler.ForceLogToFile("Failed to Load " + moduleInfo.Name + " Events");
                        }
                    }
                }
                catch (Exception)
                {
                    CECustomHandler.ForceLogToFile("Failed to fetch DependedModuleIds from " + moduleID);
                }
            }

            modules = findingModules;

            return(modulePaths);
        }
Beispiel #28
0
        public static void writeFile(string dir, string fileName, string content)
        {
            if (Path.IsPathRooted(fileName))
            {
                throw new ArgumentException();
            }

            string fullPath = Path.GetFullPath(Path.Combine(dir, fileName));

            dir = Path.GetDirectoryName(fullPath);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            File.WriteAllText(fullPath, content);
        }
Beispiel #29
0
        private void zvu_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var directory = FilePath.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var player1   = new SoundPlayer(FilePath.Combine(directory, "click.wav"));

            if (Media.sound == true)
            {
                player1.Play();
                Media.sound = false;
                zvu.Source  = new BitmapImage(new Uri(@"Images\zvukвыбрано.png", UriKind.Relative));
            }
            else
            {
                player1.Stop();
                Media.sound = true;
                zvu.Source  = new BitmapImage(new Uri(@"Images\zvuk.png", UriKind.Relative));
            }
        }
        private void OpenFile()
        {
            var settings = new OpenFileDialogSettings
            {
                Title            = "Select image",
                InitialDirectory = IOPath.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                Filter           = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                                   "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                   "Portable Network Graphic (*.png)|*.png"
            };

            bool?success = dialogService.ShowOpenFileDialog(this, settings);

            if (success == true)
            {
                Path = settings.FileName;
            }
        }