Exemple #1
0
    /// <summary>
    /// Registers the bundles.
    /// </summary>
    /// <param name="bundles">The bundles.</param>
    /// <param name="logger">The logger.</param>
    public static void RegisterBundles(BundleCollection bundles, ILogger logger)
    {
      logger.LogDebug("START: ModuleConfig.RegisterBundles");
      try
      {
        logger.Indent();
        logger.LogDebug("GetViewModules");
        var vModules = MEFConfig.Container.GetExports<IViewModule>();

        // process each module
        logger.LogDebug("Iterating ViewModules");
        logger.Indent();
        foreach (var module in vModules)
        {
          // get the non lazy module value
          var mod = module.Value; // as IViewModule;

          if (mod != null)
          {
            // add any bundles the module may need
            mod.RegisterBundles(bundles);
          }

          logger.LogDebug(mod.GetType().FullName);
        }
        logger.UnIndent();

      }
      finally
      {
        logger.UnIndent();
        logger.LogDebug("END: ModuleConfig.RegisterBundles");
      }
    }
        /// <inheritdoc />
        public void Build()
        {
            _logger.Debug("Loading symbols from extension scripts");

            using var _ = _logger.Indent();

            var entries = _options
                          .ExtensionScriptPaths
                          .Select(_fileSystemAdapter.ResolvePath)
                          .SelectMany(LoadEntriesFromSource)
                          .ToArray();

            var dictionary = new Dictionary <string, Func <string> >(entries.Length);

            foreach (var(key, value) in entries)
            {
                dictionary[key] = value;
            }

            var properties = dictionary.Select(kvp => (kvp.Key, $"(function)={kvp.Value()}"));

            _logger.LogProperties(LogEventLevel.Verbose, properties);

            Functions = dictionary;
        }
        public void Resolve()
        {
            m_log.DoubleRuleOff();
            m_log.WriteLine("Resolving merges...");

            using (m_log.Indent())
            {
                ResolveMerges();
            }
        }
        /// <summary>
        /// Create extra commits for files that have been marked as "head-only".
        /// </summary>
        public void CreateHeadOnlyCommits(IEnumerable <string> headOnlyBranches, BranchStreamCollection streams,
                                          FileCollection allFiles)
        {
            var branches     = SortBranches(headOnlyBranches, streams);
            var branchMerges = new Dictionary <string, string>();

            if (branches.Any())
            {
                m_log.DoubleRuleOff();
                m_log.WriteLine("Creating head-only commits");
            }

            using (m_log.Indent())
            {
                foreach (var branch in branches)
                {
                    // record where this branch will be merged to
                    if (streams[branch].Predecessor != null)
                    {
                        branchMerges[streams[branch].Predecessor.Branch] = branch;
                    }

                    string branchMergeFrom;
                    branchMerges.TryGetValue(branch, out branchMergeFrom);

                    CreateHeadOnlyCommit(branch, streams, allFiles, branchMergeFrom);
                }
            }
        }
        /// <summary>
        /// Transforms a template file
        /// </summary>
        private void TransformTemplateFile(string sourcePath, string targetPath)
        {
            using var _ = _logger.Indent(LogEventLevel.Debug, "Transforming content file {source}", sourcePath);
            var content = _fileSystemAdapter.ReadFile(sourcePath);

            _fileSystemAdapter.WriteFile(targetPath, _contentResolver.ReplaceSymbols(content));
        }
Exemple #6
0
        public bool Resolve(IEnumerable <string> branches, IEnumerable <Commit> commits)
        {
            var rule = m_branchpointRule;

            m_resolvedCommits = new Dictionary <string, Commit>();
            m_commits         = commits.ToListIfNeeded();

            m_log.DoubleRuleOff();
            m_log.WriteLine("Matching branches to branchpoints");
            using (m_log.Indent())
            {
                foreach (var branch in branches.Where(b => rule.IsMatch(b)))
                {
                    var tag = rule.Apply(branch);

                    var commit = ResolveBranchpoint(branch, tag);
                    if (commit != null)
                    {
                        m_resolvedCommits[branch] = commit;
                        m_log.WriteLine("Branch {0} -> Tag {1}", branch, tag);
                    }
                    else
                    {
                        m_log.WriteLine("Branch {0}: tag {1} is unresolved", branch, tag);
                    }
                }
            }

            var otherBranches = branches.Except(m_resolvedCommits.Keys).ToList();

            if (otherBranches.Any())
            {
                var result = m_fallback.Resolve(otherBranches, m_commits);

                foreach (var kvp in m_fallback.ResolvedTags)
                {
                    m_resolvedCommits[kvp.Key] = kvp.Value;
                }

                m_commits = m_fallback.Commits.ToListIfNeeded();
                return(result);
            }
            else
            {
                return(true);
            }
        }
Exemple #7
0
    /// <summary>
    /// Start the Application.
    /// </summary>
    protected void Application_Start()
    {
      System.Diagnostics.Trace.WriteLine("{0} :: Application Starting".FormatWith(DateTime.Now.ToString("HH:mm:ss.ff")));

      // MEF will load all the modules from the specified path.
      // Currently this is just the normal bin folder as having them
      // anywhere else can cause problems for the views
      System.Diagnostics.Trace.WriteLine("{0} ::  Initialising MEF".FormatWith(DateTime.Now.ToString("HH:mm:ss.ff")));
      MEFConfig.RegisterMEF(this, Server.MapPath(@"~\bin\"));

      _logger = MEFConfig.Container.GetExport<ILogger>().Value;
      _settings = MEFConfig.Container.GetExport<ISettings>().Value;

      // once mef is configured we can check the database
      CheckDatabase();

      _logger.Indent();
      try
      {
        _logger.LogDebug("Configuring View Engine");
        // Setup a custom view engine.
        // This knows how to deal with views in module folders.
        ViewEngines.Engines.Clear();

        // WARNING!!! Helpers assume that JonesieViewEngine is the first index in the ViewEngines array!!! Changing this
        // will break a lot of things.
        ViewEngines.Engines.Add(new JonesieViewEngine(MEFConfig.Container.GetExports<IViewModule>()));

        // Just the usual MVC startup fluff
        AreaRegistration.RegisterAllAreas();
        AuthConfig.RegisterAuth(_settings);
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

        // need to map the SignalR hub early
        RouteTable.Routes.MapHubs();

        // register routes for service and view modules and bundles for view modules
        ModuleConfig.RegisterRoutes(RouteTable.Routes, GlobalConfiguration.Configuration.Routes, _logger);
        ModuleConfig.RegisterBundles(BundleTable.Bundles, _logger);

        // now that everything else is done we can tell the modules to go ahead and get ready 
        ModuleConfig.InitialiseModules(_logger);

        // register the default routes and bundle after the modules
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        // we need to do this early so we can use IsInRole for security trimming the menus
        _logger.LogDebug("Initialising Web Security");
        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", false);
      }
      finally
      {
        _logger.UnIndent();
      }

      _logger.LogDebug("Application Started");
    }
Exemple #8
0
        public override bool Resolve(IEnumerable <string> tags, IEnumerable <Commit> commits)
        {
            m_log.DoubleRuleOff();
            m_log.WriteLine("Resolving tags");

            using (m_log.Indent())
            {
                return(base.Resolve(tags, commits));
            }
        }
 /// <summary>
 /// Begins an indented section.
 /// </summary>
 public static IDisposable Indent(this ILogger logger
                                  , LogEventLevel logEventLevel
                                  , string messageTemplate
                                  , params object[] propertyValue)
 {
     logger.Write(logEventLevel, messageTemplate, propertyValue);
     return(logger.IsEnabled(logEventLevel)
         ? logger.Indent()
         : NoContext.Instance);
 }
Exemple #10
0
        /// <inheritdoc />
        public object CreateInstance(Type type, IDictionary <Type, object> injectables)
        {
            using var _ = _logger.Indent(LogEventLevel.Verbose, "Creating type '{type}' instance", type);

            return(type
                   .GetConstructors()
                   .Select(ctor => BuildInstance(ctor, injectables))
                   .FirstOrDefault(instance => instance != null)
                   ?? throw Exceptions.IncompatibleConstructor());
        }
        public void Build()
        {
            _logger.Debug("Loading symbols passed in options");

            using var _ = _logger.Indent();

            foreach (var(key, value) in _properties)
            {
                _logger.Verbose("{key}={value}", key, value);
            }
        }
Exemple #12
0
    /// <summary>
    /// Registers the routes.
    /// </summary>
    /// <param name="viewRoutes">The view routes.</param>
    /// <param name="apiRoutes">The API routes.</param>
    /// <param name="logger">The logger.</param>
    public static void RegisterRoutes(RouteCollection viewRoutes, HttpRouteCollection apiRoutes, ILogger logger)
    {

      logger.LogDebug("START: ModuleConfig.RegisterRoutes");
      try
      {
        logger.Indent();

        logger.LogDebug("GetViewModules");
        var vModules = MEFConfig.Container.GetExports<IViewModule>();
        logger.LogDebug("GetServiceModules");
        var sModules = MEFConfig.Container.GetExports<IServiceModule>();

        logger.LogDebug("Iterating ViewModules");
        logger.Indent();
        foreach (var module in vModules)
        {
          var mod = module.Value;
          mod.RegisterRoutes(viewRoutes);

          logger.LogDebug(mod.GetType().FullName);
        }
        logger.UnIndent();

        logger.LogDebug("Iterating ServiceModules");
        logger.Indent();
        foreach (var module in sModules)
        {
          var mod = module.Value;
          mod.RegisterRoutes(apiRoutes);

          logger.LogDebug(mod.GetType().FullName);
        }
        logger.UnIndent();
      }
      finally
      {
        logger.UnIndent();
        logger.LogDebug("END: ModuleConfig.RegisterRoutes");
      }
    }
Exemple #13
0
        public async Task StartAsync(Func <Task> action, CancellationToken token)
        {
            lock (this)
            {
                if (IsRunning)
                {
                    throw new InvalidOperationException("Can't start the thread loop twice.");
                }

                IsRunning = true;
            }

            using (logger.Indent())
                await RunAsync(action, token);
        }
        private IList <MetadataReference> BuildReferences()
        {
            using var _ = _logger.Indent(LogEventLevel.Verbose, "Building core metadata references");

            var coreAssemblyPaths = CoreAssemblies
                                    .Concat(AncillaryAssemblies)
                                    .Select(path => _assemblyResolver.GetAssemblyPath(path));

            var userAssemblyPaths = _options
                                    .AssemblyReferences
                                    .Select(_assemblyResolver.GetAssemblyPath);

            var combinedPaths = coreAssemblyPaths.Concat(userAssemblyPaths);

            return(combinedPaths
                   .Select(CreateMetadataReference)
                   .ToList());
        }
Exemple #15
0
        /// <inheritdoc />
        public void Build()
        {
            _logger.Debug("Loading symbols from environment variables");

            using var _ = _logger.Indent();

            var variables = Environment
                            .GetEnvironmentVariables()
                            .Cast <DictionaryEntry>()
                            .Select(entry => ((string)entry.Key, (string)entry.Value))
                            .ToArray();

            _logger.LogProperties(LogEventLevel.Debug, variables);

            foreach (var(key, value) in variables)
            {
                _variableDictionary.Add(key, value);
            }
        }
Exemple #16
0
        async Task HandleNextMessageAsync()
        {
            var nextMessage = pendingMessages.Dequeue();

            using (logger.Indent())
            {
                foreach (var interceptor in windowMessageInterceptors)
                {
                    var messageName     = FormatMessage(nextMessage.Message);
                    var interceptorName = interceptor.GetType()
                                          .Name;

                    logger.Information(
                        $"Passing message {messageName} to interceptor {interceptorName}.");

                    interceptor.ReceiveMessageEvent(nextMessage);
                }
            }
        }
        /// <summary>
        /// Verify commits
        /// </summary>
        public static IEnumerable <Commit> Verify(this IEnumerable <Commit> commits, ILogger log)
        {
            bool anyFailed = false;

            foreach (var commit in commits)
            {
                bool passed = commit.Verify();
                yield return(commit);

                if (!passed)
                {
                    if (!anyFailed)
                    {
                        log.DoubleRuleOff();
                        log.WriteLine("Commit verification");
                        anyFailed = true;
                    }

                    using (log.Indent())
                    {
                        log.WriteLine("Verification failed: {0} {1}", commit.CommitId, commit.Time);
                        foreach (var revision in commit)
                        {
                            log.WriteLine("  {0} r{1}", revision.File, revision.Revision);
                        }

                        foreach (var error in commit.Errors)
                        {
                            log.WriteLine(error);
                        }

                        log.RuleOff();
                    }
                }
            }

            if (anyFailed)
            {
                throw new RepositoryConsistencyException("One or more commits failed verification");
            }
        }
        /// <summary>
        /// Resolve tags and try and fix those that don't immediately resolve.
        /// </summary>
        /// <returns>true if all tags were resolved (potentially after being fixed), or false
        /// if fixing tags failed</returns>
        public virtual bool Resolve(IEnumerable <string> tags, IEnumerable <Commit> commits)
        {
            m_allCommits = commits.ToListIfNeeded();
            SetCommitIndices(m_allCommits);

            m_unresolvedTags.Clear();
            this.ResolvedTags = new Dictionary <string, Commit>();

            foreach (var tag in tags)
            {
                m_log.WriteLine("Resolve {0}", tag);

                using (m_log.Indent())
                {
                    Commit commit = null;
                    try
                    {
                        commit = ResolveTag(tag);
                    }
                    catch (TagResolutionException tre)
                    {
                        m_log.WriteLine("{0}", tre.Message);
                    }

                    if (commit == null)
                    {
                        m_unresolvedTags.Add(tag);
                        m_log.WriteLine("Unresolved");
                    }
                    else
                    {
                        ResolvedTags[tag] = commit;
                        m_log.WriteLine("Resolved: {0}", commit.ConciseFormat);
                    }
                }
            }

            CheckCommitIndices(m_allCommits);
            return(m_unresolvedTags.Count == 0);
        }
        public void Apply(IList <Commit> commitStream)
        {
            int destLocation = commitStream.IndexOf(m_finalCommit);
            int searchStart  = destLocation;
            var commits      = m_files.Keys.OrderBy(c => c.Index).ToList();

            Dump();
            m_log.WriteLine("Applying:");

            using (m_log.Indent())
            {
                // handle in reverse order
                for (int i = commits.Count - 1; i >= 0; i--)
                {
                    var commitToMove = commits[i];
                    int location     = commitStream.IndexOfFromEnd(commitToMove, searchStart);
                    if (location < 0)
                    {
                        // assume already moved
                        m_log.WriteLine("Skip moving {0} after {1}", commitToMove.ConciseFormat, m_finalCommit.ConciseFormat);
                        continue;
                    }

                    // does the commit need splitting?
                    var files = m_files[commitToMove];
                    if (files.Count() < commitToMove.Count())
                    {
                        m_log.WriteLine("Split {0}", commitToMove.CommitId);

                        using (m_log.Indent())
                        {
                            int    index = commitToMove.Index;
                            Commit splitCommitNeedMove;
                            Commit splitCommitNoMove;
                            SplitCommit(commitToMove, files, out splitCommitNeedMove, out splitCommitNoMove);

                            commitStream[location] = splitCommitNoMove;
                            commitStream.Insert(location + 1, splitCommitNeedMove);
                            destLocation++;

                            if (m_finalCommit == commitToMove)
                            {
                                m_finalCommit = splitCommitNeedMove;
                            }
                            commitToMove = splitCommitNeedMove;

                            // update Commit indices
                            for (int j = location; j < commitStream.Count; j++)
                            {
                                commitStream[j].Index = index++;
                            }

                            location++;
                        }
                    }

                    m_log.WriteLine("Move {0}({1}) after {2}({3})", commitToMove.ConciseFormat, location,
                                    m_finalCommit.ConciseFormat, destLocation);
                    commitStream.Move(location, destLocation);
                    destLocation--;
                }
            }
        }
Exemple #20
0
        XmlQualifiedName ParseElement(XmlSchemaElement element, bool isTopLevel = false)
        {
            log.WriteLine("Found element {0}", GetParticleDesc(element));

            if (element.RefName != null && !element.RefName.IsEmpty)
            {
                return(element.RefName);
            }

            TempXmlElement tempXmlElement;

            if (elements.TryGetValue(element, out tempXmlElement))
            {
                // TODO detect real equals or conflict, if conflict merge
                return(element.QualifiedName);
            }

            tempXmlElement                           = new TempXmlElement();
            tempXmlElement.element                   = new SimpleXmlElement();
            tempXmlElement.element.Name              = element.QualifiedName.Name;
            tempXmlElement.element.Namespace         = element.QualifiedName.Namespace;
            tempXmlElement.element.IsTopLevelElement = isTopLevel;

            elements.Add(element, tempXmlElement);

            List <SimpleXmlAttribute> attributes = new List <SimpleXmlAttribute>();

            // if the element is a simple type, it cannot have attributes of children, thus ignore it
            // if the element is a complex type, we'll parse it.
            if (element.ElementSchemaType is XmlSchemaComplexType)
            {
                XmlSchemaComplexType type = (XmlSchemaComplexType)element.ElementSchemaType;
                using (log.Indent())
                {
                    log.WriteLine("Attributes");
                    using (log.Indent())
                    {
                        foreach (XmlSchemaAttribute attribute in type.AttributeUses.Values)
                        {
                            attributes.Add(ParseAttribute(attribute));
                            log.WriteLine("{0}", attribute.QualifiedName.Name);
                        }
                    }

                    XmlSchemaParticle particle = type.ContentTypeParticle;
                    if (particle != null)
                    {
                        log.WriteLine("Child Particle {0}", GetParticleDesc(particle));
                        using (log.Indent())
                        {
                            if (particle is XmlSchemaGroupRef)
                            {
                                tempXmlElement.children = ParseGoupRef((XmlSchemaGroupRef)particle);
                            }
                            else if (particle is XmlSchemaGroupBase)
                            {
                                tempXmlElement.children = ParseGroupBase((XmlSchemaGroupBase)particle);
                            }
                            else if (particle.GetType().Name == "EmptyParticle")
                            {
                            }
                            else
                            {
                                throw new NotImplementedException(particle.GetType().Name);
                            }
                        }
                    }
                }
            }

            tempXmlElement.element.Attributes = attributes;

            // TODO merge attrs and children on conflicts

            return(element.QualifiedName);
        }
Exemple #21
0
        public void Import()
        {
            m_stream = OpenOutput();

            try
            {
                bool printProgress = !Console.IsOutputRedirected;
                int  totalCommits  = m_player.Count;
                var  progress      = new ImportProgress(totalCommits);

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                using (m_log.Indent())
                {
                    int    count          = 0;
                    Commit lastMainCommit = null;
                    foreach (var commit in m_player.Play())
                    {
                        ImportCommit(commit);

                        if (commit.Branch == "MAIN")
                        {
                            lastMainCommit = commit;
                        }

                        count++;
                        if (printProgress)
                        {
                            progress.Update(stopWatch.Elapsed, count);
                        }
                    }

                    if (printProgress)
                    {
                        Console.Out.WriteLine();
                    }

                    ImportTags();

                    if (lastMainCommit != null && m_config.MarkerTag != null)
                    {
                        ImportTag(m_config.MarkerTag, lastMainCommit);
                    }
                }

                m_log.WriteLine();
                m_log.WriteLine("Imported {0} commits", totalCommits);
                m_log.WriteLine("Imported {0} tags", m_tags.Count);
                m_log.WriteLine();
            }
            catch (IOException ioe)
            {
                // if the error is broken pipe, then catch the exception - we should get an error in
                // GitRepo.EndImport in the finally block below
                if ((ioe.HResult & 0xffff) == (int)WinError.BrokenPipe)
                {
                    m_brokenPipe = true;
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                CloseOutput();
            }
        }
Exemple #22
0
    /// <summary>
    /// Initialises the modules internals.
    /// </summary>
    /// <param name="logger">The logger.</param>
    public static void InitialiseModules(ILogger logger)
    {
      logger.LogDebug("START: ModuleConfig.InitialiseModules");
      try
      {
        logger.Indent();
        logger.LogDebug("GetModules");

        var modules = MEFConfig.Container.GetExports<IServiceModule>().Select(m => (IModule)(m.Value))
                    .Union(
                        MEFConfig.Container.GetExports<IViewModule>().Select(m => (IModule)(m.Value))
                    );

        // process each module
        logger.LogDebug("Iterating Modules");
        logger.Indent();
        foreach (var module in modules)
        {
          // get the non lazy module value
          if (module != null)
          {
            module.InternalInit();
          }

          logger.LogDebug(module.GetType().FullName);
        }
        logger.UnIndent();
      }
      finally
      {
        logger.UnIndent();
        logger.LogDebug("END: ModuleConfig.InitialiseModules");
      }
    }