本文整理汇总了C#中ExceptionlessConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# ExceptionlessConfiguration类的具体用法?C# ExceptionlessConfiguration怎么用?C# ExceptionlessConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionlessConfiguration类属于命名空间,在下文中一共展示了ExceptionlessConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDefaultPlugins
public static void AddDefaultPlugins(ExceptionlessConfiguration config) {
config.AddPlugin<ConfigurationDefaultsPlugin>();
config.AddPlugin<SimpleErrorPlugin>();
config.AddPlugin<DuplicateCheckerPlugin>();
config.AddPlugin<EnvironmentInfoPlugin>();
config.AddPlugin<SubmissionMethodPlugin>();
}
示例2: GetSettings
public SettingsResponse GetSettings(ExceptionlessConfiguration config, int version, IJsonSerializer serializer) {
if (!config.IsValid)
return new SettingsResponse(false, message: "Invalid client configuration settings.");
string url = String.Format("{0}/projects/config?v={1}", GetServiceEndPoint(config), version);
HttpResponseMessage response;
try {
_client.Value.AddAuthorizationHeader(config.ApiKey);
response = _client.Value.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult();
} catch (Exception ex) {
var message = String.Concat("Unable to retrieve configuration settings. Exception: ", ex.GetMessage());
return new SettingsResponse(false, message: message);
}
if (response != null && response.StatusCode == HttpStatusCode.NotModified)
return new SettingsResponse(false, message: "Settings have not been modified.");
if (response == null || response.StatusCode != HttpStatusCode.OK)
return new SettingsResponse(false, message: String.Concat("Unable to retrieve configuration settings: ", GetResponseMessage(response)));
var json = GetResponseText(response);
if (String.IsNullOrWhiteSpace(json))
return new SettingsResponse(false, message: "Invalid configuration settings.");
var settings = serializer.Deserialize<ClientConfiguration>(json);
return new SettingsResponse(true, settings.Settings, settings.Version);
}
示例3: CheckVersion
public static void CheckVersion(int version, ExceptionlessConfiguration config) {
int currentVersion = GetVersion(config);
if (version <= currentVersion)
return;
UpdateSettings(config, currentVersion);
}
示例4: UpdateSettings
public static void UpdateSettings(ExceptionlessConfiguration config) {
if (String.IsNullOrEmpty(config.ApiKey) || String.Equals(config.ApiKey, "API_KEY_HERE", StringComparison.OrdinalIgnoreCase)) {
config.Resolver.GetLog().Error(typeof(SettingsManager), "Unable to update settings: ApiKey is not set.");
return;
}
var serializer = config.Resolver.GetJsonSerializer();
var client = config.Resolver.GetSubmissionClient();
var response = client.GetSettings(config, serializer);
if (!response.Success || response.Settings == null)
return;
var savedServerSettings = GetSavedServerSettings(config);
config.Settings.Apply(response.Settings);
// TODO: Store snapshot of settings after reading from config and attributes and use that to revert to defaults.
// Remove any existing server settings that are not in the new server settings.
foreach (string key in savedServerSettings.Keys.Except(response.Settings.Keys)) {
if (config.Settings.ContainsKey(key))
config.Settings.Remove(key);
}
var persistedClientData = config.Resolver.Resolve<PersistedDictionary>();
persistedClientData[String.Concat(config.GetQueueName(), "-ServerConfigVersion")] = response.SettingsVersion.ToString();
var fileStorage = config.Resolver.GetFileStorage();
fileStorage.SaveObject(GetConfigPath(config), response.Settings);
}
示例5: PostUserDescription
public SubmissionResponse PostUserDescription(string referenceId, UserDescription description, ExceptionlessConfiguration config, IJsonSerializer serializer) {
if (!config.IsValid)
return new SubmissionResponse(500, message: "Invalid client configuration settings.");
string data = serializer.Serialize(description);
string url = String.Format("{0}/events/by-ref/{1}/user-description", GetServiceEndPoint(config), referenceId);
HttpResponseMessage response;
try {
HttpContent content = new StringContent(data, Encoding.UTF8, "application/json");
// don't compress data smaller than 4kb
if (data.Length > 1024 * 4)
content = new GzipContent(content);
_client.Value.AddAuthorizationHeader(config.ApiKey);
response = _client.Value.PostAsync(url, content).ConfigureAwait(false).GetAwaiter().GetResult();
} catch (Exception ex) {
return new SubmissionResponse(500, message: ex.Message);
}
int settingsVersion;
if (Int32.TryParse(GetSettingsVersionHeader(response.Headers), out settingsVersion))
SettingsManager.CheckVersion(settingsVersion, config);
return new SubmissionResponse((int)response.StatusCode, GetResponseMessage(response));
}
示例6: UpdateSettings
public static void UpdateSettings(ExceptionlessConfiguration config, int? version = null) {
if (config == null || !config.IsValid || !config.Enabled)
return;
try {
if (!version.HasValue || version < 0)
version = GetVersion(config);
var serializer = config.Resolver.GetJsonSerializer();
var client = config.Resolver.GetSubmissionClient();
var response = client.GetSettings(config, version.Value, serializer);
if (!response.Success || response.Settings == null)
return;
var savedServerSettings = GetSavedServerSettings(config);
config.Settings.Apply(response.Settings);
// TODO: Store snapshot of settings after reading from config and attributes and use that to revert to defaults.
// Remove any existing server settings that are not in the new server settings.
foreach (string key in savedServerSettings.Keys.Except(response.Settings.Keys)) {
if (config.Settings.ContainsKey(key))
config.Settings.Remove(key);
}
var persistedClientData = config.Resolver.Resolve<PersistedDictionary>();
persistedClientData[String.Concat(config.GetQueueName(), "-ServerConfigVersion")] = response.SettingsVersion.ToString();
var fileStorage = config.Resolver.GetFileStorage();
fileStorage.SaveObject(GetConfigPath(config), response.Settings);
} catch (Exception ex) {
config.Resolver.GetLog().Error(typeof(SettingsManager), ex, "Error occurred updating settings.");
}
}
示例7: CheckVersion
public static void CheckVersion(int version, ExceptionlessConfiguration config) {
var persistedClientData = config.Resolver.Resolve<PersistedDictionary>();
if (version <= persistedClientData.GetInt32(String.Concat(config.GetQueueName(), "-ServerConfigVersion"), -1))
return;
UpdateSettings(config);
}
示例8: CanUpdateSettingsFromServer
public void CanUpdateSettingsFromServer() {
var config = new ExceptionlessConfiguration(DependencyResolver.Default);
config.ApiKey = "e3d51ea621464280bbcb79c11fd6483e";
config.Settings["LocalSetting"] = "1";
config.Settings["LocalSettingToOverride"] = "1";
var submissionClient = new Mock<ISubmissionClient>();
submissionClient.Setup(m => m.Submit(It.IsAny<IEnumerable<Event>>(), config, It.IsAny<IJsonSerializer>()))
.Callback(() => SettingsManager.CheckVersion(1, config))
.Returns(() => new SubmissionResponse(202, "Accepted"));
submissionClient.Setup(m => m.GetSettings(config, It.IsAny<IJsonSerializer>()))
.Returns(() => new SettingsResponse(true, new SettingsDictionary { { "Test", "Test" }, { "LocalSettingToOverride", "2" } }, 1));
config.Resolver.Register<ISubmissionClient>(submissionClient.Object);
var client = new ExceptionlessClient(config);
Assert.Equal(2, client.Configuration.Settings.Count);
Assert.False(client.Configuration.Settings.ContainsKey("Test"));
Assert.Equal("1", client.Configuration.Settings["LocalSettingToOverride"]);
client.SubmitEvent(new Event { Type = "Log", Message = "Test" });
client.ProcessQueue();
Assert.True(client.Configuration.Settings.ContainsKey("Test"));
Assert.Equal("2", client.Configuration.Settings["LocalSettingToOverride"]);
Assert.Equal(3, client.Configuration.Settings.Count);
var storage = config.Resolver.GetFileStorage() as InMemoryFileStorage;
Assert.True(storage.Exists(config.GetQueueName() + "\\server-settings.json"));
config.Settings.Clear();
config.ApplySavedServerSettings();
Assert.True(client.Configuration.Settings.ContainsKey("Test"));
Assert.Equal("2", client.Configuration.Settings["LocalSettingToOverride"]);
Assert.Equal(2, client.Configuration.Settings.Count);
}
示例9: AddAuthorizationHeader
public static void AddAuthorizationHeader(this WebRequest request, ExceptionlessConfiguration configuration) {
var authorizationHeader = new AuthorizationHeader {
Scheme = ExceptionlessHeaders.Bearer,
ParameterText = configuration.ApiKey
};
request.Headers[HttpRequestHeader.Authorization] = authorizationHeader.ToString();
}
示例10: PostEvents
public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessConfiguration config, IJsonSerializer serializer) {
foreach (Event e in events) {
string data = serializer.Serialize(e);
string referenceId = !string.IsNullOrWhiteSpace(e.ReferenceId) ? e.ReferenceId : Guid.NewGuid().ToString("D");
_eventContainer[referenceId] = data;
}
return new SubmissionResponse(200);
}
示例11: AddDefaultPlugins
public static void AddDefaultPlugins(ExceptionlessConfiguration config) {
config.AddPlugin<ConfigurationDefaultsPlugin>();
config.AddPlugin<HandleAggregateExceptionsPlugin>();
config.AddPlugin<SimpleErrorPlugin>();
config.AddPlugin<DuplicateCheckerPlugin>();
config.AddPlugin<EnvironmentInfoPlugin>();
config.AddPlugin<SubmissionMethodPlugin>();
config.AddPlugin<CancelSessionsWithNoUserPlugin>();
}
示例12: ApplySavedServerSettings
public static void ApplySavedServerSettings(ExceptionlessConfiguration config) {
if (String.IsNullOrEmpty(config.ApiKey) || String.Equals(config.ApiKey, "API_KEY_HERE", StringComparison.OrdinalIgnoreCase)) {
config.Resolver.GetLog().Error(typeof(SettingsManager), "Unable to apply saved server settings: ApiKey is not set.");
return;
}
var savedServerSettings = GetSavedServerSettings(config);
config.Settings.Apply(savedServerSettings);
}
示例13: PostUserDescription
public SubmissionResponse PostUserDescription(string referenceId, UserDescription description, ExceptionlessConfiguration config, IJsonSerializer serializer) {
var ev = Events.FirstOrDefault(e => e.ReferenceId == referenceId);
if (ev == null)
return new SubmissionResponse(404, "Not Found");
ev.Data[Event.KnownDataKeys.UserDescription] = description;
return new SubmissionResponse(200, "OK");
}
示例14: Collect
public static RequestInfo Collect(HttpContextBase context, ExceptionlessConfiguration config) {
if (context == null)
return null;
var info = new RequestInfo {
HttpMethod = context.Request.HttpMethod,
UserAgent = context.Request.UserAgent,
Path = String.IsNullOrEmpty(context.Request.Path) ? "/" : context.Request.Path
};
try {
info.ClientIpAddress = context.Request.UserHostAddress;
} catch (ArgumentException ex) {
config.Resolver.GetLog().Error(ex, "An error occurred while setting the Client Ip Address.");
}
try {
info.IsSecure = context.Request.IsSecureConnection;
} catch (ArgumentException ex) {
config.Resolver.GetLog().Error(ex, "An error occurred while setting Is Secure Connection.");
}
if (context.Request.Url != null)
info.Host = context.Request.Url.Host;
if (context.Request.UrlReferrer != null)
info.Referrer = context.Request.UrlReferrer.ToString();
if (context.Request.Url != null)
info.Port = context.Request.Url.Port;
info.Cookies = context.Request.Cookies.ToDictionary(config.DataExclusions);
if (context.Request.Form.Count > 0)
info.PostData = context.Request.Form.ToDictionary(config.DataExclusions);
else if (context.Request.ContentLength > 0 && context.Request.ContentLength < 1024 * 4) {
try {
context.Request.InputStream.Position = 0;
using (var inputStream = new StreamReader(context.Request.InputStream))
info.PostData = inputStream.ReadToEnd();
} catch (Exception ex) {
info.PostData = "Error retrieving POST data: " + ex.Message;
}
} else if (context.Request.ContentLength > 0) {
string value = Math.Round(context.Request.ContentLength / 1024m, 0).ToString("N0");
info.PostData = String.Format("Data is too large ({0}) to be included.", value + "kb");
}
try {
info.QueryString = context.Request.QueryString.ToDictionary(config.DataExclusions);
} catch (Exception ex) {
config.Resolver.GetLog().Error(ex, "An error occurred while getting the cookies");
}
return info;
}
示例15: DefaultEventQueue
public DefaultEventQueue(ExceptionlessConfiguration config, IExceptionlessLog log, ISubmissionClient client, IObjectStorage objectStorage, IJsonSerializer serializer, TimeSpan? processQueueInterval, TimeSpan? queueStartDelay) {
_log = log;
_config = config;
_client = client;
_storage = objectStorage;
_serializer = serializer;
if (processQueueInterval.HasValue)
_processQueueInterval = processQueueInterval.Value;
_queueTimer = new Timer(OnProcessQueue, null, queueStartDelay ?? TimeSpan.FromSeconds(2), _processQueueInterval);
}