Пример #1
0
 public override FilestoreFile Get(SampleEventMap map)
 {
     if (map != null)
     {
         SampleEventMapItem id = map.Get(KnownDetType.Fish);
         if (id != null)
         {
             IFileStoreProvider p = FileStore;
             if (p != null)
             {
                 return(p.Get(id.DetId)); //TODO add validation checking if we want
             }
         }
     }
     return(null);
 }
Пример #2
0
        static void Main(string[] args)
        {
            ConfigurationManager.Instance.Bootstrap();
            ConfigurationManager.Instance.Initialize();
            ConfigurationManager.Instance.Start();
            Console.WriteLine("ConfigurationManager: " + ConfigurationManager.Instance.State.ToString());

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

            FileStoreManager.Instance.Initialize();
            FileStoreManager.Instance.Start();
            Console.WriteLine("FileStore: " + FileStoreManager.Instance.State.ToString());

            IFileStoreProvider prov = FileStoreManager.Instance.GetProvider();

            Console.WriteLine("Prov: " + (prov == null).ToString());

            if (prov != null)
            {
                Guid          id  = Guid.NewGuid();
                FilestoreFile fil = prov.Make(id);
                if (fil != null)
                {
                    Console.WriteLine("Got file");
                    string     s  = "Hello from testing";
                    TextWriter wr = new StreamWriter(fil);
                    for (int i = 0; i < 100; i++)
                    {
                        wr.WriteLine(s);
                    }
                    wr.Flush();
                    wr.Close();
                    fil.Dispose();
                    Console.WriteLine("Done");

                    fil = prov.Get(id);
                    if (fil != null)
                    {
                        Console.WriteLine("Opened file");
                        wr = new StreamWriter(fil);
                        for (int i = 0; i < 100; i++)
                        {
                            wr.WriteLine(s);
                        }
                        wr.Flush();
                        wr.Close();
                        fil.Dispose();
                        Console.WriteLine("Wrote");
                        prov.Delete(id);
                        Console.WriteLine("Done");
                    }
                }

                prov.DeleteExpired();
            }

            Console.WriteLine("Enter to exit");
            Console.ReadLine();
        }
Пример #3
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);

                    if (!string.IsNullOrEmpty(meth))
                    {
                        if (meth.StartsWith(Upload, StringComparison.OrdinalIgnoreCase))
                        {
                            string err = null;
                            try
                            {
                                string fName = MetaInfo.GetFileName(context);             //TODO -- add origin filename handling
                                if (fName != null && MetaInfo.SupportedUploadType(fName)) //this might be a bogus way to go
                                {
                                    if (prov == null)
                                    {
                                        prov = FileStoreManager.Instance.GetProvider();
                                    }

                                    if (prov != null)
                                    {
                                        Stream input = context.Request.Body;
                                        if (input != null)
                                        {
                                            FilestoreFile fil = prov.MakeTemp();
                                            if (fil != null)
                                            {
                                                input.CopyTo(fil);
                                                fil.Flush();
                                                fil.Close();
                                                fil.FileName = fName;
                                                prov.Update(fil);
                                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, "\"" + fil.FileId.ToString() + "\""));
                                                return;
                                            }
                                            else
                                            {
                                                err = "failed to make";
                                            }
                                        }
                                        else
                                        {
                                            err = "no file received";
                                        }
                                    }
                                    else
                                    {
                                        err = "no provider";
                                    }
                                }
                                else
                                {
                                    err = "unsupported file extension";  //this might be a bogus way to go
                                }
                            }
                            catch
                            { err = "unknown error"; }

                            if (err == null)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                            }
                            else
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed, "\"" + err + "\""));
                            }
                            return;
                        }
                        if (meth.StartsWith(Download, StringComparison.OrdinalIgnoreCase))
                        {
                            string err = null;
                            try
                            {
                                //this should be a Guid string
                                string filename = Uri.UnescapeDataString(meth.Substring(Download.Length));
                                Guid   fileId;

                                if (Guid.TryParse(filename, out fileId))
                                {
                                    if (prov == null)
                                    {
                                        prov = FileStoreManager.Instance.GetProvider();
                                    }

                                    if (prov != null)
                                    {
                                        FilestoreFile fil = prov.Get(fileId);
                                        if (fil != null)
                                        {
                                            if (fil.Length > -1)
                                            {
                                                //send the bytes of a file in the response body
                                                context.Response.Headers.Add("Content-Disposition", "attachment ; filename=\"" + fil.FileName + "\"");
                                                context.Response.StatusCode  = HttpStatusCodes.Status200OK;
                                                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                                                fil.CopyTo(context.Response.Body);
                                                return;
                                            }
                                            else
                                            {
                                                err = "no stream";
                                            }
                                        }
                                        else
                                        {
                                            err = "no such file";
                                        }
                                    }
                                    else
                                    {
                                        err = "no provider";
                                    }
                                }
                                else
                                {
                                    err = "fileid is not legal";
                                }
                            }
                            catch
                            { err = "unknown error"; }

                            if (err == null)
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                            }
                            else
                            {
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed, "\"" + err + "\""));
                            }
                            return;
                        }
                    }
                }
                else
                {
                    context.Response.StatusCode = HttpStatusCodes.Status401Unauthorized;
                    return;
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }