Пример #1
0
        public void CanAuthorDocuments()
        {
            // Setup
            var researcher = new Researcher {Name = "Payam Yavari"};
            researcher.AuthorDocument("The Speed of Sounds", "...");
            researcher.AuthorDocument("The speed of Stones", "...");

            // Act
            researcher.Save();
            ScopeManagement.ResetScope();

            // Assert
            researcher = Researcher.Find(researcher.Id);
            Assert.AreEqual(2, researcher.Documents.Count);

            var document = researcher.Documents.First();
            Assert.AreEqual("The Speed of Sounds", document.Title);
            Assert.AreEqual("...", document.Text);
            Assert.AreEqual("Payam Yavari", document.AuthorName);

            document = researcher.Documents.Last();
            Assert.AreEqual("The speed of Stones", document.Title);
            Assert.AreEqual("...", document.Text);
            Assert.AreEqual("Payam Yavari", document.AuthorName);
        }
Пример #2
0
 public Page2()
 {
     CurrentResearcher = new Researcher();
     /*CurrentProject = new Project();
     CurrentPaper = new Paper();*/
     InitializeComponent();
 }
        public IHttpActionResult PutResearcher(int id, Researcher researcher)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != researcher.Id)
            {
                return BadRequest();
            }

            db.Entry(researcher).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResearcherExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #4
0
 public ActionResult Create(FormCollection form)
 {
     var researcher = new Researcher();
     TryUpdateModel(researcher);
     researcher.Save();
     return RedirectToAction("Index");
 }
Пример #5
0
 public static void AddInitialData()
 {
     _FstBehavioralTestTypeAndBehaviors();
     ObjectRecognitionBehavioralTestTypeAndBehaviors();
     PlusMazeBehavioralTestTypeAndBehaviors();
     var researcher = new Researcher { Username = "******", Password = "******" };
     researcher.Save();
 }
Пример #6
0
        public static Project CreateDefaultFst(Researcher researcher, String name)
        {
            if (researcher == null)
            {
                Logger.logError("Invalid Researcher");
                return null;
            }

            var project = new Project { Name = name };

            var preTest = new BehavioralTest
            {
                Name = "preTest",
                BehavioralTestType = BehavioralTestType.Fst,
            };
            project.AddBehavioralTest(preTest);

            var test = new BehavioralTest
            {
                Name = "test",
                BehavioralTestType = BehavioralTestType.Fst,
            };
            project.AddBehavioralTest(test);

            Researcher.Current.AddProject(project);

            var preTestSession = new Session
            {
                Name = "",
            };
            preTest.AddSession(preTestSession);

            var preTestTrial = new Trial
            {
                Name = "",
                Duration = 15 * 60,
            };
            preTestSession.AddTrial(preTestTrial);

            var testSession = new Session
            {
                Name = "",
            };
            test.AddSession(testSession);

            var testTrial2 = new Trial
            {
                Name = "",
                Duration = 5 * 60,
            };
            testSession.AddTrial(testTrial2);

            Researcher.Current.Save();

            return project;
        }
Пример #7
0
 /*public string DummyProperty {
     get { return _dummyProperty; }
     set { _dummyProperty = value; }
 }*/
 public Page1()
 {
     CurrentResearcher = new Researcher();
     CurrentProject = new Project();
     RColl.CollectionChanged += (sender, args) => { Updated = true; };
     //RColl.Count();
     Updated = false;
     //Reset();
     InitializeComponent();
 }
        public IHttpActionResult PostResearcher(Researcher researcher)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Researchers.Add(researcher);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = researcher.Id }, researcher);
        }
Пример #9
0
        public void CanAddFavourite()
        {
            // Setup
            var researcher = new Researcher();
            researcher.AuthorDocument("New document", "...");
            researcher.Save();

            // Act
            researcher.AddFavourite(researcher.Documents.First().Id);
            researcher.AddFavourite(researcher.Documents.First().Id);

            // Assert
            researcher = Researcher.Find(researcher.Id);
            Assert.AreEqual(1, researcher.Favourites.Count);
        }
Пример #10
0
 public AdminResearcherForm(Researcher researcher)
     : this()
 {
     if (researcher != null)
     {
         _researcher = researcher;
         txtUsername.Text = researcher.Username;
         txtPassword.Text = researcher.Password;
         txtConfirmPassword.Text = researcher.Password;
         if (researcher.IsAdmin)
         {
             txtUsername.Enabled = false;
         }
     }
 }
Пример #11
0
        public void CanPersist()
        {
            // Setup
            var researcher = new Researcher();
            researcher.Name = "Jane Smith";
            researcher.Email = "*****@*****.**";
            researcher.Username = "******";

            // Act
            researcher.Save();

            // Assert
            researcher = Researcher.FindByUsername(researcher.Username);
            Assert.IsInstanceOf<Researcher>(researcher);
            Assert.AreEqual("Jane Smith", researcher.Name);
            Assert.AreEqual("*****@*****.**", researcher.Email);
            Assert.AreEqual("jsmith", researcher.Username);
        }
Пример #12
0
        public void CanPersist()
        {
            // Setup
            var author = new Researcher {Name = "Payam Yavari"};
            author.Save();
            var document = new Document();
            document.Title = "New Findings";
            document.Text = "Paragraphs of text";
            document.Author = author;

            // Act
            document.Save();

            // Assert
            document = Document.Find(document.Id);
            Assert.AreEqual("New Findings", document.Title);
            Assert.AreEqual("Paragraphs of text", document.Text);
            Assert.AreEqual("Payam Yavari", document.AuthorName);
        }
Пример #13
0
 public void LoadResearcher()
 {
     OpenFileDialog dialog = new OpenFileDialog();
     if (dialog.ShowDialog() == true)
         try {
             mRes = Researcher.Deserialize(dialog.FileName);
         }
         catch {
             MessageBox.Show("An error occured while loading researcher from file.");
         }
     mCurrentProject = new Project();
     mCurrentPaper = new Paper();
     mUpdated = false;
     OnPropertyChanged("");
 }
Пример #14
0
 public void NewResearcher()
 {
     mRes = new Researcher("<Place your ad here>", "<Here can be ad too>");
     mCurrentProject = new Project();
     mCurrentPaper = new Paper();
     mUpdated = false;
     OnPropertyChanged("");
 }
        /// <summary>
        /// Sends "contact researcher" message
        /// </summary>
        /// <param name="researcher">Researcher</param>
        /// <param name="languageId">Message language identifier</param>
        /// <param name="senderEmail">Sender email</param>
        /// <param name="senderName">Sender name</param>
        /// <param name="subject">Email subject. Pass null if you want a message template subject to be used.</param>
        /// <param name="body">Email body</param>
        /// <returns>Queued email identifier</returns>
        public virtual IList <int> SendContactResearcherMessage(Researcher researcher, int languageId, string senderEmail,
                                                                string senderName, string subject, string body)
        {
            if (researcher == null)
            {
                throw new ArgumentNullException(nameof(researcher));
            }

            //var store = _storeContext.CurrentStore;
            //languageId = EnsureLanguageIsActive(languageId, store.Id);

            //var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.ContactResearcherMessage, store.Id);
            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.ContactResearcherMessage, 0);

            if (!messageTemplates.Any())
            {
                return(new List <int>());
            }

            //tokens
            var commonTokens = new List <Token>
            {
                new Token("ContactUs.SenderEmail", senderEmail),
                new Token("ContactUs.SenderName", senderName),
                new Token("ContactUs.Body", body, true)
            };

            return(messageTemplates.Select(messageTemplate =>
            {
                //email account
                var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

                string fromEmail;
                string fromName;
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    fromEmail = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body = $"<strong>From</strong>: {WebUtility.HtmlEncode(senderName)} - {WebUtility.HtmlEncode(senderEmail)}<br /><br />{body}";
                }
                else
                {
                    fromEmail = senderEmail;
                    fromName = senderName;
                }

                var tokens = new List <Token>(commonTokens);
                //_messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
                _messageTokenProvider.AddResearcherTokens(tokens, researcher);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                var toEmail = researcher.Email;
                var toName = $"{researcher.FirstName} {researcher.LastName}";

                return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName,
                                        fromEmail: fromEmail,
                                        fromName: fromName,
                                        subject: subject,
                                        replyToEmailAddress: senderEmail,
                                        replyToName: senderName);
            }).ToList());
        }
Пример #16
0
        private void researchersListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                researcher = (Researcher)e.AddedItems[0];
                researcher = rc.LoadResearcherDetails(researcher);
                ResearcherDetailsPanel.DataContext = researcher;
                //Show past positions
                positionsListView.Items.Clear();
                foreach (var p in researcher.positions)
                {
                    if (researcher.position.Level != EmploymentLevel.Student && p.End != default(DateTime))
                    {
                        positionsListView.Items.Add(p.Start + "\t" + p.End + "\t" + p.Title() + Environment.NewLine);
                    }
                }


                staff = new Staff(researcher);
                rc.GetViewableStudents();
                students = rc.VisibleStudents.ToList();
                if (researcher.position.Level != EmploymentLevel.Student)
                {
                    threeYear.Content    = staff.ThreeYearAverage;
                    performance.Content  = staff.PerformancePercentage;
                    supervisions.Content = staff.Supervisions;
                }
                else
                {
                    threeYear.Content    = null;
                    performance.Content  = null;
                    supervisions.Content = null;
                }

                if (researcher.position.Level == EmploymentLevel.Student)
                {
                    Student student = (from s in students
                                       where researcher.ID == s.ID
                                       select s).SingleOrDefault();
                    degree.Content = student.Degree;

                    researchers = rc.VisibleResearchers.ToList();

                    var supervisor = (from s in researchers
                                      where s.ID == student.SupervisorID
                                      select s).SingleOrDefault();
                    supervisors.Content = supervisor.GivenName + " " + supervisor.FamilyName;
                }
                else
                {
                    degree.Content      = null;
                    supervisors.Content = null;
                }

                //Show publications
                pc = new PublicationsController(researcher);
                pc.SortPublicationList();
                publications = pc.VisiblePublications.ToList();
                publicationsListView.ItemsSource = publications;
            }
        }
Пример #17
0
 public TradePathHistogramControl(Researcher researcher, bool isAverage, bool toEnd) : base(parent => new TradePathHistogramPane(researcher, parent, isAverage, toEnd))
 {
     updatePlot(researcher.positions);
 }
Пример #18
0
 public TradePathHistogramPane(Researcher researcher, QGraphControl parent, bool isAverage, bool toEnd) : base(parent)
 {
     this.researcher = researcher;
     this.isAverage  = isAverage;
     this.toEnd      = toEnd;
 }
Пример #19
0
        // return the researcher's previous position list
        public static List <Position> fetchPreviousPositions(MySqlConnection conn, Researcher r)
        {
            List <Position> positions = new List <Position>();

            MySqlDataReader rdr = null;

            try
            {
                conn.Open();
                int id = r.getId();

                //if the end time is null, set a defaut value '3000-01-01 00:00:00'
                MySqlCommand cmd = new MySqlCommand("select level,start, IFNULL(end, '3000-01-01 00:00:00') " +
                                                    "from position " +
                                                    "where end is not null and id=?id", conn);

                cmd.Parameters.AddWithValue("id", id);
                rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    DateTime endTime = rdr.GetDateTime(2);

                    //if the end time equals the default time, set the end time to 'new DateTime()'
                    if (endTime.Year == 3000)
                    {
                        DateTime rtEnd = new DateTime();
                        positions.Add(new Position
                        {
                            level = rdr.GetValue(0).ToString(),
                            start = rdr.GetDateTime(1),
                            end   = rtEnd
                        });
                    }
                    else
                    {
                        positions.Add(new Position
                        {
                            level = rdr.GetValue(0).ToString(),
                            start = rdr.GetDateTime(1),
                            end   = endTime
                        });
                    }
                }
            }
            catch (MySqlException e)
            {
                ERDAdapter.ReportError("loading training sessions", e);
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }

            /*
             * foreach( Position p in positions)
             *  {
             *  Console.WriteLine("@@@@@@@@@@@@@@: " + p.ToString());
             * }
             */

            return(positions);
        }
Пример #20
0
 public static Researcher completeResearcherDetails(MySqlConnection conn, Researcher r)
 {
     return(r);
 }
Пример #21
0
        ////Load all details of the current researcher
        public Researcher LoadResearcherDetails(Researcher r)
        {
            Researcher currentResearcher = ERDAdapter.completeResearcherDetails(r);

            return(currentResearcher);
        }
Пример #22
0
        // by using the researcher id, get the researcher details
        public static Researcher fetchFullResearcherDetails(MySqlConnection conn, int id)
        {
            Researcher researcher = new Researcher();
            Student    rStudent   = new Student();
            Staff      rStaff     = new Staff();

            String type = "";

            MySqlDataReader rdr = null;

            //MySqlDataReader rdr2 = null;

            try
            {
                conn.Open();

                // This part will generate the supersision count of the researcher
                MySqlCommand cmd2 = new MySqlCommand("select count(*) as supervisioncount " +
                                                     "from researcher " +
                                                     "where supervisor_id=?supervisor_id", conn);

                cmd2.Parameters.AddWithValue("supervisor_id", id);
                rdr = cmd2.ExecuteReader();
                while (rdr.Read())
                {
                    researcher.Supervisions = rdr.GetInt32(0);
                }
                rdr.Close();


                // This part will generate the researcher detailed information
                MySqlCommand cmd = new MySqlCommand("select given_name, family_name, title, unit, campus, email, photo,level, current_start, utas_start, " +
                                                    "timestampdiff(day, DATE_FORMAT(utas_start,'%Y-%m-%d'),DATE_FORMAT(SYSDATE(), '%Y-%m-%d')) as days, " +
                                                    "type, IFNULL(degree, '') " +
                                                    "from researcher " +
                                                    "where id=?id", conn);

                cmd.Parameters.AddWithValue("id", id);
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    researcher.GivenName  = rdr.GetString(0);
                    researcher.FamilyName = rdr.GetString(1);
                    researcher.Title      = rdr.GetString(2);
                    researcher.Unit       = rdr.GetString(3);
                    researcher.Campus     = rdr.GetString(4);
                    researcher.Email      = rdr.GetString(5);
                    researcher.Photo      = rdr.GetString(6);

                    //Check whether 'Level' is null
                    if (!rdr.IsDBNull(7))
                    {
                        researcher.Level = rdr.GetString(7);
                    }
                    else
                    {
                        researcher.Level = "";
                    }

                    researcher.CurrentJobStart = rdr.GetDateTime(8);
                    researcher.EarliestStart   = rdr.GetDateTime(9);

                    float years  = (float)rdr.GetInt32(10) / 365;
                    int   dayInt = (int)(years * 100);
                    years = (float)dayInt / 100;

                    researcher.Tenure = years;



                    type = rdr.GetString(11);

                    // if the researche type equals 'Student', generate student object
                    if (type == "Student")
                    {
                        rStudent.GivenName       = researcher.GivenName;
                        rStudent.FamilyName      = researcher.FamilyName;
                        rStudent.Title           = researcher.Title;
                        rStudent.Unit            = researcher.Unit;
                        rStudent.Campus          = researcher.Campus;
                        rStudent.Email           = researcher.Email;
                        rStudent.Photo           = researcher.Photo;
                        rStudent.Level           = researcher.Level;
                        rStudent.CurrentJobStart = researcher.CurrentJobStart;
                        rStudent.EarliestStart   = researcher.EarliestStart;
                        rStudent.Tenure          = researcher.Tenure;
                        rStudent.Supervisions    = researcher.Supervisions;
                        rStudent.Degree          = rdr.GetString(12);
                    }
                    // if the researche type equals 'Student', generate staff object
                    else
                    {
                        rStaff.GivenName       = researcher.GivenName;
                        rStaff.FamilyName      = researcher.FamilyName;
                        rStaff.Title           = researcher.Title;
                        rStaff.Unit            = researcher.Unit;
                        rStaff.Campus          = researcher.Campus;
                        rStaff.Email           = researcher.Email;
                        rStaff.Photo           = researcher.Photo;
                        rStaff.Level           = researcher.Level;
                        rStaff.CurrentJobStart = researcher.CurrentJobStart;
                        rStaff.EarliestStart   = researcher.EarliestStart;
                        rStaff.Tenure          = researcher.Tenure;
                        rStaff.Supervisions    = researcher.Supervisions;
                    }
                }
            }
            catch (MySqlException e)
            {
                ERDAdapter.ReportError("loading training sessions", e);
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }


            // return student object
            if (type == "Student")
            {
                //get the publication count
                rStudent.PublicationsCount = PublicationAdapter.fetchPublicationCounts(conn, id);
                return(rStudent);
            }
            // return staff object
            else
            {
                //get the publication count
                rStaff.PublicationsCount = PublicationAdapter.fetchPublicationCounts(conn, id);
                rStaff.ThreeYearAverage  = calThreeYearAveragePublications(conn, id);

                // according to the level of staff, calculate the performance data
                switch (rStaff.Level)
                {
                case "A": rStaff.Performance = (float)(rStaff.ThreeYearAverage / 0.5);
                    break;

                case "B":
                    rStaff.Performance = rStaff.ThreeYearAverage;
                    break;

                case "C":
                    rStaff.Performance = (float)(rStaff.ThreeYearAverage / 2);
                    break;

                case "D":
                    rStaff.Performance = (float)(rStaff.ThreeYearAverage / 3.2);
                    break;

                case "E":
                    rStaff.Performance = (float)(rStaff.ThreeYearAverage / 4);
                    break;
                }

                return(rStaff);
            }
        }
Пример #23
0
        static void Main(string[] args)
        {
            var         t          = WebSocket.Driver;
            IUnitOfWork unitOfWork = new EFUnitOfWork();
            Stopwatch   stopwatch  = new Stopwatch();

            stopwatch.Start();
            ResearcherSaver.SaveResearcher("fiot3", "asoiu4", "Yuri", "M", "Gordienko", "0000-0002-7700-5649", unitOfWork);
            stopwatch.Stop();
            Console.WriteLine("all: " + stopwatch.Elapsed.TotalSeconds + " seconds");
            //var pub = unitOfWork.Publications.Find(item => item.AccountPublications.Any(ui => ui.Account.ResearcherAccounts.Any(y => y.Researcher.Chair.Faculty.FacultyName == "fiot")));
            ////Stopwatch stopwatch = new Stopwatch();
            //Console.WriteLine(DateIndex.GetIndex(new I10Index(), pub, DateTime.MinValue, DateTime.MaxValue));
            stopwatch.Restart();
            Researcher researchery = GoogleSchoolarParser.GetResearcherAsync("5Ih2GqMAAAAJ");

            //researchery.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine("google: " + stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            Researcher researcherq = PublonsParser.GetResearcherAsync("2379217");

            //researcherq.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            Researcher researcherw = ScopusParser.GetResearcherAsync("7101756666");

            //researcherw.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researchery = GoogleSchoolarParser.GetResearcherAsync("5Ih2GqMAAAAJ");
            //researchery.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researcherq = PublonsParser.GetResearcherAsync("2379217");
            //researcherq.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researcherw = ScopusParser.GetResearcherAsync("7101756666");
            //researcherw.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researchery = GoogleSchoolarParser.GetResearcherAsync("5Ih2GqMAAAAJ");
            //researchery.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researcherq = PublonsParser.GetResearcherAsync("2379217");
            //researcherq.Save(unitOfWork);
            stopwatch.Stop();
            //Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researcherw = ScopusParser.GetResearcherAsync("7101756666");
            //researcherw.Save(unitOfWork);
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researchery = GoogleSchoolarParser.GetResearcherAsync("5Ih2GqMAAAAJ");
            //researchery.Save(unitOfWork);
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researcherq = PublonsParser.GetResearcherAsync("2379217");
            //researcherq.Save(unitOfWork);
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            stopwatch.Restart();
            researcherw = ScopusParser.GetResearcherAsync("7101756666");
            //researcherw.Save(unitOfWork);
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed.TotalSeconds + " seconds");

            Console.WriteLine("====================");
            Console.ReadKey();
        }
Пример #24
0
 public string GetName([Parent] Researcher researcher)
 {
     return(researcher.Name);
 }
Пример #25
0
        private void LbResearcher_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //get selected researcher object
            Researcher researcherSel = (Researcher)lbResearcher.SelectedItem;

            if (researcherSel == null)
            {
                return;
            }
            //Initialize Component
            btnShowSupName.Visibility   = Visibility.Collapsed;
            lbSupName.Visibility        = Visibility.Collapsed;
            lbPrePosition.Visibility    = Visibility.Collapsed;
            lablePrePosition.Visibility = Visibility.Collapsed;
            lbPrePosition.ItemsSource   = null;

            string reseacherType = Convert.ToString(researcherSel.Type);

            if (reseacherType == "Staff")
            {
                Staff staff = new Staff();
                staff                   = Database.Database.LoadStaffDetails(researcherSel.Id);
                staff.PubCount          = Database.Database.PubCounts(researcherSel.Id);
                staff.SupervisionsCount = Database.Database.GetSupCount(researcherSel.Id);
                // create a varible TYAve to store 3-year average value
                // we will pass it to GetPerformance function below
                double TYAve = Database.Database.GetTYAve(researcherSel.Id);
                staff.TYAve       = TYAve;
                staff.Performance = Database.Database.GetPerformance(researcherSel.Level, TYAve);
                spResearcherDetails.DataContext = staff;
                // Switch "Show Name" button visibility to visible for staff whose PubCounts are not 0.
                if (staff.SupervisionsCount != 0)
                {
                    btnShowSupName.Visibility = Visibility.Visible;
                }

                lbPrePosition.Visibility    = Visibility.Visible;
                lablePrePosition.Visibility = Visibility.Visible;

                lbSupName.ItemsSource = Database.Database.GetSupervisionsList(researcherSel.Id);

                List <Position> listPrePosition = Database.Database.LoadPrePositions(researcherSel.Id);
                lbPrePosition.ItemsSource = listPrePosition;
            }
            else if (reseacherType == "Student")
            {
                Student student = new Student();
                student = Database.Database.LoadStudentDetails(researcherSel.Id);
                student.SupervisorName          = Database.Database.GetSupName(researcherSel.Id);
                student.PubCount                = Database.Database.PubCounts(researcherSel.Id);
                spResearcherDetails.DataContext = student;
                // Hide the "Show Name" button for student
                btnShowSupName.Visibility = Visibility.Collapsed;
            }

            List <Publication> listPublication = Database.Database.LoadPublications(researcherSel.Id);

            lbPublication.ItemsSource  = listPublication;
            researcherSel.Publications = listPublication;


            //clean publication content
            spPublicationDetails.DataContext = null;
        }
Пример #26
0
    private static void InsertProject()
    {
        Random rnd = new Random();
            var researcher = new Researcher { Username = "******" + rnd.Next(1, 10000).ToString(), Password = "******" };

            var project = new Project { Name = "my project" + rnd.Next(1, 10000).ToString() };
            var behavioralTestType = NHibernateHelper.OpenSession().Get<BehavioralTestType>(1);
            var behavioralTest = new BehavioralTest { Name = "first test", Project = project, BehavioralTestType = behavioralTestType};

            project.AddBehavioralTest(behavioralTest);
            researcher.AddProject(project);

            researcher.Save();

            System.Console.WriteLine("inserted new researcher with project!");
            FindResearcherById((int)researcher.Id);
    }
Пример #27
0
        public void CanRemoveFavourite()
        {
            // Setup
            var researcher = new Researcher();
            researcher.AuthorDocument("Title", "...");
            researcher.Save();
            researcher.AddFavourite(researcher.Documents.First().Id);

            // Act
            Researcher.Find(researcher.Id).RemoveFavourite(1);

            // Assert
            Assert.AreEqual(0, Researcher.Find(researcher.Id).Favourites.Count);
            Assert.AreEqual(0, Favourite.FindAll().Count());
        }
Пример #28
0
 private void DeleteCommandHandler(object sender, ExecutedRoutedEventArgs e)
 {
     RColl.RemoveResearcher(CurrentResearcher);
     CurrentResearcher = new Researcher();
 }
Пример #29
0
 public DetailedResearch(Researcher research)
 {
     BindingContext = research ?? throw new ArgumentNullException();
     InitializeComponent();
 }
Пример #30
0
 public static ObservableCollection <Publication> LoadPublicationsFor(Researcher r)
 {
     return(new ObservableCollection <Publication>(Database.LoadPublications(r)));
 }
Пример #31
0
        // return the student list in which the students' supervisor is the rearcher
        public static List <Student> LoadSupervisionStudents(Researcher r)
        {
            List <Student> studentList = ERDAdapter.fetchSupervisionStudents(r);

            return(studentList);
        }
 public void Setup()
 {
     _controller = new ResearchersController();
     _controller.SetFakeControllerContext();
     var user = new Researcher
     {
         Email = "*****@*****.**",
         Username = "******"
     };
     user.Save();
 }
        /// <summary>
        /// Sends 'New researcher account submitted' message to a store owner
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="researcher">Researcher</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual IList <int> SendNewResearcherAccountApplyStoreOwnerNotification(User user, Researcher researcher, int languageId)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (researcher == null)
            {
                throw new ArgumentNullException(nameof(researcher));
            }

            //var store = _storeContext.CurrentStore;
            //languageId = EnsureLanguageIsActive(languageId, store.Id);

            //var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.NewResearcherAccountApplyStoreOwnerNotification, store.Id);
            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.NewResearcherAccountApplyStoreOwnerNotification, 0);

            if (!messageTemplates.Any())
            {
                return(new List <int>());
            }

            //tokens
            var commonTokens = new List <Token>();

            _messageTokenProvider.AddUserTokens(commonTokens, user);
            _messageTokenProvider.AddResearcherTokens(commonTokens, researcher);

            return(messageTemplates.Select(messageTemplate =>
            {
                //email account
                var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

                var tokens = new List <Token>(commonTokens);
                //_messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
                _messageTokenProvider.AddUserTokens(tokens, user);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                var toEmail = emailAccount.Email;
                var toName = emailAccount.DisplayName;

                return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
            }).ToList());
        }
Пример #34
0
        private void AddCustomResearcherCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            Researcher newResearcher = researcherStub.DeepCopy() as Researcher;

            team.Add(newResearcher);
        }
 /// <summary>
 /// Event handler for when a Researcher tries to login. 
 /// On Success they will be directed to the Researcher Form.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnResSubmit_Click(object sender, EventArgs e)
 {
     string queryString = "select Res_ID, user_name, first_name, last_name, email from Researcher where user_name = '" + tbResUser.Text + "' and password = '******'";
     DatabaseQuery query = new DatabaseQuery(queryString, DatabaseQuery.Type.Select);
     if (query.Results.Count == 0) {
         lblResSatus.Text = "Invalid login. Please try again.";
     }
     else if (query.Results.Count == 1) {
         int user_id = Convert.ToInt32(query.Results[0][0]);
         string user_name = query.Results[0][1];
         string first_name = query.Results[0][2];
         string last_name = query.Results[0][3];
         string email = query.Results[0][4];
         Researcher res = new Researcher(user_id, user_name, first_name, last_name, email);
         Session["user"] = res;
         Response.Redirect("ResearcherForm.aspx");
     }
     else {
         throw new Exception("submitting user_name: " + tbResUser.Text + " returned incorrect number of rows: " + query.Results.Count);
     }
 }
Пример #36
0
 private void AddResearcherHandler(object sender, ExecutedRoutedEventArgs e)
 {
     ((ResearcherObservableCollection)Application.Current.Resources
         ["KeyResearcherCollection"]).AddResearcher(CurrentResearcher);
     CurrentResearcher = new Researcher();
     ((TabControl) Application.Current.MainWindow.FindName("MainTabControl"))
         .SelectedIndex = 0;
 }
        /// <summary>
        /// Register user
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual UserRegistrationResult RegisterUser(UserRegistrationRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (request.User == null)
            {
                throw new ArgumentException("Can't load current user");
            }

            var result = new UserRegistrationResult();

            if (request.User.IsSearchEngineAccount())
            {
                result.AddError("Search engine can't be registered");
                return(result);
            }

            if (request.User.IsBackgroundTaskAccount())
            {
                result.AddError("Background task account can't be registered");
                return(result);
            }

            if (request.User.IsRegistered())
            {
                result.AddError("Current user is already registered");
                return(result);
            }

            if (string.IsNullOrEmpty(request.Email))
            {
                result.AddError("EmailIsNotProvided");
                return(result);
            }

            if (!CommonHelper.IsValidEmail(request.Email))
            {
                result.AddError("WrongEmail");
                return(result);
            }

            if (string.IsNullOrWhiteSpace(request.Password))
            {
                result.AddError("Password Is Not Provided");
                return(result);
            }

            if (_userSettings.UsernamesEnabled && string.IsNullOrEmpty(request.Username))
            {
                result.AddError("Username Is Not Provided");
                return(result);
            }

            //validate unique user
            if (_userService.GetUserByEmail(request.Email) != null)
            {
                result.AddError("Email Already Exists");
                return(result);
            }

            //at this point request is valid
            request.User.UserName = request.Username;
            request.User.Email    = request.Email;

            var userPassword = new UserPassword
            {
                UserId         = request.User.Id,
                PasswordFormat = request.PasswordFormat,
                CreatedOnUtc   = DateTime.UtcNow
            };

            switch (request.PasswordFormat)
            {
            case PasswordFormat.Clear:
                userPassword.Password = request.Password;
                break;

            case PasswordFormat.Encrypted:
                userPassword.Password = _encryptionService.EncryptText(request.Password);
                break;

            case PasswordFormat.Hashed:
                var saltKey = _encryptionService.CreateSaltKey(ResearchUserServiceDefaults.PasswordSaltKeySize);
                userPassword.PasswordSalt = saltKey;
                userPassword.Password     = _encryptionService.CreatePasswordHash(request.Password, saltKey, _userSettings.HashedPasswordFormat);
                break;
            }

            _userService.InsertUserPassword(userPassword);
            //add to 'researcherRole' role
            var researcherRole = _userService.GetUserRoleBySystemName(ResearchUserDefaults.ResearchersRoleName);

            if (researcherRole == null)
            {
                throw new ResearchException("'Researchers' role could not be loaded");
            }

            request.User.UserUserRoleMappings.Add(new UserUserRoleMapping {
                UserRole = researcherRole
            });
            //remove from 'Guests' role
            var guestRole = request.User.UserRoles.FirstOrDefault(cr => cr.SystemName == ResearchUserDefaults.GuestsRoleName);

            if (guestRole != null)
            {
                request.User.UserUserRoleMappings
                .Remove(request.User.UserUserRoleMappings.FirstOrDefault(mapping => mapping.UserRoleId == guestRole.Id));
            }
            //_userService.UpdateUser(request.User);
            var researcher = new Researcher
            {
                ResearcherCode = _researcherService.GetNextNumber(),
                Email          = request.User.Email,
                AgencyId       = request.User.AgencyId,
                FirstName      = request.User.FirstName,
                LastName       = request.User.LastName,
                IDCard         = request.IDCard,
                TitleId        = request.User.TitleId,
                Gender         = request.Gender,
                IsActive       = true,
                PersonalTypeId = (int)PersonalType.Academic,
            };

            _researcherService.InsertResearcher(researcher);
            request.User.ResearcherId = researcher.Id;
            request.User.Roles        = researcherRole.SystemName;
            _userService.UpdateUser(request.User);
            //_workContext.CurrentUser = request.User;

            return(result);
        }
Пример #38
0
        public static Project CreateDefaultObjectRecognition(Researcher researcher, String name)
        {
            if (researcher == null)
            {
                Logger.logError("Invalid Researcher");
                return null;
            }

            var project = new Project { Name = name };

            var test = new BehavioralTest
            {
                Name = "Test1",
                BehavioralTestType = BehavioralTestType.ObjectRecognition,
            };

            project.AddBehavioralTest(test);

            Researcher.Current.AddProject(project);

            var testSession = new Session
            {
                Name = "S1",
            };
            test.AddSession(testSession);

            var testTrial = new Trial
            {
                Name = "T1",
                Duration = 300,
            };
            testSession.AddTrial(testTrial);

            testTrial = new Trial
            {
                Name = "T2",
                Duration = 300,
            };
            testSession.AddTrial(testTrial);

            testTrial = new Trial
            {
                Name = "T3",
                Duration = 300,
            };
            testSession.AddTrial(testTrial);

            testSession = new Session
            {
                Name = "S2",
            };
            test.AddSession(testSession);

            testTrial = new Trial
            {
                Name = "T1",
                Duration = 300,
            };
            testSession.AddTrial(testTrial);

            testTrial = new Trial
            {
                Name = "T2",
                Duration = 300,
            };
            testSession.AddTrial(testTrial);

            testTrial = new Trial
            {
                Name = "T3",
                Duration = 300,
            };
            testSession.AddTrial(testTrial);

            Researcher.Current.Save();

            return project;
        }
Пример #39
0
        public Researcher FetchFullResearcherDetails(Researcher researcher)
        {
            MySqlDataReader rdr     = null;
            bool            isEmpty = true;

            try
            {
                conn.Open();

                MySqlCommand cmd = new MySqlCommand("select * from researcher where id=?id", conn);
                cmd.Parameters.AddWithValue("id", researcher.Id);

                using (rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        if (researcher is Student)
                        {
                            var student = researcher as Student;
                            student.Degree     = rdr.GetString("degree");
                            student.Supervisor = new Staff {
                                Id = rdr.GetInt32("supervisor_id")
                            };
                        }
                        else
                        {
                            var staff = researcher as Staff;
                            staff.currentLevel = (EmploymentLevel)Enum.Parse(typeof(EmploymentLevel), rdr.GetString("level"));
                        }
                        PopulateResearcher(rdr, researcher);
                        isEmpty = false;
                    }
                }

                if (isEmpty)
                {
                    return(null);
                }

                if (researcher is Student)
                {
                    var student = researcher as Student;
                    cmd = new MySqlCommand("select * from researcher where id=?id", conn);
                    cmd.Parameters.AddWithValue("id", student.Supervisor.Id);
                    using (rdr = cmd.ExecuteReader())
                    {
                        if (rdr.Read())
                        {
                            PopulateStaff(rdr, student.Supervisor);
                        }
                    }
                }
                else
                {
                    var staff = researcher as Staff;
                    cmd = new MySqlCommand("select * from researcher where supervisor_id=?id", conn);
                    cmd.Parameters.AddWithValue("id", staff.Id);
                    using (rdr = cmd.ExecuteReader())
                    {
                        staff.Supervisions.Clear();
                        while (rdr.Read())
                        {
                            var student = new Student();
                            PopulateStudent(rdr, student);
                            student.Supervisor = staff;
                            staff.Supervisions.Add(student);
                        }
                    }
                }


                cmd = new MySqlCommand("select * from position where id=?id order by start", conn);
                cmd.Parameters.AddWithValue("id", researcher.Id);
                using (rdr = cmd.ExecuteReader())
                {
                    researcher.AllPositions.Clear();
                    while (rdr.Read())
                    {
                        researcher.AllPositions.Add(new Position
                        {
                            Level = (EmploymentLevel)Enum.Parse(typeof(EmploymentLevel), rdr.GetString("level")),
                            start = rdr.IsDBNull(rdr.GetOrdinal("start")) ? (DateTime?)null : rdr.GetDateTime("start"),
                            end   = rdr.IsDBNull(rdr.GetOrdinal("end")) ? (DateTime?)null : rdr.GetDateTime("end")
                        });
                    }
                }

                cmd = new MySqlCommand("select p.* from publication p join researcher_publication rp on p.doi=rp.doi where rp.researcher_id=?id order by year desc, title", conn);
                cmd.Parameters.AddWithValue("id", researcher.Id);
                using (rdr = cmd.ExecuteReader())
                {
                    researcher.AllPublications.Clear();
                    while (rdr.Read())
                    {
                        var id = rdr.GetString(4);
                        researcher.AllPublications.Add(new Publication
                        {
                            DOI       = rdr.GetString(0),
                            Title     = rdr.GetString(1),
                            Authors   = rdr.GetString(2),
                            Year      = rdr.GetString(3),
                            Type      = (OutputType)Enum.Parse(typeof(OutputType), rdr.GetString(4)),
                            CiteAs    = rdr.GetString(5),
                            Available = rdr.GetDateTime(6),
                            Age       = DateTime.Now.Subtract(rdr.GetDateTime(6)).Days.ToString() + " Days"
                        });
                    }
                }
            }
            catch (MySqlException e)
            {
                throw new Exception("loading staff", e);
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return(researcher);
        }
Пример #40
0
        private static void InsertProject()
        {
            Random rnd = new Random();
            var researcher = new Researcher { Username = "******" + rnd.Next(1, 10000).ToString(), Password = "******" };

            var project = new Project { Name = "my project" + rnd.Next(1, 10000).ToString() };
            //var behavioralTestType = null;// NHibernateHelper.OpenSession().Get<BehavioralTestType>(1);
            var behavioralTest = new BehavioralTest { Name = "first test", Project = project };

            project.AddBehavioralTest(behavioralTest);
            researcher.AddProject(project);

            researcher.Save();
        }
Пример #41
0
 public Researcher CompleteResearcherDetails(Researcher r)
 {
     return(null);
 }
Пример #42
0
 public void AddDefaultResearcher()
 {
     Researcher res = new Researcher();
     res.AddProjects(new Project());
     res.AddProjects(new Project());
     res.AddProjects(new Project());
     Researchers.AddResearcher(res);
     res = new Researcher("OLOLOLO", "F**K");
     CurrentResearcher = res;
     res.AddProjects(new Project());
     Researchers.AddResearcher(res);
     SelectedProject = res.Projects.First();
 }
 /// <summary>
 /// Automatically fills in the appropriate text in the forms from the given logged in user
 /// This should only be used when a user is logged in and their information is stored in the Session
 /// </summary>
 /// <param name="userType">Determines if user is a Researcher or Participant</param>
 private void autoFillForms(SuperUser.UserType userType)
 {
     SuperUser user = (SuperUser)Session["user"];
     int userID = user.UserID;
     switch (userType) {
         case SuperUser.UserType.Researcher:
             Researcher res = new Researcher(userID);
             tbResUserName.Text = res.UserName;
             tbResFirstName.Text = res.FirstName;
             tbResLastName.Text = res.LastName;
             tbResEmail.Text = res.Email;
             break;
         case SuperUser.UserType.Participant:
             Participant par = new Participant(userID);
             tbParUserName.Text = par.UserName;
             tbParFirstName.Text = par.FirstName;
             tbParLastName.Text = par.LastName;
             tbParEmail.Text = par.Email;
             break;
     }
 }
    /// <summary>
    /// Event handler when a researcher is finished creating/editing an account. 
    /// If there are no errors, the session variable will be set to the user and they
    /// will be redirected to the researcher form.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResSubmit_Click(object sender, EventArgs e)
    {
        if (isFormValid(SuperUser.UserType.Researcher)) {
            string queryString = "";
            DatabaseQuery query;
            if (Request.QueryString["edit"] == "true") {
                int resID = ((Researcher)Session["user"]).UserID;
                DAL.UpdateResearcher(resID, tbResFirstName.Text, tbResLastName.Text, tbResUserName.Text, tbResEmail.Text, tbResPassword.Text);
            }
            else {
                try {
                    DAL.InsertResearcher(tbResUserName.Text, tbResFirstName.Text, tbResLastName.Text, tbResEmail.Text, tbResPassword.Text);
                }
                catch (Exception exception) {
                    lblParStatus.Text = exception.Message;
                    lblParStatus.Visible = true;
                    return;
                }
            }
            lblResStatus.Text = "";

            queryString = "select Res_ID from Researcher where User_Name = '" + tbResUserName.Text + "'";
            query = new DatabaseQuery(queryString, DatabaseQuery.Type.Select);
            int user_id = Convert.ToInt32(query.Results[0][0]);

            Researcher res = new Researcher(user_id, tbResUserName.Text, tbResFirstName.Text, tbResLastName.Text, tbResEmail.Text);
            Session["user"] = res;

            Response.Redirect("ResearcherForm.aspx");
        }
    }
Пример #45
0
        public async Task <bool> CreateUser(UserManager <AuthorTestUser> userManager, string email, string firstName, Researcher researcher, string role)
        {
            var check = await userManager.FindByEmailAsync(email);

            if (check == null)
            {
                var user = new AuthorTestUser
                {
                    Email    = email,
                    UserName = email,

                    Researcher = researcher
                };

                await userManager.CreateAsync(user, "password");

                await userManager.AddToRoleAsync(user, role);

                return(true);
            }
            return(false);
        }