Exemplo n.º 1
0
 /// <summary>
 /// Instantiates a publishing page object
 /// </summary>
 /// <param name="page">ListItem holding the page to analyze</param>
 /// <param name="pageTransformation">Page transformation information</param>
 public PublishingPage(ListItem page, PageTransformation pageTransformation, BaseTransformationInformation baseTransformationInformation, IList <ILogObserver> logObservers = null) : base(page, null, pageTransformation, logObservers)
 {
     // no PublishingPageTransformation specified, fall back to default
     this.publishingPageTransformation  = new PageLayoutManager(base.RegisteredLogObservers).LoadDefaultPageLayoutMappingFile();
     this.baseTransformationInformation = baseTransformationInformation;
     this.functionProcessor             = new PublishingFunctionProcessor(page, cc, null, this.publishingPageTransformation, baseTransformationInformation, base.RegisteredLogObservers);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Instantiates a publishing page object
 /// </summary>
 /// <param name="page">ListItem holding the page to analyze</param>
 /// <param name="pageTransformation">Page transformation information</param>
 public PublishingPage(ListItem page, PageTransformation pageTransformation, PublishingPageTransformation publishingPageTransformation, BaseTransformationInformation baseTransformationInformation, ClientContext targetContext = null, IList <ILogObserver> logObservers = null) : base(page, null, pageTransformation, logObservers)
 {
     this.publishingPageTransformation  = publishingPageTransformation;
     this.baseTransformationInformation = baseTransformationInformation;
     this.targetContext     = targetContext;
     this.functionProcessor = new PublishingFunctionProcessor(page, cc, targetContext, this.publishingPageTransformation, baseTransformationInformation, base.RegisteredLogObservers);
 }
        /// <summary>
        /// Instantiates the base builtin function library
        /// </summary>
        /// <param name="pageClientContext">ClientContext object for the site holding the page being transformed</param>
        /// <param name="sourceClientContext">The ClientContext for the source </param>
        /// <param name="clientSidePage">Reference to the client side page</param>
        public PublishingBuiltIn(BaseTransformationInformation baseTransformationInformation, ClientContext sourceClientContext, ClientContext targetClientContext, IList <ILogObserver> logObservers = null) : base(sourceClientContext)
        {
            if (logObservers != null)
            {
                foreach (var observer in logObservers)
                {
                    base.RegisterObserver(observer);
                }
            }

            this.sourceClientContext           = sourceClientContext;
            this.targetClientContext           = targetClientContext;
            this.baseTransformationInformation = baseTransformationInformation;
            this.parser  = new HtmlParser();
            this.builtIn = new BuiltIn(this.baseTransformationInformation, targetClientContext, sourceClientContext, logObservers: logObservers);
        }
Exemplo n.º 4
0
        public void LogTransformationDone(TimeSpan duration, string pageType, BaseTransformationInformation baseTransformationInformation)
        {
            if (this.telemetryClient == null)
            {
                return;
            }

            try
            {
                // Prepare event data
                Dictionary <string, string> properties = new Dictionary <string, string>(10);
                Dictionary <string, double> metrics    = new Dictionary <string, double>(5);

                // Populate properties

                // Page transformation engine version
                properties.Add(EngineVersion, this.version);
                // Type of page being transformed
                properties.Add(PageType, pageType);
                // In-Place upgrade or cross farm
                properties.Add(CrossSite, baseTransformationInformation.IsCrossSiteTransformation.ToString());
                // Type of transform (intra or cross farm)
                properties.Add(CrossFarm, baseTransformationInformation.IsCrossFarmTransformation.ToString());
                // SharePoint Environments
                properties.Add(SourceVersion, NormalizeSharePointVersions(baseTransformationInformation.SourceVersion).ToString());
                properties.Add(SourceVersionNumber, baseTransformationInformation.SourceVersionNumber);
                properties.Add(TargetVersion, NormalizeSharePointVersions(baseTransformationInformation.TargetVersion).ToString());
                properties.Add(TargetVersionNumber, baseTransformationInformation.TargetVersionNumber);
                // Azure AD tenant
                properties.Add(AADTenantId, this.aadTenantId.ToString());

                // Populate metrics
                if (duration != null)
                {
                    // How long did it take to transform this page
                    metrics.Add(Duration, duration.TotalSeconds);
                }

                // Send the event
                this.telemetryClient.TrackEvent(PageTransformed, properties, metrics);
            }
            catch
            {
                // Eat all exceptions
            }
        }
Exemplo n.º 5
0
        public MyCustomFunctions(BaseTransformationInformation baseTransformationInformation, ClientContext pageClientContext, ClientContext sourceClientContext, ClientSidePage clientSidePage, IList <ILogObserver> logObservers) : base(pageClientContext)
        {
            if (logObservers != null)
            {
                foreach (var observer in logObservers)
                {
                    base.RegisterObserver(observer);
                }
            }

            // This is an optional property, in cross site transfer the two contexts would be different.
            this.sourceClientContext           = sourceClientContext;
            this.clientSidePage                = clientSidePage;
            this.baseTransformationInformation = baseTransformationInformation;
            this.urlTransformator              = new UrlTransformator(baseTransformationInformation, this.sourceClientContext, this.clientContext, base.RegisteredLogObservers);
            this.userTransformator             = new UserTransformator(baseTransformationInformation, this.sourceClientContext, this.clientContext, base.RegisteredLogObservers);
        }
Exemplo n.º 6
0
        public void LogTransformationDone(TimeSpan duration, string pageType, BaseTransformationInformation baseTransformationInformation)
        {
            if (this.telemetryClient == null)
            {
                return;
            }

            try
            {
                // Prepare event data
                Dictionary <string, string> properties = new Dictionary <string, string>();
                Dictionary <string, double> metrics    = new Dictionary <string, double>();

                if (duration != null)
                {
                    properties.Add("Duration", duration.Seconds.ToString());
                }

                this.telemetryClient.TrackEvent("TransformationEngine.PageDone", properties, metrics);

                // Also add to the metric of transformed pages via the service endpoint
                this.telemetryClient.GetMetric($"TransformationEngine.PagesTransformed").TrackValue(1);
                this.telemetryClient.GetMetric($"TransformationEngine.PageDuration").TrackValue(duration.TotalSeconds);
                this.telemetryClient.GetMetric($"TransformationEngine.{pageType}").TrackValue(1);

                // Log source environment type
                this.telemetryClient.GetMetric($"TransformationEngine.Source{baseTransformationInformation.SourceVersion.ToString()}").TrackValue(1);

                // Cross farm or not?
                if (baseTransformationInformation.IsCrossFarmTransformation)
                {
                    this.telemetryClient.GetMetric($"TransformationEngine.CrossFarmTransformation").TrackValue(1);
                }
                else
                {
                    this.telemetryClient.GetMetric($"TransformationEngine.IntraFarmTransformation").TrackValue(1);
                }
            }
            catch
            {
                // Eat all exceptions
            }
        }
Exemplo n.º 7
0
        public PublishingFunctionProcessor(ListItem page, ClientContext sourceClientContext, ClientContext targetClientContext, PublishingPageTransformation publishingPageTransformation, BaseTransformationInformation baseTransformationInformation, IList <ILogObserver> logObservers = null)
        {
            //Register any existing observers
            if (logObservers != null)
            {
                foreach (var observer in logObservers)
                {
                    base.RegisterObserver(observer);
                }
            }

            this.page = page;
            this.publishingPageTransformation  = publishingPageTransformation;
            this.sourceClientContext           = sourceClientContext;
            this.targetClientContext           = targetClientContext;
            this.baseTransformationInformation = baseTransformationInformation;

            RegisterAddons();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="page">Page to operate on</param>
        /// <param name="sourceClientContext">Clientcontext of the source site</param>
        /// <param name="targetClientContext">Clientcontext of the target site</param>
        /// <param name="publishingPageTransformation">Publishing page layout mapping</param>
        /// <param name="baseTransformationInformation">Page transformation information</param>
        /// <param name="logObservers">Connected loggers</param>
        public PublishingFunctionProcessor(ListItem page, ClientContext sourceClientContext, ClientContext targetClientContext, PublishingPageTransformation publishingPageTransformation, BaseTransformationInformation baseTransformationInformation, IList <ILogObserver> logObservers = null)
        {
            //Register any existing observers
            if (logObservers != null)
            {
                foreach (var observer in logObservers)
                {
                    base.RegisterObserver(observer);
                }
            }

            this.page = page;
            this.publishingPageTransformation  = publishingPageTransformation;
            this.sourceClientContext           = sourceClientContext;
            this.targetClientContext           = targetClientContext;
            this.baseTransformationInformation = baseTransformationInformation;

            // we may have null values being passed over from unit tests
            if (this.sourceClientContext != null && this.targetClientContext != null && this.baseTransformationInformation != null)
            {
                RegisterAddons();
            }
        }
        /// <summary>
        /// Instantiates the function processor. Also loads the defined add-ons
        /// </summary>
        /// <param name="page">Client side page for which we're executing the functions/selectors as part of the mapping</param>
        /// <param name="pageTransformation">Webpart mapping information</param>
        public FunctionProcessor(ClientContext sourceClientContext, ClientSidePage page, PageTransformation pageTransformation, BaseTransformationInformation baseTransformationInformation, IList <ILogObserver> logObservers = null)
        {
            this.page = page;
            this.pageTransformation = pageTransformation;

            //Register any existing observers
            if (logObservers != null)
            {
                foreach (var observer in logObservers)
                {
                    base.RegisterObserver(observer);
                }
            }

            // instantiate default built in functions class
            this.addOnTypes       = new List <AddOnType>();
            this.builtInFunctions = Activator.CreateInstance(typeof(BuiltIn), baseTransformationInformation, this.page.Context, sourceClientContext, this.page, base.RegisteredLogObservers);

            // instantiate the custom function classes (if there are)
            foreach (var addOn in this.pageTransformation.AddOns)
            {
                try
                {
                    string path = "";
                    if (addOn.Assembly.Contains("\\") && System.IO.File.Exists(addOn.Assembly))
                    {
                        path = addOn.Assembly;
                    }
                    else
                    {
                        path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, addOn.Assembly);
                    }

                    var assembly   = Assembly.LoadFile(path);
                    var customType = assembly.GetType(addOn.Type);
                    var instance   = Activator.CreateInstance(customType, this.page.Context);

                    this.addOnTypes.Add(new AddOnType()
                    {
                        Name     = addOn.Name,
                        Assembly = assembly,
                        Instance = instance,
                        Type     = customType,
                    });
                }
                catch (Exception ex)
                {
                    LogError(LogStrings.Error_FailedToInitiateCustomFunctionClasses, LogStrings.Heading_FunctionProcessor, ex);
                    throw;
                }
            }
        }
 /// <summary>
 /// Instantiates a publishing page object
 /// </summary>
 /// <param name="page">ListItem holding the page to analyze</param>
 /// <param name="pageTransformation">Page transformation information</param>
 public PublishingPageOnPremises(ListItem page, PageTransformation pageTransformation, PublishingPageTransformation publishingPageTransformation, BaseTransformationInformation baseTransformationInformation, ClientContext targetContext = null, IList <ILogObserver> logObservers = null) : base(page, pageTransformation, publishingPageTransformation, baseTransformationInformation, targetContext, logObservers)
 {
 }
 /// <summary>
 /// Instantiates a publishing page object
 /// </summary>
 /// <param name="page">ListItem holding the page to analyze</param>
 /// <param name="pageTransformation">Page transformation information</param>
 public PublishingPageOnPremises(ListItem page, PageTransformation pageTransformation, BaseTransformationInformation baseTransformationInformation, IList <ILogObserver> logObservers = null) : base(page, pageTransformation, baseTransformationInformation, logObservers)
 {
 }