Esempio n. 1
0
        public static IAppBuilder UseChromeBookmarkSearch(this IAppBuilder app)
        {
            ICurrentEnvironment env = app.Services.GetService(typeof(ICurrentEnvironment)) as ICurrentEnvironment;

            ChromeBookmarkSearchComponent.Initialize(env);
            return(app.UseComponent <ChromeBookmarkSearchComponent>());
        }
Esempio n. 2
0
        public ListedRunnerPlugin(ICurrentEnvironment env, ILoggerFactory loggerFactory)
        {
            if (Instance != null)
            {
                throw new Exception($"cannot create another instance of {nameof(ListedRunnerPlugin)}");
            }

            UpdateConfigurations(env);
            loggerFactory.CreateLogger("Runner");
            Instance = this;
        }
Esempio n. 3
0
        public ListedRunnerPlugin(ICurrentEnvironment env, ILoggerFactory loggerFactory)
        {
            if (Instance != null)
            {
                throw new Exception($"cannot create another instance of {nameof(ListedRunnerPlugin)}");
            }

            actions      = new List <RunCommandAction>();
            logger       = loggerFactory.CreateLogger("Runner");
            updateAction = new UpdateRunnerAction();
            Instance     = this;
            UpdateConfigurations(env);
        }
        public static void Initialize(ICurrentEnvironment env)
        {
            Stream    defaultConfigStream = Assembly.GetExecutingAssembly().LoadStream("Chrome.BookmarkSearch.default.json");
            SetRecord defaultConfig       = Converter.ReadJson(defaultConfigStream) as SetRecord;

            string configPath = env.ConfigDirectory + "\\bookmarksearch.json";

            if (File.Exists(configPath))
            {
                try
                {
                    Stream    userConfigStream = File.OpenRead(configPath);
                    SetRecord userConfig       = Converter.ReadJson(userConfigStream) as SetRecord;
                    userConfigStream.Dispose();
                    defaultConfig.Combine(userConfig);
                }
                catch
                {
                }
            }
            else
            {
                try
                {
                    defaultConfigStream.Seek(0, SeekOrigin.Begin);
                    FileStream configStream = File.Create(configPath);
                    defaultConfigStream.CopyTo(configStream);
                    configStream.Flush();
                    configStream.Dispose();
                }
                catch
                {
                }
            }
            defaultConfigStream.Dispose();
            ConfigurationRecord = defaultConfig;
            Config = new SearchConfig()
            {
                SearchUrl    = ConfigurationRecord.ReadAs <bool>("allow_url_search"),
                EnableSearch = ConfigurationRecord.ReadAs <bool>("enable")
            };

            Bookmarks = BookmarkCollection.Retrive();
            SearchPatternErrorAction = new ErrorAction(null, "搜索模式错误", "搜索模式错误");
        }
Esempio n. 5
0
        public static void Initialize(ICurrentEnvironment env)
        {
            if (Initialized)
            {
                return;
            }

            string filePath = Path.Combine(env.LogDirectory.FullName, "logs.txt");

            LogFile = new FileInfo(filePath);
            if (!LogFile.Exists)
            {
                stream = File.Create(filePath);
                stream.Flush();
                stream.Dispose();
                LogFile = new FileInfo(filePath);
            }
            stream      = LogFile.Open(FileMode.Append, FileAccess.Write, FileShare.Read);
            writer      = new StreamWriter(stream);
            Initialized = true;
        }
Esempio n. 6
0
        public PluginProvider(ICurrentEnvironment env, IServiceProvider services)
        {
            DirectoryInfo pluginDirectory = env.PluginDirectory;

            LoadPlugins(pluginDirectory, services);
        }
 /// <summary>
 /// Server mapping repository.
 /// </summary>
 /// <param name="configManager">Configuration manager.</param>
 /// <param name="currentEnviroment">Current enviroment.</param>
 /// <param name="httpContext">Http context.</param>
 public DefaultServerMappingRepository(IConfigurationManager configManager, ICurrentEnvironment currentEnviroment, IHttpContextRepository httpContext)
 {
     this._configManager     = configManager;
     this._currentEnviroment = currentEnviroment;
     this._httpContext       = httpContext;
 }
 /// <summary>
 /// Default config service provider construction.
 /// </summary>
 /// <param name="serializer"></param>
 /// <param name="currentEnvironment"></param>
 public DefaultConfigServiceProvider(ISerializer serializer, ICurrentEnvironment currentEnvironment)
 {
     this._serializer         = serializer;
     this._currentEnvironment = currentEnvironment;
 }
Esempio n. 9
0
        internal void UpdateConfigurations(ICurrentEnvironment env)
        {
            actions.Clear();
            logger.LogMessageAsync("A");
            string filename   = "runner.json";
            string iconPath   = "icons";
            string configPath = Path.Combine(env.ConfigDirectory.FullName, "runner");

            if (!Directory.Exists(configPath))
            {
                Directory.CreateDirectory(configPath);
            }
            iconPath = Path.Combine(configPath, iconPath);
            filename = Path.Combine(configPath, filename);
            logger.LogMessageAsync("B");
            if (File.Exists(filename))
            {
                FileStream stream = File.Open(filename, FileMode.Open);
                ListRecord record = Hake.Extension.ValueRecord.Json.Converter.ReadJson(stream) as ListRecord;
                stream.Close();
                stream.Dispose();
                logger.LogMessageAsync("C");
                try
                {
                    List <CommandData> data = ObjectMapper.ToObject <List <CommandData> >(record);
                    foreach (CommandData cmd in data)
                    {
                        if (cmd.IconPath != null)
                        {
                            actions.Add(new RunCommandAction(cmd.Command, cmd.ExePath, Path.Combine(iconPath, cmd.IconPath), cmd.Admin, cmd.WorkingDirectory, cmd.Args));
                        }
                        else
                        {
                            actions.Add(new RunCommandAction(cmd.Command, cmd.ExePath, null, cmd.Admin, cmd.WorkingDirectory, cmd.Args));
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.LogExceptionAsync(ex);
                }
            }
            else
            {
                List <CommandData> data = new List <CommandData>();
                foreach (string command in PREDEFINED_COMMANDS)
                {
                    data.Add(new CommandData()
                    {
                        Command  = command,
                        ExePath  = null,
                        IconPath = null
                    });
                    actions.Add(new RunCommandAction(command, null, null, false, null, null));
                }
                FileStream   stream = File.Create(filename);
                ListRecord   record = GetCommandsRecord(data);
                string       json   = Hake.Extension.ValueRecord.Json.Converter.Json(record);
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(json);
                writer.Flush();
                writer.Close();
                writer.Dispose();
                stream.Close();
                stream.Dispose();
                logger.LogWarningAsync("runner.json not exists, write default configuration to new file");
            }
        }
Esempio n. 10
0
 public Logger(string category, ICurrentEnvironment env)
 {
     FileLogger.Initialize(env);
     Category = category;
 }
Esempio n. 11
0
        internal void UpdateConfigurations(ICurrentEnvironment env)
        {
            actions.Clear();

            string filename   = "runner.json";
            string iconPath   = "icons";
            string configPath = Path.Combine(env.ConfigDirectory.FullName, "runner");

            if (!Directory.Exists(configPath))
            {
                Directory.CreateDirectory(configPath);
            }
            iconPath = Path.Combine(configPath, iconPath);
            filename = Path.Combine(configPath, filename);
            if (File.Exists(filename))
            {
                FileStream   stream  = File.Open(filename, FileMode.Open);
                StreamReader reader  = new StreamReader(stream);
                string       content = reader.ReadToEnd();
                reader.Close();
                reader.Dispose();
                stream.Close();
                stream.Dispose();
                try
                {
                    List <CommandData> data = JsonConvert.DeserializeObject <List <CommandData> >(content);
                    foreach (CommandData cmd in data)
                    {
                        if (cmd.IconPath != null)
                        {
                            actions.Add(new RunCommandAction(cmd.Command, cmd.ExePath, Path.Combine(iconPath, cmd.IconPath), cmd.Admin, cmd.WorkingDirectory, cmd.Args));
                        }
                        else
                        {
                            actions.Add(new RunCommandAction(cmd.Command, cmd.ExePath, null, cmd.Admin, cmd.WorkingDirectory, cmd.Args));
                        }
                    }
                }
                catch
                {
                }
            }
            else
            {
                List <CommandData> data = new List <CommandData>();
                foreach (string command in PREDEFINED_COMMANDS)
                {
                    data.Add(new CommandData()
                    {
                        Command  = command,
                        ExePath  = null,
                        IconPath = null
                    });
                    actions.Add(new RunCommandAction(command, null, null, false, null, null));
                }
                FileStream   stream = File.Create(filename);
                string       json   = JsonConvert.SerializeObject(data, Formatting.Indented);
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(json);
                writer.Flush();
                writer.Close();
                writer.Dispose();
                stream.Close();
                stream.Dispose();
            }
        }
Esempio n. 12
0
 public void Invoke(ICurrentEnvironment env)
 {
     ListedRunnerPlugin.Instance?.UpdateConfigurations(env);
 }