Exemplo n.º 1
0
        public string AddArtifact_Code(int projectId = -1, string code = null, string type = null, string token = null)
        {
            if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))  //This is a preflight request
            {
                return null;
            }
            else
            {
                try
                {
                    int userId = -1;
                    if (token != null)
                    {
                        userId = authenticationEngine.authenticate(token);
                    }
                    else
                    {
                        return AddErrorHeader("A token must be passed in", 2);
                    }
                    if (userId < 0)
                    {
                        return AddErrorHeader("User is not authenticated, please log in!", 2);
                    }
                    User user = userManager.GetUser(userId);
                    if (projectId > 0)
                    {
                        if (!projectManager.IsUserOwnerOfProject(projectId, user))
                        {
                            return AddErrorHeader("User is not authorized to complete this action", 3);
                        }
                    }
                    else
                    {
                        return AddErrorHeader("A projectId must be passed in", 1);
                    }
                    JsonModels.Artifact response = new JsonModels.Artifact();
                    if (code != null && type != null)
                    {
                        response = projectManager.AddCodeElement(projectId, code, type);
                        aa.CreateAnalytic("Add_Media", DateTime.Now, user.userName, "Code Sample");
                    }
                    else
                    {
                        return AddErrorHeader("code and type must be passed in", 1);
                    }
                    string returnVal;
                    try
                    {
                        returnVal = Serialize(response);
                    }
                    catch (Exception exception)
                    {
                        return AddErrorHeader(exception.Message, 1);
                    }
                    activityManager.AddActivity(user.id, "Artifact", "Added", response.id);

                    return AddSuccessHeader(returnVal);
                }
                catch (Exception ex)
                {
                    logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex.ToString());
                    return AddErrorHeader("Error occured uploading your video", 1);
                }
            }
        }
Exemplo n.º 2
0
        public string AddArtifact_Media(int projectId, string token, string qqfile=null)
        {
            if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))  //This is a preflight request
            {
                return null;
            }
            else
            {
                try
                {
                    int userId = authenticationEngine.authenticate(token);
                    if (userId < 0)
                    {
                        return AddErrorHeader("You are not authenticated, please log in!", 2);
                    }
                    //int newProjectElementId = -1;
                    JsonModels.UploadReponse response = new JsonModels.UploadReponse();
                    User user = userManager.GetUser(userId);
                    string artifactType = "null";
                    if (!projectManager.IsUserOwnerOfProject(projectId, user))
                    {
                        //return Json(new { Error = "Can't add picture at this time" });
                        return AddErrorHeader("You are not authorized to add this picture", 3);
                    }
                    if (Request != null)
                    {
                        if (qqfile == null && Request.Files.Count == 0)
                        {
                            return AddErrorHeader("No files submitted to server", 1);
                        }

                        var length = Request.ContentLength;
                        var bytes = new byte[length];
                        Stream s;
                        if (qqfile == "System.Web.HttpPostedFileWrapper")
                        {
                            qqfile = Request.Files[0].FileName;
                            s = Request.Files[0].InputStream;
                        }
                        else
                        {
                            Request.InputStream.Read(bytes, 0, length);
                            s = new MemoryStream(bytes);
                        }
                        //logAccessor.CreateLog(DateTime.Now, "Upload Artifact Media - 700", "request.files[0].filename:"+Request.Files[0].FileName);
                        //logAccessor.CreateLog(DateTime.Now, "Upload Artifact Media - 701", "request.files[0].contenttype:" + Request.Files[0].ContentType);

                        if (qqfile.Contains(".jpeg") || qqfile.Contains(".jpg") || qqfile.Contains(".png") || qqfile.Contains(".bmp") || qqfile.Contains(".JPEG") || qqfile.Contains(".JPG") || qqfile.Contains(".PNG") || qqfile.Contains(".BMP"))
                        {
                            response = projectManager.UploadPictureElement(projectId, s, qqfile);
                            if (response == null)
                            {
                                return AddErrorHeader("An error occured saving the docuement.", 1);
                            }
                            aa.CreateAnalytic("Add_Media", DateTime.Now, user.userName, "Picture");
                            artifactType = "picture";
                        }
                        else if (qqfile.Contains(".PDF") || qqfile.Contains(".pdf") || qqfile.Contains(".doc") || qqfile.Contains(".docx") || qqfile.Contains(".ppt") || qqfile.Contains(".pptx") || qqfile.Contains(".xls") || qqfile.Contains(".xlsx") || qqfile.Contains(".txt") || qqfile.Contains(".rtf") || qqfile.Contains(".DOC") || qqfile.Contains(".DOCX") || qqfile.Contains(".PPT") || qqfile.Contains(".PPTX") || qqfile.Contains(".XLS") || qqfile.Contains(".XLSX") || qqfile.Contains(".TXT") || qqfile.Contains(".RTF"))
                        {
                            response = projectManager.AddDocumentElement(projectId, null, s, qqfile, user.userName);

                            //check if this is development enviroment or LIVE
                            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));

                            if (response == null)
                            {
                                return AddErrorHeader("File type not accepted", 1);
                            }
                            aa.CreateAnalytic("Add_Media", DateTime.Now, user.userName, "Document");
                            artifactType = "document";
                        }
                        else
                        {
                            return AddErrorHeader("You did not upload an accepted picture or document type: (jpeg, jpg, png, bmp, doc, docx, ppt, pptx, xls, xlsx, txt, rtf", 1);
                        }
                    }
                    else
                    {
                        return AddErrorHeader("Server did not receive file post", 1);
                    }
                    //refresh the user object with the changes
                    user = userManager.GetUser(userId);
                    //build the artifact response

                    JsonModels.Artifact artifactResponse = new JsonModels.Artifact();
                    artifactResponse.id = response.id;
                    if(artifactType == "picture")
                    {
                        artifactResponse.artifactLocation = RoleEnvironment.GetConfigurationSettingValue("storageAccountUrl").ToString()+"thumbnails/" + response.artifactURL;
                        artifactResponse.fileLocation = response.fileURL;
                    }
                    else if (artifactType == "document")
                    {
                        artifactResponse.artifactLocation = response.artifactURL;
                        artifactResponse.fileLocation = response.fileURL;
                    }

                    artifactResponse.title = response.name;
                    artifactResponse.type = artifactType;
                    artifactResponse.creationDate = DateTime.Now.ToString();

                    string realReturnVal;
                    try
                    {
                        realReturnVal = Serialize(artifactResponse);
                    }
                    catch (Exception exception)
                    {
                        return AddErrorHeader(exception.Message, 1);
                    }
                    activityManager.AddActivity(user.id, "Artifact", "Added", artifactResponse.id);
                    return AddSuccessHeader(realReturnVal);
                }
                catch (Exception ex)
                {
                    logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex.ToString());
                    return AddErrorHeader("Problem saving media to cloud storage", 1);
                }
            }
        }
Exemplo n.º 3
0
        //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;
            }
        }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
 public JsonModels.Artifact GetArtifactJson(ProjectElement element)
 {
     JsonModels.Artifact artifactJson = new JsonModels.Artifact();
     if (element != null)
     {
         artifactJson.description = element.description;
         artifactJson.title = element.title;
         artifactJson.id = element.id;
         if (element.GetType() == typeof(ProjectElement_Document))
         {
             ProjectElement_Document ped = (ProjectElement_Document)element;
             artifactJson.artifactLocation = ped.documentThumbnailLocation;
             artifactJson.fileLocation = ped.documentLocation;
             artifactJson.type = "document";
             return artifactJson;
         }
         else if (element.GetType() == typeof(ProjectElement_Picture))
         {
             ProjectElement_Picture pep = (ProjectElement_Picture)element;
             artifactJson.artifactLocation = pep.pictureThumbnailLocation;
             artifactJson.fileLocation = pep.pictureLocation;
             artifactJson.type = "picture";
             return artifactJson;
         }
         else if (element.GetType() == typeof(ProjectElement_Audio))
         {
             ProjectElement_Audio pea = (ProjectElement_Audio)element;
             artifactJson.artifactLocation = pea.audioLocation;
             artifactJson.fileLocation = pea.audioLocation;
             artifactJson.type = "audio";
             return artifactJson;
         }
         else if (element.GetType() == typeof(ProjectElement_Code))
         {
             ProjectElement_Code pec = (ProjectElement_Code)element;
             artifactJson.artifactLocation = pec.code;
             artifactJson.fileLocation = pec.type;
             artifactJson.type = "code";
             return artifactJson;
         }
         else if (element.GetType() == typeof(ProjectElement_Video))
         {
             ProjectElement_Video pev = (ProjectElement_Video)element;
             artifactJson.artifactLocation = pev.videoId;
             artifactJson.fileLocation = pev.videoType;
             artifactJson.type = "video";
             return artifactJson;
         }
         else
         {
             return null;
         }
     }
     else
     {
         return null;
     }
 }