Esempio n. 1
0
        // Private Methods (2) 

        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var cfgFile = new FileInfo(@"./config.ini");

            if (cfgFile.Exists)
            {
                var config = new IniFileConfigRepository(cfgFile);

                var list = new SynchronizedObservableCollection <CompareTask>();
                list.AddRange(CompareTask.FromConfig(config)
                              .OrderBy(c => c.DisplayName, StringComparer.CurrentCultureIgnoreCase)
                              .ThenBy(c => c.Name, StringComparer.CurrentCultureIgnoreCase));

                this.ViewModel.Tasks = list;
            }
        }
Esempio n. 2
0
        private static int Main(string[] args)
        {
            var app = new App();

            app.CommandLineArgs = args;
            app.InitializeComponent();

            // config
            {
                var cfgFile = Path.Combine(Environment.CurrentDirectory, "config.ini");
                var cfg     = new IniFileConfigRepository(filePath: cfgFile,
                                                          isReadOnly: false);

                app.Config = cfg;
            }

            return(app.Run(new MainWindow()));
        }
Esempio n. 3
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var rootDir = new DirectoryInfo(this.Server.MapPath("~/bin"));

            var config = new IniFileConfigRepository(filePath: Path.Combine(rootDir.FullName, "config.ini"),
                                                     isReadOnly: false);

            // ServiceLocator
            {
                this.GlobalCompositionCatalog = new AggregateCatalog();

                // assemblies
                {
                    var asms = new HashSet <Assembly>();
                    asms.Add(typeof(global::MarcelJoachimKloubert.ServerAdmin.IServerAdminObject).Assembly);
                    asms.Add(this.GetType().Assembly);

                    foreach (var a in asms)
                    {
                        this.GlobalCompositionCatalog.Catalogs.Add(new AssemblyCatalog(a));
                    }
                }

                this.GlobalCompositionContainer = new CompositionContainer(this.GlobalCompositionCatalog, true);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.Configuration.IConfigRepository>(config.MakeReadOnly());
                this.GlobalCompositionContainer.ComposeExportedValue <global::System.Web.HttpApplication>(this);

                var innerLocator = new ExportProviderServiceLocator(this.GlobalCompositionContainer);

                this.GlobalServiceLocator = new DelegateServiceLocator(innerLocator);

                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.ServiceLocation.IServiceLocator>(this.GlobalServiceLocator);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.ServiceLocation.Impl.DelegateServiceLocator>(this.GlobalServiceLocator);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.ServiceLocation.Impl.ExportProviderServiceLocator>(innerLocator);

                ServiceLocator.SetLocator(this.GlobalServiceLocator);
            }
        }
Esempio n. 4
0
        private void ReloadTasks()
        {
            this.Button_ReloadConfig
            .InvokeSafe((btn) => btn.Enabled = false);

            Task.Factory.StartNew((state) =>
            {
                var frm = (MainForm)state;
                try
                {
                    var config = new IniFileConfigRepository(@"./config.ini");

                    frm.ListView_Tasks
                    .InvokeSafe((lv, lvState) =>
                    {
                        try
                        {
                            lv.Items.Clear();
                            while (lv.Items.Count > 0)
                            {
                                var t      = lv.Items[0].Tag as GitTask;
                                t.Error   -= lvState.Form.Task_Error;
                                t.Started -= lvState.Form.Task_Started;
                                t.Stopped -= lvState.Form.Task_Stopped;

                                lv.Items.RemoveAt(0);
                            }

                            lv.Groups.Clear();

                            foreach (var grpName in GitTask.FromConfig(lvState.Config)
                                     .Select(t => t.Group)
                                     .Distinct()
                                     .OrderBy(gn => gn, StringComparer.CurrentCultureIgnoreCase))
                            {
                                var lvg    = new ListViewGroup();
                                lvg.Header = string.IsNullOrWhiteSpace(grpName) ? "(no group)" : grpName;
                                lvg.Tag    = grpName;

                                lv.Groups.Add(lvg);
                            }

                            foreach (var task in GitTask.FromConfig(lvState.Config)
                                     .OrderBy(t => t.DisplayName, StringComparer.CurrentCultureIgnoreCase))
                            {
                                try
                                {
                                    var lvi  = new ListViewItem();
                                    lvi.Text = task.DisplayName ?? string.Empty;
                                    lvi.Text = task.DisplayName ?? string.Empty;
                                    lvi.Tag  = task;

                                    lvi.Group = CollectionHelper.SingleOrDefault(lv.Groups
                                                                                 .Cast <ListViewGroup>(),
                                                                                 lvg => object.Equals(lvg.Tag, task.Group));

                                    try
                                    {
                                        task.Error   += lvState.Form.Task_Error;
                                        task.Started += lvState.Form.Task_Started;
                                        task.Stopped += lvState.Form.Task_Stopped;

                                        lv.Items.Add(lvi);
                                        lvState.Form.UpdateIcon(lvi);
                                    }
                                    catch
                                    {
                                        task.Error   -= lvState.Form.Task_Error;
                                        task.Started -= lvState.Form.Task_Started;
                                        task.Stopped -= lvState.Form.Task_Stopped;

                                        throw;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    lvState.Form.ShowError(ex);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            lvState.Form.ShowError(ex);
                        }
                    }, actionState: new
                    {
                        Config = config,
                        Form   = frm,
                    });
                }
                catch (Exception ex)
                {
                    frm.ShowError(ex);
                }
                finally
                {
                    frm.Button_ReloadConfig
                    .InvokeSafe((btn) => btn.Enabled = true);
                }
            }, state: this);
        }
Esempio n. 5
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var rootDir = new DirectoryInfo(this.Server.MapPath("~/bin"));

            // app context
            var app = new CloudApp();
            {
                IConfigRepository config;
                var configIni = new FileInfo(Path.Combine(rootDir.FullName,
                                                          "config.ini"));
                if (configIni.Exists)
                {
                    config = new IniFileConfigRepository(configIni);
                }
                else
                {
                    config = new KeyValuePairConfigRepository();
                }

                app.Config = config.MakeReadOnly();
            }

            // principal repository
            var pricRepo = new PrincipalRepository();

            {
                pricRepo.LocalDataDirectory = rootDir.FullName;
                {
                    string temp;
                    if (app.Config.TryGetValue <string>("Data", out temp, "Directories") &&
                        string.IsNullOrWhiteSpace(temp) == false)
                    {
                        pricRepo.LocalDataDirectory = temp.Trim();
                    }
                }

                var iniFile = new FileInfo(Path.Combine(rootDir.FullName, "users.ini"));
                if (iniFile.Exists)
                {
                    pricRepo.UserRepository = new IniFileConfigRepository(iniFile);
                }

                pricRepo.Reload();
            }

            // URL routes
            {
                // files
                RouteTable.Routes.Add(new Route
                                      (
                                          "files",
                                          new FilesHttpHandler()
                                      ));

                // messages
                RouteTable.Routes.Add(new Route
                                      (
                                          "messages",
                                          new MessagesHttpHandler()
                                      ));
            }

            // ServiceLocator
            {
                this.GlobalCompositionCatalog = new AggregateCatalog();
                this.GlobalCompositionCatalog.Catalogs.Add(new AssemblyCatalog(typeof(global::MarcelJoachimKloubert.CloudNET.Classes.ICloudApp).Assembly));

                this.GlobalCompositionContainer = new CompositionContainer(this.GlobalCompositionCatalog, true);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CloudNET.Classes.ICloudApp>(app);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CloudNET.Classes.Security.IPrincipalRepository>(pricRepo);
                this.GlobalCompositionContainer.ComposeExportedValue <global::System.Web.HttpApplication>(this);

                var innerLocator = new ExportProviderServiceLocator(this.GlobalCompositionContainer);

                this.GlobalServiceLocator = new DelegateServiceLocator(innerLocator);

                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.ServiceLocation.IServiceLocator>(this.GlobalServiceLocator);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.ServiceLocation.Impl.DelegateServiceLocator>(this.GlobalServiceLocator);
                this.GlobalCompositionContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.ServiceLocation.Impl.ExportProviderServiceLocator>(innerLocator);

                ServiceLocator.SetLocator(this.GlobalServiceLocator);
            }

            this.Application[APP_VAR_APPCONTEXT] = app;
            this.Application[APP_VAR_PRINCIPALS] = pricRepo;
        }
Esempio n. 6
0
        private static int Main(string[] args)
        {
            try
            {
                var configFile = new FileInfo(Path.Combine(Environment.CurrentDirectory,
                                                           "config.ini"));

                var ini = new IniFileConfigRepository(configFile);

                foreach (var settings in DocumentationSettings.FromConfig(ini)
                         .Where(ds => ds.IsActive))
                {
                    try
                    {
                        var site = new Site(settings.WikiUrl,
                                            settings.Username, settings.Password.ToUnsecureString());

                        var doc = AssemblyDocumentation.FromFile(new FileInfo(settings.AssemblyFile));
                        doc.UpdateSettings(settings);

                        var asmPageName = doc.GetWikiPageName();

                        var asmPage = new Page(site, asmPageName);
                        asmPage.LoadWithMetadata();
                        asmPage.ResolveRedirect();

                        asmPage.text = doc.ToMediaWiki();
                        asmPage.Save();
                    }
                    catch (Exception ex)
                    {
                        GlobalConsole.Current
                        .InvokeForConsoleColor((c, state) => c.WriteLine(state.Exception),
                                               new
                        {
                            Exception = ex.GetBaseException() ?? ex,
                        }, foreColor: ConsoleColor.Red
                                               , bgColor: ConsoleColor.Black);
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                GlobalConsole.Current
                .InvokeForConsoleColor((c, state) => c.WriteLine(state.Exception),
                                       new
                {
                    Exception = ex.GetBaseException() ?? ex,
                }, foreColor: ConsoleColor.Yellow
                                       , bgColor: ConsoleColor.Red);

                return(1);
            }
            finally
            {
#if DEBUG
                global::MarcelJoachimKloubert.CLRToolbox.IO.GlobalConsole.Current.WriteLine();
                global::MarcelJoachimKloubert.CLRToolbox.IO.GlobalConsole.Current.WriteLine();
                global::MarcelJoachimKloubert.CLRToolbox.IO.GlobalConsole.Current.WriteLine("===== ENTER ====");
                global::MarcelJoachimKloubert.CLRToolbox.IO.GlobalConsole.Current.ReadLine();
#endif
            }
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            try
            {
                var config = new IniFileConfigRepository(@"./config.ini");

                foreach (var taskName in config.GetCategoryNames())
                {
                    bool isActive;
                    config.TryGetValue <bool>(category: taskName,
                                              name: "is_active",
                                              value: out isActive,
                                              defaultVal: true);

                    if (isActive == false)
                    {
                        continue;
                    }

                    string name;
                    config.TryGetValue <string>(category: taskName,
                                                name: "name",
                                                value: out name);

                    string username;
                    config.TryGetValue <string>(category: taskName,
                                                name: "username",
                                                value: out username);

                    string email;
                    config.TryGetValue <string>(category: taskName,
                                                name: "email",
                                                value: out email);

                    string pwd;
                    config.TryGetValue <string>(category: taskName,
                                                name: "password",
                                                value: out pwd);

                    bool useCredentials;
                    config.TryGetValue <bool>(category: taskName,
                                              name: "use_credentials",
                                              value: out useCredentials,
                                              defaultVal: false);

                    GlobalConsole.Current
                    .InvokeForConsoleColor((c, s) => c.WriteLine("[TASK] '{0}'...",
                                                                 s.TaskName.Trim()),
                                           new
                    {
                        TaskName = string.IsNullOrWhiteSpace(name) ? taskName : name,
                    }, foreColor: ConsoleColor.White);

                    try
                    {
                        string method;
                        config.TryGetValue <string>(category: taskName,
                                                    name: "method",
                                                    value: out method);

                        if (string.IsNullOrWhiteSpace(method))
                        {
                            method = _METHOD_PUSH;
                        }

                        method = method.ToUpper().Trim();
                        switch (method)
                        {
                        case _METHOD_PULL:
                        case _METHOD_PUSH:
                            break;

                        default:
                            // invalid
                            GlobalConsole.Current
                            .InvokeForConsoleColor((c, s) => c.WriteLine("  [UNKNOWN] Method '{0}'!",
                                                                         s.Method),
                                                   new
                            {
                                Method = method,
                            }, foreColor: ConsoleColor.Yellow);
                            continue;
                        }

                        var sourceDir = new DirectoryInfo(config.GetValue <string>(category: taskName,
                                                                                   name: "source"));

                        if (sourceDir.Exists == false)
                        {
                            GlobalConsole.Current
                            .InvokeForConsoleColor((c, s) => c.WriteLine("  [NOT FOUND] Repository at '{0}'!",
                                                                         s.SourceDirectory.FullName),
                                                   new
                            {
                                SourceDirectory = sourceDir,
                            }, foreColor: ConsoleColor.Yellow);

                            continue;
                        }

                        var repoOpts = new RepositoryOptions();
                        repoOpts.WorkingDirectoryPath = sourceDir.FullName;

                        GlobalConsole.Current
                        .InvokeForConsoleColor((c, s) => c.Write("  [OPEN] Repository at '{0}'... ",
                                                                 s.SourceDirectory.FullName),
                                               new
                        {
                            SourceDirectory = sourceDir,
                        });

                        using (var repo = new Repository(sourceDir.FullName, repoOpts))
                        {
                            GlobalConsole.Current
                            .InvokeForConsoleColor((c) => c.WriteLine("[OK]"),
                                                   foreColor: ConsoleColor.Green);

                            string remotes;
                            config.TryGetValue <string>(category: taskName,
                                                        name: "remotes",
                                                        value: out remotes);

                            var remoteList = new HashSet <string>();
                            remoteList.AddRange((remotes ?? string.Empty).Split('\n')
                                                .Select(x => x.ToUpper().Trim()));

                            foreach (var remoteName in remoteList)
                            {
                                try
                                {
                                    var filteredRepoRemotes = repo.Network.Remotes.Where(x => remoteList.Where(y => y != string.Empty).LongCount() < 1 ||
                                                                                         remoteName ==
                                                                                         (x.Name ?? string.Empty).ToUpper().Trim())
                                                              .ToArray();

                                    if (filteredRepoRemotes.Length > 0)
                                    {
                                        try
                                        {
                                            Action <Repository, IEnumerable <Remote>, bool, string, string, string> action = null;

                                            switch (method)
                                            {
                                            case _METHOD_PULL:
                                                action = Pull;
                                                break;

                                            case _METHOD_PUSH:
                                                action = Push;
                                                break;
                                            }

                                            if (action != null)
                                            {
                                                action(repo, filteredRepoRemotes,
                                                       useCredentials,
                                                       username, email, pwd);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            GlobalConsole.Current
                                            .InvokeForConsoleColor((c, s) => c.WriteLine(s.Exception),
                                                                   new
                                            {
                                                Exception = ex.GetBaseException() ?? ex,
                                            }, foreColor: ConsoleColor.Red);
                                        }
                                    }
                                    else
                                    {
                                        GlobalConsole.Current
                                        .InvokeForConsoleColor((c) => c.WriteLine("[NOT FOUND] Remote configuration!"),
                                                               foreColor: ConsoleColor.Yellow);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    GlobalConsole.Current
                                    .InvokeForConsoleColor((c, s) => c.WriteLine(s.Exception),
                                                           new
                                    {
                                        Exception = ex.GetBaseException() ?? ex,
                                    }, foreColor: ConsoleColor.Red);
                                }
                            }

                            GlobalConsole.Current
                            .InvokeForConsoleColor((c, s) => c.Write("  [CLOSE] Repository at '{0}'... ",
                                                                     s.SourceDirectory.FullName),
                                                   new
                            {
                                SourceDirectory = sourceDir,
                            });
                        }

                        GlobalConsole.Current
                        .InvokeForConsoleColor((c) => c.WriteLine("[OK]"),
                                               foreColor: ConsoleColor.Green);
                    }
                    catch (Exception ex)
                    {
                        GlobalConsole.Current
                        .InvokeForConsoleColor((c, s) => c.WriteLine(s.Exception),
                                               new
                        {
                            Exception = ex.GetBaseException() ?? ex,
                        }, foreColor: ConsoleColor.Red);
                    }
                    finally
                    {
                        GlobalConsole.Current.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalConsole.Current
                .InvokeForConsoleColor((c, s) => c.WriteLine(s.Exception),
                                       new
                {
                    Exception = ex.GetBaseException() ?? ex,
                }, foreColor: ConsoleColor.Yellow
                                       , bgColor: ConsoleColor.Red);
            }

            GlobalConsole.Current
            .WriteLine().WriteLine()
            .WriteLine("===== ENTER =====")
            .ReadLine();
        }