Exemplo n.º 1
0
        public Notifier()
        {
            var providerResolver = new ProviderResolver(Services.Providers);

            _targetManager = new TargetManager(Services.Targets);
            _builder       = new Notification.Builder(providerResolver);
        }
        public DocumentMappingResult <TElement> MapToType <TElement>(Func <Dictionary <string, string> > getFieldsMethod, SelectMethod selectMethod)
        {
            // if the result type is not IStandardTemplateItem, use the default functionality
            if (!IsSynthesisType <TElement>())
            {
                return(new DocumentMappingResult <TElement>(default(TElement), false));
            }

            // initializers can't really support sub-selects of objects. Error if that's what's being used.
            if (selectMethod != null)
            {
                throw new NotSupportedException("Using Select on a Synthesis object type is supported. Convert the query to a list or array before selecting, then select using LINQ to objects.");
            }

            var evaluatedFields = getFieldsMethod();

            ShortID templateId;

            if (!evaluatedFields.ContainsKey("_template") || !ShortID.TryParse(evaluatedFields["_template"], out templateId))
            {
                templateId = ID.Null.ToShortID();
            }

            var initializer = _overrideInitializer ?? ProviderResolver.FindGlobalInitializer(templateId.ToID());

            var result = initializer.CreateInstanceFromSearch(evaluatedFields);

            if (result is TElement)
            {
                return(new DocumentMappingResult <TElement>((TElement)result, true));
            }

            return(new DocumentMappingResult <TElement>(default(TElement), true));           // note that this is still 'success', because we mapped onto a Synthesis type so we do not want to use default mapping
        }
Exemplo n.º 3
0
        public void SendNoticeAsync(INotifyAction action, string objectID, SendNoticeCallback sendCallback, params ITagValue[] args)
        {
            var subscriptionSource = ProviderResolver.GetEnsure <ISubscriptionSource>(notifySource);
            var recipients         = subscriptionSource.GetRecipients(action, objectID);

            SendNoticeToAsync(action, objectID, recipients, null, sendCallback, false, args);
        }
Exemplo n.º 4
0
        private static string CreateSyncSummary()
        {
            var sb = new StringBuilder();

            // force getting the latest templates from sitecore
            ProviderResolver.Current.TemplateInputProvider.Refresh();

            var sync = ProviderResolver.CreateSyncEngine();

            var result = sync.AreTemplatesSynchronized();
            var count  = result.Count(x => !x.IsSynchronized);

            if (result.AreTemplatesSynchronized)
            {
                sb.Append("<p>Templates and model are currently synchronized.</p>");
            }
            else
            {
                sb.AppendFormat("<p>{0} template{1} not synchronized. ", count, count == 1 ? " is" : "s are");
                sb.Append("<a href=\"?synthesis-syncstatus=1\">Details</a>");
                if (DebugUtility.IsDynamicDebugEnabled)
                {
                    sb.Append(" | <a href=\"?synthesis-regenerate=1\">Regenerate Now</a>");
                }
                sb.Append("</p>");
            }

            return(sb.ToString());
        }
        private void DoRegenerateSync()
        {
            foreach (var configuration in ProviderResolver.GetConfigurations())
            {
                var syncResult = GetSyncResult(configuration);

                if (syncResult.AreTemplatesSynchronized)
                {
                    return;
                }

                if (!syncResult.AreTemplatesSynchronized)
                {
                    foreach (var template in syncResult)
                    {
                        if (!template.IsSynchronized)
                        {
                            Log.Warn("Synthesis template desynchronization ({0}): {1}".FormatWith(configuration.Name, template), this);
                        }
                    }
                }

                string projectPathValue = StartupRegenerateProjectPath;

                if (StartupRegenerateProjectPath == "auto" || string.IsNullOrWhiteSpace(StartupRegenerateProjectPath))
                {
                    projectPathValue = ResolveAutoProjectPath(configuration.GeneratorParametersProvider.CreateParameters(configuration.Name));

                    if (projectPathValue == null)
                    {
                        throw new InvalidOperationException("Unable to automatically find a valid project file to build. I looked at sibling and parent folders to the concrete file output path for *proj.");
                    }
                }
                else
                {
                    projectPathValue = ConfigurationUtility.ResolveConfigurationPath(projectPathValue);
                }

                if (!File.Exists(projectPathValue))
                {
                    throw new InvalidOperationException("The auto-rebuild project file \"" + projectPathValue + "\" did not exist.");
                }

                var metadata = configuration.CreateMetadataGenerator().GenerateMetadata();

                configuration.CreateCodeGenerator().Generate(metadata);

                var outputLogPath = Path.GetDirectoryName(projectPathValue) + Path.DirectorySeparatorChar + "synthesis-autobuild.log";

                if (!BuildUtility.BuildProject(projectPathValue, "Release", outputLogPath))
                {
                    Log.Error("Synthesis automatic project build on " + projectPathValue + " failed! Review the build log at " + outputLogPath + " to find out what happened.", this);
                }

                Log.Info("Synthesis detected templates were not synchronized for {0} and attempted to automatically rebuild {1} to correct the problem.".FormatWith(configuration.Name, projectPathValue), this);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Regenerates code for all registered Synthesis configurations
        /// </summary>
        public static void RegenerateAll()
        {
            var configurations = ProviderResolver.GetConfigurations();

            ExecMetadataWithAutoFriending(configurations, (configuration, metadata) =>
            {
                configuration.CreateCodeGenerator().Generate(metadata);
            });
        }
Exemplo n.º 7
0
        private static void DoOnDemandSyncReport(HttpContext context)
        {
            var timer = new Stopwatch();

            timer.Start();

            // force getting the latest templates from sitecore
            ProviderResolver.Current.TemplateInputProvider.Refresh();

            var sync = ProviderResolver.CreateSyncEngine();

            var result = sync.AreTemplatesSynchronized();
            var sco    = result.Where(x => x.Locations == SyncSource.Sitecore).ToList();
            var mo     = result.Where(x => x.Locations == SyncSource.Model).ToList();
            var ma     = result.Where(x => x.Locations == SyncSource.Both).ToList();
            var nonsyn = result.Where(x => !x.IsSynchronized).ToList();

            timer.Stop();

            var results = new StringBuilder();

            results.AppendLine("<ul>");

            results.AppendLine("<li>Synchronized: <strong>" + result.AreTemplatesSynchronized.ToString() + "</strong></li>");
            results.AppendLine("<li>Total Items: <strong>" + result.Count + "</strong></li>");
            results.AppendLine("<li>Total Not Synchronized: <strong>" + nonsyn.Count + "</strong></li>");
            results.AppendLine("<li>Total Sitecore Only: <strong>" + sco.Count + "</strong></li>");
            results.AppendLine("<li>Total Model Only: <strong>" + mo.Count + "</strong></li>");
            results.AppendLine("<li>Total in Both: <strong>" + ma.Count + "</strong></li>");
            results.AppendLine("<li>Sync time taken: <strong>" + timer.ElapsedMilliseconds + " ms</strong></li>");

            results.AppendLine("</ul>");

            results.AppendLine("<table cellpadding=\"3\" cellspacing=\"1\">");
            results.AppendLine("<thead><tr>");
            results.AppendLine("<th>Template</th><th class=\"flag\">Sitecore</th><th class=\"flag\">Model</th><th class=\"flag\">Sync</th>");
            results.AppendLine("</tr></thead>");

            results.AppendLine("<tbody>");
            foreach (var item in result.OrderBy(x => x.SitecoreTemplateName ?? x.ModelTypeName))
            {
                results.AppendLine("<tr>");

                results.AppendFormat("<td>{0}</td>", item.SitecoreTemplateName ?? item.ModelTypeName);
                results.AppendFormat("<td style=\"background-color: {0}\">&nbsp;</td>", (item.Locations == SyncSource.Sitecore || item.Locations == SyncSource.Both) ? "green" : "red");
                results.AppendFormat("<td style=\"background-color: {0}\">&nbsp;</td>", (item.Locations == SyncSource.Model || item.Locations == SyncSource.Both) ? "green" : "red");
                results.AppendFormat("<td style=\"background-color: {0}\">&nbsp;</td>", (item.IsSynchronized) ? "green" : "red");

                results.AppendLine("</tr>");
            }
            results.AppendLine("</tbody></table>");

            context.Response.Write(WrapReport("Synthesis Template Status", results.ToString()));

            context.Response.End();
        }
Exemplo n.º 8
0
        public virtual void Process(PipelineArgs args)
        {
            var types          = GetTypesInRegisteredAssemblies();
            var configurations = GetConfigurationsFromTypes(types);

            foreach (var configRegistration in configurations)
            {
                ProviderResolver.RegisterConfiguration(configRegistration.GetConfiguration());
            }
        }
Exemplo n.º 9
0
        private void DoRegenerateSync(XmlNode config)
        {
            var syncResult = GetSyncResult();

            if (syncResult.AreTemplatesSynchronized)
            {
                return;
            }

            if (!syncResult.AreTemplatesSynchronized)
            {
                foreach (var template in syncResult)
                {
                    if (!template.IsSynchronized)
                    {
                        Log.Warn("Synthesis template desynchronization: " + template, this);
                    }
                }
            }

            var projectPathNode = config.SelectSingleNode("setting[@name='StartupRegenerateProjectPath']");

            if (projectPathNode == null || projectPathNode.Attributes["value"] == null)
            {
                throw new InvalidOperationException("The StartupRegenerateProjectPath setting must be specified when Synthesis Sync StartupCheckMode is set to Regenerate");
            }

            var projectPathValue = projectPathNode.Attributes["value"].InnerText;

            if (projectPathValue == "auto")
            {
                projectPathValue = ResolveAutoProjectPath();

                if (projectPathValue == null)
                {
                    throw new InvalidOperationException("Unable to automatically find a valid project file to build. I looked at sibling and parent folders to the concrete file output path for *proj.");
                }
            }

            if (!File.Exists(projectPathValue))
            {
                throw new InvalidOperationException("The auto-rebuild project file \"" + projectPathValue + "\" did not exist.");
            }

            ProviderResolver.CreateGenerator().GenerateToDisk();

            var outputLogPath = Path.GetDirectoryName(projectPathValue) + Path.DirectorySeparatorChar + "synthesis-autobuild.log";

            if (!BuildUtility.BuildProject(projectPathValue, "Release", outputLogPath))
            {
                Log.Error("Synthesis automatic project build on " + projectPathValue + " failed! Review the build log at " + outputLogPath + " to find out what happened.", this);
            }

            Log.Info("Synthesis detected templates were not synchronized and attempted to automatically rebuild " + projectPathValue + " to correct the problem.", this);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Converts an Item into a strongly typed item
        /// </summary>
        /// <returns>The converted item, or null if the conversion failed</returns>
        /// <remarks>If a conversion exception occurs, it can be found in the Sitecore log</remarks>
        public static IStandardTemplateItem AsStronglyTyped(this Item item)
        {
            if (item == null)
            {
                return(null);
            }

            ITemplateInitializer initializer = ProviderResolver.FindGlobalInitializer(item.TemplateID);

            return(initializer.CreateInstance(item));
        }
        private static string CreateSyncSummary()
        {
            var sb = new StringBuilder();

            var configurations = ProviderResolver.GetConfigurations();

            if (configurations.Any())
            {
                foreach (var configuration in configurations)
                {
                    var configName = configuration.Name.IsNullOrEmpty() ? "Unnamed Configuration" : configuration.Name;

                    // force getting the latest templates from sitecore
                    configuration.TemplateInputProvider.Refresh();

                    var sync = configuration.CreateSyncEngine();

                    var result = sync.AreTemplatesSynchronized();
                    var count  = result.Count(x => !x.IsSynchronized);

                    if (result.AreTemplatesSynchronized)
                    {
                        sb.AppendFormat("<p><strong>{0}</strong>: Templates and model are currently synchronized.</p>", configName);
                    }
                    else
                    {
                        sb.AppendFormat("<p><strong>{0}</strong>: {1} template{2} not synchronized. ", configName, count,
                                        count == 1 ? " is" : "s are");
                        sb.Append("<a href=\"?synthesis-syncstatus=1\">Details</a>");
                    }
                }

                sb.Append("<p>Note: if Synthesis configuration file changes are made you should force a regenerate</p>");

                if (DebugUtility.IsDynamicDebugEnabled)
                {
                    sb.Append("<p><a href=\"?synthesis-regenerate=1\">Regenerate Now</a></p>");
                }
                else
                {
                    sb.Append("<p>(enable debug compilation if you want to regenerate)</p>");
                }
            }
            else
            {
                sb.Append(@"<p><em>Synthesis currently has no model configurations registered.</em></p> 
<p>This probably means you need to enable the <code>RegisterDefaultConfiguration</code> processor in the <code>initialize</code> pipeline, 
or that you need to register your own configurations in separate initialize pipeline processors.</p>
<p>Synthesis cannot run any generation or syncing until a configuration is registered</p>.");
            }

            return(sb.ToString());
        }
Exemplo n.º 12
0
        private TemplateComparisonResultCollection GetSyncResult()
        {
            var sw = new Stopwatch();

            sw.Start();
            TemplateComparisonResultCollection syncResult = ProviderResolver.CreateSyncEngine().AreTemplatesSynchronized();

            sw.Stop();

            Log.Info("Synthesis Template synchronization check completed in " + sw.ElapsedMilliseconds + " ms", this);

            return(syncResult);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the template sync status for all registered Synthesis configurations
        /// </summary>
        public static IEnumerable <KeyValuePair <IProviderConfiguration, TemplateComparisonResultCollection> > CheckSyncAll()
        {
            var configurations = ProviderResolver.GetConfigurations();

            var results = new List <KeyValuePair <IProviderConfiguration, TemplateComparisonResultCollection> >(configurations.Count);

            ExecMetadataWithAutoFriending(configurations, (configuration, metadata) =>
            {
                results.Add(new KeyValuePair <IProviderConfiguration, TemplateComparisonResultCollection>(configuration, configuration.CreateSyncEngine(metadata).AreTemplatesSynchronized()));
            });

            return(results);
        }
Exemplo n.º 14
0
        public virtual void Process(PipelineArgs args)
        {
            /*while(!Debugger.IsAttached)
             * {
             *  System.Threading.Thread.Sleep(1000);
             * }*/
            var types          = GetTypesInRegisteredAssemblies();
            var configurations = GetConfigurationsFromTypes(types);

            foreach (var configRegistration in configurations)
            {
                ProviderResolver.RegisterConfiguration(configRegistration.GetConfiguration());
            }
        }
Exemplo n.º 15
0
        private static void DoOnDemandRegenerate(HttpContext context)
        {
            var timer = new Stopwatch();

            timer.Start();
            ProviderResolver.Current.TemplateInputProvider.Refresh();
            ProviderResolver.CreateGenerator().GenerateToDisk();
            timer.Stop();

            string result = string.Format("<p>Generation complete in {0} ms. You will want to rebuild to pick up the changes.</p>", timer.ElapsedMilliseconds);

            context.Response.Write(WrapReport("Regenerating Model", result));

            context.Response.End();
        }
        private void DoLogSync()
        {
            foreach (var configuration in ProviderResolver.GetConfigurations())
            {
                var syncResult = GetSyncResult(configuration);

                if (!syncResult.AreTemplatesSynchronized)
                {
                    foreach (var template in syncResult)
                    {
                        if (!template.IsSynchronized)
                        {
                            Log.Warn("Synthesis template desynchronization ({0}): {1}".FormatWith(configuration.Name, template), this);
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Converts a Sitecore Field into a Synthesis field equivalent
        /// </summary>
        public static FieldType AsStronglyTyped(this Field field)
        {
            if (field == null)
            {
                return(null);
            }

            var templateField = field.Item.Template.GetField(field.ID);
            var configuration = ProviderResolver.FindConfigurationWithTemplate(field.Item.TemplateID);

            Assert.IsNotNull(configuration, "The template field was not part of any Synthesis template.");

            var mapping = configuration.FieldMappingProvider.GetFieldType(new ItemTemplateFieldInfo(templateField));

            var lazy = new Lazy <Field>(() => field);

            return(Activator.CreateInstance(mapping.InternalFieldType, lazy, null) as FieldType);
        }
        private static void InitProviders()
        {
            ProviderResolver <TripProvider> .Configure()
            .AppendActive(new Mocks.MockTripProvider()
            {
                JsonDataPath = HttpContext.Current.Server.MapPath("~/App_Data/trips.json")
            });

            ProviderResolver <PersonProvider> .Configure()
            .AppendActive(new Mocks.MockPersonProvider()
            {
                JsonDataPath = HttpContext.Current.Server.MapPath("~/App_Data/people.json")
            });

            ProviderResolver <LocationProvider> .Configure()
            .AppendActive(new Mocks.MockLocationProvider()
            {
                JsonDataPath = HttpContext.Current.Server.MapPath("~/App_Data/locations.json")
            });
        }
        private static void DoOnDemandRegenerate(HttpContext context)
        {
            var timer = new Stopwatch();

            timer.Start();

            var    configurations = ProviderResolver.GetConfigurations();
            string result         = string.Empty;

            foreach (var configuration in configurations)
            {
                var configName = configuration.Name.IsNullOrEmpty() ? "Unnamed Configuration" : configuration.Name;
                configuration.TemplateInputProvider.Refresh();
                var metadata = configuration.CreateMetadataGenerator().GenerateMetadata();
                configuration.CreateCodeGenerator().Generate(metadata);
                result += "<p>Regenerated <strong>{0}</strong></p>".FormatWith(configName);
            }
            timer.Stop();

            result += string.Format("<p>Generation complete in {0} ms. You will want to rebuild to pick up the changes.</p>", timer.ElapsedMilliseconds);
            context.Response.Write(WrapReport("Regenerating Model", result));

            context.Response.End();
        }
 public void Process(PipelineArgs args)
 {
     ProviderResolver.RegisterConfiguration(new ConfigurationProviderConfiguration());
 }
Exemplo n.º 21
0
 public Builder(ProviderResolver resolver)
 {
     _resolver = resolver;
 }