示例#1
0
        public Application GetApplicationById(Guid id)
        {
            if (id == InternalGetAssessmentId())
            {
                return(GetAssessmentApplication());
            }

            if (id == GetMiniQuizAppicationId())
            {
                return(GetMiniQuizAppication());
            }

            var q = new ApplicationQuery
            {
                Id   = id,
                Role = Context.Role.Id
            };

            if (!BaseSecurity.IsSysAdmin(Context))
            {
                q.SchoolId = Context.SchoolId;
            }

            using (var uow = Read())
            {
                return(new ApplicationDataAccess(uow)
                       .GetApplication(q));
            }
        }
示例#2
0
        public PaginatedList <Application> GetApplicationsWithLive(Guid?developerId, ApplicationStateEnum?state, string filter, int start = 0, int count = Int32.MaxValue)
        {
            var onlyWithLive = state == ApplicationStateEnum.Live;
            var query        = new ApplicationQuery
            {
                DeveloperId = developerId,
                State       = onlyWithLive ? null : state,
                Filter      = filter,
                Ban         = !BaseSecurity.IsSysAdminOrDeveloper(Context) ? false : (bool?)null
            };

            var apps = GetApplications(query).Where(x => x.State != ApplicationStateEnum.Live).ToList();

            if (onlyWithLive)
            {
                apps = apps.Where(a => a.OriginalRef.HasValue).ToList();
            }
            var appsLiveIds = apps.Where(x => x.OriginalRef.HasValue).Select(x => x.OriginalRef.Value).ToList();

            if (appsLiveIds.Count > 0)
            {
                var liveApps = GetApplicationsByIds(appsLiveIds);
                foreach (var app in apps)
                {
                    if (app.OriginalRef.HasValue)
                    {
                        app.LiveApplication = liveApps.First(x => x.Id == app.OriginalRef);
                    }
                }
            }
            return(new PaginatedList <Application>(apps, start / count, count));
        }
        private async void ReceivedEvent(object sender, BasicDeliverEventArgs e)
        {
            if (e.RoutingKey == "find")
            {
                var      message     = Encoding.UTF8.GetString(e.Body);
                JObject  receivedObj = JsonConvert.DeserializeObject <JObject>(message);
                DateTime from        = receivedObj["From"].Value <DateTime>();
                DateTime to          = receivedObj["To"].Value <DateTime>();
                string   requestId   = receivedObj["RequestId"].Value <string>();

                if (Db.Connection.State != System.Data.ConnectionState.Open)
                {
                    await Db.Connection.OpenAsync();
                }
                var query  = new ApplicationQuery(Db);
                var result = await query.FindAvailableDrivers(from, to);

                JObject reply = new JObject();
                reply.Add("RequestId", requestId);
                reply.Add("Command", "driverFound");
                reply.Add("Drivers", JToken.FromObject(result));

                Booking booking = new Booking(Db);
                booking.ApplicationId = result[0].ApplicationID;
                booking.FromTime      = from;
                booking.ToTime        = to;
                await booking.InsertAsync();

                PublishFoundDrivers("driver", "found", reply.ToString());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string path = this.ViewName.ControlPath();

            ApplicationQuery applicationQuery = new ApplicationQuery
            {
                NumRecords   = this.NumRecords,
                CategoryID   = this.CategoryID,
                GroupID      = this.GroupID,
                IsRestricted = this.IsRestricted,
                TruncateText = false,
                CacheMinutes = this.CacheMinutes,
                SueetieApplicationViewTypeID = (int)SueetieApplicationViewType.Blogs,
                SortBy = (int)this.BlogSortType
            };

            List <SueetieBlog> sueetieBlogs = SueetieBlogs.GetSueetieBlogList(applicationQuery);

            foreach (SueetieBlog blog in sueetieBlogs)
            {
                Sueetie.Controls.BlogView control = (Sueetie.Controls.BlogView)LoadControl(path);
                control.Blog = blog;
                phAggregatedBlogs.Controls.Add(control);
            }
        }
        public void ApplicationIdentifier()
        {
            var query = new ApplicationQuery();
            var data  = Guid.NewGuid();

            query.ApplicationIdentifier = data;
            Assert.AreEqual <Guid>(data, query.ApplicationIdentifier);
        }
示例#6
0
 private PaginatedList <Application> GetApplications(ApplicationQuery query)
 {
     using (var uow = Read())
     {
         query.Role        = Context.Role.Id;
         query.DeveloperId = Context.DeveloperId;
         return(new ApplicationDataAccess(uow).GetPaginatedApplications(query));
     }
 }
        public async Task <IActionResult> GetAllApplications()
        {
            await Db.Connection.OpenAsync();

            var query  = new ApplicationQuery(Db);
            var result = await query.GetAllAsync();

            return(new OkObjectResult(result));
        }
示例#8
0
 /// <summary>
 /// 测试Sql查询对象
 /// </summary>
 public async Task <PagerList <Application> > TestSqlQuery(ApplicationQuery query)
 {
     return(await Sql
            .Select <Application>(t => t.Id, "Id")
            .Select <Application>(t => new object[] { t.Code, t.Name, t.Comment, t.Enabled, t.RegisterEnabled, t.Version })
            .From <Application>()
            .WhereIfNotEmpty <Application>(t => t.Code.Contains(query.Keyword))
            .ToPagerListAsync <Application>(query));
 }
示例#9
0
 public static ListViewModel Create(ApplicationQuery query, Page<Application> applications)
 {
     return new ListViewModel
     {
         SortOptions = new GridSortOptions
         {
             Column = query.SortColumn,
             Direction = (MvcContrib.Sorting.SortDirection)query.SortDirection
         },
         Items = ListItemViewModel.Create(applications)
     };
 }
示例#10
0
        public PaginatedList <Application> GetApplications(int start = 0, int count = int.MaxValue, bool?live = null, bool?canAttach = null)
        {
            var query = new ApplicationQuery
            {
                Start     = start,
                Count     = count,
                Live      = live,
                CanAttach = canAttach
            };

            return(GetApplications(query));
        }
示例#11
0
        public PaginatedList <Application> GetApplications(int start = 0, int count = int.MaxValue, bool?live = null, bool?canAttach = null)
        {
            var query = new ApplicationQuery
            {
                Start     = start,
                Count     = count,
                Live      = live,
                CanAttach = canAttach,
                Ban       = !BaseSecurity.IsSysAdminOrDeveloper(Context) ? false : (bool?)null
            };

            return(GetApplications(query));
        }
示例#12
0
        public PaginatedList <Application> GetApplications(IList <Guid> categoriesIds, IList <int> gradeLevels, string filterWords, int start = 0, int count = int.MaxValue, bool?myApps = null, bool withBanned = false)
        {
            var query = new ApplicationQuery
            {
                CategoryIds = categoriesIds,
                GradeLevels = gradeLevels,
                Filter      = filterWords,
                Start       = start,
                Count       = count,
                Ban         = !withBanned && !BaseSecurity.IsSysAdminOrDeveloper(Context) ? false : (bool?)null
            };

            return(GetApplications(query));
        }
        public async Task <IActionResult> AcceptApplication(int id)
        {
            await Db.Connection.OpenAsync();

            var query  = new ApplicationQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            result.Accepted = true;
            await result.UpdateAsync();

            return(new OkObjectResult(result));
        }
示例#14
0
 private PaginatedList <Application> GetApplications(ApplicationQuery query)
 {
     using (var uow = Read())
     {
         query.Role = Context.Role.Id;
         if (!BaseSecurity.IsSysAdmin(Context))
         {
             query.SchoolId    = Context.SchoolId;
             query.DeveloperId = Context.DeveloperId;
             if (!ApplicationSecurity.HasAccessToBannedApps(Context))
             {
                 query.Ban = false;
             }
         }
         return(new ApplicationDataAccess(uow).GetPaginatedApplications(query));
     }
 }
示例#15
0
        private static void GatherConfigsForSubscription(Subscription subscription, Dictionary <string, NotificationConfig> configs)
        {
            // go through related events, and gather available configs
            foreach (var @event in subscription.RelatedEvents)
            {
                // config already resolved for this contentpath
                if (configs.ContainsKey(@event.ContentPath))
                {
                    continue;
                }

                // check custom config
                var query            = new ApplicationQuery(NotificationConfig.CONFIGFOLDERNAME, false, false, HierarchyOption.Path);
                var configHeads      = query.ResolveApplications(NotificationConfig.NOTIFICATIONCONFIGCONTENTNAME, @event.ContentPath, NotificationConfig.NOTIFICATIONCONFIGTYPENAME);
                var targetConfigHead = configHeads.FirstOrDefault();

                NotificationConfig configNode = null;
                if (targetConfigHead != null)
                {
                    configNode = Node.LoadNode(targetConfigHead.Id) as NotificationConfig;
                }
                configs.Add(@event.ContentPath, configNode);
            }
        }
示例#16
0
 IEnumerable <Application> IApplication.List(ApplicationQuery query, CancellationToken?cancellationToken)
 {
     return(_context.Invoke(f => f.List(query, cancellationToken)));
 }
示例#17
0
        public override async Task <ApplicationResponse> GetApplication(ApplicationQuery request, ServerCallContext context)
        {
            var application = await dataContext.Applications.SingleOrThrowNotFound(a => a.Name == request.Name);

            var appDeployments = await dataContext.Deployments
                                 .Where(a => a.ApplicationId == application.ApplicationId)
                                 .OrderByDescending(d => d.DeploymentDateTime)
                                 .ToListAsync();

            var pods = (await kubeApiClient.PodsV1().List(kubeNamespace: application.Namespace))
                       .ToLookup(pod => pod.Metadata.Labels[KubeNaming.AppLabelKey]);
            var services = (await kubeApiClient.ServicesV1().List(kubeNamespace: application.Namespace))
                           .ToDictionary(s => s.Metadata.Name);
            var deployments = (await kubeApiClient.DeploymentsV1().List(kubeNamespace: application.Namespace))
                              .ToDictionary(d => d.Metadata.Name);
            var statefulSets = (await kubeApiClient.StatefulSetV1().List(kubeNamespace: application.Namespace))
                               .ToDictionary(d => d.Metadata.Name);
            var ingresses = (await kubeApiClient.IngressesV1Beta1().List(kubeNamespace: application.Namespace))
                            .ToDictionary(d => d.Metadata.Name);

            var entryPointIngress = ingresses.GetValueOrDefault(KubeNaming.EntryPointIngressName);

            return(new ApplicationResponse
            {
                Name = application.Name,
                IngressUrl = entryPointIngress != null ? "https://" + entryPointIngress.Spec.Rules.Single().Host : null,
                Description = application.Description,
                Owner = application.Owner,
                Repository = application.Repository,
                LastUpdatedTime = Timestamp.FromDateTimeOffset(application.UpdatedDateTime),
                Services = { services.Values.Select(ProjectToServiceResponse) },
                Deployments = { appDeployments.Select(ProjectToDeployment) },
            });

            ApplicationResponse.Types.Service ProjectToServiceResponse(ServiceV1 service)
            {
                var serviceName = service.Metadata.Name;
                var servicePods = pods[serviceName];
                var deployment  = deployments.GetValueOrDefault(serviceName);
                var statefulSet = statefulSets.GetValueOrDefault(serviceName);
                var ingress     = ingresses.GetValueOrDefault(serviceName);

                var podSpec = deployment?.Spec.Template.Spec
                              ?? statefulSet?.Spec.Template.Spec
                              ?? throw new InvalidOperationException($"No deployment or statefulSet for service {serviceName}");

                var podMetrics = deployment != null
                    ? new ApplicationResponse.Types.PodMetrics
                {
                    TotalPods    = deployment.Status.Replicas ?? 0,
                    UpToDatePods = deployment.Status.UpdatedReplicas ?? 0,
                    DesiredPods  = deployment.Spec.Replicas ?? 1,
                    ReadyPods    = deployment.Status.ReadyReplicas ?? 0,
                }
                    : new ApplicationResponse.Types.PodMetrics
                {
                    TotalPods    = statefulSet.Status.Replicas,
                    UpToDatePods = statefulSet.Status.UpdatedReplicas ?? 0,
                    DesiredPods  = statefulSet.Spec.Replicas ?? 1,
                    ReadyPods    = statefulSet.Status.ReadyReplicas ?? 0,
                };


                return(new ApplicationResponse.Types.Service
                {
                    Name = serviceName,
                    InternalHostname = $"{serviceName}.{application.Name}",
                    IngressUrl = ingress != null
                        ? "https://" + ingress.Spec.Rules.Single().Host
                        : null,
                    Ports =
                    {
                        service.Spec.Ports
                        .Where(port => port.Name != KubeNaming.HttpPortName)
                        .Select(port => new ApplicationResponse.Types.Port
                        {
                            TargetPort = port.TargetPort.Int32Value,
                            ExposedPort = port.NodePort,
                            HostName = $"{serviceName}.{cludOptions.BaseHostname}",
                            Type = port.Protocol,
                        })
                    },
                    ImageName = KubeNaming.ImageNameWithoutCludRegistryUrl(podSpec.Containers.FirstOrDefault()?.Image ?? string.Empty),
                    PodMetrics = podMetrics,
                    // TODO this does not return the correct reuslt - look at https://github.com/kubernetes/kubernetes/blob/74bcefc8b2bf88a2f5816336999b524cc48cf6c0/pkg/controller/deployment/util/deployment_util.go#L745
                    DeploymentInProgress = deployment != null
                        ? deployment.Status.Conditions.Any(c => c.Type == "Progressing" && c.Status == "True")
                        : statefulSet.Status.Conditions.Any(c => c.Type == "Progressing" && c.Status == "True"),
                    Pods =
                    {
                        servicePods.Select(pod => new ApplicationResponse.Types.Pod
                        {
                            Name = pod.Metadata.Name,
                            CreationDate = Timestamp.FromDateTime(pod.Metadata.CreationTimestamp ?? throw new InvalidOperationException("Pod does not have a creationTimestamp")),
                            Status = pod.Status.Phase,
                            StatusMessage = pod.Status.Message ?? string.Empty,
                            Image = KubeNaming.ImageNameWithoutCludRegistryUrl(pod.Spec.Containers.FirstOrDefault()?.Image ?? string.Empty),
                        })
                    }
                });
示例#18
0
        private PartialViewResult List(ApplicationQuery query)
        {
            Session.Set(query);

            var applications = Context.Applications.Search(query);
            var model = ListViewModel.Create(query, applications);

            var message = GetRedirectedMessage();
            if (message != null)
            {
                model.Message = message;
            }

            return PartialView(MVC.Application.Views.List, model);
        }
示例#19
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <param name="query">查询实体</param>
 public PagerList <Application> Query(ApplicationQuery query)
 {
     return(_sqlQuery.Starts("Name", query.Name)
            .Select("ApplicationId As Id,*")
            .GetPageList <Application>("Systems.Applications", Connection, query));
 }
示例#20
0
 public void CreateQuery(ApplicationQuery query)
 {
     _context.Queries.Add(query);
     _context.SaveChanges();
 }