Esempio n. 1
0
        static void CreateProjs(IProjectProvider prov, ProjectStatusType activeStatus)
        {
            Guid sysId = new Guid("{5914629d-dd2d-4f1f-a06f-1b199fe19b37}");
            Guid pnlId = new Guid("{f9e1d49f-0b91-41cc-a88f-a24afa1a669e}");
            Guid aceId = new Guid("{6ca626ef-aab6-4746-8f18-7d97097055df}");

            CompoundIdentity pnnlId  = new CompoundIdentity(sysId, pnlId);
            CompoundIdentity usaceId = new CompoundIdentity(sysId, aceId);

            string orgName;

            orgName = "Columbia River System Project";
            if (!prov.Exists(orgName))
            {
                Project org = prov.Create(orgName, usaceId);
                if (org != null)
                {
                    orgName = "Columbia River System Monitoring";
                    org     = prov.Create(orgName, usaceId, org);

                    if (org != null)
                    {
                        orgName = "PNNL USACE Columbia River Monitoring Support";
                        prov.Create(orgName, pnnlId, org);
                    }

                    if (!prov.Exists(orgName))
                    {
                        Console.WriteLine("Exists returns false after creating");
                    }
                }
            }

            if (activeStatus != null)
            {
                orgName = "Columbia River System Project";
                IEnumerable <Project> projs = prov.Get(orgName);
                Project org = null;
                foreach (Project cur in projs)
                {
                    org = cur;
                    break;
                }
                org.Affiliates.Add(pnnlId);
                org.Affiliates.Add(usaceId);
                prov.Update(org);

                prov.AddInfo(new ProjectInformation(org.Identity, Guid.NewGuid(), "Test info", null, null));
                prov.AddStatus(new ProjectStatus(org.Identity, Guid.NewGuid(), activeStatus.Identity, "Test status", DateTime.UtcNow));
            }
        }
Esempio n. 2
0
        public override void Handle(HttpContext context, CancellationToken cancel)
        {
            if (context != null)
            {
                UserIdentityBase user = Security.Session.GetUser(context);
                if (user != null)
                {
                    UserSecurityContext ctx = new UserSecurityContext(user);
                    string localUrl         = RestUtils.LocalUrl(this, context.Request);
                    string meth             = RestUtils.StripLocal(this.BaseUrl, localUrl);
                    meth = meth.Substring(1);

                    if (!string.IsNullOrEmpty(meth))
                    {
                        if (context.Request.Method == "POST")
                        {
                            if (meth.Equals("deployments", StringComparison.OrdinalIgnoreCase))
                            {
                                try
                                {
                                    HashSet <CompoundIdentity> eventIds      = null;
                                    HashSet <CompoundIdentity> deploymentIds = null;
                                    HashSet <CompoundIdentity> siteIds       = null;
                                    DateTime?start = null;
                                    DateTime?end   = null;

                                    JToken token = JsonUtils.GetDataPayload(context.Request);
                                    if (token != null)
                                    {
                                        if (token["events"] != null)
                                        {
                                            eventIds = JsonUtils.ToIds(token["events"]);
                                        }

                                        if (token["deployments"] != null)
                                        {
                                            deploymentIds = JsonUtils.ToIds(token["deployments"]);
                                        }

                                        if (token["sites"] != null)
                                        {
                                            siteIds = JsonUtils.ToIds(token["sites"]);
                                        }

                                        if (token["start"] != null)
                                        {
                                            start = JsonUtils.ToDate(token["start"]);
                                        }

                                        if (token["end"] != null)
                                        {
                                            end = JsonUtils.ToDate(token["end"]);
                                        }
                                    }

                                    IWQDeploymentProvider provider = WaterQualityManager.Instance.GetDeploymentProvider(ctx);                                     //filters WQ deployments by user context
                                    if (provider != null)
                                    {
                                        IEnumerable <WaterQualityDeployment> deployments = GetDeployments(provider, eventIds, deploymentIds, siteIds, start, end);
                                        JArray jdeployments = Jsonifier.ToJson(deployments);

                                        if (jdeployments != null)
                                        {
                                            RestUtils.Push(context.Response, JsonOpStatus.Ok, jdeployments.ToString());
                                            return;
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                                            return;
                                        }
                                    }
                                }
                                catch
                                {
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                    return;
                                }
                            }
                            else if (meth.Equals("measurements", StringComparison.OrdinalIgnoreCase))
                            {
                                try
                                {
                                    //TODO: ask about iterative calls for deployments (each deployment is a separate db call)

                                    IWQMeasurementProvider provider = WaterQualityManager.Instance.GetMeasurementProvider(ctx);
                                    if (provider != null)
                                    {
                                        HashSet <CompoundIdentity> eventIds      = null;
                                        HashSet <CompoundIdentity> deploymentIds = null;
                                        HashSet <CompoundIdentity> siteIds       = null;
                                        DateTime?start = null;
                                        DateTime?end   = null;

                                        JToken token = JsonUtils.GetDataPayload(context.Request);
                                        if (token != null)
                                        {
                                            if (token["events"] != null)
                                            {
                                                eventIds = JsonUtils.ToIds(token["events"]);
                                            }

                                            if (token["deployments"] != null)
                                            {
                                                deploymentIds = JsonUtils.ToIds(token["deployments"]);
                                            }

                                            if (token["sites"] != null)
                                            {
                                                siteIds = JsonUtils.ToIds(token["sites"]);
                                            }

                                            if (token["start"] != null)
                                            {
                                                start = JsonUtils.ToDate(token["start"]);
                                            }

                                            if (token["end"] != null)
                                            {
                                                end = JsonUtils.ToDate(token["end"]);
                                            }
                                        }

                                        IWQDeploymentProvider depProvider = WaterQualityManager.Instance.GetDeploymentProvider(ctx);                                         //provider will autofilter WQ deployments by user context
                                        IEnumerable <WaterQualityDeployment> deployments = GetDeployments(depProvider, eventIds, deploymentIds, siteIds, null, null);

                                        List <WaterQualityMeasurement> measurements = new List <WaterQualityMeasurement>();

                                        if (start != null || end != null)
                                        {
                                            DateTime queryStart;
                                            DateTime queryEnd;
                                            if (start == null)
                                            {
                                                queryStart = WQUtils.GlobalMinDate;
                                            }
                                            else
                                            {
                                                queryStart = start.Value;
                                            }

                                            if (end == null)
                                            {
                                                queryEnd = DateTime.UtcNow;
                                            }
                                            else
                                            {
                                                queryEnd = end.Value;
                                            }

                                            foreach (WaterQualityDeployment dep in deployments)
                                            {
                                                measurements.AddRange(provider.Get(dep.Identity, queryStart, queryEnd));
                                            }
                                        }
                                        else
                                        {
                                            foreach (WaterQualityDeployment dep in deployments)
                                            {
                                                measurements.AddRange(provider.Get(dep.Identity));
                                            }
                                        }

                                        JArray jmeasurements = Jsonifier.ToJson(measurements);

                                        if (jmeasurements != null)
                                        {
                                            RestUtils.Push(context.Response, JsonOpStatus.Ok, jmeasurements.ToString());
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                                        }
                                        return;
                                    }
                                    RestUtils.Push(context.Response, JsonOpStatus.Failed);
                                }
                                catch
                                {
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                    return;
                                }
                            }
                            else if (meth.Equals("export", StringComparison.OrdinalIgnoreCase))
                            {
                                try
                                {
                                    HashSet <CompoundIdentity> eventIds      = null;
                                    HashSet <CompoundIdentity> deploymentIds = null;
                                    HashSet <CompoundIdentity> siteIds       = null;
                                    DateTime?start = null;
                                    DateTime?end   = null;

                                    JToken token = JsonUtils.GetDataPayload(context.Request);
                                    if (token != null)
                                    {
                                        if (token["events"] != null)
                                        {
                                            eventIds = JsonUtils.ToIds(token["events"]);
                                        }

                                        if (token["deployments"] != null)
                                        {
                                            deploymentIds = JsonUtils.ToIds(token["deployments"]);
                                        }

                                        if (token["sites"] != null)
                                        {
                                            siteIds = JsonUtils.ToIds(token["sites"]);
                                        }

                                        if (token["start"] != null)
                                        {
                                            start = JsonUtils.ToDate(token["start"]);
                                        }

                                        if (token["end"] != null)
                                        {
                                            end = JsonUtils.ToDate(token["end"]);
                                        }
                                    }

                                    IWQDeploymentProvider  depProvider           = WaterQualityManager.Instance.GetDeploymentProvider(ctx);
                                    IWQMeasurementProvider measProvider          = WaterQualityManager.Instance.GetMeasurementProvider(ctx);
                                    ISiteProvider          siteProvider          = SiteManager.Instance.GetSiteProvider(ctx);
                                    ISampleEventProvider   sampProvider          = FieldActivityManager.Instance.GetSampleEventProvider(ctx);
                                    IOrganizationProvider  orgProvider           = OrganizationManager.Instance.GetOrganizationProvider(ctx);
                                    IFieldTripProvider     fieldTripProvider     = FieldActivityManager.Instance.GetFieldTripProvider(ctx);
                                    IFieldActivityProvider fieldActivityProvider = FieldActivityManager.Instance.GetFieldActivityProvider(ctx);
                                    IProjectProvider       projectProvider       = ProjectManager.Instance.GetProvider(ctx);

                                    if (depProvider != null && measProvider != null && siteProvider != null && sampProvider != null &&
                                        orgProvider != null && fieldTripProvider != null && fieldActivityProvider != null && projectProvider != null)
                                    {
                                        IEnumerable <WaterQualityDeployment>  deployments  = GetDeployments(depProvider, eventIds, deploymentIds, siteIds, null, null);                                       //on export, time filters apply to measurements only
                                        IEnumerable <WaterQualityMeasurement> measurements = GetMeasurements(measProvider, start, end, deployments);

                                        //Get sites and sample events
                                        List <CompoundIdentity>     selected_siteIds  = deployments.Select(x => x.SiteId).ToList();
                                        List <CompoundIdentity>     selected_eventIds = deployments.Select(x => x.SampleEventId).ToList();
                                        IEnumerable <Site>          sitesData         = GetSites(siteProvider, selected_siteIds);
                                        IEnumerable <SamplingEvent> eventsData        = sampProvider.Get(selected_eventIds);

                                        //Get orgs and field trips
                                        List <CompoundIdentity>    selected_orgIds       = eventsData.Select(x => x.PrincipalOrgId).ToList();
                                        List <CompoundIdentity>    selected_fieldTripIds = eventsData.Select(x => x.FieldTripId).ToList();
                                        IEnumerable <Organization> orgData       = orgProvider.Get(selected_orgIds);
                                        IEnumerable <FieldTrip>    fieldTripData = fieldTripProvider.Get(selected_fieldTripIds);

                                        //Get field activities
                                        List <CompoundIdentity>     selected_fieldActivityIds = fieldTripData.Select(x => x.FieldActivityId).ToList();
                                        IEnumerable <FieldActivity> fieldActivityData         = fieldActivityProvider.Get(selected_fieldActivityIds);

                                        //Get projects
                                        List <CompoundIdentity> selected_projectIds = fieldActivityData.Select(x => x.ProjectId).ToList();
                                        IEnumerable <Project>   projectData         = projectProvider.Get(selected_projectIds);

                                        Guid fileId = CreateDeploymentFile(eventsData, deployments, measurements, sitesData,
                                                                           orgData, fieldTripData, fieldActivityData, projectData);

                                        if (fileId != null)
                                        {
                                            JObject o = new JObject();
                                            o.Add("fileid", fileId.ToString());
                                            o.Add("fileext", fileExtension);
                                            RestUtils.Push(context.Response, JsonOpStatus.Ok, o);
                                        }
                                        else
                                        {
                                            RestUtils.Push(context.Response, JsonOpStatus.Failed);
                                        }
                                        return;
                                    }
                                    RestUtils.Push(context.Response, JsonOpStatus.Failed);
                                }
                                catch
                                {
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ConfigurationManager.Instance.Bootstrap();
            ConfigurationManager.Instance.Initialize();
            ConfigurationManager.Instance.Start();
            Console.WriteLine("Config state: " + ConfigurationManager.Instance.State);

            LogManager.Instance.Bootstrap();
            LogManager.Instance.Initialize();
            LogManager.Instance.Start();
            Console.WriteLine("Log state: " + LogManager.Instance.State);

            AuthorizationManager.Instance.Bootstrap();
            AuthorizationManager.Instance.Initialize();
            AuthorizationManager.Instance.Start();
            Console.WriteLine("Auth state: " + AuthorizationManager.Instance.State);

            LocalSystemUser     usr     = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
            UserSecurityContext context = new UserSecurityContext(usr);

            if (AuthorizationManager.Instance.State == Osrs.Runtime.RunState.Running)
            {
                //RegisterPermissions(context);
                //Grant(context);
            }

            ProjectManager.Instance.Initialize();
            Console.WriteLine("Projects state: " + ProjectManager.Instance.State);
            ProjectManager.Instance.Start();
            Console.WriteLine("Projects state: " + ProjectManager.Instance.State);

            if (ProjectManager.Instance.State == Osrs.Runtime.RunState.Running)
            {
                IProjectStatusTypeProvider statProv = ProjectManager.Instance.GetStatusTypeProvider(context);
                if (statProv != null)
                {
                    IEnumerable <ProjectStatusType> typs = statProv.Get("Active");
                    ProjectStatusType activeStatus       = null;
                    if (typs != null)
                    {
                        foreach (ProjectStatusType cur in typs)
                        {
                            activeStatus = cur;
                        }
                    }
                    if (activeStatus == null)
                    {
                        activeStatus = statProv.Create("Active", "An active project");
                    }


                    IProjectProvider prov = ProjectManager.Instance.GetProvider(context);
                    if (prov != null)
                    {
                        Console.WriteLine("Creating projects");
                        CreateProjs(prov, activeStatus);

                        IEnumerable <Project> projs = prov.Get();
                        foreach (Project p in projs)
                        {
                            Console.WriteLine(p.Name);
                        }
                    }
                }
            }

            Console.WriteLine("ALL COMPLETE - Enter to exit");
            Console.ReadLine();
        }