Example #1
0
        public string NotesList(string parm)
        {
            if (parm == "")
            {
                return("{}");
            }
            List <Note> notes  = new Data.Note().getProtocolNotes(decimal.Parse(parm), 1, 1);
            string      retval = "";

            foreach (Note n in notes)
            {
                if (retval == "")
                {
                    retval = "\"" + n.CKey + "\":" + "\"" + n.Title + "\"";
                }
                else
                {
                    retval = retval + ",\"" + n.CKey + "\":" + "\"" + n.Title + "\"";
                }
            }

            //remove non-ascii
            retval = System.Text.RegularExpressions.Regex.Replace(retval, @"[^\u0000-\u007F]+", string.Empty);

            //remove control characters
            string output = new string(retval.Where(c => !char.IsControl(c)).ToArray());

            return("{" + retval + "}");
        }
Example #2
0
        internal static NoteInfo FetchNoteInfo(Data.Note data)
        {
            var result = new NoteInfo();

            result.Fetch(data);
            return(result);
        }
        public async Task <Data.Note> CreateNote(CreatedNote newNote)
        {
            try
            {
                var note = new Data.Note()
                {
                    Title          = newNote.Title,
                    Text           = newNote.Text,
                    IsCompleted    = newNote.IsCompleted,
                    Completable    = newNote.Completable,
                    CreatedDate    = DateTime.Now,
                    LastUpdateTime = DateTime.Now
                };

                await _dataContext.Notes.AddAsync(note);

                await _dataContext.SaveChangesAsync();

                return(note);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #4
0
        protected void Insert(Data.Note data)
        {
            data.NoteId      = this.ReadProperty(NoteIdProperty);
            data.CreatedBy   = ((BusinessIdentity)Csla.ApplicationContext.User.Identity).UserId;
            data.CreatedDate = DateTime.Now;

            this.Update(data);
        }
Example #5
0
        public void Run(CatalogRecord record, ManagedFile file, ApplicationUser user, ApplicationDbContext db, string processingDirectory, string agencyId)
        {
            if (string.IsNullOrWhiteSpace(agencyId))
            {
                agencyId = "int.example";
            }

            VersionableBase.DefaultAgencyId = agencyId;

            // Set SPSS path.
            string spssPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);

            SpssRaw.Instance.Initialize(spssPath);

            var existingPhysicalInstance = GetExistingPhysicalInstance(file, agencyId);

            string path         = Path.Combine(processingDirectory, file.Name);
            string errorMessage = string.Empty;

            // Create the PhysicalInstance
            // Calculate the summary statistics.
            if (file.Name.EndsWith(".dta"))
            {
                errorMessage = CreateOrUpdatePhysicalInstanceForFile <StataImporter>(file.Id, path, agencyId, existingPhysicalInstance);
            }
            if (file.Name.EndsWith(".sav"))
            {
                errorMessage = CreateOrUpdatePhysicalInstanceForFile <SpssImporter>(file.Id, path, agencyId, existingPhysicalInstance);
            }
            if (file.Name.EndsWith(".csv"))
            {
                errorMessage = CreateOrUpdatePhysicalInstanceForFile <CsvImporter>(file.Id, path, agencyId, existingPhysicalInstance);
            }
            if (file.Name.EndsWith(".rdata") ||
                file.Name.EndsWith(".rda"))
            {
                errorMessage = CreateOrUpdatePhysicalInstanceForFile <RDataImporter>(file.Id, path, agencyId, existingPhysicalInstance);
            }

            // Log any errors.
            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                var note = new Data.Note()
                {
                    CatalogRecord = file.CatalogRecord,
                    File          = file,
                    Timestamp     = DateTime.UtcNow,
                    User          = user,
                    Text          = errorMessage
                };
                db.Notes.Add(note);
                db.SaveChanges();
            }
        }
Example #6
0
 protected void Update(Data.Note data)
 {
     if (this.IsSelfDirty)
     {
         data.SourceType   = (int)this.ReadProperty(SourceTypeProperty);
         data.SourceId     = this.ReadProperty(SourceIdProperty);
         data.Body         = this.ReadProperty(BodyProperty);
         data.ModifiedBy   = ((BusinessIdentity)Csla.ApplicationContext.User.Identity).UserId;
         data.ModifiedDate = DateTime.Now;
     }
 }
Example #7
0
        protected override void DataPortal_DeleteSelf()
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var data = new Data.Note
                {
                    NoteId = this.ReadProperty(NoteIdProperty)
                };

                ctx.ObjectContext.Notes.DeleteObject(data);

                ctx.ObjectContext.SaveChanges();
            }
        }
Example #8
0
        protected override void DataPortal_DeleteSelf()
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                        .GetManager(Database.ApplicationConnection, false))
            {
                var data = new Data.Note
                {
                    NoteId = this.ReadProperty(NoteIdProperty)
                };

                ctx.ObjectContext.Notes.DeleteObject(data);

                ctx.ObjectContext.SaveChanges();
            }
        }
Example #9
0
 private void Fetch(Data.Note data)
 {
     this.LoadProperty(NoteIdProperty, data.NoteId);
     this.LoadProperty(SourceTypeProperty, data.SourceType);
     this.LoadProperty(SourceIdProperty, data.SourceId);
     this.LoadProperty(BodyProperty, data.Body);
     this.LoadProperty(ModifiedByProperty, data.ModifiedBy);
     this.LoadProperty(ModifiedByNameProperty, data.ModifiedByUser.Name);
     this.LoadProperty(ModifiedByEmailProperty, data.ModifiedByUser.Email);
     this.LoadProperty(ModifiedDateProperty, data.ModifiedDate);
     this.LoadProperty(CreatedByProperty, data.CreatedBy);
     this.LoadProperty(CreatedByNameProperty, data.CreatedByUser.Name);
     this.LoadProperty(CreatedByEmailProperty, data.CreatedByUser.Email);
     this.LoadProperty(CreatedDateProperty, data.CreatedDate);
 }
Example #10
0
        protected override void DataPortal_Insert()
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                        .GetManager(Database.ApplicationConnection, false))
            {
                var data = new Data.Note();

                this.Insert(data);

                ctx.ObjectContext.AddToNotes(data);

                ctx.ObjectContext.SaveChanges();

                this.LoadProperty(NoteIdProperty, data.NoteId);
                this.LoadProperty(CreatedByProperty, data.CreatedBy);
                this.LoadProperty(CreatedDateProperty, data.CreatedDate);
            }
        }
Example #11
0
        protected override void DataPortal_Insert()
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var data = new Data.Note();

                this.Insert(data);

                ctx.ObjectContext.AddToNotes(data);

                ctx.ObjectContext.SaveChanges();

                this.LoadProperty(NoteIdProperty, data.NoteId);
                this.LoadProperty(CreatedByProperty, data.CreatedBy);
                this.LoadProperty(CreatedDateProperty, data.CreatedDate);
            }
        }
Example #12
0
        protected override void DataPortal_Update()
        {
            using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities>
                        .GetManager(Database.ApplicationConnection, false))
            {
                var data = new Data.Note
                {
                    NoteId = this.ReadProperty(NoteIdProperty)
                };

                ctx.ObjectContext.Notes.Attach(data);

                this.Update(data);

                ctx.ObjectContext.SaveChanges();

                this.LoadProperty(ModifiedByProperty, data.ModifiedBy);
                this.LoadProperty(ModifiedDateProperty, data.ModifiedDate);
            }
        }
Example #13
0
        protected override void DataPortal_Update()
        {
            using (var ctx = Csla.Data.ObjectContextManager <ApplicationEntities>
                             .GetManager(Database.ApplicationConnection, false))
            {
                var data = new Data.Note
                {
                    NoteId = this.ReadProperty(NoteIdProperty)
                };

                ctx.ObjectContext.Notes.Attach(data);

                this.Update(data);

                ctx.ObjectContext.SaveChanges();

                this.LoadProperty(ModifiedByProperty, data.ModifiedBy);
                this.LoadProperty(ModifiedDateProperty, data.ModifiedDate);
            }
        }
Example #14
0
        public Data.Note ToModel()
        {
            var res = new Data.Note
            {
                Id               = Id,
                Title            = Title,
                Content          = Content,
                CategoryId       = CategoryId,
                CreationTime     = CreationTime,
                ModificationTime = ModificationTime,
                UserId           = UserId,
                Status           = Status,
            };

            if (Keywords == null)
            {
                res.Keywords = Array.Empty <string>();
            }
            else
            {
                res.Keywords = Keywords.Split(';').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToArray();
            }
            return(res);
        }
Example #15
0
        public static Note FromModel(Data.Note data)
        {
            Note res = new Note
            {
                Id               = data.Id,
                Title            = data.Title,
                Content          = data.Content,
                CategoryId       = data.CategoryId,
                CreationTime     = data.CreationTime,
                ModificationTime = data.ModificationTime,
                UserId           = data.UserId,
                Status           = data.Status,
            };

            if (data.Keywords == null)
            {
                res.Keywords = string.Empty;
            }
            else
            {
                res.Keywords = string.Join(";", data.Keywords.Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)));
            }
            return(res);
        }
Example #16
0
        public ActionResult AddNote(Guid id, Guid fileId, string note)
        {
            if (string.IsNullOrWhiteSpace(note))
            {
                return(Content(string.Empty));
            }

            using (var db = ApplicationDbContext.Create())
            {
                var file = GetFile(fileId, db);

                var user = db.Users.Where(x => x.UserName == User.Identity.Name)
                           .FirstOrDefault();

                if (!file.CatalogRecord.Curators.Any(x => x.UserName == User.Identity.Name) &&
                    !file.CatalogRecord.Approvers.Any(x => x.UserName == User.Identity.Name) &&
                    !OrganizationHelper.DoesUserHaveRight(db, User, file.CatalogRecord.Organization.Id, Right.CanApprove))
                {
                    throw new HttpException(403, "Only curators may perform this task.");
                }

                string agency = file.CatalogRecord.Organization.AgencyID;

                try
                {
                    var client   = RepositoryHelper.GetClient();
                    var variable = client.GetLatestItem(id, agency) as Variable;

                    var noteObj = new Data.Note()
                    {
                        CatalogRecord  = file.CatalogRecord,
                        File           = file,
                        Timestamp      = DateTime.UtcNow,
                        User           = user,
                        Text           = note,
                        VariableAgency = variable.AgencyId,
                        VariableId     = variable.Identifier,
                        VariableName   = variable.ItemName.Best
                    };
                    db.Notes.Add(noteObj);

                    // Log the adding of the note.
                    var log = new Event()
                    {
                        EventType            = EventTypes.AddNote,
                        Timestamp            = DateTime.UtcNow,
                        User                 = user,
                        RelatedCatalogRecord = file.CatalogRecord,
                        Title                = "Add a Note",
                        Details              = note
                    };
                    log.RelatedManagedFiles.Add(file);

                    db.Events.Add(log);

                    db.SaveChanges();

                    var comment = new CommentModel()
                    {
                        UserName = User.Identity.Name,
                        Date     = noteObj.Timestamp.ToShortDateString(),
                        Comment  = noteObj.Text
                    };
                    return(Json(comment));
                }
                catch (Exception ex)
                {
                    throw new HttpException(500, ex.Message);
                }
            }
        }
Example #17
0
        public bool Execute()
        {
            string path = Path.Combine(GitRepositoryPath, CatalogRecordId.ToString());

            //path = Path.Combine(path, ".git");

            logger.Debug("Starting AddFiles operation for " + path);

            var managedFiles = new List <ManagedFile>();

            // virus check
            bool virusError = false;

            using (var db = ApplicationDbContext.Create())
            {
                ApplicationUser user = new ApplicationUser {
                    Id = UserId.ToString()
                };
                db.Users.Attach(user);
                CatalogRecord record = new CatalogRecord {
                    Id = CatalogRecordId
                };
                db.CatalogRecords.Attach(record);
                foreach (var incomingFile in IncomingFileNames)
                {
                    var log = new Data.Event()
                    {
                        EventType            = EventTypes.EditManagedFile,
                        Timestamp            = DateTime.UtcNow,
                        User                 = user,
                        RelatedCatalogRecord = record,
                        Title                = "Virus Scan",
                        Details              = string.Empty
                    };

                    ManagedFile mf = db.Files.Where(x => x.Id == incomingFile.Key).First();
                    managedFiles.Add(mf);
                    log.RelatedManagedFiles.Add(mf);

                    string fileNameOnly = Path.GetFileName(incomingFile.Value);

                    // Virus check
                    try
                    {
                        mf.VirusCheckMethod = "ClamAV";
                        mf.VirusCheckDate   = DateTime.UtcNow;

                        logger.Debug("Running virus check on " + incomingFile.Value);

                        ClamClient scanner = new ClamClient("localhost", 3310);
                        var        result  = scanner.ScanFileOnServer(incomingFile.Value);

                        switch (result.Result)
                        {
                        case ClamScanResults.Clean:
                            mf.Status            = Data.FileStatus.Accepted;
                            mf.AcceptedDate      = DateTime.UtcNow;
                            mf.VirusCheckOutcome = "OK";

                            log.Details = "Clean virus scan on " + fileNameOnly;
                            logger.Debug(log.Details);

                            break;

                        case ClamScanResults.VirusDetected:
                            //TODO delete/quarentine? remove from incoming files.
                            mf.Status            = Data.FileStatus.Rejected;
                            mf.VirusCheckOutcome = log.Details;

                            //result.InfectedFiles.First().VirusName
                            virusError  = true;
                            log.Details = "Virus " + result.InfectedFiles.First().VirusName + "found on " + fileNameOnly;
                            logger.Warn(log.Details);

                            break;

                        case ClamScanResults.Error:
                            mf.Status            = Data.FileStatus.Accepted;
                            mf.AcceptedDate      = DateTime.UtcNow;
                            mf.VirusCheckOutcome = log.Details;

                            virusError  = true;
                            log.Details = "Virus scan error on " + fileNameOnly + " " + result.RawResult;
                            logger.Error(log.Details);

                            break;
                        }
                    }
                    catch (System.Net.Sockets.SocketException se)
                    {
                        virusError           = true;
                        log.Details          = "Could not connect to virus scanner for " + fileNameOnly + " " + se.Message;
                        mf.VirusCheckOutcome = log.Details;

                        logger.Error("Socket exception during virus check", se);
                    }
                    catch (Exception e)
                    {
                        virusError           = true;
                        log.Details          = "Error during virus scan " + fileNameOnly + " " + e.Message;
                        mf.VirusCheckOutcome = log.Details;

                        logger.Error("Problem during virus check", e);
                    }

                    db.Events.Add(log);
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                }
            }

            if (virusError)
            {
                return(false);
            }

            // Add the files to the git repository.
            using (Repository repo = new Repository(path))
            {
                #region rename
                foreach (var rename in RenamedFileNames)
                {
                    Guid   fileId           = rename.Key;
                    string originalFileName = rename.Value.Item1;
                    string newFileName      = rename.Value.Item2;

                    string source      = Path.Combine(repo.Info.WorkingDirectory, originalFileName);
                    string destination = Path.Combine(repo.Info.WorkingDirectory, newFileName);
                    //File.Move(source, destination);
                    LibGit2Sharp.Commands.Move(repo, source, destination);
                }

                string authorEmail = UserEmail;
                if (string.IsNullOrWhiteSpace(authorEmail))
                {
                    authorEmail = "*****@*****.**";
                }

                Signature author    = new Signature(Username, authorEmail, DateTime.UtcNow);
                Signature committer = new Signature(UserId.ToString(), UserId.ToString() + "@curator", DateTime.UtcNow);

                try
                {
                    Commit commit = repo.Commit("Renaming Files", author, committer);
                }
                catch
                {
                    // Nothing to rename
                }
                #endregion

                foreach (var incomingFile in IncomingFileNames)
                {
                    string filename    = Path.GetFileName(incomingFile.Value);
                    string destination = Path.Combine(repo.Info.WorkingDirectory, filename);
                    File.Copy(incomingFile.Value, destination, true);

                    // For files that are larger than a gigabyte, do not stage them.
                    // gitlib throws an AccessViolationException.
                    var fileInfo = new FileInfo(incomingFile.Value);
                    if (fileInfo.Length > 1024 * 1024 * 1024)
                    {
                        continue;
                    }

                    try
                    {
                        LibGit2Sharp.Commands.Stage(repo, filename);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error while staging. " + ex.Message);
                    }
                }


                if (string.IsNullOrWhiteSpace(CommitMessage))
                {
                    CommitMessage = "Adding Files";
                }

                try
                {
                    if (repo.Index.Count > 0)
                    {
                        Commit commit = repo.Commit(CommitMessage, author, committer);
                    }
                }
                catch
                {
                    // TODO
                }
            }

            // Find the agency ID to use, based on the CatalogRecord.
            string agencyId = null;
            using (var db = ApplicationDbContext.Create())
            {
                var record = db.CatalogRecords.Where(x => x.Id == this.CatalogRecordId).Include(x => x.Organization).FirstOrDefault();
                if (record != null && record.Organization != null && !string.IsNullOrWhiteSpace(record.Organization.AgencyID))
                {
                    agencyId = record.Organization.AgencyID;
                }
                else
                {
                    //TODO error
                }

                var user = db.Users.Find(UserId.ToString());

                // Run any addin actions on each file.
                foreach (var file in managedFiles)
                {
                    foreach (var addin in FileActions)
                    {
                        try
                        {
                            if (!addin.CanRun(file))
                            {
                                continue;
                            }

                            addin.Run(file.CatalogRecord, file, user, db, path, agencyId);
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Error running file action: " + addin.Name, ex);

                            var note = new Data.Note()
                            {
                                CatalogRecord = file.CatalogRecord,
                                File          = file,
                                Timestamp     = DateTime.UtcNow,
                                User          = user,
                                Text          = "Error runnning file action: " + addin.Name + ". " + ex.Message
                            };
                            db.Notes.Add(note);
                            db.SaveChanges();
                        }
                    }
                }
            }

            return(true);
        }
Example #18
0
 public Note(Data.Note note)
 {
     Id       = note.Id;
     TaskId   = note.TaskId;
     NoteText = note.NoteText;
 }
Example #19
0
        public ActionResult AddNote(Guid id, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(Content(string.Empty));
            }

            // Get the CatalogRecord, so we can figure out what agency ID to use.
            using (var db = ApplicationDbContext.Create())
            {
                var user = db.Users.Where(x => x.UserName == User.Identity.Name)
                           .FirstOrDefault();
                if (user == null)
                {
                    return(RedirectToAction("Index"));
                }


                var file = GetFile(id, db);

                if (!file.CatalogRecord.Curators.Any(x => x.UserName == User.Identity.Name) &&
                    !file.CatalogRecord.Approvers.Any(x => x.UserName == User.Identity.Name) &&
                    file.CatalogRecord.CreatedBy.UserName != User.Identity.Name &&
                    !OrganizationHelper.DoesUserHaveRight(db, User, file.CatalogRecord.Organization.Id, Right.CanApprove))
                {
                    throw new HttpException(403, "Only curators may perform this task.");
                }

                try
                {
                    var note = new Data.Note()
                    {
                        CatalogRecord = file.CatalogRecord,
                        File          = file,
                        Timestamp     = DateTime.UtcNow,
                        User          = user,
                        Text          = text
                    };
                    db.Notes.Add(note);

                    // Log the adding of the note.
                    var log = new Event()
                    {
                        EventType            = EventTypes.AddNote,
                        Timestamp            = DateTime.UtcNow,
                        User                 = user,
                        RelatedCatalogRecord = file.CatalogRecord,
                        Title                = "Add a Note",
                        Details              = text
                    };
                    log.RelatedManagedFiles.Add(file);

                    db.Events.Add(log);

                    db.SaveChanges();

                    return(Content(string.Empty));
                }
                catch (Exception ex)
                {
                    throw new HttpException(500, ex.Message);
                }
            }
        }