示例#1
0
        static internal IList <IPlugin3> GetPlugins(Context context, LPath mainProgramDirectory)
        {
            var pluginDirectories = new List <LPath>();

            try
            {
                pluginDirectories.AddRange(mainProgramDirectory.CatDir("plugin").GetDirectories().ToList());
            }
            catch
            {
            }

            try
            {
                var pluginDirectoriesDevelopment = mainProgramDirectory.Parent.Parent.GetDirectories()
                                                   .Where(_ => _.FileName.Contains("plugin") && !_.FileName.Contains("Test") && !_.FileName.Equals("hagen.plugin"))
                                                   .Select(_ => _.CatDir("bin"))
                                                   .Where(_ => _.IsDirectory);
                pluginDirectories.AddRange(pluginDirectoriesDevelopment);
            }
            catch
            {
            }

            log.Info(pluginDirectories.ListFormat());

            return(pluginDirectories.SelectMany(_ => LoadPluginDirectory(context, _, mainProgramDirectory))
                   .Where(_ => _ != null).ToList());
        }
示例#2
0
        public override System.Drawing.Icon GetIcon()
        {
            System.Drawing.Icon icon = null;

            if (String.IsNullOrEmpty(FileName))
            {
            }
            else
            {
                if (FileName.StartsWith("http://"))
                {
                    return(BrowserIcon);
                }
                else if (LPath.IsValid(FileName))
                {
                    var p = new LPath(FileName);
                    if (p.IsDirectory)
                    {
                        icon = IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Closed);
                    }
                    else if (p.IsFile)
                    {
                        icon = IconReader.GetFileIcon(p, IconReader.IconSize.Large, false);
                    }
                }
            }
            return(icon);
        }
示例#3
0
 internal static void Open(LPath textFile)
 {
     NotepadPlusPlus.Get().Match(
         _ => _.Open(textFile),
         () => Process.Start("notepad.exe", textFile)
         );
 }
示例#4
0
        static internal IEnumerable <IPlugin3> LoadPluginDirectory(Context context, LPath pluginDirectory, LPath mainProgramDirectory)
        {
            var pluginDlls = pluginDirectory.GetFiles("*plugin*.dll")
                             .Where(_ => !_.FileName.Equals("hagen.plugin.dll"));

            return(pluginDlls.SelectMany(_ => LoadPlugin(_, context, mainProgramDirectory)));
        }
示例#5
0
        static T ReadYamlConfig <T>(LPath yamlFile) where T : new()
        {
            if (yamlFile.IsFile)
            {
                var deserializer = new DeserializerBuilder()
                                   .WithNamingConvention(CamelCaseNamingConvention.Instance)
                                   .Build();

                using (var r = yamlFile.ReadText())
                {
                    return(deserializer.Deserialize <T>(r));
                }
            }
            else
            {
                yamlFile.EnsureParentDirectoryExists();
                var serializer = new SerializerBuilder()
                                 .WithNamingConvention(CamelCaseNamingConvention.Instance)
                                 .Build();

                using (var w = yamlFile.WriteText())
                {
                    var c = new T();
                    serializer.Serialize(w, c);
                    return(c);
                }
            }
        }
示例#6
0
        public Icon GetIcon(string FileName)
        {
            System.Drawing.Icon icon = Icons.Default;

            if (string.IsNullOrEmpty(FileName))
            {
            }
            else
            {
                if (FileName.StartsWith("http://"))
                {
                    return(Icons.Browser);
                }
                else if (LPath.IsValid(FileName))
                {
                    var p = new LPath(FileName);
                    if (p.IsDirectory)
                    {
                        icon = IconReader.GetFolderIcon(IconReader.IconSize.Large, IconReader.FolderType.Closed);
                    }
                    else if (p.IsFile)
                    {
                        var ext = p.Extension.ToLower();
                        return(GetOrAdd(byExtension, ext, () =>
                        {
                            icon = IconReader.GetFileIcon(p, IconReader.IconSize.Large, false);
                            return icon;
                        }));
                    }
                }
            }
            return(icon);
        }
示例#7
0
        public static void CreateFromTemplate(this ITextTransform transform, LPath source, LPath destination)
        {
            // Console.WriteLine("{0} -> {1}", source, destination);

            if (source.IsFile)
            {
                destination.EnsureParentDirectoryExists();
                if (IsBinaryFile(source))
                {
                    source.CopyFile(destination);
                }
                else
                {
                    using (var w = destination.WriteText())
                        using (var r = source.ReadText())
                        {
                            transform.Transform(r, w);
                        }
                }
            }
            else
            {
                foreach (var i in source.Info.GetChildren())
                {
                    transform.CreateFromTemplate(i.FullName, destination.CatDir(transform.Transform(i.Name)));
                }
            }
        }
示例#8
0
        protected override IEnumerable <IResult> GetResults(IQuery query)
        {
            if (!String.IsNullOrEmpty(query.Text) && LPath.IsValid(query.Text))
            {
                var path = new LPath(query.Text);

                if (path.IsFile)
                {
                    yield return(new SimpleAction(
                                     query.Context.LastExecutedStore,
                                     path.ToString(),
                                     String.Format("Show {0} in Explorer", path.ToString()),
                                     () =>
                    {
                        // show in explorer
                        Process.Start("explorer.exe", ("/select," + path.ToString()).Quote());
                    }).ToResult(Priority.High));
                }
                else if (path.IsDirectory)
                {
                    yield return(new SimpleAction(
                                     query.Context.LastExecutedStore,
                                     path.ToString(),
                                     String.Format("Show {0} in Explorer", path.ToString()),
                                     () =>
                    {
                        // show in explorer
                        Process.Start("explorer.exe", ("/root," + path.ToString()).Quote());
                    }).ToResult(Priority.High));
                }
            }
        }
示例#9
0
        LPath GetNonExistingPath(LPath p)
        {
            if (!p.Exists)
            {
                return(p);
            }

            var d  = p.Parent;
            var fp = p.FileNameParts;

            for (int i = 1; i < 1000; ++i)
            {
                LPath npe;
                if (fp.Length <= 1)
                {
                    npe = d.CatDir(fp.Concat(new[] { i.ToString() }).Join("."));
                }
                else
                {
                    npe = d.CatDir(fp.Take(fp.Length - 1).Concat(new[] { i.ToString() }).Concat(fp.Skip(fp.Length - 1)).Join("."));
                }
                if (!npe.Exists)
                {
                    return(npe);
                }
            }
            throw new System.IO.IOException("Cannot make a unique path for {0}".F(p));
        }
示例#10
0
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            // log.Info(args.Details());
            var name     = new AssemblyName(args.Name).Name;
            var fileName = name + ".dll";

            var path = hagenDirectory.CatDir(fileName);

            if (path.IsFile)
            {
                goto found;
            }

            if (args.RequestingAssembly != null)
            {
                path = new LPath(args.RequestingAssembly.Location).Sibling(fileName);
                if (path.IsFile)
                {
                    goto found;
                }
            }

            return(null);

found:
            log.Info(path);
            return(Assembly.LoadFile(path));
        }
示例#11
0
 string GuessCompany(string companyProperty)
 {
     if (String.IsNullOrEmpty(companyProperty))
     {
         return(LPath.GetValidFilename(Environment.UserName));
     }
     return(companyProperty);
 }
示例#12
0
 static IAction RunProgram(string name, LPath program, params object[] parameters)
 {
     return(new SimpleAction(
                name, () =>
     {
         Process.Start(program, parameters.Select(p => p.SafeToString().Quote()).Join(" "));
     }));
 }
示例#13
0
 string GuessProduct(string productProperty, LPath dest)
 {
     if (String.IsNullOrEmpty(productProperty))
     {
         return(dest.FileNameWithoutExtension);
     }
     return(productProperty);
 }
示例#14
0
 static bool IsBinaryFile(LPath f)
 {
     if (string.Equals(f.Extension, ".ico"))
     {
         return(true);
     }
     return(false);
 }
示例#15
0
文件: Plugins.cs 项目: sidiandi/hagen
        static bool IsPlugin(LPath x)
        {
            // return x.FileNameWithoutExtension.StartsWith("hagen.plugin.screen");

            return
                (assemblyFileExtension.Is(x) &&
                 x.FileNameWithoutExtension.StartsWith("hagen.plugin.", StringComparison.InvariantCultureIgnoreCase) &&
                 !x.FileNameWithoutExtension.EndsWith("Tests", StringComparison.InvariantCultureIgnoreCase));
        }
 public FileSystemWatcherNotesProvider(LPath notesDir)
 {
     this.notesDir = notesDir;
     this.ReadNotes();
     this.watcher = new FileSystemWatcher(notesDir);
     this.watcher.NotifyFilter        = NotifyFilters.Size | NotifyFilters.LastWrite;
     this.watcher.Changed            += Watcher_Changed;
     this.watcher.EnableRaisingEvents = true;
 }
示例#17
0
文件: Screen.cs 项目: sidiandi/hagen
 LPath GetDestinationFilename(DateTime time, string title)
 {
     return(context.DocumentDirectory.CatDir(
                "screen",
                time.ToString("yyyy"),
                time.ToString("yyyy-MM-dd"),
                LPath.GetValidFilename(time.ToString("yyyy-MM-ddTHH-mm-ss.ffffzzz") + "_" + title + ".png")
                ));
 }
示例#18
0
        public void SetAndGet()
        {
            var path = new LPath(@"C:\temp\test.exe");

            RunOnLogon.Set(path, true);
            Assert.IsTrue(RunOnLogon.Get(path));
            RunOnLogon.Set(path, false);
            Assert.IsFalse(RunOnLogon.Get(path));
        }
示例#19
0
        public static string FileNameWithContext(this LPath resolvedPath)
        {
            var parts = resolvedPath.Parts.Reverse();

            if (resolvedPath.IsUnc)
            {
                parts = parts.Concat(new[] { resolvedPath.Share, resolvedPath.Server });
            }
            return(parts.Take(4).Join(" < "));
        }
示例#20
0
 public LPath Capture(Rectangle bounds, LPath destination)
 {
     using (var bitmap = Capture(bounds))
     {
         destination.EnsureParentDirectoryExists();
         bitmap.Save(destination.ToString(), System.Drawing.Imaging.ImageFormat.Png);
         log.InfoFormat("Screenshot of {0} saved in {1}", bounds, destination);
         return(destination);
     }
 }
示例#21
0
        public void ShowReport()
        {
            var p = new LPath("work-time-report.txt");

            using (var output = new StreamWriter(p))
            {
                new activityReport.Program(this.logDatabase).WorktimeReport(output, TimeIntervalExtensions.LastDays(180));
            }
            Process.Start("notepad.exe", p.ToString().Quote());
        }
示例#22
0
 public static string ReadText(LPath file, string section)
 {
     if (String.IsNullOrEmpty(section))
     {
         return(System.IO.File.ReadAllText(file));
     }
     else
     {
         return(ReadSections(file)[section]);
     }
 }
示例#23
0
        void ShowReport(string name, Action <TextWriter, TimeInterval> report)
        {
            var p = hagen.DataDirectory.CatDir("Reports", LPath.GetValidFilename(name) + ".txt");

            p.EnsureParentDirectoryExists();
            using (var output = new StreamWriter(p))
            {
                report(output, TimeIntervalExtensions.LastDays(180));
            }
            Process.Start("notepad.exe", p.ToString().Quote());
        }
示例#24
0
        public static bool Get(LPath path)
        {
            var valueName = path.FileName;
            var value     = Registry.GetValue(runKey, valueName, String.Empty);

            if (value == null)
            {
                return(false);
            }
            var storedPath = new LPath((string)value);

            return(object.Equals(storedPath, path));
        }
示例#25
0
        static LPath CreateMeetingMinutesMarkdownFile(AppointmentItem selectedAppointment)
        {
            var chpRoot = new LPath(@"C:\src\chp");
            var mdFile  = chpRoot.CatDir(
                "doc", "meetings",
                $"{selectedAppointment.Start:yyyy-MM-dd} {Sidi.IO.LPath.GetValidFilename(selectedAppointment.Subject)}",
                "Readme.md");

            if (!mdFile.Exists)
            {
                mdFile.EnsureParentDirectoryExists();
                mdFile.WriteAllText(GetMarkdown(selectedAppointment));
            }
            return(mdFile);
        }
示例#26
0
        public static IEnumerable <Action> GetPathExecutables()
        {
            FileActionFactory f = new FileActionFactory();
            var exeExtensions   = new FileType("exe", "bat", "cmd", "msc", "cpl");

            var path = Regex.Split(System.Environment.GetEnvironmentVariable("PATH"), @"\;")
                       .SafeSelect(x => LPath.Parse(x)).ToList();

            log.InfoFormat("Searching {0}", path);

            return(path.SelectMany(p =>
            {
                return p.GetFiles().Where(x => exeExtensions.Is(x))
                .SafeSelect(x => f.FromFile(x));
            }));
        }
示例#27
0
        public void Merge(PathList pathList)
        {
            var   directories = pathList.Where(x => x.IsDirectory).ToList();
            LPath root        = directories.First().Parent;

            foreach (var d in directories)
            {
                var temp = GetNonExistingPath(d.Parent.CatDir(LPath.GetRandomFileName()));
                d.Move(temp);
                foreach (var c in temp.GetChildren())
                {
                    var dest = GetNonExistingPath(root.CatDir(c.FileName));
                    c.Move(dest);
                }
            }
        }
示例#28
0
        internal void LoadPlugin(LPath pluginAssemblyPath)
        {
            try
            {
                var plugin = PluginProvider2.LoadPlugin(pluginAssemblyPath, this.hagen.Context, Paths.BinDir);

                foreach (var i in plugin.SelectMany(_ => _.GetActionSources()))
                {
                    actionSource.Add(i);
                }
            }
            catch (Exception ex)
            {
                log.Error($"Failed to load {pluginAssemblyPath}.", ex);
            }
        }
示例#29
0
 public static IEnumerable <Note> Read(LPath markdownFile)
 {
     try
     {
         var source = new TextLocation(markdownFile, 1);
         var items  = Content.Parse(markdownFile.ReadAllText()).ToArray();
         var notes  = ExtractNotes(items)
                      .Select(note => { note.Source = source; return(note); })
                      .ToList();
         log.InfoFormat("Read {1} notes from {0}", markdownFile, notes.Count);
         return(notes);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("Error reading {0}", markdownFile), ex);
     }
 }
示例#30
0
        void Flatten(Operation op, LPath directory)
        {
            if (!directory.IsDirectory)
            {
                return;
            }

            var files = Find.AllFiles(directory)
                        .Select(x => x.FullName).ToList();

            foreach (var source in files)
            {
                var destination = GetNonExistingPath(directory.CatDir(source.FileName));
                source.Move(destination);
            }
            op.DeleteEmptyDirectories(directory);
        }
示例#31
0
 private void renderLine(LPath path)
 {
     if(path!=null)
     {
         for(int i =0; i<2;i++){
             if(path.N > 1)
             {
                 if(i==0) lineRenderer1.SetVertexCount(2);
                 lineRenderer1.SetPosition (i,new Vector3 (CELL_WIDH * path.PATH [i].C + MIN_X + CELL_WIDH/2, CELL_HEIGHT * path.PATH [i].R + MIN_Y + CELL_HEIGHT/2, 0));
             }
             if(path.N > 2)
             {
                 if(i==0) lineRenderer2.SetVertexCount(2);
                 lineRenderer2.SetPosition (i,new Vector3 (CELL_WIDH * path.PATH [i+1].C + MIN_X + CELL_WIDH/2, CELL_HEIGHT * path.PATH [i+1].R + MIN_Y + CELL_HEIGHT/2, 0));
             }
             if(path.N > 3)
             {
                 if(i==0) lineRenderer3.SetVertexCount(2);
                 lineRenderer3.SetPosition (i,new Vector3 (CELL_WIDH * path.PATH [i+2].C + MIN_X + CELL_WIDH/2, CELL_HEIGHT * path.PATH [i+2].R + MIN_Y + CELL_HEIGHT/2, 0));
             }
         }
         /*for(int i =0;i<path.N; i++){
             Vector3 vec3 = new Vector3 (CELL_WIDH * path.PATH [i].C + MIN_X + CELL_WIDH/2, CELL_HEIGHT * path.PATH [i].R + MIN_Y + CELL_HEIGHT/2, 0);
             lineRenderer.SetPosition (i, vec3);
         }*/
     }
 }