예제 #1
0
        public JsonResult getWeather(decimal latitude, decimal longitude, string dateCaught, string timeCaught)
        {
            //  https://developer.forecast.io/docs/v2  <-- Weather API Documentation

            DateTime imageDateTime = new DateTime();

            try
            {
                //convert date and time strings
                imageDateTime = Convert.ToDateTime(dateCaught + ' ' + timeCaught);
            }
            catch (Exception ex)
            {
                ErrorLoggingClass errorLog = new ErrorLoggingClass();
                errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "FishController", "getWeather", User.Identity.Name, "dateCaught:" + dateCaught + ", timeCaught:" + timeCaught);
                return(Json(false));
            }

            float lat = (float)latitude;
            float lng = (float)longitude;

            ForecastIORequest request = new ForecastIORequest(_forecastIO_API_Key, lat, lng, imageDateTime, Unit.us, null);
            var response = request.Get();

            FishModels.FishWeather fw = new FishModels.FishWeather();
            fw.current = response.currently;
            fw.daily   = response.daily;
            fw.hourly  = response.hourly;

            //save response to session
            Session["FishWeather"] = fw;

            var result = new {
                temp      = fw.current.temperature,
                feelsLike = fw.current.apparentTemperature,
                icon      = fw.current.icon,
                summary   = fw.current.summary,
                windSpd   = fw.current.windSpeed,
                windDir   = convertBearingToDirection(fw.current.windBearing),
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public Models.FishModels.AmazonS3Url UploadToS3(MemoryStream stream, string testName)
        {
            try
            {
                string   userID   = getUserID();
                int      anglerID = dbClass.GetAnglerID();
                MiniGuid g        = MiniGuid.NewGuid();

                string objectKey = string.Format("imgs/{0}/{1}.jpg", anglerID.ToString(), g);

                PutObjectResponse response = new PutObjectResponse();

                // Create S3 service client.
                using (IAmazonS3 s3Client = new AmazonS3Client(RegionEndpoint.USEast1))
                {
                    // Setup request for putting an object in S3.
                    PutObjectRequest request = new PutObjectRequest
                    {
                        BucketName  = _awsBucketName,
                        Key         = objectKey,
                        InputStream = stream      //SEND THE FILE STREAM
                    };

                    //todo: change this expiration stuff to a few months. Not sure if changing it here is enough, forgot how the caching stuff worked.
                    request.Headers.Expires      = new DateTime(2020, 1, 1); //.. this shouldnt be a set date anyway...
                    request.Headers.CacheControl = "max-age=77760000";       //..this might be the one that sets time
                    //request.Headers["expires"] = "Thu, 01 Dec 1994 16:00:00 GMT";

                    response = s3Client.PutObject(request);   // Make service call and get back the response.
                }

                FishModels.AmazonS3Url s3UrlObject = new Models.FishModels.AmazonS3Url();
                s3UrlObject = dbClass.GeneratePreSignedURL(objectKey);
                return(s3UrlObject);
            }
            catch (Exception ex)
            {
                ErrorLoggingClass errorLog = new ErrorLoggingClass();
                errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "Upload Image", "FishController", "UploadToS3", User.Identity.Name, "");
                return(null);
            }
        }
예제 #3
0
        public JsonResult DeleteImageFromS3(string objectKey)
        {
            try
            {
                AmazonS3Client      s3Client = new AmazonS3Client();
                DeleteObjectRequest request  = new DeleteObjectRequest();

                request.BucketName = _awsBucketName;
                request.Key        = objectKey;

                s3Client.DeleteObject(request);
                s3Client.Dispose();

                return(Json(true));
            }
            catch (Exception ex) {
                ErrorLoggingClass errorLog = new ErrorLoggingClass();
                errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "FishController", "DeleteImageFromS3", User.Identity.Name, null);
                return(Json(false));
            }
        }