Пример #1
0
 public void ServiceUpdated(Guid serviceId, ServiceItem service, ServiceAnalytics analytics)
 {
     OnServiceChanged(new ServiceChangedEventArgs()
     {
         ServiceId = serviceId, Status = analytics.Status, PID = analytics.ProcessID, AutoRestart = service.ForceRestart, Restarts = analytics.Restarts
     });
 }
Пример #2
0
        public object Get(AnalyticsServicesUserRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            var result  = new List <WebAnalyticsService>();

            try {
                context.Open();
                context.LogInfo(this, string.Format("/analytics/service/user/{0} GET", request.Identifier));

                ServiceAnalytics analytics = new ServiceAnalytics(context);
                var user = User.FromUsername(context, request.Identifier);
                analytics.AddServices(request.startdate, request.enddate, user.UserId);
                foreach (var service in analytics.Services)
                {
                    result.Add(new WebAnalyticsService(service));
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Пример #3
0
        public object Put(AnalyticsAsdRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            var result  = new List <WebAnalyticsService>();

            try {
                context.Open();
                context.LogInfo(this, string.Format("/analytics/asd/{0} PUT", request.Id));

                if (string.IsNullOrEmpty(request.Usernames))
                {
                    return(new List <WebAnalyticsService>());
                }
                var usernames  = request.Usernames.Split(',');
                var usernamesS = "'" + string.Join("','", usernames) + "'";

                string sql = string.Format("SELECT id FROM usr WHERE username IN ({0});", usernamesS);
                context.LogDebug(this, sql);
                var requestids = context.GetQueryIntegerValues(sql);
                context.LogDebug(this, "found " + requestids.Length);

                if (requestids.Length > 0)
                {
                    ServiceAnalytics analytics = new ServiceAnalytics(context);
                    analytics.AddServices(request.startdate, request.enddate, requestids.ToList());
                    foreach (var service in analytics.Services)
                    {
                        result.Add(new WebAnalyticsService(service));
                    }
                }
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Пример #4
0
        public object Put(AnalyticsServicesCommunityRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            var result  = new List <WebAnalyticsService>();

            try {
                context.Open();
                context.LogInfo(this, string.Format("/analytics/service/community/{0} PUT", request.Identifier));

                if (string.IsNullOrEmpty(request.Usernames))
                {
                    return(new List <WebAnalyticsService>());
                }
                var usernames  = request.Usernames.Split(',');
                var usernamesS = "'" + string.Join("','", usernames) + "'";

                string sql = string.Format("SELECT id FROM usr WHERE username IN ({0});", usernamesS);
                context.LogDebug(this, sql);
                var requestids = context.GetQueryIntegerValues(sql);
                context.LogDebug(this, "found " + requestids.Length);

                ServiceAnalytics analytics = new ServiceAnalytics(context);
                var community = ThematicCommunity.FromIdentifier(context, request.Identifier);
                if (!community.CanUserManage(context.UserId))
                {
                    return(new List <WebAnalyticsService>());
                }
                var userids = community.GetUsersIds();
                context.LogDebug(this, "found " + userids.Count);

                var ids = new List <int>();
                foreach (var id in requestids)
                {
                    if (userids.Contains(id))
                    {
                        if (!ids.Contains(id))
                        {
                            ids.Add(id);
                        }
                    }
                }

                context.LogDebug(this, ids.Count + " in common");

                var apps       = new List <string>();
                var cachedapps = community.GetThematicApplicationsCached();
                foreach (var app in cachedapps)
                {
                    apps.Add(app.UId);
                }

                context.LogDebug(this, "found " + apps.Count + " apps");

                analytics.AddServices(request.startdate, request.enddate, ids, apps);
                foreach (var service in analytics.Services)
                {
                    result.Add(new WebAnalyticsService(service));
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }