示例#1
0
        public TelemetrySink(ITelemetrySink telemetrySink)
        {
            if (telemetrySink == null)
            {
                throw new ArgumentNullException();
            }

            this.TelemetrySinksList.Add(telemetrySink);
        }
        internal protected ComponentTelemetryClient(string applicationName, ITelemetrySink telemetrySink, ITelemetryContext telemetryContext, ITelemetryInitializerChain initializers, IDictionary <string, string> contextProperties = null)
            : base()
        {
            this.TelemetrySink   = telemetrySink;
            this.Context         = telemetryContext;
            this.Initializers    = initializers;
            this.ApplicationName = applicationName;

            if (contextProperties != null && contextProperties.Count > 0)
            {
                Utils.CopyDictionary <string>(contextProperties, this.Context.Properties);
            }
        }
 public Bus(SingleInstanceFactory singleInstanceFactory, ITelemetrySink telemetrySink)
 {
     _singleInstanceFactory = singleInstanceFactory;
     _telemetrySink         = telemetrySink;
 }
示例#4
0
 /// <summary>
 /// Private constructor so the class cannot be instantiated by any other class
 /// </summary>
 private AxeWindowsTelemetrySink(ITelemetrySink telemetrySink)
 {
     _telemetrySink = telemetrySink;
 }
        static void InnerMain(Mutex InstanceMutex, EventWaitHandle ActivateEvent, string[] Args)
        {
            string ServerAndPort  = null;
            string UserName       = null;
            string BaseUpdatePath = null;

            Utility.ReadGlobalPerforceSettings(ref ServerAndPort, ref UserName, ref BaseUpdatePath);

            List <string> RemainingArgs = new List <string>(Args);

            string UpdateSpawn;

            ParseArgument(RemainingArgs, "-updatespawn=", out UpdateSpawn);

            string UpdatePath;

            ParseArgument(RemainingArgs, "-updatepath=", out UpdatePath);

            bool bRestoreState;

            ParseOption(RemainingArgs, "-restorestate", out bRestoreState);

            bool bUnstable;

            ParseOption(RemainingArgs, "-unstable", out bUnstable);

            string ProjectFileName;

            ParseArgument(RemainingArgs, "-project=", out ProjectFileName);

            string UpdateConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate.ini");

            MergeUpdateSettings(UpdateConfigFile, ref UpdatePath, ref UpdateSpawn);

            string SyncVersionFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SyncVersion.txt");

            if (File.Exists(SyncVersionFile))
            {
                try
                {
                    SyncVersion = File.ReadAllText(SyncVersionFile).Trim();
                }
                catch (Exception)
                {
                    SyncVersion = null;
                }
            }

            string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UnrealGameSync");

            Directory.CreateDirectory(DataFolder);

            // Create the log file
            using (TimestampLogWriter Log = new TimestampLogWriter(new BoundedLogWriter(Path.Combine(DataFolder, "UnrealGameSync.log"))))
            {
                Log.WriteLine("Application version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
                Log.WriteLine("Started at {0}", DateTime.Now.ToString());

                string SessionId = Guid.NewGuid().ToString();
                Log.WriteLine("SessionId: {0}", SessionId);

                if (ServerAndPort == null || UserName == null)
                {
                    Log.WriteLine("Missing server settings; finding defaults.");
                    GetDefaultServerSettings(ref ServerAndPort, ref UserName, Log);
                    Utility.SaveGlobalPerforceSettings(ServerAndPort, UserName, BaseUpdatePath);
                }

                using (BoundedLogWriter TelemetryLog = new BoundedLogWriter(Path.Combine(DataFolder, "Telemetry.log")))
                {
                    TelemetryLog.WriteLine("Creating telemetry sink for session {0}", SessionId);

                    ITelemetrySink PrevTelemetrySink = Telemetry.ActiveSink;
                    using (ITelemetrySink TelemetrySink = DeploymentSettings.CreateTelemetrySink(UserName, SessionId, TelemetryLog))
                    {
                        Telemetry.ActiveSink = TelemetrySink;

                        Telemetry.SendEvent("Startup", new { User = Environment.UserName, Machine = Environment.MachineName });

                        AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                        PerforceConnection DefaultConnection = new PerforceConnection(UserName, null, ServerAndPort);
                        using (UpdateMonitor UpdateMonitor = new UpdateMonitor(DefaultConnection, UpdatePath))
                        {
                            ProgramApplicationContext Context = new ProgramApplicationContext(DefaultConnection, UpdateMonitor, DeploymentSettings.ApiUrl, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn, ProjectFileName, bUnstable, Log);
                            Application.Run(Context);

                            if (UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
                            {
                                InstanceMutex.Close();
                                bool bLaunchUnstable = UpdateMonitor.RelaunchUnstable ?? bUnstable;
                                Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bLaunchUnstable ? " -unstable" : ""));
                            }
                        }
                    }
                    Telemetry.ActiveSink = PrevTelemetrySink;
                }
            }
        }
示例#6
0
 public InstrumentedWorkflowActivityBase()
     : base()
 {
     this.TelemetrySink = Container.Resolve <ITelemetrySink>();
 }
示例#7
0
 /// <summary>
 /// Constructor for <see cref="InstrumentedPluginBase"/>.
 /// </summary>
 /// <param name="unsecureConfig"></param>
 /// <param name="secureConfig"></param>
 public InstrumentedPluginBase(string unsecureConfig, string secureConfig)
     : base(unsecureConfig, secureConfig)
 {
     TelemetrySink = Container.Resolve <ITelemetrySink>();
 }
 /// <summary>
 /// Method to allow the ITelemetrySink to be replaced for unit tests
 /// </summary>
 /// <param name="newSink">The new sink to use. If null, the default sink will be set</param>
 internal static void SetTelemetrySink(ITelemetrySink newSink)
 {
     Sink = newSink ?? TelemetrySink.DefaultTelemetrySink;
 }
 public IComponentTelemetryClient BuildClient(string applicationName, ITelemetrySink telemetrySink, IDictionary <string, string> contextProperties = null)
 {
     return(new ComponentTelemetryClient(applicationName, telemetrySink, telemetryContext.BuildNew(), InitializerChain, contextProperties));
 }
示例#10
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <remarks>
        /// Microsoft CRM plugins must be thread-safe and stateless.
        /// </remarks>
        public override void Execute(IServiceProvider serviceProvider)
        {
            var sw           = System.Diagnostics.Stopwatch.StartNew();
            var success      = true;
            var responseCode = "200";

            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            tracingService.Trace(string.Format(CultureInfo.InvariantCulture, "Entering {0}.Execute()", this.GetType().ToString()));

            var executionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Setup sink if it has not already been done. This is done here to cover the possibility that an implementing class might override
            // the default, non-static, property implementation.
            var lockObj = new object();

            lock (lockObj)
            {
                if (TelemetrySink is null)
                {
                    TelemetrySink = Container.Resolve <ITelemetrySink>();
                }
            }


            var telemetryFactory       = Container.Resolve <ITelemetryFactory>();
            var telemetryClientFactory = Container.Resolve <ITelemetryClientFactory>();

            //Create a dictionary of custom telemetry properties based on values in the execution context.
            var propertyManager = Container.Resolve <ICDSTelemetryPropertyManager>();
            var properties      = propertyManager.CreatePropertiesDictionary(this.GetType().ToString(), executionContext);

            using (var telemetryClient = telemetryClientFactory.BuildClient(
                       this.GetType().ToString(),
                       this.TelemetrySink,
                       properties))
            {
                #region Setup Telemetry Context

                //capture execution context attributes that fit in telemetry context
                telemetryClient.Context.Operation.Name = executionContext.MessageName;
                telemetryClient.Context.Operation.CorrelationVector = executionContext.CorrelationId.ToString();
                telemetryClient.Context.Operation.Id = executionContext.OperationId.ToString();
                telemetryClient.Context.Session.Id   = executionContext.CorrelationId.ToString();

                //Capture data context if the telemetry provider supports data key context.
                var asDataContext = telemetryClient.Context as ISupportDataKeyContext;
                if (asDataContext != null)
                {
                    asDataContext.Data.RecordSource = executionContext.OrganizationName;
                    asDataContext.Data.RecordType   = executionContext.PrimaryEntityName;
                    asDataContext.Data.RecordId     = executionContext.PrimaryEntityId.ToString();
                }

                #endregion

                try
                {
                    var matchingRegistrations = this.PluginEventRegistrations
                                                .Where(a => (int)a.Stage == executionContext.Stage &&
                                                       (string.IsNullOrWhiteSpace(a.MessageName) || string.Compare(a.MessageName, executionContext.MessageName, StringComparison.InvariantCultureIgnoreCase) == 0) &&
                                                       (string.IsNullOrWhiteSpace(a.EntityName) || string.Compare(a.EntityName, executionContext.PrimaryEntityName, StringComparison.InvariantCultureIgnoreCase) == 0));

                    if (matchingRegistrations.Any())
                    {
                        var factory = Container.Resolve <IInstrumentedCDSExecutionContextFactory <IInstrumentedCDSPluginExecutionContext> >();

                        using (var cdsExecutionContext = factory.CreateCDSExecutionContext(executionContext, serviceProvider, this.Container, telemetryClient))
                        {
                            if (!TelemetrySink.IsConfigured)
                            {
                                TelemetrySink.OnConfigure = () => { return(this.ConfigureTelemetrySink(cdsExecutionContext)); };
                            }

                            foreach (var registration in matchingRegistrations)
                            {
                                try
                                {
                                    registration.Invoke(cdsExecutionContext);
                                }
                                catch (InvalidPluginExecutionException ex)
                                {
                                    success      = false;
                                    responseCode = "400"; //indicates a business rule error
                                    if (telemetryClient != null && telemetryFactory != null)
                                    {
                                        telemetryClient.Track(telemetryFactory.BuildMessageTelemetry(ex.Message, eSeverityLevel.Error));
                                    }
                                    throw;
                                }
                                catch (Exception ex)
                                {
                                    success      = false;
                                    responseCode = "500"; //indicates a server error
                                    if (telemetryClient != null && telemetryFactory != null)
                                    {
                                        telemetryClient.Track(telemetryFactory.BuildExceptionTelemetry(ex));
                                    }
                                    throw;
                                }
                                finally
                                {
                                    if (this.TrackExecutionPerformance && telemetryFactory != null && telemetryClient != null)
                                    {
                                        var r = telemetryFactory.BuildRequestTelemetry("PluginExecution", null, new Dictionary <string, string> {
                                            { "handlerName", registration.HandlerId }
                                        });
                                        r.Duration     = sw.Elapsed;
                                        r.ResponseCode = responseCode;
                                        r.Success      = success;

                                        telemetryClient.Track(r);
                                    }

                                    if (this.FlushTelemetryAfterExecution && telemetryClient != null)
                                    {
                                        telemetryClient.Flush();
                                    }

                                    sw.Restart();
                                }
                            }
                        } //using cdsExecutionContext
                    }
                }
                catch (InvalidPluginExecutionException ex)
                {
                    tracingService.Trace(string.Format("Exception: {0}", ex.Message));
                    throw;
                }
                catch (Exception ex)
                {
                    tracingService.Trace(string.Format("Exception: {0}", ex.Message));
                    throw new InvalidPluginExecutionException(string.Format("Unhandled Plugin Exception {0}", ex.Message), ex);
                }
            } //using telemetryClient.

            sw.Stop();
            sw = null;

            tracingService.Trace(string.Format(CultureInfo.InvariantCulture, "Exiting {0}.Execute()", this.GetType().ToString()));
        }