public List<JsonModels.CompleteProject> GetCompleteProjects(int[] id, List<string> projectPrivacyPrivledge) { List<JsonModels.CompleteProject> projects = new List<JsonModels.CompleteProject>(); ProjectAccessor pa = new ProjectAccessor(); if (projectPrivacyPrivledge == null) { projectPrivacyPrivledge = new List<string>(); projectPrivacyPrivledge.Add("public"); projectPrivacyPrivledge.Add("network"); projectPrivacyPrivledge.Add("private"); } foreach (int i in id) { JsonModels.CompleteProject cp = new JsonModels.CompleteProject(); ReorderEngine re = new ReorderEngine(); Project p = pa.GetProject(i); if (p != null) { if (p.isActive == true && (projectPrivacyPrivledge.Contains(p.privacy) || p.privacy == null)) { cp.id = p.id; if (p.name != null) { cp.title = p.name; } else { cp.title = null; } if (p.description != null) { cp.description = p.description; } else { cp.description = null; } cp.projectTags = GetProjectTags(p.id); //we have to reset everyone's project order or when you add a new element this breaks - removes all old elements List<int> peIds = new List<int>(); //just reset order if its null - duh! if (p.projectElementOrder == null | p.projectElementOrder == "") { p = resetProjectElementOrder(p); if (p.projectElementOrder != null) { List<int> IDS = re.stringOrderToList(p.projectElementOrder); int[] ids = IDS.ToArray(); cp.artifactOrder = p.projectElementOrder; cp.artifacts = GetArtifacts(ids); } else { cp.artifactOrder = null; cp.artifacts = null; } } else //projectElementOrder isn't null { List<int> IDS = re.stringOrderToList(p.projectElementOrder); int[] ids = IDS.ToArray(); cp.artifacts = GetArtifacts(ids); cp.artifactOrder = p.projectElementOrder; } if (p.coverPicture != null) { cp.coverPicture = p.coverPicture; } if (p.coverPictureThumbnail != null) { cp.coverPictureThumbnail = p.coverPictureThumbnail; } if (p.dateModified != null) { cp.dateModified = p.dateModified.ToString(); } if (p.privacy != null) { cp.privacy = p.privacy; } cp.props = GetProjectProps(p.id); projects.Add(cp); } } } if (projects.Count != 0) { return projects; } else { return null; } }
//returns artifacts for documents, pictures, videos, and audio public List<JsonModels.Artifact> GetArtifacts(int[] id) { List<JsonModels.Artifact> artifacts = new List<JsonModels.Artifact>(); ProjectAccessor pa = new ProjectAccessor(); int add = 0; foreach (int i in id) { add = 0; JsonModels.Artifact a = new JsonModels.Artifact(); ProjectElement pe = pa.GetProjectElement(i); if (pe != null) { a.id = pe.id; if (pe.GetType() == typeof(ProjectElement_Document)) { a.type = "document"; ProjectElement_Document ped = (ProjectElement_Document)pe; if (ped.documentThumbnailLocation != null) { a.artifactLocation = ped.documentThumbnailLocation; } if (ped.documentThumbnailLocation == null && ped.documentLocation != null) { a.artifactLocation = ped.documentLocation; } if (ped.documentLocation != null) { a.fileLocation = ped.documentLocation; } a.creationDate = "?/?/????"; if (ped.description != null) { a.description = ped.description; } else { a.description = null; } if (ped.title != null) { a.title = ped.title; } else { a.title = null; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Picture)) { a.type = "picture"; ProjectElement_Picture pep = (ProjectElement_Picture)pe; if (pep.pictureThumbnailLocation != null) { a.artifactLocation = pep.pictureThumbnailLocation; } if (pep.pictureLocation != null) { a.fileLocation = pep.pictureLocation; } a.creationDate = "?/?/????"; if (pep.description != null) { a.description = pep.description; } else { a.description = ""; } if (pep.title != null) { a.title = pep.title; } else { a.title = null; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Video)) { a.type = "video"; ProjectElement_Video pev = (ProjectElement_Video)pe; if (pev.videoId != null) { a.artifactLocation = pev.videoId; } if (pev.description != null) { a.description = pev.description; } else { a.description = null; } a.creationDate = "?/?/????"; if (pev.title != null) { a.title = pev.title; } else { a.title = null; } if (pev.videoType != null) { a.fileLocation = pev.videoType; } else { a.fileLocation = null; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Audio)) { a.type = "audio"; ProjectElement_Audio pea = (ProjectElement_Audio)pe; if (pea.audioLocation != null) { a.artifactLocation = pea.audioLocation; } if (pea.description != null) { a.description = pea.description; } else { a.description = null; } a.creationDate = "?/?/????"; if (pea.title != null) { a.title = pea.title; } else { a.title = null; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Code)) { a.type = "code"; ProjectElement_Code pec = (ProjectElement_Code)pe; if (pec.code != null) { a.artifactLocation = pec.code; } if (pec.description != null) { a.description = pec.description; } else { a.description = null; } a.creationDate = "?/?/????"; if (pec.title != null) { a.title = pec.title; } else { a.title = null; } if (pec.fileLocation != null) { a.fileLocation = pec.fileLocation; } else { a.fileLocation = null; } add = 1; } } if (add == 1) { artifacts.Add(a); } } if (artifacts.Count != 0) { return artifacts; } else { return null; } }
public List<JsonModels.Artifact> GetArtifacts(List<ProjectElement> elements) { List<JsonModels.Artifact> artifacts = new List<JsonModels.Artifact>(); ProjectAccessor pa = new ProjectAccessor(); int add = 0; foreach (ProjectElement pe in elements) { add = 0; JsonModels.Artifact a = new JsonModels.Artifact(); if (pe != null) { a.id = pe.id; if (pe.GetType() == typeof(ProjectElement_Document)) { a.type = "document"; ProjectElement_Document ped = (ProjectElement_Document)pe; if (ped.documentThumbnailLocation != null) { a.artifactLocation = ped.documentThumbnailLocation; } a.creationDate = "?/?/????"; if (ped.description != null) { a.description = ped.description; } if (ped.title != null) { a.title = ped.title; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Picture)) { a.type = "picture"; ProjectElement_Picture pep = (ProjectElement_Picture)pe; if (pep.pictureLocation != null) { a.artifactLocation = pep.pictureLocation; } //if (pep.pictureGalleriaThumbnailLocation != null) //{ // a.thumbnailLocation = pep.pictureGalleriaThumbnailLocation; //} a.creationDate = "?/?/????"; if (pep.description != null) { a.description = pep.description; } if (pep.title != null) { a.title = pep.title; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Video)) { a.type = "video"; ProjectElement_Video pev = (ProjectElement_Video)pe; if (pev.videoId != null) { a.artifactLocation = pev.videoId; } if (pev.description != null) { a.description = pev.description; } a.creationDate = "?/?/????"; if (pev.title != null) { a.title = pev.title; } add = 1; } else if (pe.GetType() == typeof(ProjectElement_Audio)) { a.type = "audio"; ProjectElement_Audio pea = (ProjectElement_Audio)pe; if (pea.audioLocation != null) { a.artifactLocation = pea.audioLocation; } if (pea.description != null) { a.description = pea.description; } a.creationDate = "?/?/????"; if (pea.title != null) { a.title = pea.title; } add = 1; } } if (add == 1) { artifacts.Add(a); } } if (artifacts.Count != 0) { return artifacts; } else { return null; } }
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; } }