Пример #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var db = new Models.Database())
            {
                string userName = this.userName.Text;
                var user = db.Passwords.Include(p => p.hitchBOT).Include(p => p.Projects).FirstOrDefault(p => p.Username == userName);

                if (user == null)
                {
                    //lblError.Text = "Username not found!";
                    this.errorAlert.Attributes.Remove("class");
                    this.errorAlert.Attributes.Add("class", "alert alert-danger");
                    this.errorAlert.InnerText = "Username not found!";
                }
                else
                {
                    if (user.Hash == Models.PasswordHandler.GetHash(passWord.Text))
                    {
                        Session["New"] = user;
                        Response.Redirect("LandingPage.aspx");
                    }
                    else
                    {
                        //lblError.Text = "Incorrect PW";
                        this.errorAlert.Attributes.Remove("class");
                        this.errorAlert.Attributes.Add("class", "alert alert-danger");
                        this.errorAlert.InnerText = "Incorrect PW";
                    }
                }
            }
        }
Пример #2
0
 public List<Models.Location> GetAllLocationsInOrder(int HitchBotLocationsID)
 {
     using (var db = new Models.Database())
     {
         return db.hitchBOTs.First(h => h.ID == HitchBotLocationsID).Locations.OrderBy(l => l.TakenTime).ToList();
     }
 }
Пример #3
0
        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";
            }
        }
Пример #4
0
        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;
        }
Пример #5
0
 public Models.Project GetProjectByID(int ID)
 {
     using (var db = new Models.Database())
     {
         return db.Projects.Where(p => p.ID == ID).Include(p => p.EndLocation).Include(p => p.StartLocation).FirstOrDefault();
     }
 }
Пример #6
0
 public List<Models.Project> GetCurrentProjects()
 {
     using (var db = new Models.Database())
     {
         return db.Projects.Where(p => p.EndTime == null).Include(p => p.EndLocation).Include(p => p.StartLocation).ToList();
     }
 }
Пример #7
0
 public Models.hitchBOT GetHitchbot(int ID)
 {
     using (var db = new Models.Database())
     {
         var hw = db.hitchBOTs.First(h => h.ID == ID);
         return hw;
     }
 }
Пример #8
0
 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;
 }
Пример #9
0
 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;
     }
 }
Пример #10
0
        public static async Task<int> PostTweetWithLocationAndWeather(int HitchBotID, int LocationID)
        {
            string URL;
            using (var db = new Models.Database())
            {
                var location = db.Locations.First(l => l.ID == LocationID);
                URL = "http://api.openweathermap.org/data/2.5/weather?lat=" + location.Latitude + "&lon=" + location.Longitude;
                dynamic weather = Helpers.WebHelper.GetJSON(Helpers.WebHelper.GetRequest(URL));
                Models.Database_Excluded.Weather WeatherEvent = new Models.Database_Excluded.Weather(weather, location.NearestCity);

                return await PostTweetWithLocation(HitchBotID, LocationID, CleverScriptHelper.GetWeatherTweet(WeatherEvent, HitchBotID));
            }
        }
Пример #11
0
 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;
 }
Пример #12
0
 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;
 }
Пример #13
0
        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;
            }
        }
Пример #14
0
        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;
        }
Пример #15
0
        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);
            }
        }
Пример #16
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["New"] != null)
     {
         var user = (Models.Password)Session["New"];
         using (var db = new Models.Database())
         {
             int hitchBOTid = user.hitchBOT.ID;
             var img = db.Images.Include(i => i.HitchBOT).Where(i => i.HitchBOT.ID == hitchBOTid && (i.TimeApproved == null || i.TimeDenied == null)).OrderBy(i => i.TimeTaken);
             if (string.IsNullOrEmpty(this.imagePreview.ImageUrl))
             {
                 this.imagePreview.ImageUrl = "http://imgur.com/" + img.FirstOrDefault().url + ".jpg";
                 this.imgurLink.NavigateUrl = "http://imgur.com/" + img.FirstOrDefault().url;
             }
         }
     }
     else
     {
         Response.Redirect("Unauthorized.aspx");
     }
 }
Пример #17
0
        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;
        }
Пример #18
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;
        }
Пример #19
0
        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;
        }
Пример #20
0
        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;
            }
        }
Пример #21
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);
            }
        }
Пример #22
0
 public static TwitterContext GetContext(int HitchBotID, out string UserID)
 {
     using (var db = new Models.Database())
     {
         return new TwitterContext(GetAuthorization(db.TwitterAccounts.First(ta => ta.HitchBot.ID == HitchBotID), out UserID));
     }
 }
Пример #23
0
 public Models.Location GetMostRecentLocation(int HitchBotID)
 {
     //makes the assumption that the TakenTime is correct from the HitchBot. This will most likely be correct as the Tablets should get the time from cell networks.
     using (var db = new Models.Database())
     {
         return db.hitchBOTs.Where(h => h.ID == HitchBotID).Include(l => l.Locations).FirstOrDefault().Locations.OrderByDescending(l => l.TakenTime).First();
     }
 }
Пример #24
0
 public static SingleUserAuthorizer GetAuthorization(Models.TwitterAccount TwitterAccount, out string UserID)
 {
     UserID = TwitterAccount.UserID;
     using (var db = new Models.Database())
     {
         return new SingleUserAuthorizer()
         {
             CredentialStore = new SingleUserInMemoryCredentialStore
             {
                 ConsumerKey = TwitterAccount.consumerKey,
                 ConsumerSecret = TwitterAccount.consumerSecret,
                 AccessToken = TwitterAccount.accessToken,
                 AccessTokenSecret = TwitterAccount.accessTokenSecret
             }
         };
     }
 }