public bool UpdateTabletStatus(int HitchBotID, string timeTaken, bool isPluggedIn, double BatteryVoltage, double BatteryPercent, double BatteryTemp) { DateTime TimeTaken = DateTime.ParseExact(timeTaken, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); using (var db = new Models.Database()) { var hitchbot = db.hitchBOTs.First(h => h.ID == HitchBotID); var TabletStatus = new Models.TabletStatus() { TimeAdded = DateTime.UtcNow, TimeTaken = TimeTaken, BatteryTemp = BatteryTemp, BatteryPercentage = BatteryPercent, BatteryVoltage = BatteryVoltage, IsCharging = isPluggedIn, HitchBOT = hitchbot }; db.TabletStatusI.Add(TabletStatus); db.SaveChanges(); } return true; }
public async Task<string> checkFollowers(int HitchBotID) { var twitterCtx = Helpers.TwitterHelper.GetContext(HitchBotID); using (var db = new Models.Database()) { var TwitterAccount = db.TwitterAccounts.First(ta => ta.HitchBot.ID == HitchBotID); string UserID = TwitterAccount.UserID; var friendship = await (from friend in twitterCtx.Friendship where friend.Type == FriendshipType.FollowersList && friend.UserID == UserID select friend).SingleOrDefaultAsync(); var twitterFriends = db.TwitterFriends.Where(tf => tf.TwitterAccount.ID == TwitterAccount.ID); foreach (LinqToTwitter.User myUser in friendship.Users) { string tempUserID = myUser.UserIDResponse.ToString(); if (!twitterFriends.Any(tu => tu.UserID == tempUserID)) { User x = await twitterCtx.CreateFriendshipAsync(myUser.ScreenNameResponse, true); db.TwitterFriends.Add( new Models.TwitterFriend() { UserID = myUser.UserIDResponse.ToString(), ScreenName = myUser.ScreenNameResponse, TwitterAccount = TwitterAccount, TimeAdded = DateTime.UtcNow, TimeFollowed = DateTime.UtcNow }); } } db.SaveChanges(); return "Success"; } }
public bool AcceptImage(int ImageAcceptID) { using (var db = new Models.Database()) { var img = db.Images.First(i => i.ID == ImageAcceptID); img.TimeApproved = DateTime.UtcNow; db.SaveChanges(); } return true; }
public bool EndProject(int toEndID) { using (var db = new Models.Database()) { var projectToEnd = db.Projects.First(p => p.ID == toEndID); projectToEnd.EndTime = DateTime.UtcNow; db.SaveChanges(); return true; } }
public bool StartProject(string Name, string Description, DateTime StartTime) { using (var db = new Models.Database()) { var newProject = new Models.Project(); newProject.Name = Name; newProject.Description = Description; newProject.StartTime = StartTime; newProject.TimeAdded = DateTime.UtcNow; db.Projects.Add(newProject); db.SaveChanges(); } return true; }
public bool AddHitchBotToProject(int ProjectID, string HitchbotName, DateTime Creation) { using (var db = new Models.Database()) { var project = db.Projects.First(p => p.ID == ProjectID); var newHitchBot = new Models.hitchBOT { CreationTime = Creation, TimeAdded = DateTime.UtcNow, Name = HitchbotName }; project.hitchBOTs.Add(newHitchBot); db.SaveChanges(); } return true; }
public bool AddSpeech(int HitchBotID, string SpeechSaid, string TimeTaken) { using (var db = new Models.Database()) { var speechEvent = new Models.SpeechEvent(); speechEvent.TimeAdded = DateTime.UtcNow; speechEvent.SpeechSaid = SpeechSaid; speechEvent.OccuredTime = DateTime.ParseExact(TimeTaken, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); var hitchbot = db.hitchBOTs.Include(h => h.Conversations).First(h => h.ID == HitchBotID); speechEvent.Conversation = hitchbot.CurrentConversation; db.SpeechEvents.Add(speechEvent); db.SaveChanges(); hitchbot.Conversations.OrderBy(l => l.StartTime).Last().SpeechEvents.Add(speechEvent); db.SaveChanges(); return true; } }
public bool AddException(int HitchBotID, string Message, string TimeOccured) { using (var db = new Models.Database()) { DateTime RealTimeOccured = DateTime.ParseExact(TimeOccured, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); var hitchBOT = db.hitchBOTs.First(h => h.ID == HitchBotID); var exception = new Models.ExceptionLog() { Message = Message.Replace("%20", " "), TimeOccured = RealTimeOccured, HitchBOT = hitchBOT, TimeAdded = DateTime.UtcNow }; db.Exceptions.Add(exception); db.SaveChanges(); } return true; }
public HttpResponseMessage StartNewConversation(int HitchBotID, string StartTime, bool adsaa = true) { try { DateTime StartTimeReal = DateTime.ParseExact(StartTime, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); using (var db = new Models.Database()) { var hitchbot = db.hitchBOTs.Include(l => l.Locations).Include(h => h.Conversations).FirstOrDefault(h => h.ID == HitchBotID); if (hitchbot == null) { string message = string.Format("HitchBOT with id = {0} not found", HitchBotID); HttpError error = new HttpError(message); return Request.CreateErrorResponse(HttpStatusCode.NotFound, error); } if (DateTime.UtcNow - (hitchbot.Conversations.LastOrDefault() ?? (new Models.Conversation { StartTime = DateTime.UtcNow.Subtract(new TimeSpan(5)) })).StartTime > TimeSpan.FromHours(3)) { var location = hitchbot.Locations.OrderBy(l => l.TakenTime).FirstOrDefault(); var newConversation = new Models.Conversation() { StartTime = StartTimeReal, TimeAdded = DateTime.UtcNow, StartLocation = location, HitchBOT = hitchbot }; db.Conversations.Add(newConversation); db.SaveChanges(); } return Request.CreateResponse(HttpStatusCode.OK, true); } } catch (FormatException) { string message = string.Format("{0} is not a valid DateTime. Please use format yyyyMMddHHmmss", StartTime); HttpError error = new HttpError(message); return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error); } }
public static async Task<int> PostTweetWithLocation(int HitchBotID, int LocationID, string TweetText) { using (var db = new Models.Database()) { var Location = db.Locations.First(l => l.ID == LocationID); try { string UserID; var twitterContext = GetContext(HitchBotID, out UserID); Status response = await twitterContext.TweetAsync(TweetText, (decimal)Location.Latitude, (decimal)Location.Longitude, true); if (string.IsNullOrEmpty(Location.NearestCity)) Location.NearestCity = response.Place.FullName; db.SaveChanges(); return AddTweetToDatabase(UserID, response); } //catch (TwitterQueryException e) //{ // return e.ToString(); //} //catch (InvalidOperationException e) //{ // return e.ToString(); //} //catch (System.Data.SqlClient.SqlException e) //{ // return e.ToString(); //} //catch (System.NotSupportedException e) //{ // return e.ToString(); //} catch (Exception e) { } } return 0; }
public bool AddImage(int HitchBotID, int locationID, string timeTaken, string URL) { DateTime TimeTaken = DateTime.ParseExact(timeTaken, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); using (var db = new Models.Database()) { var hitchBOT = db.hitchBOTs.First(l => l.ID == HitchBotID); var location = db.Locations.First(l => l.ID == locationID); var image = new Models.Image() { Location = location, HitchBOT = hitchBOT, url = URL, TimeAdded = DateTime.UtcNow, TimeTaken = TimeTaken }; db.Images.Add(image); db.SaveChanges(); } return true; }
public static async Task<int> PostTweetText(int HitchBotID, string TweetText) { using (var db = new Models.Database()) { try { string UserID; var twitterContext = GetContext(HitchBotID, out UserID); Status response = await twitterContext.TweetAsync(TweetText); db.SaveChanges(); return AddTweetToDatabase(UserID, response); } //catch (TwitterQueryException e) //{ // return e.ToString(); //} //catch (InvalidOperationException e) //{ // return e.ToString(); //} //catch (System.Data.SqlClient.SqlException e) //{ // return e.ToString(); //} //catch (System.NotSupportedException e) //{ // return e.ToString(); //} catch (Exception e) { } } return 0; }
public async Task<HttpResponseMessage> AddSpeechListen(int HitchBotID, string SpeechSaid, string SpeechHeard, string TimeTaken, string Person, string Notes, string MatchedLineLabel, int? MatchAccuracy = null, string RmsDecibelLevel = "", int? EnvironmentType = null, int? GoogleRecognitionScore = null, int? RecognitionScore = null, int? ResponseScore = null, int? RecognizerEnum = null) { using (var db = new Models.Database()) { var OccuredTime = DateTime.ParseExact(TimeTaken, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); var speechEvent = new Models.SpeechLogEvent() { HitchBOTID = HitchBotID, Notes = Notes, Person = Person, SpeechHeard = SpeechHeard, SpeechSaid = SpeechSaid, TimeOccured = OccuredTime, TimeAdded = DateTime.UtcNow, EnvironmentType = EnvironmentType, MatchAccuracy = MatchAccuracy, MatchedLineLabel = MatchedLineLabel, RecognitionScore = RecognitionScore, GoogleRecognitionScore = GoogleRecognitionScore, ResponseScore = ResponseScore, RecognizerType = (RecognizerType)(RecognizerEnum ?? 0) }; if (!string.IsNullOrWhiteSpace(RmsDecibelLevel)) { double tempRMS; if (double.TryParse(RmsDecibelLevel, out tempRMS)) speechEvent.RmsDecibalLevel = tempRMS; } db.SpeechLogEvents.Add(speechEvent); db.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, true); } }
public static int AddTweetToDatabase(string UserID, Status newStatus) { using (var db = new Models.Database()) { var TwitterStatus = new Models.TwitterStatus() { TwitterAccount = db.TwitterAccounts.First(ta => ta.UserID == UserID), TweetID = newStatus.StatusID.ToString(), Text = newStatus.Text, TimeTweeted = newStatus.CreatedAt, TimeAdded = DateTime.UtcNow }; db.TwitterStatuses.Add(TwitterStatus); db.SaveChanges(); return TwitterStatus.ID; } }