Пример #1
0
 public JsonModels.UploadReponse AddAudioElement(int projectId, string description, Stream fileStream, string fileName)
 {
     Project p = pa.GetProject(projectId);
     BlobStorageAccessor ba = new BlobStorageAccessor();
     string location = null;
     string[] s2 = fileName.Split('.');
     string extention = s2[s2.Count() - 1].ToLower();
     if (extention.ToLower() == "mp3")
     {
         location = ba.uploadMP3(fileStream, false).ToString();
     }
     else if (extention.ToLower() == "ogg")
     {
         location = ba.uploadOGG(fileStream, false).ToString();
     }
     else if (extention.ToLower() == "wav")
     {
         location = ba.uploadWAV(fileStream, false).ToString();
     }
     else if (extention.ToLower() == "m4a")
     {
         location = ba.uploadM4A(fileStream, false).ToString();
     }
     else
     {
         //upload unknown file type. do this or display message
         Uri result = ba.uploadUnknown(fileStream, false, extention);
         if (result == null)
         {
             return null;
         }
         else
         {
             location = result.ToString();
         }
     }
     ProjectElement_Audio pe = new ProjectElement_Audio
     {
         description = description,
         audioLocation = location,
         title = fileName,
     };
     int pID = pa.AddProjectElement(p, pe);
     return new JsonModels.UploadReponse { id = pID, fileURL = location, name = fileName };
 }
Пример #2
0
        public string UpdateCoverPicture(int networkId, Stream coverPicture)
        {
            try
            {
                string messageQueueName = "uploadqueue"; //queue name must be in lower case
                CloudQueueClient queueClient;
                CloudQueue queue;
                CloudStorageAccount storageAccount;
                BlobStorageAccessor blobStorageAccessor = new BlobStorageAccessor();
                storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
                queueClient = storageAccount.CreateCloudQueueClient();
                queue = queueClient.GetQueueReference(messageQueueName);
                queue.CreateIfNotExist();

                string fileName = Guid.NewGuid().ToString();
                string artifactURL = string.Format("{0}{1}", fileName, ".jpeg");

                string blobReference = blobStorageAccessor.uploadImage(coverPicture, false).ToString();
                string coverPictureLocation = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString()+"thumbnails/" + artifactURL;
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", blobReference, networkId, "thumbnail", "Network", 170, 170, "", artifactURL));
                queue.AddMessage(message);

                bool updated = networkAccessor.UpdateNetworkCoverPicture(networkId, coverPictureLocation);
                if (updated)
                {
                    return coverPictureLocation;
                }
                else
                {
                    return "Error";
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "Network Manager - AddNetworkAdmin", ex.StackTrace);
                return "Error";
            }
        }
 public string testThumbnail(string qqfile = null)
 {
     if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
     {
         return null;
     }
     try
     {
         var length = Request.ContentLength;
         var bytes = new byte[length];
         Request.InputStream.Read(bytes, 0, length);
         Stream s = new MemoryStream(bytes);
         ThumbnailEngine te = new ThumbnailEngine();
         Bitmap b = te.CreateProfileThumbnail(s, 100, 100);
         MemoryStream ms = new MemoryStream();
         b.Save(ms, ImageFormat.Bmp);
         BlobStorageAccessor ba = new BlobStorageAccessor();
         string location = ba.uploadImage(ms, false).ToString();
         return location;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Пример #4
0
        public JsonModels.UploadReponse UploadPictureElement(int projectId, Stream pictureStream, string fileName, bool isCoverPicture = false)
        {
            try
            {
                BlobStorageAccessor blobStorageAccessor = new BlobStorageAccessor();
                UploadManager uploadManager = new UploadManager();
                ProjectAccessor projectAccessor = new ProjectAccessor();

                //initiate queue message
                storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
                queueClient = storageAccount.CreateCloudQueueClient();
                queue = queueClient.GetQueueReference(messageQueueName);
                queue.CreateIfNotExist();

                string imageURI = blobStorageAccessor.uploadImage(pictureStream, false).ToString();
                Project p = pa.GetProject(projectId);
                if (isCoverPicture)
                {
                    string FileNameThumb1 = Guid.NewGuid().ToString();
                    string artifactURL1 = string.Format("{0}{1}", FileNameThumb1, ".jpeg");
                    CloudQueueMessage message3 = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", imageURI, p.id, "thumbnail", "ProjectPicture", 266, 266, "", artifactURL1));
                    queue.AddMessage(message3);
                    p.coverPictureThumbnail = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString() + "thumbnails/" + artifactURL1;
                    p.coverPicture = imageURI;

                    p.dateModified = DateTime.Now;

                    Project newP = projectAccessor.UpdateProject(p);
                    return new JsonModels.UploadReponse { id = p.id, fileURL = imageURI, name = fileName, galeriaURL = "noGalleryURL", artifactURL = artifactURL1, description = "default description" };
                }
                else
                {
                    string FileNameThumb = Guid.NewGuid().ToString();
                    string artifactURL = string.Format("{0}{1}", FileNameThumb, ".jpeg");
                    ProjectElement_Picture pe = new ProjectElement_Picture
                    {
                        title = GetTitle(fileName),
                        pictureLocation = imageURI,
                        pictureThumbnailLocation = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString()+"thumbnails/" + artifactURL
                    };
                    int projectElementId = pa.AddProjectElement(p, pe);
                    if (projectElementId == -1)
                    {
                        logAccessor.CreateLog(DateTime.Now, "ProjectManager - UploadPictureElement", "problem saving project element - 165 ProjectManager");
                        return null;
                    }

                    //string FileNameGaleria = Guid.NewGuid().ToString();
                    //string galleryURL = string.Format("{0}{1}", FileNameGaleria, ".jpeg");

                    CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", imageURI, projectElementId, "thumbnail", "PictureElement", 635, 397, "", artifactURL));
                    //CloudQueueMessage message2 = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", imageURI, projectElementId, "thumbnail", "PictureElement_Galleria", 1000, 750, "", galleryURL));
                    queue.AddMessage(message);
                    //queue.AddMessage(message2);
                    return new JsonModels.UploadReponse { id = projectElementId, fileURL = imageURI, name = fileName, galeriaURL = "galleryURL", artifactURL = artifactURL, description = null };
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "ProjectManager - UploadPictureElement", ex.StackTrace);
                return null;
            }
        }
Пример #5
0
        public JsonModels.UploadReponse AddDocumentElement(int projectId, string description, Stream fileStream, string fileName, string userName)
        {
            Project p = pa.GetProject(projectId);
            BlobStorageAccessor ba = new BlobStorageAccessor();
            string location = null;
            string[] s2 = fileName.Split('.');
            string extention = s2[s2.Count() - 1].ToLower();

            UserAccessor ua = new UserAccessor();
            User u = ua.GetUser(userName);
            string fullName = u.firstName +" " +  u.lastName;

            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
            queueClient = storageAccount.CreateCloudQueueClient();
            queue = queueClient.GetQueueReference(messageQueueName);
            queue.CreateIfNotExist();
            string documentText = "";

            //string PDFLocation = "notset";
            if (extention == "pdf")
            {
                location = ba.uploadPDF(fileStream, false).ToString();
                UploadManager um = new UploadManager();
                //location = um.stampThatShit(location, fullName, null);
                //documentText = um.ExtractText(location);
            }
            else if (extention == "doc" || extention == "docx")
            {
                location = ba.uploadDOC(fileStream, false, "."+extention).ToString();
            }
            else if (extention == "ppt" || extention == "pptx")
            {
                location = ba.uploadUnknown(fileStream, false, extention).ToString();
            }
            else if( extention == "xls" || extention == "xlsx")
            {
                location = ba.uploadUnknown(fileStream,false, extention).ToString();
            }
            else if (extention == "rtf")
            {
                location = ba.uploadUnknown(fileStream, false, extention).ToString();
            }
            else if (extention == "txt")
            {
                location = ba.uploadUnknown(fileStream, false, extention).ToString();
            }
            else
            {
                //upload unknown file type. do this or display message
                Uri result = ba.uploadUnknown(fileStream, false, extention);
                if (result == null)
                {
                    return null;
                }
                else
                {
                    location = result.ToString();
                }
            }
            String FileName = Guid.NewGuid().ToString();
            string uniqueBlobName = string.Format("{0}{1}", FileName, ".pdf");
            string docThumb = "";
            if (extention == "pdf")
            {
                docThumb = location;
            }
            else
            {
                docThumb = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString()+"pdfs/" + uniqueBlobName;
            }
            ProjectElement_Document pe = new ProjectElement_Document
            {
                description = description,
                documentLocation = location,
                title = fileName,
                documentText = documentText,
                documentThumbnailLocation = docThumb
            };
            int projectElementId = pa.AddProjectElement(p, pe);
            if (extention == "doc" || extention == "docx")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/Word2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            else if (extention == "ppt" || extention == "pptx")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/PowerPoint2Pdf", 0, 0, "", uniqueBlobName));
                queue.AddMessage(message);
            }
            else if( extention == "xls" || extention == "xlsx")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/Excel2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            else if (extention == "rtf")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/RichText2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            else if (extention == "txt")
            {
                CloudQueueMessage message = new CloudQueueMessage(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", location, projectElementId, "documentConversion", @"http://do.convertapi.com/Text2Pdf", 0, 0, fullName, uniqueBlobName));
                queue.AddMessage(message);
            }
            if (extention == "pdf")
            {
                return new JsonModels.UploadReponse { id = projectElementId, fileURL = location, name = fileName, artifactURL = location };
            }
            return new JsonModels.UploadReponse { id = projectElementId, fileURL = location, artifactURL = docThumb, name = fileName };
        }