/// <summary> /// Converts a zipped, binary format of IOsbideEvent back into object form /// </summary> /// <param name="data"></param> /// <returns></returns> public static IOsbideEvent FromZippedBinary(byte[] data, SerializationBinder binder = null) { MemoryStream zippedStream = new MemoryStream(data); MemoryStream rawStream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); string FileName = ""; //unzip the memory stream using (ZipFile zip = ZipFile.Read(zippedStream)) { if (zip.Entries.Count == 1) { ZipEntry entry = zip.Entries.ElementAt(0); FileName = entry.FileName; entry.Extract(rawStream); rawStream.Position = 0; } else { throw new Exception("Expecting a zip file with exactly one item."); } } if (binder != null) { formatter.Binder = binder; } //figure out what needs to be deserialized IOsbideEvent evt = (IOsbideEvent)formatter.Deserialize(rawStream); return(evt); }
public EventLog(IOsbideEvent evt) : this() { DateReceived = DateTime.UtcNow; LogType = evt.EventName; Data = new EventLogData() { LogId = this.Id, BinaryData = EventFactory.ToZippedBinary(evt) }; }
public override void SubmitEventRequested(object sender, SubmitEventArgs e) { base.SubmitEventRequested(sender, e); IOsbideEvent evt = e.Event; evt.EventDate = DateTime.UtcNow; evt.SolutionName = dte.Solution.FullName; //send off to the service client NotifyEventCreated(this, new EventCreatedArgs(evt)); }
public EventLog(IOsbideEvent evt, OsbideUser sender) : this(evt) { //were we sent a null user? if (sender.FirstName == null && sender.LastName == null) { //replace with a generic user sender = OsbideUser.GenericUser(); } Sender = sender; if (sender.Id != 0) { SenderId = sender.Id; } }
/// <summary> /// Converts the supplied IOsbideEvent into a zipped, binary format /// </summary> /// <param name="evt"></param> /// <returns></returns> public static byte[] ToZippedBinary(IOsbideEvent evt) { MemoryStream memStream = new MemoryStream(); MemoryStream zipStream = new MemoryStream(); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(memStream, evt); //go back to position zero so that the zip file can read the memory stream memStream.Position = 0; //zip up to save space using (ZipFile zip = new ZipFile()) { ZipEntry entry = zip.AddEntry(evt.EventName, memStream); zip.Save(zipStream); zipStream.Position = 0; } return(zipStream.ToArray()); }
public override void GenericCommand_AfterCommandExecute(string Guid, int ID, object CustomIn, object CustomOut) { base.GenericCommand_AfterCommandExecute(Guid, ID, CustomIn, CustomOut); Command cmd = GetCommand(Guid, ID); string commandName = ""; if (cmd != null) { commandName = cmd.Name; //Speed up the process by always ignoring boring commands if (boringCommands.Contains(commandName) == false) { IOsbideEvent oEvent = EventFactory.FromCommand(commandName, dte); //protect against the off-chance that we'll get a null return value if (oEvent != null) { //let others know that we have created a new event NotifyEventCreated(this, new EventCreatedArgs(oEvent)); } } } }
public EventLog SubmitLog(EventLog log, OsbideUser user) { LocalErrorLog errorLogger = new LocalErrorLog(); errorLogger.SenderId = user.Id; errorLogger.Content = "About to save log " + log.LogType + " to DB. "; errorLogger.LogDate = DateTime.Now; log.Sender = null; log.SenderId = user.Id; log.DateReceived = DateTime.UtcNow; log.EventTypeId = Convert.ToInt32(Enum.Parse(typeof(EventTypes), log.LogType)); //insert into the DB Db.EventLogs.Add(log); try { Db.SaveChanges(); errorLogger.Content += "Item saved. "; } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { errorLogger.Content += "Error saving: "; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); errorLogger.Content += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } Db.LocalErrorLogs.Add(errorLogger); Db.SaveChanges(); return(null); } catch (Exception ex) { errorLogger.Content += "Error saving: " + ex.Message; System.Diagnostics.Trace.TraceInformation(ex.Message); Db.LocalErrorLogs.Add(errorLogger); Db.SaveChanges(); return(null); } //Tease apart log information and insert into the appropriate DB table IOsbideEvent evt = null; try { errorLogger.Content += "About to unzip event."; evt = EventFactory.FromZippedBinary(log.Data.BinaryData, new OsbideDeserializationBinder()); evt.EventLogId = log.Id; } catch (Exception) { errorLogger.Content += "Error unzipping event."; Db.LocalErrorLogs.Add(errorLogger); Db.SaveChanges(); return(null); } var hashtags = string.Empty; var usertags = string.Empty; if (log.LogType == AskForHelpEvent.Name) { Db.AskForHelpEvents.Add((AskForHelpEvent)evt); AskForHelpEvent ask = evt as AskForHelpEvent; //send email to interested parties //find all of this user's subscribers and send them an email List <OsbideUser> observers = new List <OsbideUser>(); observers = (from subscription in Db.UserSubscriptions join dbUser in Db.Users on new { InstitutionId = subscription.ObserverInstitutionId, SchoolId = subscription.ObserverSchoolId } equals new { InstitutionId = user.InstitutionId, SchoolId = user.SchoolId } where subscription.SubjectSchoolId == user.SchoolId && subscription.SubjectInstitutionId == user.InstitutionId && dbUser.ReceiveEmailOnNewFeedPost == true select dbUser).ToList(); if (observers.Count > 0) { string url = StringConstants.GetActivityFeedDetailsUrl(log.Id); string body = "Greetings,<br />{0} asked for help regarding the following item:<br />\"{1}\"<br />To view this " + "conversation online, please visit {2} or visit your OSBIDE user profile.<br /><br />Thanks,<br />OSBIDE<br /><br />" + "These automated messages can be turned off by editing your user profile."; body = string.Format(body, user.FirstAndLastName, ask.UserComment, url); List <MailAddress> to = new List <MailAddress>(); foreach (OsbideUser observer in observers) { to.Add(new MailAddress(observer.Email)); } Email.Send("[OSBIDE] Someone has asked for help!", body, to); } } else if (log.LogType == BuildEvent.Name) { BuildEvent build = (BuildEvent)evt; Db.BuildEvents.Add(build); string pattern = "error ([^:]+)"; //strip out non-critical errors List <BuildEventErrorListItem> errorItems = build.ErrorItems.Where(e => e.ErrorListItem.CriticalErrorName.Length > 0).ToList(); build.ErrorItems.Clear(); build.ErrorItems = errorItems; //log all errors in their own DB for faster search List <string> errors = new List <string>(); Dictionary <string, ErrorType> errorTypes = new Dictionary <string, ErrorType>(); foreach (BuildEventErrorListItem item in build.ErrorItems) { Match match = Regex.Match(item.ErrorListItem.Description, pattern); //ignore bad matches if (match.Groups.Count == 2) { string errorCode = match.Groups[1].Value.ToLower().Trim(); ErrorType type = Db.ErrorTypes.Where(t => t.Name == errorCode).FirstOrDefault(); if (type == null) { if (errorTypes.ContainsKey(errorCode) == false) { type = new ErrorType() { Name = errorCode }; Db.ErrorTypes.Add(type); } else { type = errorTypes[errorCode]; } } if (errorCode.Length > 0 && errors.Contains(errorCode) == false) { errors.Add(errorCode); } errorTypes[errorCode] = type; } } Db.SaveChanges(); foreach (string errorType in errors) { Db.BuildErrors.Add(new BuildError() { BuildErrorTypeId = errorTypes[errorType].Id, LogId = log.Id }); } } else if (log.LogType == CutCopyPasteEvent.Name) { Db.CutCopyPasteEvents.Add((CutCopyPasteEvent)evt); } else if (log.LogType == DebugEvent.Name) { Db.DebugEvents.Add((DebugEvent)evt); } else if (log.LogType == EditorActivityEvent.Name) { Db.EditorActivityEvents.Add((EditorActivityEvent)evt); } else if (log.LogType == ExceptionEvent.Name) { Db.ExceptionEvents.Add((ExceptionEvent)evt); } else if (log.LogType == FeedPostEvent.Name) { hashtags = string.Join(",", ParseHashtags(((FeedPostEvent)evt).Comment)); usertags = string.Join(",", ParseUserTags(((FeedPostEvent)evt).Comment)); Db.FeedPostEvents.Add((FeedPostEvent)evt); } else if (log.LogType == HelpfulMarkGivenEvent.Name) { Db.HelpfulMarkGivenEvents.Add((HelpfulMarkGivenEvent)evt); } else if (log.LogType == LogCommentEvent.Name) { Db.LogCommentEvents.Add((LogCommentEvent)evt); } else if (log.LogType == SaveEvent.Name) { Db.SaveEvents.Add((SaveEvent)evt); } else if (log.LogType == SubmitEvent.Name) { errorLogger.Content += "Submit event detected. "; Db.SubmitEvents.Add((SubmitEvent)evt); } try { errorLogger.Content += "Attempting to save to DB. "; Db.SaveChanges(); /* * if(hashtags.Length >= 0 || usertags.Length >= 0 ) * * using (var context = new OsbideProcs()) * { * context.InsertPostTags(log.Id, usertags, hashtags); * } * */ } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { errorLogger.Content += "Error saving to DB: "; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); errorLogger.Content += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); Db.LocalErrorLogs.Add(errorLogger); Db.SaveChanges(); } } return(null); } catch (Exception ex) { errorLogger.Content += "Error saving to DB: " + ex.Message; Db.LocalErrorLogs.Add(errorLogger); Db.SaveChanges(); System.Diagnostics.Trace.TraceInformation(ex.Message); return(null); } //Db.LocalErrorLogs.Add(errorLogger); //Db.SaveChanges(); return(log); }
public EventCreatedArgs(IOsbideEvent osbideEvent) { OsbideEvent = osbideEvent; }
/// <summary> /// Helper method for posting a comment. Will return true if everything went OK, false otherwise /// </summary> /// <param name="logId"></param> /// <param name="comment"></param> /// <returns></returns> protected bool PostComment(string logId, string comment) { int id = -1; if (Int32.TryParse(logId, out id) == true) { //comments made on comments or mark helpful events need to be routed back to the original source IOsbideEvent checkEvent = Db.LogCommentEvents.Where(l => l.EventLogId == id).FirstOrDefault(); if (checkEvent != null) { id = (checkEvent as LogCommentEvent).SourceEventLogId; } else { checkEvent = Db.HelpfulMarkGivenEvents.Where(l => l.EventLogId == id).FirstOrDefault(); if (checkEvent != null) { id = (checkEvent as HelpfulMarkGivenEvent).LogCommentEvent.SourceEventLogId; } } LogCommentEvent logComment = new LogCommentEvent() { Content = comment, SourceEventLogId = id, SolutionName = "OSBIDE" }; OsbideWebService client = new OsbideWebService(); Authentication auth = new Authentication(); string key = auth.GetAuthenticationKey(); EventLog log = null; if (string.IsNullOrEmpty(comment) == false) { log = new EventLog(logComment, CurrentUser); log = client.SubmitLog(log, CurrentUser); } else { return(false); } logComment = Db.LogCommentEvents.Where(l => l.EventLogId == log.Id).FirstOrDefault(); //the code below performs two functions: // 1. Send interested parties email notifications // 2. Log the comment in the social activity log (displayed on an individual's profile page) //find others that have posted on this same thread List <OsbideUser> interestedParties = Db.LogCommentEvents .Where(l => l.SourceEventLogId == id) .Where(l => l.EventLog.SenderId != CurrentUser.Id) .Select(l => l.EventLog.Sender) .ToList(); //(email only) find those that are subscribed to this thread List <OsbideUser> subscribers = (from logSub in Db.EventLogSubscriptions join user in Db.Users on logSub.UserId equals user.Id where logSub.LogId == id && logSub.UserId != CurrentUser.Id && user.ReceiveNotificationEmails == true select user).ToList(); //check to see if the author wants to be notified of posts OsbideUser eventAuthor = Db.EventLogs.Where(l => l.Id == id).Select(l => l.Sender).FirstOrDefault(); //master list shared between email and social activity log Dictionary <int, OsbideUser> masterList = new Dictionary <int, OsbideUser>(); if (eventAuthor != null) { masterList.Add(eventAuthor.Id, eventAuthor); } foreach (OsbideUser user in interestedParties) { if (masterList.ContainsKey(user.Id) == false) { masterList.Add(user.Id, user); } } //add the current user for activity log tracking, but not for emails OsbideUser creator = new OsbideUser(CurrentUser); creator.ReceiveNotificationEmails = false; //force no email send on the current user if (masterList.ContainsKey(creator.Id) == true) { masterList.Remove(creator.Id); } masterList.Add(creator.Id, creator); //update social activity foreach (OsbideUser user in masterList.Values) { CommentActivityLog social = new CommentActivityLog() { TargetUserId = user.Id, LogCommentEventId = logComment.Id }; Db.CommentActivityLogs.Add(social); } Db.SaveChanges(); //form the email list SortedDictionary <int, OsbideUser> emailList = new SortedDictionary <int, OsbideUser>(); //add in interested parties from our master list foreach (OsbideUser user in masterList.Values) { if (user.ReceiveNotificationEmails == true) { if (emailList.ContainsKey(user.Id) == false) { emailList.Add(user.Id, user); } } } //add in subscribers to email list foreach (OsbideUser user in subscribers) { if (emailList.ContainsKey(user.Id) == false) { emailList.Add(user.Id, user); } } //send emails if (emailList.Count > 0) { //send email string url = StringConstants.GetActivityFeedDetailsUrl(id); string body = "Greetings,<br />{0} has commented on a post that you have previously been involved with:<br />\"{1}\"<br />To view this " + "conversation online, please visit {2} or visit your OSBIDE user profile.<br /><br />Thanks,<br />OSBIDE<br /><br />" + "These automated messages can be turned off by editing your user profile."; body = string.Format(body, logComment.EventLog.Sender.FirstAndLastName, logComment.Content, url); List <MailAddress> to = new List <MailAddress>(); foreach (OsbideUser user in emailList.Values) { to.Add(new MailAddress(user.Email)); } Email.Send("[OSBIDE] Activity Notification", body, to); } } return(true); }
public static IOsbideEvent FromCommand(string commandName, DTE2 dte) { IOsbideEvent oEvent = null; //debugging events if (debugCommands.Contains(commandName)) { DebugActions action = (DebugActions)debugCommands.IndexOf(commandName); DebugEvent debug = new DebugEvent(); debug.SolutionName = dte.Solution.FullName; debug.EventDate = DateTime.UtcNow; //sometimes document name can be null try { debug.DocumentName = dte.ActiveDocument.Name; } catch (Exception) { debug.DocumentName = dte.Solution.FullName; } //add line number if applicable if (action == DebugActions.StepInto || action == DebugActions.StepOut || action == DebugActions.StepOver ) { //line number can be null if there is no document open try { TextSelection debugSelection = dte.ActiveDocument.Selection; debugSelection.SelectLine(); int lineNumber = debugSelection.CurrentLine; debug.LineNumber = lineNumber; debug.DebugOutput = debugSelection.Text; } catch (Exception) { debug.LineNumber = 0; } } //kind of reappropriating this for our current use. Consider refactoring. debug.ExecutionAction = (int)action; //throw the content of the output window into the event if we just stopped debugging if (action == DebugActions.StopDebugging) { OutputWindowPane debugWindow = dte.ToolWindows.OutputWindow.OutputWindowPanes.Item("Debug"); if (debugWindow != null) { TextDocument text = debugWindow.TextDocument; TextSelection selection = text.Selection; selection.StartOfDocument(); selection.EndOfDocument(true); debug.DebugOutput = selection.Text; selection.EndOfDocument(); } } oEvent = debug; } else if (cutCopyPasteCommands.Contains(commandName)) { CutCopyPasteEvent ccp = new CutCopyPasteEvent(); ccp.SolutionName = dte.Solution.FullName; ccp.EventDate = DateTime.UtcNow; ccp.EventAction = cutCopyPasteCommands.IndexOf(commandName); ccp.Content = Clipboard.GetText(); //sometimes document name can be null try { ccp.DocumentName = dte.ActiveDocument.Name; } catch (Exception) { ccp.DocumentName = dte.Solution.FullName; } oEvent = ccp; } return(oEvent); }
public SubmitEventArgs(IOsbideEvent evt) { Event = evt; }
public void SubmitEvent(IOsbideEvent evt) { SubmitEventRequested(this, new SubmitEventArgs(evt)); }