public static string readBase64FileStream(MidiFile crumbsmodel)
        {
            string appPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
            string path = MidiFileHelper.getMidiPath(crumbsmodel);
            string FullPath = appPhysicalPath + path;

            return readBase64String(FullPath);
        }
        public ActionResult Create(MidiFile crumbsmodel)
        {
            if (ModelState.IsValid)
            {
                User user = CurrentUser;
                if (user != null)
                {

                    try
                    {
                        crumbsmodel.Provider = crumbsRepository.FindProviderByUserKey(user.UserKey);
                        crumbsmodel.FileName = crumbsmodel.Name + ".mid";

                        string errorMessage = MidiFileHelper.writeBase64FileStream(crumbsmodel);
                        if (!string.IsNullOrEmpty(errorMessage))
                        {
                            crumbsmodel.Description = errorMessage;
                            crumbsmodel.Status = -1;
                        }
                        else
                        {
                            crumbsmodel.Status = 0;
                        }

                        crumbsRepository.InsertOrUpdateMidiFile(crumbsmodel);
                        crumbsRepository.Save();
                    }
                    catch (Exception e)
                    {
                        crumbsmodel.Description = e.Message;
                        crumbsmodel.Status = -1;
                    }

                    return RedirectToAction("MidiFiles");
                }
            }

            return View(crumbsmodel);
        }
        private void CheckMIDIPermissions(MidiFile crumbsmodel)
        {
            User user = CurrentUser;
            if (user == null)
            {
                ViewBag.Price = crumbsRepository.FindPriceForUser(20, 10, crumbsmodel.MidiID);

                ViewBag.VeryLimitedPlayback = true;
            }
            else
            {
                Payment payment = crumbsRepository.FindPaymentForMIDI(user.UserID, crumbsmodel.MidiID);
                if (payment == null)
                {
                    // No Payment for this Midi - find the current price for this user
                    ViewBag.Price = crumbsRepository.FindPriceForUser(user.UserID, 10, crumbsmodel.MidiID);
                }
                else
                {
                    ViewBag.Payment = payment;
                    ViewBag.User = user;
                }
            }
        }
 private long AddNewPlay(MidiFile crumbsmodel, short type)
 {
     return AddNewPlay(crumbsmodel.MidiID, type);
 }
        public ActionResult MidiPlayer(int id, string name)
        {
            MidiFile crumbsmodel = crumbsRepository.FindMidiFile(id);
            if (crumbsmodel == null)
                crumbsmodel = new MidiFile();

            ViewBag.LimitedPlayback = null;
            ViewBag.MidiPlayer = true;
            ViewBag.UserMidi = true;
            return View(crumbsmodel);
        }
        protected int CheckUserPermissions(MidiFile crumbsmodel = null)
        {
            User user = CurrentUser;
            if (crumbsmodel != null && crumbsmodel.Status == 2)
            {
            }
            else if (user == null)
            {
                if (crumbsmodel != null)
                {
                    ViewBag.Price = crumbsRepository.FindPriceForUser(20, 10, crumbsmodel.MidiID);
                }
                else
                {
                    ViewBag.Price = crumbsRepository.FindPriceForUser(20, 10);
                }

                ViewBag.VeryLimitedPlayback = true;
                return 2;
            }
            else if (crumbsmodel != null && crumbsmodel.Visibility == 2)
            {
            }
            else
            {
                if (crumbsmodel != null)
                {
                    ViewBag.Price = crumbsRepository.FindPriceForUser(user.UserID, 10, crumbsmodel.MidiID);
                }
                else
                {
                    ViewBag.Price = crumbsRepository.FindPriceForUser(user.UserID, 10);
                }

                Payment payment = crumbsRepository.FindPaymentForUser(user.UserID);
                if (payment == null)
                {
                    FreePlay freePlay = crumbsRepository.FindFreePlayForUser(user.UserID);
                    if (freePlay == null)
                    {
                        ViewBag.LimitedPlayback = true;
                        return 1;
                    }
                    else
                    {
                        ViewBag.FreePlay = freePlay;
                    }
                }
                else
                {
                    ViewBag.Payment = payment;
                }
            }

            return 0;
        }
        public static string readChordStream(MidiFile crumbsmodel)
        {
            List<Bar> chords = null;

            string appPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
            string path = MidiFileHelper.getChordsPath(crumbsmodel);
            string FullPath = appPhysicalPath + path;

            try
            {
                FileStream fs = new FileStream(FullPath,
                                       FileMode.Open,
                                       FileAccess.Read);

                BinaryFormatter bin = new BinaryFormatter();
                chords = (List<Bar>)bin.Deserialize(fs);

                fs.Close();
            }
            catch (Exception)
            {
                return null;
            }

            JavaScriptSerializer ser = new JavaScriptSerializer();
            return ser.Serialize(chords);
        }
 public static string getMidiPath(MidiFile crumbsmodel)
 {
     return "/midi/" + crumbsmodel.Provider.Folder + "/" + crumbsmodel.FileName;
 }
        public static string writeFingerStream(MidiFile crumbsmodel)
        {
            string appPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
            string path = MidiFileHelper.getFingersPath(crumbsmodel);
            string FullPath = appPhysicalPath + path;

            JavaScriptSerializer ser = new JavaScriptSerializer();
            List<Finger> fingers = ser.Deserialize<List<Finger>>(crumbsmodel.FingerStream);

            try
            {
                FileStream fs = new FileStream(FullPath,
                                       FileMode.Create,
                                       FileAccess.Write);

                BinaryFormatter bin = new BinaryFormatter();
                bin.Serialize(fs, fingers);

                fs.Close();
            }
            catch (Exception e)
            {
                return string.Format("Can't save the file {0}: {1}", FullPath, e.Message);
            }

            return "Fingering was successfully updated.";
        }
Beispiel #10
0
 public static string getFingersPath(MidiFile crumbsmodel)
 {
     string path = getMidiPath(crumbsmodel);
     return path.Replace(".mid", ".fingers");
 }
Beispiel #11
0
 public static string getChordsPath(MidiFile crumbsmodel)
 {
     string path = getMidiPath(crumbsmodel);
     return path.Replace(".mid", ".chords");
 }
        public bool SendMail(User user, Mailing mail, Price price, MidiFile file)
        {
            if (user.Email == null)
                return false;

            if (price != null)
            {
                if (UpdatePromotionalPricing(user, price) == false)
                    return false;
            }

            try
            {
                SmtpClient client = new SmtpClient("m02.internetmailserver.net", 587);
                client.EnableSsl = false;
                MailAddress from = new MailAddress("*****@*****.**", "PianoCrumbs.com");
                MailAddress to = new MailAddress(user.Email, "");
                MailMessage message = new MailMessage(from, to);
                message.Subject = mail.Subject;
                message.IsBodyHtml = true;

                string fileName = "";
                string urlAction = "";

                if (file != null)
                {
                    fileName = file.Name;
                    urlAction = Url.Action("MidiView", "Crumbs", new { id = file.MidiID, name = file.DisplayName }, "http");
                }

                string latestLinks = "";
                IQueryable<MidiFile> latestFiles = crumbsRepository.LatestCrumbs.Take(5);
                foreach (var item in latestFiles)
                {
                    string url = Url.Action("MidiView", "Crumbs", new { id = item.MidiID, name = item.DisplayName }, "http");
                    latestLinks += string.Format("<p><a href='{0}'>{0}</a></p>", url);
                }

                string popualrLinks = "";
                IQueryable<MidiFile> popularFiles = crumbsRepository.RatedCrumbs.Take(5);
                foreach (var item in popularFiles)
                {
                    string url = Url.Action("MidiView", "Crumbs", new { id = item.MidiID, name = item.DisplayName }, "http");
                    popualrLinks += string.Format("<p><a href='{0}'>{0}</a></p>", url);
                }

                message.Body = string.Format(mail.Text, user.UserName, fileName, urlAction, latestLinks, popualrLinks);

                string unsubLink = Url.Action("Unsubscribe", "Account", new { username = user.UserName, reset = CrumbsExtensions.HashResetParams(user.UserName, user.UserKey) }, Request.Url.Scheme);
                message.Body += "<p><a href='" + unsubLink + "'>Unsubscribe</a>";

                NetworkCredential myCreds = new NetworkCredential("*****@*****.**", "Crumbs123", "");
                client.Credentials = myCreds;

                client.Send(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception is:" + ex.ToString());
                return false;
            }

            SentMail sent = new SentMail();
            sent.UserID = user.UserID;
            sent.MailID = mail.ID;
            sent.Date = DateTime.Now;

            crumbsRepository.InsertOrUpdateSentMail(sent);
            crumbsRepository.Save();

            return true;
        }
 public ActionResult EditDescription(MidiFile crumbsmodel)
 {
     if (ModelState.IsValid && crumbsmodel.MidiID > 0)
     {
         crumbsRepository.UpdateDescription(crumbsmodel.MidiID, crumbsmodel.Text);
         crumbsRepository.Save();
         return RedirectToAction("Descriptions");
     }
     return View(crumbsmodel);
 }
 public ActionResult Create()
 {
     MidiFile crumbsmodel = new MidiFile();
     ViewBag.MidiPlayer = true;
     return View(crumbsmodel);
 }
        public ActionResult Edit(MidiFile crumbsmodel)
        {
            if (ModelState.IsValid && crumbsmodel.MidiID > 0)
            {
                //if (!string.IsNullOrEmpty(crumbsmodel.FileStream))
                //{
                //    string errorMessage = MidiFileHelper.writeBase64FileStream(crumbsmodel, Request.ServerVariables["APPL_PHYSICAL_PATH"]);
                //    if (!string.IsNullOrEmpty(errorMessage))
                //    {
                //        crumbsmodel.Description = errorMessage;
                //        crumbsmodel.Status = -1;
                //    }
                //    else
                //    {
                //        crumbsmodel.Status = 0;
                //    }
                //}

                crumbsRepository.InsertOrUpdateMidiFile(crumbsmodel);
                crumbsRepository.Save();
                return RedirectToAction("Index");
            }
            return View(crumbsmodel);
        }
        public ActionResult CreateUserMidi(MidiFile crumbsmodel)
        {
            if (ModelState.IsValid)
            {
                User user = CurrentUser;
                if (user != null)
                {

                    try
                    {
                        crumbsmodel.Status = 2;
                        crumbsmodel.Visibility = 2;
                        crumbsmodel.CreateDate = DateTime.Now;
                        crumbsmodel.Provider = crumbsRepository.FindProviderByUserKey(user.UserKey);

                        string errorMessage = MidiFileHelper.writeBase64FileStream(crumbsmodel);
                        if (!string.IsNullOrEmpty(errorMessage))
                        {
                            crumbsmodel.Description = errorMessage;
                            crumbsmodel.Status = -1;
                        }
                        else
                        {
                            crumbsmodel.Status = 2;
                        }

                        crumbsRepository.InsertOrUpdateMidiFile(crumbsmodel);
                        crumbsRepository.Save();
                    }
                    catch (Exception e)
                    {
                        crumbsmodel.Description = e.Message;
                        crumbsmodel.Status = -1;
                    }

                    return RedirectToAction("MidiPlayer", "Home");
                }
            }

            return View(crumbsmodel);
        }