Ejemplo n.º 1
0
        public CorsHandler(IHttpHandler next, CorsOptions options)
        {
            MethodContract.NotNull(next, nameof(next));
            MethodContract.NotNull(options, nameof(options));

            //lock it down so it can't change while in use
            this.options = new CorsOptions();
            foreach (string cur in options.Origins)
            {
                this.options.Origins.Add(cur);
            }

            foreach (string cur in options.RequestHeaders)
            {
                this.options.RequestHeaders.Add(cur);
            }

            foreach (string cur in options.ResponseHeaders)
            {
                this.options.ResponseHeaders.Add(cur);
            }

            foreach (HttpVerbs cur in options.Verbs)
            {
                foreach (string v in CorsConstants.SimpleMethods) //short list, so not horrible esp. since we do this once per corshandler instance
                {
                    this.hasNonSimpleVerbs = this.hasNonSimpleVerbs || v.Equals(cur.ToString());
                }
                this.options.Verbs.Add(cur);
            }

            this.options.PreflightMaxAge     = options.PreflightMaxAge;
            this.options.SupportsCredentials = options.SupportsCredentials;
            this.Next = next;
        }
Ejemplo n.º 2
0
        public SimpleFileHandler(string localPath, IEnumerable <string> defaultFiles, MimeTypes mimeTypes, FileExtensions allowed, FileExtensions disallowed)
            : base()
        {
            MethodContract.NotNull(localPath, nameof(localPath));
            MethodContract.NotNull(defaultFiles, nameof(defaultFiles));
            MethodContract.NotNull(mimeTypes, nameof(mimeTypes));

            this.mapper    = new DirectoryMapper(localPath);
            this.mimeTypes = mimeTypes;
            if (defaultFiles != null)
            {
                foreach (string curFil in defaultFiles)
                {
                    this.defaultFiles.Add(curFil);
                }
            }

            if (allowed != null)
            {
                this.allowedExtensions = allowed;
            }
            else
            {
                this.allowedExtensions = new FileExtensions();
            }

            if (disallowed != null)
            {
                this.disallowedExtensions = disallowed;
            }
            else
            {
                this.disallowedExtensions = new FileExtensions();
            }
        }
Ejemplo n.º 3
0
 internal PersistedCredential(Guid userId, byte[] payload, byte[] token)
 {
     MethodContract.NotNull(payload, nameof(payload));
     this.userId   = userId;
     this.rawData  = payload;
     this.rawToken = token;
 }
 public UserPasswordCredential(string userName, string password)
 {
     MethodContract.NotNull(userName, nameof(userName));
     MethodContract.NotNull(password, nameof(password));
     this.userName = userName;
     this.password = password;
 }
Ejemplo n.º 5
0
        public HttpListenerServerListener(IEnumerable <string> urls, IHttpHandler handler) : base()
        {
            MethodContract.NotNull(urls, nameof(urls));
            MethodContract.NotNull(handler, nameof(handler));
            foreach (string url in urls)
            {
                Uri x;
                MethodContract.Assert(Uri.TryCreate(url, UriKind.Absolute, out x), string.Format("{0} not a valid uri", nameof(urls)));
                MethodContract.Assert(x.Scheme == Uri.UriSchemeHttp || x.Scheme == Uri.UriSchemeHttps, string.Format("{0} not a valid http/https uri", nameof(urls)));
                if (url.EndsWith("/"))
                {
                    this.urls.Add(url);
                }
                else
                {
                    this.urls.Add(url + '/');
                }
            }

            this.handler  = handler;
            this.listener = new System.Net.HttpListener();
            this.listener.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
            foreach (string uri in this.urls)
            {
                this.listener.Prefixes.Add(uri);
            }
        }
Ejemplo n.º 6
0
 internal PersistedCredential(Guid userId, string payload, string token)
 {
     MethodContract.NotNull(payload, nameof(payload));
     this.userId    = userId;
     this.text      = payload;
     this.textToken = token;
 }
Ejemplo n.º 7
0
        public SingleServerTaskPool(IListener <T> listener, IHandler <T> handler, ServerTaskPoolOptions options)
        {
            MethodContract.NotNull(listener, nameof(listener));
            MethodContract.NotNull(handler, nameof(handler));
            MethodContract.NotNull(options, nameof(options));

            Setup((Func <T>)listener.GetContext, (Action <T>)handler.Handle, options);
        }
Ejemplo n.º 8
0
        public FieldTeamMember(CompoundIdentity personId, CompoundIdentity fieldTeamMemberRoleId)
        {
            MethodContract.NotNull(personId, nameof(personId));
            MethodContract.NotNull(fieldTeamMemberRoleId, nameof(fieldTeamMemberRoleId));

            this.PersonId = personId;
            this.fieldTeamMemberRoleId = fieldTeamMemberRoleId;
        }
Ejemplo n.º 9
0
        public SingleServerTaskPool(Func <T> listener, Action <T> handler, ServerTaskPoolOptions options)
        {
            MethodContract.NotNull(listener, nameof(listener));
            MethodContract.NotNull(handler, nameof(handler));
            MethodContract.NotNull(options, nameof(options));

            Setup(listener, handler, options);
        }
        public static TaskPool CreateScavengingTaskPool(Action toRun, TaskPoolOptions options)
        {
            MethodContract.NotNull(toRun, nameof(toRun));
            ScavengingTaskPoolRunner runner = new ScavengingTaskPoolRunner(toRun);
            TaskPool pool = new TaskPool(runner.Run, options);

            runner.pool = pool;
            return(pool);
        }
Ejemplo n.º 11
0
        public Organization(CompoundIdentity id, string name, string description)
        {
            MethodContract.NotNull(id, nameof(id));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity    = id;
            this.name        = name;
            this.Description = description;
        }
Ejemplo n.º 12
0
 internal HandoffEvent(Func <T> listener, Action <T> handler, int maxQueueSize)
 {
     MethodContract.NotNull(listener, nameof(listener));
     MethodContract.NotNull(handler, nameof(handler));
     MethodContract.Assert(maxQueueSize > 0, nameof(maxQueueSize));
     this.listen       = listener;
     this.handle       = handler;
     this.maxQueueSize = maxQueueSize;
 }
Ejemplo n.º 13
0
        public HerbSampleDTO(Guid vegSampleId, VegHerbSampleDTO innerItem)
        {
            MethodContract.Assert(!Guid.Empty.Equals(vegSampleId), nameof(vegSampleId));
            MethodContract.NotNull(innerItem, nameof(innerItem));

            this.VegSampleId  = vegSampleId;
            this.TaxaUnitId   = innerItem.TaxaUnitId;
            this.PercentCover = innerItem.PercentCover;
            this.Description  = innerItem.Description;
        }
Ejemplo n.º 14
0
        public FieldTeam(CompoundIdentity id, string name, string description)
        {
            MethodContract.NotNull(id, nameof(id));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity    = id;
            this.name        = name;
            this.Description = description;
            this.Members     = new FieldTeamMembers();
        }
Ejemplo n.º 15
0
        public TreeSampleDTO(Guid vegSampleId, VegTreeSampleDTO innerItem)
        {
            MethodContract.NotNull(innerItem, nameof(innerItem));
            MethodContract.Assert(!Guid.Empty.Equals(vegSampleId), nameof(vegSampleId));

            this.VegSampleId        = vegSampleId;
            this.TaxaUnitId         = innerItem.TaxaUnitId;
            this.DiameterBreastHigh = innerItem.DiameterBreastHigh;
            this.Description        = innerItem.Description;
        }
Ejemplo n.º 16
0
        public ShrubSampleDTO(Guid vegSampleId, VegShrubSampleDTO innerItem)
        {
            MethodContract.NotNull(innerItem, nameof(innerItem));
            MethodContract.Assert(!Guid.Empty.Equals(vegSampleId), nameof(vegSampleId));

            this.VegSampleId = vegSampleId;
            this.TaxaUnitId  = innerItem.TaxaUnitId;
            this.SizeClass   = innerItem.SizeClass;
            this.Count       = innerItem.Count;
            this.Description = innerItem.Description;
        }
Ejemplo n.º 17
0
        public Site(CompoundIdentity id, CompoundIdentity owner, string name, string description)
        {
            MethodContract.Assert(!id.IsNullOrEmpty(), nameof(id));
            MethodContract.NotNull(!owner.IsNullOrEmpty(), nameof(owner));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity    = id;
            this.owner       = owner;
            this.name        = name;
            this.Description = description;
        }
Ejemplo n.º 18
0
        public OrganizationAlias(CompoundIdentity orgId, CompoundIdentity schemeId, string name)
        {
            MethodContract.NotNull(orgId, nameof(orgId));
            MethodContract.NotNull(schemeId, nameof(schemeId));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity            = orgId;
            this.AliasSchemeIdentity = schemeId;
            this.name     = name;
            this.origName = name;
        }
Ejemplo n.º 19
0
        public TaxaUnitType(CompoundIdentity id, string name, CompoundIdentity taxonomyId, string description)
        {
            MethodContract.NotNull(id, nameof(id));
            MethodContract.NotNull(taxonomyId, nameof(taxonomyId));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity    = id;
            this.taxonId     = taxonomyId;
            this.name        = name;
            this.Description = description;
        }
Ejemplo n.º 20
0
        public EnvelopeN(T[] mins, T[] maxes)
        {
            MethodContract.NotNull(mins, nameof(mins));
            MethodContract.NotNull(maxes, nameof(maxes));
            MethodContract.Assert(mins.Length == maxes.Length, nameof(mins) + " length doesn't match " + nameof(maxes));

            this.ordinateMaxs = new T[maxes.Length];
            this.ordinateMins = new T[mins.Length];
            Array.Copy(mins, this.ordinateMins, mins.Length);
            Array.Copy(maxes, this.ordinateMaxs, maxes.Length);
        }
Ejemplo n.º 21
0
        public SiteAlias(CompoundIdentity siteId, CompoundIdentity schemeId, string name)
        {
            MethodContract.NotNull(siteId, nameof(siteId));
            MethodContract.NotNull(schemeId, nameof(schemeId));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity            = siteId;
            this.AliasSchemeIdentity = schemeId;
            this.origName            = name;
            this.name = name;
        }
        public OrganizationAliasScheme(CompoundIdentity id, CompoundIdentity owningOrgId, string name, string description)
        {
            MethodContract.NotNull(id, nameof(id));
            MethodContract.NotNull(owningOrgId, nameof(owningOrgId));
            MethodContract.NotNullOrEmpty(name, nameof(name));

            this.Identity    = id;
            this.owner       = owningOrgId;
            this.name        = name;
            this.Description = description;
        }
Ejemplo n.º 23
0
 public FishGenetics(Guid id, Guid fishId, string geneticSampleId, string labSampleId, StockEstimates estimates, string description)
 {
     MethodContract.Assert(!Guid.Empty.Equals(id), nameof(id));
     MethodContract.Assert(!Guid.Empty.Equals(fishId), nameof(fishId));
     MethodContract.NotNull(estimates, nameof(estimates));
     this.Identity        = id;
     this.fishId          = fishId;
     this.GeneticSampleId = geneticSampleId;
     this.LabSampleId     = labSampleId;
     this.StockEstimates  = estimates;
     this.Description     = description;
 }
Ejemplo n.º 24
0
        public static HttpListenerServer Create(HttpListenerServerListener listener, ServerTaskPoolOptions options, bool useSinglePool)
        {
            MethodContract.NotNull(listener, nameof(listener));
            MethodContract.NotNull(options, nameof(options));

            if (useSinglePool)
            {
                return(new HttpListenerServer(new SingleServerTaskPool <HttpContext>(listener, options), listener));
            }
            else
            {
                return(new HttpListenerServer(new DualServerTaskPool <HttpContext>(listener, options), listener));
            }
        }
Ejemplo n.º 25
0
        private volatile int activeWaiters = 0; //how many calls to Next() are waiting

        public TaskPool(Action toRun, TaskPoolOptions options)
        {
            MethodContract.NotNull(toRun, nameof(toRun));
            this.options = new TaskPoolOptions();
            if (options != null)
            {
                this.options.MaxWaitingRequests = options.MaxWaitingRequests;
                this.options.MaxActiveWorkers   = options.MaxActiveWorkers;
                this.options.Timeout            = options.Timeout;
            }
            this.activeWorkers = 0;
            this.runner        = new TaskPoolRunner(this, toRun, this.options.Timeout);
            this.Reset();
        }
Ejemplo n.º 26
0
 internal Line2(Point2 <T> anchor, Point2 <T> orientationPoint)
 {
     if (anchor == null || orientationPoint == null)
     {
         MethodContract.NotNull(anchor, nameof(anchor));
         MethodContract.NotNull(orientationPoint, nameof(orientationPoint));
     }
     if (anchor.Equals(orientationPoint))
     {
         throw new DegenerateCaseException();
     }
     this.Anchor           = anchor;
     this.OrientationPoint = orientationPoint;
 }
Ejemplo n.º 27
0
        public UrlBaseMatchRule(IEnumerable <string> partialUris)
        {
            MethodContract.NotNull(partialUris, nameof(partialUris));

            foreach (string cur in partialUris)
            {
                if (cur.StartsWith("/"))
                {
                    this.partialUris.Add(cur);
                }
                else
                {
                    this.partialUris.Add("/" + cur); //we have to anchor for matching against /
                }
            }
        }
Ejemplo n.º 28
0
        public override void Handle(HttpContext context, CancellationToken cancel)
        {
            MethodContract.NotNull(context, nameof(context)); //this will throw if context==null

            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            string local = RestUtils.LocalUrl(this, request);
            string meth  = RestUtils.StripLocal(this.BaseUrl, local);

            if (create.Equals(meth, StringComparison.OrdinalIgnoreCase))
            {
                Create(response, cancel);
                return;
            }
            else if (extend.Equals(meth, StringComparison.OrdinalIgnoreCase))
            {
                //do nothing, already extended
                RestUtils.Push(response, JsonOpStatus.Ok);
                return;
            }
            else if (expire.Equals(meth, StringComparison.OrdinalIgnoreCase))
            {
                if (request.Headers.ContainsKey(Session.SessionIdName))
                {
                    Guid ssid;
                    if (Guid.TryParse(request.Headers[Session.SessionIdName], out ssid))
                    {
                        if (Prov.Expire(ssid)) //note that this will autoextend and will return false if expired
                        {
                            response.Headers.Remove(Session.SessionIdName);
                            RestUtils.Push(response, JsonOpStatus.Ok);
                            return;
                        }
                    }
                }
            }
            response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }
Ejemplo n.º 29
0
 protected ServerBase(ServerTaskPool <T> pool)
 {
     MethodContract.NotNull(pool, nameof(pool));
     this.pool = pool;
 }
Ejemplo n.º 30
0
 public SimpleServiceWrapper(IService inner)
 {
     MethodContract.NotNull(inner, nameof(inner));
     this.inner = inner;
 }