// SendRequest #if WINDOWS_PHONE_APP private bool SendRequest(MessageReport messageReport) { //Debug.WriteLine("SendRequest: " + messageReport.GetType().Name); bool sendCompleted = false; Debug.WriteLine("SendRequest: ENTER"); try { HttpWebRequest request = messageReport.WebRequest(); if (request != null) { string postBody = messageReport.PostBody(); Task <Stream> writerTask = request.GetRequestStreamAsync(); using (Stream stream = writerTask.Result) { SendRequestWritePostBody(stream, postBody); } Task <WebResponse> responseTask = request.GetResponseAsync(); using (HttpWebResponse response = (HttpWebResponse)responseTask.Result) { sendCompleted = DidReceiveResult(messageReport, response); } } } catch (Exception ie) { Crittercism.LogInternalException(ie); } Debug.WriteLine("SendRequest: EXIT ---> " + sendCompleted); return(sendCompleted); }
private void leaveBreadcrumb_Click(object sender, EventArgs e) { string[] names = { "Breadcrumb", "Strawberry", "Seed", "Grape", "Lettuce" }; string name = names[random.Next(0, names.Length)]; Crittercism.LeaveBreadcrumb(name); }
public void TruncatedBreadcrumbTest() { TestHelpers.StartApp(); string breadcrumb; { StringBuilder builder = new StringBuilder(); // start breadcrumb with sentinel to ensure we don't left-truncate builder.Append("r"); for (int i = 1; i < Breadcrumbs.MAX_TEXT_LENGTH; i++) { builder.Append("a"); } ; // end breadcrumb with "illegal" chars and check for their presence builder.Append("zzzzzzzzzz"); breadcrumb = builder.ToString(); }; Crittercism.LeaveBreadcrumb(breadcrumb); TestHelpers.LogHandledException(); MessageReport messageReport = TestHelpers.DequeueMessageType(typeof(HandledException)); Assert.IsNotNull(messageReport, "Expected a HandledException message"); String asJson = JsonConvert.SerializeObject(messageReport); Assert.IsTrue(asJson.Contains("\"breadcrumbs\":")); Assert.IsTrue(asJson.Contains("\"raaaaaa")); Assert.IsFalse(asJson.Contains("aaaaz")); Assert.IsFalse(asJson.Contains("zzz")); }
private void logNetworkRequest_Click(object sender, EventArgs e) { Random random = new Random(); string[] methods = new string[] { "GET", "POST", "HEAD", "PUT" }; string method = methods[random.Next(0, methods.Length)]; string url = urls[random.Next(0, urls.Length)]; if (random.Next(0, 2) == 1) { url = url + "?doYouLoveCrittercism=YES"; } // latency in milliseconds long latency = (long)Math.Floor(4000.0 * random.NextDouble()); long bytesRead = random.Next(0, 10000); long bytesSent = random.Next(0, 10000); long responseCode = 200; if (random.Next(0, 5) == 0) { // Some common response other than 200 == OK . long[] responseCodes = new long[] { 301, 308, 400, 401, 402, 403, 404, 405, 408, 500, 502, 503 }; responseCode = responseCodes[random.Next(0, responseCodes.Length)]; } Crittercism.LogNetworkRequest( method, url, latency, bytesRead, bytesSent, (HttpStatusCode)responseCode, WebExceptionStatus.Success); }
partial void ManualNetworkRequestButton_TouchUpInside(UIButton sender) { Random random = new Random(); string[] methods = { "GET", "POST", "HEAD" }; string method = methods [random.Next(methods.Length)]; string[] urls = { "http://www.critterwebservice.com", "http://www.crittersearchengine.com/?ilove=critters", "http://www.critterdatingservice.com/nutlovers", "http://www.crittergourmetfood.com/nutsandberries.htm", "http://www.critterworldnews.com/summerfun", "http://www.crittermoviereviews.com/starring=mrscritter", "http://www.critterburrowdecor.com" }; string url = urls [random.Next(urls.Length)]; int[] responseCodes = { 200, 202, 400, 404 }; int responseCode = responseCodes [random.Next(responseCodes.Length)]; Crittercism.LogNetworkRequest( method, url, random.NextDouble(), random.Next(10000), random.Next(1000), responseCode, 0); }
private static void OnLogMessageReceived(string logString, string stack, LogType type) { if (type == LogType.Exception && logUnhandledExceptionAsCrash) { return; } string text = $"{Crittercism.stripTimestamps(logString)}\r\n{stack}"; switch (type) { case LogType.Exception: if (stack.Contains("UnityEngine.Debug:LogException(")) { logger.LogHandledExceptionMessage(text); } else { logger.LogUnhandledException(text); } break; case LogType.Error: case LogType.Assert: logger.LogError(text); break; case LogType.Warning: case LogType.Log: break; } }
protected override void OnCreate(Bundle bundle) { OverridePendingTransition(Resource.Animation.slide_in_right, Resource.Animation.slide_out_left); base.OnCreate(bundle); SetContentView(Resource.Layout.SignInView); Crittercism.Initialize(this, "55fcbf43d224ac0a00ed3d83"); sharedPreferences = GetSharedPreferences(mSharedPreferences, FileCreationMode.Private); string LanguageValue = string.Empty; LanguageValue = GetPreference <string>(AppConstants.Language); Mvx.Resolve <IMvxTextProviderBuilder>().LoadResources(LanguageValue); // Create your application here SetButtonEffects(new List <int>() { Resource.Id.tvSigin, Resource.Id.tvSignUp, Resource.Id.tvForgotPassword, Resource.Id.rlBack }); //get preferences //Mvx.Resolve<IMvxTextProviderBuilder>().LoadResources(string.Empty); //Mvx.Resolve<IMvxTextProviderBuilder>().LoadResources(value); }
private void handledExceptionClick(object sender,RoutedEventArgs e) { try { ThrowException(); } catch (Exception ex) { Crittercism.LogHandledException(ex); } }
private void userflowClick(object sender,RoutedEventArgs e) { Button button = sender as Button; if (button != null) { Debug.Assert(button == userflowButton); String label = button.Content.ToString(); if (label == beginUserflowLabel) { App.userflowName = userflowNames[random.Next(0,userflowNames.Length)]; Crittercism.BeginUserflow(App.userflowName); // Broadcast UserflowEvent to all open windows. App.OnUserflowEvent(EventArgs.Empty); } else if (label == endUserflowLabel) { EndUserflowDialog dialog = new EndUserflowDialog(); dialog.Owner = Window.GetWindow(this); dialog.ShowDialog(); Nullable<bool> dialogResult = dialog.DialogResult; if (dialogResult == true) { switch (dialog.Answer) { case "End Userflow": Crittercism.EndUserflow(App.userflowName); break; case "Fail Userflow": Crittercism.FailUserflow(App.userflowName); break; case "Cancel Userflow": Crittercism.CancelUserflow(App.userflowName); break; }; App.userflowName = null; // Broadcast UserflowEvent to all open windows. App.OnUserflowEvent(EventArgs.Empty); } } } }
// Work will be called when a worker thread is started via // Thread thread = new Thread(new ThreadStart(Worker.Work)); // thread.Start(); public static void Work() { Console.WriteLine("Worker.Work running in its own thread."); Random random = new Random(); while (true) { // Wait around 2 second. Thread.Sleep(random.Next(4000)); if (random.Next(10) == 0) { try { string[] names = { "Breadcrumb", "Strawberry", "Seed", "Grape", "Lettuce" }; string name = names[random.Next(0, names.Length)]; Crittercism.LeaveBreadcrumb(name); } catch (Exception e) { Console.WriteLine("UNEXPECTED ERROR!!! " + e.Message); }; } else { int i = 0; int j = 5; try { int k = j / i; } catch (Exception ex) { Crittercism.LogHandledException(ex); } } } }
public void LogHandledExceptionTest() { TestHelpers.StartApp(); Crittercism.LeaveBreadcrumb("HandledExceptionBreadcrumb"); Crittercism.SetValue("favoriteFood", "Texas Sheet Cake"); TestHelpers.Cleanup(); // drop all previous messages TestHelpers.LogHandledException(); MessageReport messageReport = TestHelpers.DequeueMessageType(typeof(HandledException)); Assert.IsNotNull(messageReport, "Expected a HandledException message"); String asJson = JsonConvert.SerializeObject(messageReport); Trace.WriteLine("asJson == " + asJson); TestHelpers.CheckJsonLegacy(asJson); string[] jsonStrings = new string[] { "\"breadcrumbs\":", "\"current_session\":", "\"message\":\"session_start\"", "\"metadata\":{", "\"favoriteFood\":\"Texas Sheet Cake\"" }; foreach (String jsonFragment in jsonStrings) { Trace.WriteLine("jsonFragment == " + jsonFragment); Trace.WriteLine("asJson.Contains(jsonFragment) == " + asJson.Contains(jsonFragment)); Assert.IsTrue(asJson.Contains(jsonFragment)); } ; }
public override void OnCreate() { base.OnCreate(); var config = new ImageLoaderConfiguration.Builder(this) .MemoryCacheExtraOptions(DroidConstants.ImageSize, DroidConstants.ImageSize) // default = device screen dimensions .DiskCacheExtraOptions(DroidConstants.ImageSize, DroidConstants.ImageSize, null) .ThreadPoolSize(10) // default .ThreadPriority(Thread.NormPriority - 2) // default .TasksProcessingOrder(QueueProcessingType.Fifo) // default .MemoryCacheSize(20 * 1024 * 1024) .MemoryCacheSizePercentage(30) // default .DiskCacheSize(50 * 1024 * 1024) .DiskCacheFileCount(300) .WriteDebugLogs() .Build(); ImageLoader.Instance.Init(config); Crittercism.Init(ApplicationContext, "1c2c97937d6f4d0aa6235204ae512f4000555300"); GcmClient.CheckDevice(this); GcmClient.CheckManifest(this); GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS); var handler = new ApplicationLifecycleHandler(); RegisterActivityLifecycleCallbacks(handler); RegisterComponentCallbacks(handler); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // create a new window instance based on the screen size Window = new UIWindow(UIScreen.MainScreen.Bounds); // If you have defined a root view controller, set it here: // Window.RootViewController = myViewController; Stripe.StripeClient.DefaultPublishableKey = AppConstants.StripeAPIKey; MapServices.ProvideAPIKey("AIzaSyAiBwRUm_KZDv_sp3eI7F8hxkePqDTvY20"); presenter = IsPad ? (IMvxTouchViewPresenter) new PadPresenter(this, Window) : (IMvxTouchViewPresenter) new PhonePresenter(this, Window); var setup = new Setup(this, presenter); setup.Initialize(); //get last used language var language = NSUserDefaults.StandardUserDefaults.StringForKey(AppConstants.Language); if (string.IsNullOrEmpty(language)) { Mvx.Resolve <IMvxTextProviderBuilder>().LoadResources(string.Empty); } else { Mvx.Resolve <IMvxTextProviderBuilder>().LoadResources(language); } var startup = Mvx.Resolve <IMvxAppStart>(); startup.Start(); // make the window visible Window.MakeKeyAndVisible(); //customize navigation bar UINavigationBar.Appearance.BarTintColor = UIColor.FromRGB(35, 137, 203); UINavigationBar.Appearance.TintColor = UIColor.White; UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes(new NSDictionary(UIStringAttributeKey.ForegroundColor, UIColor.White)); UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false); //customize tab bar var textAttributes = new UITextAttributes(); textAttributes.Font = UIFont.FromName("HelveticaNeue-Bold", 17f); textAttributes.Font = FontHelper.AdjustFontSize(textAttributes.Font); UITabBarItem.Appearance.SetTitleTextAttributes(textAttributes, UIControlState.Normal); //initialize Crittercism #if DEBUG #else Crittercism.Init("55fcbf338d4d8c0a00d07a12"); #endif return(true); }
protected override void OnCreate(Bundle bundle) { OverridePendingTransition(Resource.Animation.slide_in_right, Resource.Animation.slide_out_left); base.OnCreate(bundle); SetContentView(Resource.Layout.InitialMapView); Crittercism.Initialize(this, "55fcbf43d224ac0a00ed3d83"); sharedPreferences = GetSharedPreferences(mSharedPreferences, FileCreationMode.Private); string LanguageValue = string.Empty; LanguageValue = GetPreference <string>(AppConstants.Language); Mvx.Resolve <IMvxTextProviderBuilder>().LoadResources(LanguageValue); SupportMapFragment mapViewFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.mapView); mapViewFragment.GetMapAsync(this); // Create your application here var set = this.CreateBindingSet <InitialMapView, InitialMapViewModel>(); set.Bind().For(s => s.Parkings).To(vm => vm.Parkings); set.Apply(); SetButtonEffects(new List <int>() { Resource.Id.tvGoToSigin }); //get preferences //Mvx.Resolve<IMvxTextProviderBuilder>().LoadResources(string.Empty); //Mvx.Resolve<IMvxTextProviderBuilder>().LoadResources(value); }
/// <summary> /// Gets new session breadcrumbs. /// </summary> /// <returns> The breadcrumbs. </returns> private static Breadcrumbs SessionStart(string name, int maxCount) { Breadcrumbs answer = null; try { // Breadcrumbs answer has previous_session == the previous current_session // and new current_session == empty but for new session_start breadcrumb . string path = Path.Combine(StorageHelper.CrittercismPath(), name + ".js"); if (StorageHelper.FileExists(path)) { answer = StorageHelper.Load(path, typeof(Breadcrumbs)) as Breadcrumbs; } if (answer == null) { answer = new Breadcrumbs(name, maxCount); } answer.previous_session = answer.current_session; answer.current_session = new List <Breadcrumb>(); if (name == "UserBreadcrumbs") { Dictionary <string, Object> data = new Dictionary <string, Object>(); data["text"] = "session_start"; data["level"] = (int)BreadcrumbTextType.Normal; answer.current_session.Add(new Breadcrumb(BreadcrumbType.Text, data)); } } catch (Exception ie) { Crittercism.LogInternalException(ie); }; return(answer); }
private void handledUnthrownExceptionClick(object sender, RoutedEventArgs e) { Exception exception = new Exception("description"); exception.Data.Add("MethodName", "methodName"); Crittercism.LogHandledException(exception); }
private static void Vote() { string username = Crittercism.Username(); if (username == null) { username = "******"; } string response = ""; Console.WriteLine("Do you love Crittercism?"); Console.Write(">"); string result = Console.ReadLine(); if (result.Length == 0) { result = "y"; } switch (Char.ToLower(result[0])) { case 'n': response = "doesn't love Crittercism."; break; default: response = "loves Crittercism."; break; } string breadcrumb = username + " " + response; Console.WriteLine("LeaveBreadcrumb: \"" + breadcrumb + "\""); Crittercism.LeaveBreadcrumb(breadcrumb); }
public void TestMaxUserflowCount() { for (int i = 0; i < 2 * UserflowReporter.MAX_USERFLOW_COUNT; i++) { Crittercism.BeginUserflow(i.ToString()); } Object[] loggedUserflows = UserflowReporter.AllUserflows(); Assert.AreEqual(UserflowReporter.UserflowCount(), UserflowReporter.MAX_USERFLOW_COUNT, String.Format("Expecting userflowCount : {0} to be the maximum count : {1} .", UserflowReporter.UserflowCount(), UserflowReporter.MAX_USERFLOW_COUNT)); Assert.AreEqual(UserflowReporter.UserflowCount(), loggedUserflows.Length, String.Format("Expecting userflowCount : {0} to be the # of userflows : {1} .", UserflowReporter.UserflowCount(), loggedUserflows.Length)); foreach (Userflow userflow in loggedUserflows) { int index = Int32.Parse(userflow.Name()); Assert.IsTrue(((index >= 0) && (index < UserflowReporter.MAX_USERFLOW_COUNT)), String.Format("Expecting userflow name to be an expected value between 0 and" + "MAX_USERFLOW_COUNT ({0}), name was {1}", UserflowReporter.MAX_USERFLOW_COUNT, index)); } }
private void setUsernameClick(object sender, RoutedEventArgs e) { string[] names = { "Blue Jay", "Chinchilla", "Chipmunk", "Gerbil", "Hamster", "Parrot", "Robin", "Squirrel", "Turtle" }; string name = names[random.Next(0, names.Length)]; Crittercism.SetUsername("Critter " + name); }
private static void CommandLogNetworkRequest(string arg) { Random random = new Random(); string[] methods = new string[] { "GET", "POST", "HEAD", "PUT" }; string method = methods[random.Next(0, methods.Length)]; string urlString = ""; if (!arg.Equals("")) { urlString = urls[random.Next(0, urls.Length)] + "?arg=" + WebUtility.UrlEncode(arg); } else if (random.Next(0, 2) == 1) { urlString = randomURLString(); } ; // latency in milliseconds long latency = (long)Math.Floor(4000.0 * random.NextDouble()); long bytesRead = random.Next(0, 10000); long bytesSent = random.Next(0, 10000); long responseCode = 200; if (random.Next(0, 5) == 0) { // Some common response other than 200 == OK . long[] responseCodes = new long[] { 301, 308, 400, 401, 402, 403, 404, 405, 408, 500, 502, 503 }; responseCode = responseCodes[random.Next(0, responseCodes.Length)]; } ; WebExceptionStatus exceptionStatus = WebExceptionStatus.Success; if (random.Next(0, 5) == 0) { // Simulate a network WebException was encountered. WebExceptionStatus[] exceptionStatuses = new WebExceptionStatus[] { WebExceptionStatus.NameResolutionFailure, WebExceptionStatus.ConnectFailure, WebExceptionStatus.ReceiveFailure, WebExceptionStatus.SendFailure, WebExceptionStatus.ConnectionClosed, WebExceptionStatus.TrustFailure, WebExceptionStatus.KeepAliveFailure, WebExceptionStatus.Timeout }; exceptionStatus = exceptionStatuses[random.Next(0, exceptionStatuses.Length)]; // We didn't receive a simulated response, after all. responseCode = 0; } ; Crittercism.LogNetworkRequest( method, urlString, latency, bytesRead, bytesSent, (HttpStatusCode)responseCode, WebExceptionStatus.Success); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Crittercism.Init("537a4e738039805d82000002"); (new MainWindow()).Show(); Application.Run(); }
public static void LogUnhandledException() { try { TestHelpers.ThrowException(); } catch (Exception ex) { Crittercism.LogUnhandledException(ex); } }
private void Application_Startup(object sender, StartupEventArgs e) { //// Call the Init of the unhandled managed class library "Crittercism" Crittercism.Init("YOUR APP ID GOES HERE"); //CRFilter filter=CRFilter.FilterWithString("doYouLoveCrittercism"); //Crittercism.AddFilter(filter); Crittercism.LeaveBreadcrumb("Application_Startup"); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Crittercism.Init("YOUR APP ID GOES HERE"); (new Form1()).Show(); Application.Run(); }
partial void HandledExceptionButton_TouchUpInside(UIButton sender) { try { throw new Exception("Custom exception"); } catch (Exception e) { Crittercism.LogHandledException(e); } }
private static void CommandSetUsername(string arg) { if (arg.Length == 0) { arg = "MrsCritter"; } Console.WriteLine("SetUsername: \"" + arg + "\""); Crittercism.SetUsername(arg); }
private void model_PartChanged(int slotIndex, int partIndex, AvatarModel.Part oldPart, AvatarModel.Part newPart) { string arg = Model.Definition.Slots[slotIndex].Name; string arg2 = AvatarDefinition.PartTypeStrings[partIndex]; string key = $"{base.gameObject.name}.{arg}.{arg2}"; string value = ((newPart != null && newPart.Equipment != null) ? newPart.Equipment.Name : string.Empty); Crittercism.SetValue(key, value); }
private void Application_Startup(object sender, StartupEventArgs e) { //// Call the Init of the unhandled managed class library "Crittercism" Crittercism.Init("537a4e738039805d82000002"); //CRFilter filter=CRFilter.FilterWithString("doYouLoveCrittercism"); //Crittercism.AddFilter(filter); Crittercism.LeaveBreadcrumb("Application_Startup"); Crittercism.UserflowTimeOut += UserflowTimeOutHandler; }
private bool SendRequest(MessageReport messageReport) { //////////////////////////////////////////////////////////////// // NOTE: sendCompleted is reported as "true" if we get back // an HTTP status code from the platform web server. It is // independent of whether or not the HTTP status code is an // HTTP status code we like. Therefore, a 500 internal server // error WILL count as sendCompleted == "true" . OTOH, if // there is no network connectivity at all (e.g. airplane mode // or out of network coverage), there is no HTTP status code, // only some WebException . We will report "false" in that case // and schedule a future retry. //////////////////////////////////////////////////////////////// //Debug.WriteLine("SendRequest: " + messageReport.GetType().Name); bool sendCompleted = true; Debug.WriteLine("SendRequest: ENTER"); try { HttpWebRequest request = messageReport.WebRequest(); if (request != null) { string postBody = messageReport.PostBody(); ManualResetEvent resetEvent = new ManualResetEvent(false); request.BeginGetRequestStream( (result) => { //Debug.WriteLine("SendRequest: BeginGetRequestStream"); try { using (Stream stream = request.EndGetRequestStream(result)) { SendRequestWritePostBody(stream, postBody); } request.BeginGetResponse( (asyncResponse) => { sendCompleted = DidReceiveResult(messageReport, request, asyncResponse); resetEvent.Set(); }, null); } catch { resetEvent.Set(); } }, null); { #if DEBUG Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); #endif resetEvent.WaitOne(); #if DEBUG stopWatch.Stop(); Debug.WriteLine("SendRequest: TOTAL SECONDS == " + stopWatch.Elapsed.TotalSeconds); #endif } } } catch (Exception ie) { Crittercism.LogInternalException(ie); } Debug.WriteLine("SendRequest: EXIT ---> " + sendCompleted); return(sendCompleted); }
private static void CommandBreadcrumb(string arg) { if (arg.Length == 0) { arg = "My Breadcrumb"; } Console.WriteLine("LeaveBreadcrumb: \"" + arg + "\""); Crittercism.LeaveBreadcrumb(arg); }