コード例 #1
0
ファイル: Program.cs プロジェクト: hbons/git-bin
        static int Main(string[] args)
        {
            try
            {
                var builder = new Builder();
                ApplicationRegistrations.Register(builder);
                var container = builder.Create();

                var commandFactory = container.Resolve <ICommandFactory>();

                var command = commandFactory.GetCommand(args);
                command.Execute();
            }
            catch (ಠ_ಠ lod)
            {
                GitBinConsole.WriteLine(lod.Message);
                return(1);
            }
            catch (Exception e)
            {
                GitBinConsole.WriteLine("Uncaught exception, please report this bug! " + e);
                return(2);
            }

            return(0);
        }
コード例 #2
0
ファイル: GitBinDocument.cs プロジェクト: esprite/git-bin
        public static GitBinDocument FromYaml(TextReader textReader)
        {
            var yaml = textReader.ReadToEnd();

            GitBinDocument document;
            var            serializer = new YamlSerializer <GitBinDocument>();

            try
            {
                document = serializer.Deserialize(new StringReader(yaml));
            }
            catch (YamlDotNet.Core.SyntaxErrorException e)
            {
                GitBinConsole.WriteLine("Syntax error in YAML file: {0}\n\n File contents:{1}\n", e.Message, yaml);
                throw;
            }

            return(document);
        }
コード例 #3
0
ファイル: AsyncFileProcessor.cs プロジェクト: esprite/git-bin
        public static void ProcessFiles(string[] filesToDownload, Action <string[], int> fileProcessor)
        {
            object sync = new object();

            int totalFinished = 0;

            int nextIndexToDownload = 0;

            int       totalDownloading         = 0;
            int       maxSimultaneousDownloads = 10;
            Exception lastException            = null;
            int       nextToReport             = 10;

            lock (sync)
            {
                while (nextIndexToDownload < filesToDownload.Length)
                {
                    int indexToDownload = nextIndexToDownload;
                    totalDownloading++;

                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        Exception exception = null;
                        try
                        {
                            fileProcessor(filesToDownload, indexToDownload);
                        }
                        catch (Exception e)
                        {
                            exception = e;
                        }

                        lock (sync)
                        {
                            totalDownloading--;
                            totalFinished++;

                            var percentCompleted = (int)(100 * totalFinished / (float)filesToDownload.Length);

                            if (percentCompleted >= nextToReport)
                            {
                                GitBinConsole.WriteNoPrefix(percentCompleted.ToString());
                                if (percentCompleted < 100)
                                {
                                    GitBinConsole.WriteNoPrefix(".");
                                }
                                nextToReport = percentCompleted + 10;
                            }


                            if (lastException == null)
                            {
                                lastException = exception;
                            }

                            Monitor.Pulse(sync);
                        }
                    });

                    while (lastException == null && totalDownloading >= maxSimultaneousDownloads)
                    {
                        Monitor.Wait(sync);
                    }

                    if (lastException != null)
                    {
                        throw lastException;
                    }

                    nextIndexToDownload++;
                }

                while (lastException == null && totalFinished < filesToDownload.Length)
                {
                    Monitor.Wait(sync);
                }

                if (lastException != null)
                {
                    throw lastException;
                }
            }
        }