示例#1
0
        public List <Section> GetSections(Profile userProfile)
        {
            try
            {
                List <Section> sectionsList = new List <Section>();

                var blob          = BlobMethods.GetBlockBlob(userProfile.Username + "-" + userProfile.Id + "-sections" + ".txt");
                var sections      = blob.DownloadText();
                var sectionsSplit = sections.Split(EOL);

                if (sectionsSplit[0].Split(DELIMITER)[1] != "")
                {
                    sectionsList.Add(new Section(sectionsSplit[0].Split(DELIMITER)[1]));
                }

                for (int i = 1; i < sectionsSplit.Length - 1; i += 2)
                {
                    var title       = sectionsSplit[i].Split(DELIMITER)[1];
                    var description = sectionsSplit[i + 1].Split(DELIMITER)[1];

                    if (!title.Equals("") || !description.Equals("") || i <= 1)
                    {
                        description = description.Replace("*--*", Environment.NewLine);
                        sectionsList.Add(new Section(title, description, description.Split(" ").Length > 66));
                    }
                }

                return(sectionsList);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in TutorMethods: GetSections " + e.Message);
                return(null);
            }
        }
示例#2
0
        public List <Topic> GetTopics(Profile userProfile)
        {
            try
            {
                List <Topic> topicsList = new List <Topic>();

                var blob       = BlobMethods.GetBlockBlob(userProfile.Username + "-" + userProfile.Id + "-topics" + ".txt");
                var topics     = blob.DownloadText();
                var topicSplit = topics.Split(EOL);

                for (int i = 0; i < topicSplit.Length - 1; i += 2)
                {
                    var topic          = topicSplit[i].Split(DELIMITER)[1];
                    var listOfSubjects = topicSplit[i + 1].Split(DELIMITER)[1];

                    if (!topic.Equals("") || !listOfSubjects.Equals("") || (i <= 1))
                    {
                        listOfSubjects = listOfSubjects.Replace("*--*", Environment.NewLine);
                        topicsList.Add(new Topic(topic, listOfSubjects));
                    }
                }
                return(topicsList);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in TutorMethods: GetTopics " + e.Message);
                return(null);
            }
        }
示例#3
0
        public async Task <List <string> > SaveEditedArchivedStream(HttpRequest request)
        {
            string streamThumbnail   = null;
            var    videoId           = request.Form["VideoId"];
            var    streamTitle       = request.Form["VideoTitle"];
            var    streamDescription = request.Form["VideoDescription"];

            if (request.Form.Files.Count > 0)
            {
                streamThumbnail = await BlobMethods.SaveImageIntoBlobContainer(request.Form.Files[0], videoId, 1280, 720);
            }

            var archivedStream = await Get <Video>(SQLQueries.GetArchivedStreamsWithId, videoId);

            archivedStream.StreamTitle       = streamTitle;
            archivedStream.StreamDescription = streamDescription;
            if (streamThumbnail != null)
            {
                archivedStream.StreamThumbnail = streamThumbnail;
            }

            await Save(archivedStream.Id, archivedStream);

            return(new List <string> {
                streamTitle, streamDescription, archivedStream.StreamThumbnail
            });
        }
示例#4
0
        public async Task <string> UploadAsync(string file, byte[] data, string mime)
        {
            try
            {
                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(this._options.Value.StorageConnection);
                CloudBlobClient     cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer  cloudBlobContainer  = cloudBlobClient.GetContainerReference(this._options.Value.Container);

                string uniqueFileName = BlobMethods.GetUniqueFileName(file);

                if (await cloudBlobContainer.CreateIfNotExistsAsync())
                {
                    await cloudBlobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
                }
                if (uniqueFileName != null && data != null)
                {
                    CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(uniqueFileName);
                    cloudBlockBlob.Properties.ContentType = mime;
                    await cloudBlockBlob.UploadFromByteArrayAsync(data, 0, data.Length);

                    return(uniqueFileName);
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
示例#5
0
        public async Task <string> SaveBanner(HttpRequest request, Profile userProfile)
        {
            try
            {
                if (request.Form.ContainsKey("ProfileBanner"))
                {
                    userProfile.ProfileBanner = MiscHelperMethods.defaultBanner;
                    await Save(userProfile.Id, userProfile);

                    return(MiscHelperMethods.defaultBanner);
                }

                IFormFile profileBanner = request.Form.Files[0];
                var       banner        = await BlobMethods.SaveImageIntoBlobContainer(profileBanner, userProfile.Username + "-" + userProfile.Id + "-profilebanner", 720, 242);

                userProfile.ProfileBanner = banner;
                await Save(userProfile.Id, userProfile);

                return(banner);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in EditProfileMethods-SaveBanner " + e.Message);
                return(null);
            }
        }
示例#6
0
        public async Task <ActionResult> MoveImageToBlobStorage(int id)
        {
            var storageAccountName = ConfigurationManager.AppSettings["StorageAccountName"];
            var storageAccountKey  = ConfigurationManager.AppSettings["StorageAccountKey"];
            var product            = db.Products.Where(x => x.ProductID == id)
                                     .Include(x => x.User)
                                     .Include(x => x.User.Institution).FirstOrDefault();

            if (product != null)
            {
                if (product.FullSizeImage != null && product.ThumbnailImage != null)
                {
                    var containerName = product.User.Institution.abbreviation.ToLower() + "products";
                    var thumbnailName = Guid.NewGuid().ToString();
                    var fullSizeName  = Guid.NewGuid().ToString();
                    var blobStorage   = new BlobMethods(storageAccountName, storageAccountKey, containerName);
                    await blobStorage.UploadFromByteArrayAsync(product.ThumbnailImage, thumbnailName);

                    await blobStorage.UploadFromByteArrayAsync(product.FullSizeImage, fullSizeName);

                    product.ThumbnailImageName = thumbnailName;
                    product.FullSizeImageName  = fullSizeName;
                    product.ThumbnailImage     = null;
                    product.FullSizeImage      = null;
                    db.Entry(product).State    = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
            }

            return(View());
        }
示例#7
0
        public async Task <ActionResult> MoveImagesToBlobStorage(string startDate)
        {
            var storageAccountName = ConfigurationManager.AppSettings["StorageAccountName"];
            var storageAccountKey  = ConfigurationManager.AppSettings["StorageAccountKey"];
            var start = DateTime.Parse(startDate);

            foreach (var product in db.Products.Where(x => x.DatePosted >= start).Include(x => x.User).Include(x => x.User.Institution))
            {
                if (product.FullSizeImage != null && product.ThumbnailImage != null)
                {
                    var containerName = product.User.Institution.abbreviation.ToLower() + "products";
                    var thumbnailName = Guid.NewGuid().ToString();
                    var fullSizeName  = Guid.NewGuid().ToString();
                    var blobStorage   = new BlobMethods(storageAccountName, storageAccountKey, containerName);
                    await blobStorage.UploadFromByteArrayAsync(product.ThumbnailImage, thumbnailName);

                    await blobStorage.UploadFromByteArrayAsync(product.FullSizeImage, fullSizeName);

                    product.ThumbnailImageName = thumbnailName;
                    product.FullSizeImageName  = fullSizeName;
                    product.ThumbnailImage     = null;
                    product.FullSizeImage      = null;
                    db.Entry(product).State    = System.Data.Entity.EntityState.Modified;
                }
            }
            await db.SaveChangesAsync();

            return(View());
        }
示例#8
0
        public async Task <List <string> > EditProfile(HttpRequest request, Profile userProfile)
        {
            IFormFile profilePicture           = null;
            var       firstName                = request.Form["FirstName"];
            var       lastName                 = request.Form["LastName"];
            var       occupation               = request.Form["Occupation"];
            var       location                 = request.Form["Location"];
            var       timeZone                 = request.Form["Timezone"];
            var       linkedInUrl              = request.Form["LinkedInUrl"];
            var       instagramUrl             = request.Form["InstagramUrl"];
            var       facebookUrl              = request.Form["FacebookUrl"];
            var       twitterUrl               = request.Form["TwitterUrl"];
            var       subscribeToNotifications = request.Form["SubscribeToNotifications"];

            if (request.Form.Files.Count > 0)
            {
                profilePicture = request.Form.Files[0];
            }

            Regex nameRegex = new Regex(@"^[^0-9\t\n\/<>?;:""`!@#$%^&*()\[\]{}_+=|\\]+$");

            if (!nameRegex.IsMatch(firstName))
            {
                firstName = userProfile.Name.Split('|')[0];
            }
            if (!nameRegex.IsMatch(lastName))
            {
                lastName = userProfile.Name.Split('|')[1];
            }

            userProfile.Name                  = firstName + "|" + lastName;
            userProfile.ProfileCaption        = occupation;
            userProfile.Location              = location;
            userProfile.TimeZone              = timeZone;
            userProfile.LinkedInUrl           = linkedInUrl;
            userProfile.InstagramUrl          = instagramUrl;
            userProfile.FacebookUrl           = facebookUrl;
            userProfile.TwitterUrl            = twitterUrl;
            userProfile.NotificationSubscribe = subscribeToNotifications == "true" ? "True" : "False";

            //await _scheduleMethods.UpdateTimezoneForScheduleTask(storageConfig, timeZone, userProfile.Username);

            if (profilePicture != null)
            {
                userProfile.ProfilePicture = await BlobMethods.SaveImageIntoBlobContainer(profilePicture, userProfile.Id, 240, 320);

                //if (userProfile.ProfileType == "tutor")
                //await _tutorMethods.ChangeAllArchivedStreamAndUserChannelProfilePhotos(storageConfig, userProfile.Username, userProfile.ProfilePicture); //only if tutor
            }

            await Save(userProfile.Id, userProfile);

            return(new List <string> {
                firstName, lastName, occupation, location, timeZone, linkedInUrl, userProfile.ProfilePicture
            });
        }
示例#9
0
        public async Task <IActionResult> UploadAsync(IFormFile file)
        {
            if (!BlobMethods.IsImage(file))
            {
                return(BadRequest());
            }
            string fileName = await _storage.UploadAsync(file.FileName, await file.GetBytes(), file.ContentType);

            return(Ok(new { File = fileName }));
        }
        public ActionResult Create([Bind(Include = "InstitutionID,Name,abbreviation,Extension1,Extension2,Extension3,Extension4,Extension5")] Institution institution)
        {
            if (ModelState.IsValid)
            {
                if (db.Institutions.FirstOrDefault(x => x.abbreviation.ToLower() == institution.abbreviation.ToLower()) == null)
                {
                    db.Institutions.Add(institution);
                    db.SaveChanges();
                    var containerName = institution.abbreviation.ToLower() + "products";
                    var blobStorage   = new BlobMethods(storageAccountName, storageAccountKey, containerName);
                }
                return(RedirectToAction("Index"));
            }

            return(View(institution));
        }
示例#11
0
        public async Task <string> StartStream(HttpRequest request, Profile profile)
        {
            try
            {
                var channel = await Get <DataModels.Channel>(SQLQueries.GetUserChannelWithUsername, profile.Username);

                channel.StreamTitle       = request.Form["StreamTitle"]; //save all information in database from client side request
                channel.StreamSubject     = request.Form["StreamSubject"];
                channel.StreamDescription = request.Form["StreamDescription"];
                channel.Views             = 0;
                channel.StreamColor       = GetCorrespondingStreamColor(request.Form["StreamSubject"]);
                channel.Name               = profile.Name;
                channel.ArchivedVideoId    = Guid.NewGuid().ToString();
                channel.InitialStreamCount = 0;
                await DeleteFillScheduleTask(request.Form["ScheduleId"]);

                if (request.Form.Files.Count > 0)
                {
                    channel.StreamThumbnail = await BlobMethods.SaveImageIntoBlobContainer(request.Form.Files[0], channel.ArchivedVideoId, 1280, 720);
                }
                else
                {
                    channel.StreamThumbnail = GetCorrespondingDefaultThumbnail(channel.StreamSubject);
                }

                await Save(channel.Id, channel);
                await RunLive(channel);

                return(channel.ArchivedVideoId);
            }
            catch (Exception e)
            {
                Debug d = new Debug();
                d.Id        = Guid.NewGuid().ToString();
                d.Timestamp = DateTime.UtcNow;
                d.Message   = "Error in TutorMethods: StartStream " + e.Message + " | " + e.InnerException;
                await Save(d.Id, d);

                Console.WriteLine("Error in TutorMethods: StartStream " + e.Message);
                return(null);
            }
        }
示例#12
0
        public bool SaveTopic(HttpRequest request, Profile userProfile)
        {
            try
            {
                var form = request.Form;
                var keys = form.Keys;

                string formatString = "";
                foreach (var key in keys)
                {
                    formatString += key.ToString() + DELIMITER + form[key] + EOL;
                }

                var url = BlobMethods.SaveFileIntoBlobContainer(userProfile.Username + "-" + userProfile.Id + "-topics" + ".txt", formatString);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in TutorMethods: SaveTopic " + e.Message);
                return(false);
            }
        }
示例#13
0
        public async Task <ActionResult> DeleteHiddenProducts()
        {
            var storageAccountName = ConfigurationManager.AppSettings["StorageAccountName"];
            var storageAccountKey  = ConfigurationManager.AppSettings["StorageAccountKey"];

            foreach (var product in db.Products.Where(x => x.Visible == false).Include(x => x.User).Include(x => x.User.Institution))
            {
                if (!string.IsNullOrEmpty(product.ThumbnailImageName) && !string.IsNullOrEmpty(product.ThumbnailImageName))
                {
                    var containerName = product.User.Institution.abbreviation.ToLower() + "products";
                    var thumbnailName = product.ThumbnailImageName;
                    var fullSizeName  = product.FullSizeImageName;
                    var blobStorage   = new BlobMethods(storageAccountName, storageAccountKey, containerName);
                    await blobStorage.DeleteBlobAsync(thumbnailName);

                    await blobStorage.DeleteBlobAsync(fullSizeName);
                }
                db.Products.Remove(product);
            }
            await db.SaveChangesAsync();

            return(View());
        }