Exemplo n.º 1
0
        /// <summary>
        /// 音频处理
        /// </summary>
        /// <param name="sound_path"></param>
        /// <param name="word_path"></param>
        /// <param name="language"></param>
        /// <param name="splitTime"></param>
        /// <returns></returns>
        private ApiResult SolutionAudioFile(string sound_path, string word_path, string language, double splitTime = 1.5)
        {
            ApiResult apiResult = new Models.ApiResult();

            try
            {
                Musicline2 music    = new Musicline2();
                Task       task_max = Task.Factory.StartNew(() => {
                    if (Path.GetExtension(word_path).ToLower().Contains("lrc"))
                    {
                        music.GetTimeSpanLrc(sound_path, word_path, language, splitTime);
                    }
                    else
                    {
                        music.GetTimeSpan(sound_path, word_path, language, splitTime);
                    }
                });

                Task.WaitAny(task_max);
                while (!music.isFinish)
                {
                    Thread.Sleep(10);
                }
                if (Util.isNotNull(music.results))
                {
                    apiResult.data    = new { music.results, music.originalText };
                    apiResult.success = true;
                    apiResult.message = "转换成功";
                }
                else
                {
                    apiResult.success = false;
                    apiResult.message = "转换失败";
                }
            }
            catch (Exception ex)
            {
                apiResult.success = false;
                apiResult.message = ex.Message;
            }
            return(apiResult);
        }
Exemplo n.º 2
0
        //public async Task<IActionResult> Get()
        public IActionResult Get()
        {
            //throw new InfoException("ex");

            try
            {
                //var userId = HttpContext.User.Claims.First(c => c.Type == "user_id").Value;
                //var token = await HttpContext.GetTokenAsync("access_token");
                //var jwt = new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(token);



                var list = new List <string>();

                list.Add("1");
                list.Add("2");
                list.Add("3");
                list.Add("4");
                list.Add("5");

                var result = new Models.ApiResult();
                result.Data = list;

                return(new OkObjectResult(list));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult("dasklsadkdksl"));
                //    var result = new Result()
                //    {
                //        Sev = 0,
                //        Data = ex.ToString()
                //    };

                //    return new BadRequestObjectResult(result);
            }
        }
Exemplo n.º 3
0
        public Models.ApiResult saveMessage(Message message)
        {
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            if (message == null)
            {
                result.isSuccess = false;
                result.message = "Message data is null";
                return result;
            }

            if (message.UserCreated == null)
            {
                result.isSuccess = false;
                result.message = "User created can not be null";
                return result;
            }

            if (message.DateCreated == null)
            {
                result.isSuccess = false;
                result.message = "Date Created must be included";
                return result;
            }

            // check lat/lon in range
            if (message.Latitude > 90 || message.Latitude < -90 || message.Longitude > 180 || message.Longitude < -180)
            {
                result.isSuccess = false;
                result.message = "Latitude must be between -90 and 90; Longitude must be between -180 and 180";
                return result;
            }

            if (message.Latitude.GetType() != typeof(Double) || message.Longitude.GetType() != typeof(Double))
            {
                result.isSuccess = false;
                result.message = "Latitude and Longitude must be included and of correct data type";
                return result;
            }

            try
            {
                // set DbGeography
                var sourcePoint = string.Format("POINT({0} {1})", message.Longitude.ToString().Replace(',', '.'), message.Latitude.ToString().Replace(',', '.'));
                var messageLocation = DbGeography.PointFromText(sourcePoint, 4326);
                message.MessageLocation = messageLocation;

                // Store date created/modified as UTC
                message.DateCreated = message.DateCreated.ToUniversalTime();

                db.Messages.Add(message);

                var numReturned = db.SaveChanges();
                if (numReturned == 1)
                {
                    result.isSuccess = true;
                    result.message = "Message saved successfully";
                    return result;
                }
                else
                {
                    result.isSuccess = false;
                    result.message = "Error saving message record to database";
                    return result;
                }
            }
            catch
            {
                result.isSuccess = false;
                result.message = "Error saving message record to database";
                return result;
            }
        }
Exemplo n.º 4
0
        /**** Only for seeding data
        public Models.ApiResult saveBridgeBatch(Bridge bridge)
        {
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            if (bridge == null)
            {
                result.isSuccess = false;
                result.message = "Bridge data is null";
                return result;
            }

            if (bridge.UserCreated == null)
            {
                result.isSuccess = false;
                result.message = "User created can not be null";
                return result;
            }

            // could just make it now
            if (bridge.DateCreated == null)
            {
                result.isSuccess = false;
                result.message = "Date Created must be included";
                return result;
            }

            // could just make it now
            if (bridge.DateModified == null)
            {
                result.isSuccess = false;
                result.message = "Date Modified must be included";
                return result;
            }

            // check lat/lon in range
            if (bridge.Latitude > 90 || bridge.Latitude < -90 || bridge.Longitude > 180 || bridge.Longitude < -180)
            {
                result.isSuccess = false;
                result.message = "Latitude must be between -90 and 90; Longitude must be between -180 and 180";
                return result;
            }

            if (bridge.Latitude.GetType() != typeof(Double) || bridge.Longitude.GetType() != typeof(Double))
            {
                result.isSuccess = false;
                result.message = "Latitude and Longitude must be included and of correct data type";
                return result;
            }

            bridge.NumberOfVotes = 0;    // new bridge
            bridge.isLocked = false;

            try
            {
                // set DbGeography
                var sourcePoint = string.Format("POINT({0} {1})", bridge.Longitude.ToString().Replace(',', '.'), bridge.Latitude.ToString().Replace(',', '.'));
                var bridgeLocation = DbGeography.PointFromText(sourcePoint, 4326);
                bridge.BridgeLocation = bridgeLocation;

                // Store date created/modified as UTC
                bridge.DateCreated = bridge.DateCreated.ToUniversalTime();
                bridge.DateModified = bridge.DateModified.ToUniversalTime();

                // Mark new bridge as isActive
                bridge.isActive = true;

                db.Bridges.Add(bridge);
                var numReturned = db.SaveChanges();
                if (numReturned == 1)
                {
                    result.isSuccess = true;
                    result.message = "Bridge saved successfully";
                    return result;
                }
                else
                {
                    result.isSuccess = false;
                    result.message = "Error saving bridge record to database";
                    return result;
                }
            }
            catch
            {
                result.isSuccess = false;
                result.message = "Error saving bridge record to database";
                return result;
            }
        }

        ******/
        public Models.ApiResult updateBridge(Bridge bridge)
        {
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            if (bridge == null)
            {
                result.isSuccess = false;
                result.message = "Bridge data is null";
                return result;
            }

            if (bridge.DateModified == null)
            {
                result.isSuccess = false;
                result.message = "Date Modified must be included";
                return result;
            }

            if (bridge.UserModified == null)
            {
                result.isSuccess = false;
                result.message = "User Modified must be included";
                return result;
            }

            // check lat/lon in range
            if (bridge.Latitude > 90 || bridge.Latitude < -90 || bridge.Longitude > 180 || bridge.Longitude < -180)
            {
                result.isSuccess = false;
                result.message = "Latitude must be between -90 and 90; Longitude must be between -180 and 180";
                return result;
            }

            if (bridge.Latitude.GetType() != typeof(Double) || bridge.Longitude.GetType() != typeof(Double))
            {
                result.isSuccess = false;
                result.message = "Latitude and Longitude must be included and of correct data type";
                return result;
            }

            try
            {
                var theBridge = db.Bridges.Where(b => b.Latitude <= bridge.Latitude + 0.0001 && b.Latitude >= bridge.Latitude - 0.0001 && b.Longitude <= bridge.Longitude + 0.0001 && b.Longitude >= bridge.Longitude - 0.0001 && b.isActive == true).FirstOrDefault();

                if (theBridge == null)
                {
                    result.isSuccess = false;
                    result.message = "Bridge not found";
                    return result;
                }

                // Check to see if all 3 down vote slots filled before allowing edit
                if (theBridge.User1Reason == null || theBridge.User2Reason == null || theBridge.User3Reason == null)
                {
                    result.message = "Bridge must have at least 3 down votes to be edited";
                    return result;
                }

                // Edit only one per week???????

                db.Bridges.Attach(theBridge);

                // track who made last change and when
                theBridge.DateModified = bridge.DateModified.ToUniversalTime();
                theBridge.UserModified = bridge.UserModified;

                theBridge.NumberOfVotes = 0;    // reset user input fields
                theBridge.isLocked = false;
                theBridge.User1Reason = null;
                theBridge.User1Verified = null;
                theBridge.User2Reason = null;
                theBridge.User2Verified = null;
                theBridge.User3Reason = null;
                theBridge.User3Verified = null;

                theBridge.Country = bridge.Country;  // the location - restriction fields
                theBridge.County = bridge.County;
                theBridge.FeatureCarried = bridge.FeatureCarried;
                theBridge.FeatureCrossed = bridge.FeatureCrossed;
                theBridge.Height = bridge.Height;
                theBridge.isRposted = bridge.isRposted;
                theBridge.LocationDescription = bridge.LocationDescription;
                theBridge.OtherPosting = bridge.OtherPosting;
                theBridge.State = bridge.State;
                theBridge.Township = bridge.Township;
                theBridge.WeightCombination = bridge.WeightCombination;
                theBridge.WeightDouble = bridge.WeightDouble;
                theBridge.WeightStraight_TriAxle = bridge.WeightStraight_TriAxle;
                theBridge.WeightStraight = bridge.WeightStraight;
                theBridge.Zip = bridge.Zip;

                var updateCount = db.SaveChanges();
                if (updateCount == 1)
                {
                    result.isSuccess = true;
                    result.message = "Bridge updated successfully";
                    return result;
                }
                else
                {
                    result.isSuccess = false;
                    result.message = "Error saving bridge record to database";
                    return result;
                }
            }
            catch
            {
                result.isSuccess = false;
                result.message = "Error saving bridge record to database";
                return result;
            }
        }
Exemplo n.º 5
0
        public Models.ApiResult saveBridge(Bridge bridge)
        {
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            if (bridge == null)
            {
                result.isSuccess = false;
                result.message = "Bridge data is null";
                return result;
            }

            if (bridge.UserCreated == null)
            {
                result.isSuccess = false;
                result.message = "User created can not be null";
                return result;
            }

            // could just make it now
            if (bridge.DateCreated == null)
            {
                result.isSuccess = false;
                result.message = "Date Created must be included";
                return result;
            }

            // could just make it now
            if (bridge.DateModified == null)
            {
                result.isSuccess = false;
                result.message = "Date Modified must be included";
                return result;
            }

            // check lat/lon in range
            if (bridge.Latitude > 90 || bridge.Latitude < -90 || bridge.Longitude > 180 || bridge.Longitude < -180)
            {
                result.isSuccess = false;
                result.message = "Latitude must be between -90 and 90; Longitude must be between -180 and 180";
                return result;
            }

            if (bridge.Latitude.GetType() != typeof(Double) || bridge.Longitude.GetType() != typeof(Double))
            {
                result.isSuccess = false;
                result.message = "Latitude and Longitude must be included and of correct data type";
                return result;
            }

            try
            {
                var theBridges = new List<Bridge>();
                theBridges = null;
                var isAlreadyCreated = false;
                var oneWeekAgo = DateTime.UtcNow.AddDays(-numDaysBetweenCreate);

                isAlreadyCreated = db.Bridges.Where(b => b.UserCreated == bridge.UserCreated && b.DateCreated > oneWeekAgo).ToList().Any();
                if (isAlreadyCreated)
                {
                    result.isSuccess = false;
                    result.message = "User must wait specified time between creating bridges";
                    return result;
                }
            }
            catch
            {
                result.isSuccess = false;
                result.message = "Error determining when user last created bridge. Please try again";
                return result;
            }

            bridge.NumberOfVotes = 0;    // new bridge
            bridge.isLocked = false;

            try
            {
                // set DbGeography
                var sourcePoint = string.Format("POINT({0} {1})", bridge.Longitude.ToString().Replace(',', '.'), bridge.Latitude.ToString().Replace(',', '.'));
                var bridgeLocation = DbGeography.PointFromText(sourcePoint, 4326);
                bridge.BridgeLocation = bridgeLocation;

                // Store date created/modified as UTC
                bridge.DateCreated = bridge.DateCreated.ToUniversalTime();
                bridge.DateModified = bridge.DateModified.ToUniversalTime();

                // Mark new bridge as isActive
                bridge.isActive = true;

                db.Bridges.Add(bridge);
                var numReturned = db.SaveChanges();
                if (numReturned == 1)
                {
                    result.isSuccess = true;
                    result.message = "Bridge saved successfully";
                    return result;
                }
                else
                {
                    result.isSuccess = false;
                    result.message = "Error saving bridge record to database";
                    return result;
                }
            }
            catch
            {
                result.isSuccess = false;
                result.message = "Error saving bridge record to database";
                return result;
            }
        }
Exemplo n.º 6
0
        public Models.ApiResult removeBridgeByLocation(double lat, double lon)
        {
            var bridge = new Bridge();
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            try
            {
                bridge = getBridgeByLocation(lat, lon);
                db.Bridges.Attach(bridge);

                if (bridge == null)
                {  // couldn't find bridge
                    result.message = "Bridge not found";
                    return result;
                }
                else
                {
                    // Check to see if bridge can be deleted (marked isActive assigned to false) first!!!!!!
                    if (bridge.User1Reason == null || bridge.User2Reason == null || bridge.User3Reason == null)
                    {
                        result.message = "Bridge must have at least 3 down votes to be removed";
                        return result;
                    }
                    // false == 0 == mark for delete -- true == 1 == mark for edit
                    // if at least 2/3 are marked as edit don't allow remove (only edit)
                    if (allowDelete(bridge) == false)
                    {
                        result.message = "Bridge must have at least 2 down votes of correct type to be removed";
                        return result;
                    }

                    // Delete only one per week???????

                    // Mark isActive as false for soft delete
                    bridge.isActive = false;

                    var saveOk = 1 == db.SaveChanges();
                    if (saveOk == true)
                    {
                        result.isSuccess = true;
                        result.message = "Bridge marked as inactive";
                        return result;
                    }

                    result.message = "Error removing bridge";
                    return result;
                }
            }
            catch
            {
                result.message = "Error removing bridge";
                return result;
            }
        }
Exemplo n.º 7
0
        const int numDaysBetweenCreate = 7; // allow create once a week

        #endregion Fields

        #region Methods

        public Models.ApiResult decreaseVote(int bridgeId, string userName, bool isEdit)
        {
            var theBridge = new Bridge();
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.data = null;

            if (userName == "" || userName == null)
            {
                result.isSuccess = false;
                result.message = "Username is null or empty string";
                return result;
            }

            theBridge = db.Bridges.Where(b => b.BridgeId == bridgeId && b.isActive == true).FirstOrDefault();
            if (theBridge == null)
            {
                result.isSuccess = false;
                result.message = "Bridge not found";
                return result;
            }

            // User can only down vote once
            if ((theBridge.User1Verified != null && theBridge.User1Verified == userName) ||
                (theBridge.User2Verified != null && theBridge.User2Verified == userName) ||
                (theBridge.User3Verified != null && theBridge.User3Verified == userName))
            {
                result.isSuccess = false;
                result.message = "Error: User can only down vote a bridge once";
                return result;
            }

            // Can only down vote max of 3 times
            if (theBridge.NumberOfVotes >= 3)
            {
                theBridge.NumberOfVotes = 3;
                result.isSuccess = false;
                result.message = "Error: Down vote slots full";
                return result;
            }

            // if down vote slot free grab it
            if (theBridge.User1Verified == null || theBridge.User1Verified == "")
            {
                theBridge.User1Verified = userName;
                theBridge.User1Reason = isEdit;
            }
            else if (theBridge.User2Verified == null || theBridge.User2Verified == "")
            {
                theBridge.User2Verified = userName;
                theBridge.User2Reason = isEdit;
            }
            else if (theBridge.User3Verified == null || theBridge.User3Verified == "")
            {
                theBridge.User3Verified = userName;
                theBridge.User3Reason = isEdit;
            }

            theBridge.NumberOfVotes = theBridge.NumberOfVotes + 1;

            try
            {
                if (db.SaveChanges() == 1)
                {
                    result.isSuccess = true;
                    result.message = "Down Vote Succcessfully Recorded";
                }
                else
                {
                    result.isSuccess = false;
                    result.message = "Error Saving Down Vote";
                }
                return result;
            }
            catch
            {
                result.isSuccess = false;
                result.message = "Error Saving Down Vote";
                return result;
            }
        }
Exemplo n.º 8
0
        public Models.ApiResult getByInfo(string country, string state, string county, string town)
        {
            var bridges = new List<Bridge>();
            var db = new BwareContext();
            var result = new Models.ApiResult();
            result.data = null;

            if (country == null || country == "")
            {
                result.isSuccess = false;
                result.message = "Country field must contain a value";
                return result;
            }

            if (state == null || state == "")
            {
                result.isSuccess = false;
                result.message = "State field must contain a value";
                return result;
            }

            if (county == null || county == "")
            {
                result.isSuccess = false;
                result.message = "County field must contain a value";
                return result;
            }

            if (town == null || town == "")
            {
                bridges = db.Bridges.Where(b => b.Country == country && b.State == state && b.County == county && b.isActive == true).ToList();
            }
            else // town info passed in so match that too
            {
                bridges = db.Bridges.Where(b => b.Country == country && b.State == state && b.County == county && b.Township.Contains(town) && b.isActive == true).ToList();
            }

            if (bridges == null)
            {
                result.isSuccess = false;
                result.message = "No bridges found for given area";
                return result;
            }

            result.isSuccess = true;
            result.message = "Success";
            result.multipleData = bridges;

            return result;
        }
Exemplo n.º 9
0
        public ApiResult CutAudio()
        {
            ApiResult     apiResult   = new Models.ApiResult();
            List <string> output_list = new List <string>();
            string        input       = string.Empty;

            try
            {
                Dictionary <string, string> cut_files = new Dictionary <string, string>();
                HttpFileCollection          fileList  = HttpContext.Current.Request.Files;
                if (fileList.Count < 1)
                {
                    return(new ApiResult()
                    {
                        success = false, message = "文件为空"
                    });
                }
                HttpPostedFile file   = fileList[0];
                string         folder = System.AppDomain.CurrentDomain.BaseDirectory + "NewSoundFiles/";
                if (!System.IO.Directory.Exists(Path.GetDirectoryName(folder)))
                {
                    System.IO.Directory.CreateDirectory(Path.GetDirectoryName(folder));
                }
                //先保存文件
                input = folder + "cutAudio_" + sys.getRandomStr() + Path.GetExtension(file.FileName);
                input = input.Replace("/", "\\");
                file.SaveAs(input);
                string        timespans = HttpContext.Current.Request.Form["timespans"];
                string[]      times     = timespans.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
                string        start     = "";
                string        end       = "";
                List <string> cut_times = new List <string>();
                foreach (string time in times)
                {
                    if (Util.isNotNull(time))
                    {
                        cut_times.Add(time);
                    }
                }
                //没有结束时间,所以需要加上
                string   _all_audio_time = FfmpegHelper.getMediaDuration(input);
                string[] all_audio_times = _all_audio_time.Split(':');
                string   audio_times     = (int.Parse(all_audio_times[0]) * 3600 + int.Parse(all_audio_times[1]) * 60 + double.Parse(all_audio_times[2])).ToString();
                cut_times.Add(audio_times);
                //确保没有空数据
                if (cut_times.Count > 1)
                {
                    for (int i = 1; i < cut_times.Count; i++)
                    {
                        try
                        {
                            start = cut_times[i - 1];
                            TimeSpan _start = TimeSpan.FromSeconds(double.Parse(start));
                            end = cut_times[i];
                            TimeSpan _end   = TimeSpan.FromSeconds(double.Parse(end) - double.Parse(start));
                            string   output = folder + i + "_cutAudio_" + sys.getRandomStr() + Path.GetExtension(file.FileName);
                            output = output.Replace("/", "\\");
                            output_list.Add(output);
                            bool is_success = FfmpegHelper.CutAudioFile(input, output, _start, _end);
                            //上传到服务器
                            if (File.Exists(output))
                            {
                                string server_path = UploadFile.PostFile(output);
                                cut_files.Add(start, server_path);
                            }
                        }
                        catch (Exception ex)
                        {
                            return(new ApiResult()
                            {
                                success = false,
                                message = "timespans参数不对"
                            });
                        }
                    }
                    apiResult.success = true;
                    apiResult.message = "截取成功";
                    apiResult.data    = cut_files;
                }
                else
                {
                    return(new ApiResult()
                    {
                        success = false,
                        message = "timespans参数不对"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ApiResult()
                {
                    success = false,
                    message = ex.Message
                });
            }
            finally
            {
                if (Util.isNotNull(input))
                {
                    if (File.Exists(input))
                    {
                        File.Delete(input);
                    }
                }
                foreach (string file in output_list)
                {
                    if (Util.isNotNull(file))
                    {
                        if (File.Exists(file))
                        {
                            File.Delete(file);
                        }
                    }
                }
            }
            return(apiResult);
        }
Exemplo n.º 10
0
        public async Task<Models.ApiResult> ForgotPassword(UserEmail userEmail)
        {
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(userEmail.email);
                if (user == null)
                {
                    // the user does not exist
                    result.message = "User not found";
                    return result;
                }

                try
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    String code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                    if (String.IsNullOrWhiteSpace(code))
                    {
                        result.message = "Reset password failed to generate token";
                        return result;
                    }
                    // send token back - debug only
                    // result.message = code;

                    var url = Uri.EscapeUriString("http://www.bwaremap.com/User/ResetPassword?code=") + code.Replace(" ", "+");  // Hack for + -> blank sp token
                    await UserManager.SendEmailAsync(user.Id, "Password Reset Request for B*ware", "Please reset your password by clicking <a href=\"" + url + "\">here</a>");
        
                    result.isSuccess = true;
                    result.message = "Reset Link Sent";
                }
                catch
                {
                    result.message = "Reset password failed";
                    return result;
                }

                return result;
            }

            result.message = "Username Invalid";
            return result;
        }
Exemplo n.º 11
0
        public async Task<Models.ApiResult> Register(RegisterBindingModel model)
        {
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            /** want registerResult.Errors below 
            if (!ModelState.IsValid)
            {
                result.message = "Invalid user data";
                return result;
            }
             ****/

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult registerResult = await UserManager.CreateAsync(user, model.Password);

            if (!registerResult.Succeeded)
            {
                // GetErrorResult(registerResult);
                result.message = registerResult.Errors.FirstOrDefault();
                return result;
            }

            //  return Ok();
            result.isSuccess = true;
            result.message = "User registered successfully";
            return result;
        }