Exemplo n.º 1
0
        public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle instruments)
        {
            if (this.CanModify(map))
            {
                Guid            id  = Guid.NewGuid();
                WaterQualityDET det = new WaterQualityDET();
                det.Id    = id;
                det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + instruments.PrincipalOrgId.Identity.ToString();

                int ct = 0;
                foreach (BundleElement cur in sites.Elements)
                {
                    SiteDTO tmp = new SiteDTO();
                    tmp.Key  = cur.LocalKey;
                    tmp.Name = cur.DisplayName;
                    det.Sites.Add(tmp);
                    ct++;
                }
                if (ct > 0) //has to be elements in the collection
                {
                    ct = 0;

                    foreach (BundleElement cur in instruments.Elements)
                    {
                        InstrumentDTO tmp = new InstrumentDTO();
                        tmp.Key  = cur.LocalKey;
                        tmp.Name = cur.DisplayName;
                        det.Instruments.Add(tmp);
                        ct++;
                    }

                    if (ct > 0)
                    {
                        det.Validate();
                        if (det.ValidationIssues.Count == 0)
                        {
                            IFileStoreProvider prov = this.FileStore;

                            if (prov != null)
                            {
                                FilestoreFile fil = prov.Make(id);
                                if (fil != null)
                                {
                                    ExcelWaterQualityDET excel = new ExcelWaterQualityDET(det);
                                    excel.Save(fil);
                                    fil.Flush();
                                    fil.Seek(0, System.IO.SeekOrigin.Begin);
                                    return(fil);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, bool isPrivate)
        {
            if (this.CanModify(map))
            {
                Guid   id  = Guid.NewGuid();
                VegDET det = new VegDET();
                det.Id    = id;
                det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + plotTypes.PrincipalOrgId.Identity.ToString();

                int ct = 0;
                foreach (BundleElement cur in sites.Elements)
                {
                    SiteDTO tmp = new SiteDTO();
                    tmp.Key  = cur.LocalKey;
                    tmp.Name = cur.DisplayName;
                    det.Sites.Add(tmp);
                    ct++;
                }
                if (ct > 0) //has to be elements in the collection
                {
                    ct = 0;

                    foreach (BundleElement cur in plotTypes.Elements)
                    {
                        PlotTypeDTO tmp = new PlotTypeDTO();
                        tmp.Key  = cur.LocalKey;
                        tmp.Name = cur.DisplayName;
                        det.PlotTypes.Add(tmp);
                        ct++;
                    }

                    if (ct > 0)
                    {
                        ct = 0;

                        foreach (BundleElement cur in shrubSpecies.Elements)
                        {
                            SpeciesDTO tmp = new SpeciesDTO();
                            tmp.Key  = cur.LocalKey;
                            tmp.Name = cur.DisplayName;
                            det.ShrubSpecies.Add(tmp);
                            ct++;
                        }

                        if (treeSpecies != null)
                        {
                            foreach (BundleElement cur in treeSpecies.Elements)
                            {
                                SpeciesDTO tmp = new SpeciesDTO();
                                tmp.Key  = cur.LocalKey;
                                tmp.Name = cur.DisplayName;
                                det.TreeSpecies.Add(tmp);
                                ct++;
                            }
                        }

                        if (herbSpecies != null)
                        {
                            foreach (BundleElement cur in herbSpecies.Elements)
                            {
                                SpeciesDTO tmp = new SpeciesDTO();
                                tmp.Key  = cur.LocalKey;
                                tmp.Name = cur.DisplayName;
                                det.HerbSpecies.Add(tmp);
                                ct++;
                            }
                        }

                        if (nonLiving != null)
                        {
                            foreach (BundleElement cur in nonLiving.Elements)
                            {
                                SpeciesDTO tmp = new SpeciesDTO();
                                tmp.Key  = cur.LocalKey;
                                tmp.Name = cur.DisplayName;
                                det.NonLiving.Add(tmp);
                            }
                        }

                        if (ct > 0) //have to have at least one of herb, tree, shrub to POSSIBLY be valid
                        {
                            det.Validate();
                            if (det.ValidationIssues.Count == 0)
                            {
                                IFileStoreProvider prov = this.FileStore;

                                if (prov != null)
                                {
                                    FilestoreFile fil = prov.Make(id);
                                    if (fil != null)
                                    {
                                        ExcelVegDET excel = new ExcelVegDET(det);
                                        excel.Save(fil);
                                        fil.Flush();
                                        fil.Seek(0, System.IO.SeekOrigin.Begin);
                                        return(fil);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 3
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();
        }