Ejemplo n.º 1
0
        /// <summary>
        /// Create a user event (metrics)
        /// </summary>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <Event> GetLogEvent(UserTep usr, string eventid, string message = null)
        {
            try
            {
                var properties = new Dictionary <string, object>();
                properties.Add("affiliation", usr.Affiliation);
                properties.Add("country", usr.Country);

                var logevent = new Event
                {
                    EventId = eventid,
                    Project = EventFactory.EventLogConfig.Settings["project"] != null ? EventFactory.EventLogConfig.Settings["project"].Value : "",
                    Status  = usr.Level.ToString(),
                    // Durations = durations,
                    Transmitter = EventFactory.EventLogConfig.Settings["transmitter"] != null ? EventFactory.EventLogConfig.Settings["transmitter"].Value : "",
                    Message     = message,
                    Item        = new EventItem
                    {
                        Created    = usr.GetFirstLoginDate(),
                        Updated    = usr.GetLastLoginDate(),
                        Id         = usr.Username,
                        Title      = usr.Caption,
                        Type       = "portal_user",
                        Properties = properties
                    }
                };

                return(logevent);
            }catch (Exception e) {
                context.LogError(usr, "Log event error: " + e.Message);
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Terradue.Tep.WebServer.WebUserTep"/> class.
        /// </summary>
        /// <param name="entity">Entity.</param>
        public WebUserProfileTep(IfyWebContext context, UserTep entity) : base(context, entity)
        {
            try{
                var github = Terradue.Github.GithubProfile.FromId(context, this.Id);
                this.Github   = github.Name;
                this.Gravatar = entity.GetAvatar();
            }catch (Exception) {}
            if (String.IsNullOrEmpty(this.Gravatar))
            {
                this.Gravatar = string.Format("http://www.gravatar.com/avatar/{0}", HashEmailForGravatar(string.IsNullOrEmpty(this.Email) ? "" : this.Email));
            }
            DateTime timef = entity.GetFirstLoginDate();

            this.FirstLoginDate = (timef == DateTime.MinValue ? null : timef.ToString("U"));
            DateTime timel = entity.GetLastLoginDate();

            this.LastLoginDate = (timel == DateTime.MinValue ? null : timel.ToString("U"));

            context.AccessLevel = EntityAccessLevel.Administrator;
            EntityList <WpsJob> jobs = new EntityList <WpsJob>(context);

            jobs.UserId         = this.Id;
            jobs.ItemVisibility = EntityItemVisibility.OwnedOnly;
            jobs.Load();
            CreatedJobs = jobs.Count;

            EntityList <DataPackage> dp = new EntityList <DataPackage>(context);

            dp.UserId         = this.Id;
            dp.ItemVisibility = EntityItemVisibility.OwnedOnly;
            dp.Load();
            CreatedDataPackages = dp.Count;

            var dpdefault = DataPackage.GetTemporaryForUser(context, entity);

            DefaultDataPackageItems = dpdefault.Items.Count;
        }