Exemple #1
0
            public override void Handle(HttpListenerContext request)
            {
                string body;

                using (var reader = new System.IO.StreamReader(request.Request.InputStream, request.Request.ContentEncoding))
                    body = reader.ReadToEnd();
                var containerData = JsonConvert.DeserializeObject <Dictionary <string, object> >(body);

                Configuration.Storage.Container container = new Configuration.Storage.Container()
                {
                    Identifier    = (string)containerData["identifier"],
                    FriendlyName  = (string)containerData["title"],
                    LocalFileName = (string)containerData["filename"],
                    MaximumSize   = UInt64.Parse((string)containerData["size"]),
                };
                Configuration.Database.Instance.Storage.Add(container);

                Reply(request, true);
            }
Exemple #2
0
                    private ItemState InitiateRequests(HttpListenerRequest request)
                    {
                        // TODO: Check credentials
                        string body;

                        using (var reader = new System.IO.StreamReader(request.InputStream, request.ContentEncoding))
                            body = reader.ReadToEnd();
                        var requestData = JsonConvert.DeserializeObject <Dictionary <string, string> >(body);

                        string storageIdentifier;

                        if ((requestData == null) || !requestData.TryGetValue("storage", out storageIdentifier))
                        {
                            storageIdentifier = null;
                        }

                        string cameraIdentifier;

                        if ((requestData == null) || !requestData.TryGetValue("camera", out cameraIdentifier))
                        {
                            cameraIdentifier = null;
                        }

                        DateTime?start;
                        string   startStr;

                        if ((requestData != null) && requestData.TryGetValue("start", out startStr))
                        {
                            start = DateTime.Parse(startStr);
                        }
                        else
                        {
                            start = null;
                        }

                        DateTime?end;
                        string   endStr;

                        if ((requestData != null) && requestData.TryGetValue("end", out endStr))
                        {
                            end = DateTime.Parse(endStr);
                        }
                        else
                        {
                            end = null;
                        }

                        Configuration.Storage.Container[] searchContainers = Configuration.Database.Instance.Storage.AllContainers;
                        if (storageIdentifier != null)
                        {
                            Configuration.Storage.Container found = null;
                            foreach (var container in searchContainers)
                            {
                                if (container.Identifier.Equals(storageIdentifier))
                                {
                                    found = container;
                                    break;
                                }
                            }
                            if (found == null)
                            {
                                searchContainers = new Configuration.Storage.Container[0];
                            }
                            else
                            {
                                searchContainers = new Configuration.Storage.Container[] { found }
                            };
                        }

                        ItemState result = new ItemState();

                        foreach (var container in searchContainers)
                        {
                            var storage = storageManager.GetStorage(container.Identifier);
                            if (storage != null)
                            {
                                storage.SearchTimes(cameraIdentifier, start, end, this);
                                result.expecting++;
                            }
                        }
                        return(result);
                    }