Exemple #1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string ak = textBoxAk.Text;
            string sk = textBoxSk.Text;

            if (string.IsNullOrEmpty(ak))
            {
                MessageBox.Show("AK 不能为空");
                return;
            }

            if (string.IsNullOrEmpty(sk))
            {
                MessageBox.Show("SK 不能为空");
                return;
            }

            Dictionary dicAk = new Dictionary();

            dicAk.Key   = "ak";
            dicAk.Value = ak;
            DictionaryDao.UpdateByKey(dicAk);
            Dictionary dicSk = new Dictionary();

            dicSk.Key   = "sk";
            dicSk.Value = sk;
            DictionaryDao.UpdateByKey(dicSk);

            MessageBox.Show("配置完成");
            DialogResult = DialogResult.OK;
        }
Exemple #2
0
        public void TestGetPrimaryMetadataForEveryone()
        {
            // Blow away excessive nychanis data.
            FastDAO <NycDatum> dataDao = new FastDAO <NycDatum>("PDP.Data", "NYCHANIS");
            DaoCriteria        crit    = new DaoCriteria();

            crit.Expressions.Add(new EqualExpression("IndicatorId", 201, false));
            crit.Expressions.Add(new GreaterExpression("IndicatorId", 10));
            dataDao.Delete(crit);

            // And also excessive PDB data.
            PdbTwoTableHelper helper = new PdbTwoTableHelper(Config.GetConfig("PDP.Data"), "Properties",
                                                             PdbEntityType.Properties);
            DictionaryDao primaryPdbDao = new DictionaryDao(
                dataDao.ConnDesc, helper.GetClassMapForPrimaryTable(new SecurityRole[] { SecurityRole.@public }));
            FastDAO <PdbSecondaryTableProperty> secondaryPdbDao = new FastDAO <PdbSecondaryTableProperty>(
                dataDao.ConnDesc, helper.GetClassMapForSecondaryTable());

            crit.Expressions.Clear();
            crit.Expressions.Add(new GreaterExpression("UID", 100630));
            primaryPdbDao.Delete(crit);
            crit.Expressions.Clear();
            crit.Expressions.Add(new GreaterExpression("ForeignKey", 100630));
            secondaryPdbDao.Delete(crit);
        }
Exemple #3
0
        /// <summary>
        /// Convert a Pdb Property quert result into a CSV string.
        /// </summary>
        /// <param name="result">The result to convert</param>
        /// <param name="indicatorId">Indicator Id that represtents this export</param>
        /// <returns>A string of comma seperated values, with header row and
        ///          escaped with "" around strings</returns>
        public static string ResultsAsCsv(NycResultsWithMetadata result, string indicatorId)
        {
            StringWriter writer = new StringWriter();

            List <ClassMapColDefinition> colMap = new List <ClassMapColDefinition>();

            // Additional Header properties
            NycIndicator indicator = GetIndicator(indicatorId);

            colMap.Add(new ClassMapColDefinition(_csvHeaderText, _csvHeaderText.Replace("<%DATE%>", DateTime.Now.ToShortDateString()), null));
            colMap.Add(new ClassMapColDefinition("Indicator", "Indicator", null));
            colMap.Add(new ClassMapColDefinition("Description", "Description", null));

            // Some hardcoded values need to be added to each row
            Dictionary <String, String> valuesToStuff = new Dictionary <string, string>();

            valuesToStuff.Add("Indicator", result.Indicator);
            valuesToStuff.Add("Description", indicator.Description);

            // Create some column mappings by looping through the attributes
            foreach (AbstractNamedSortable attr in result.Attrs)
            {
                // Only add it if we've got something
                if (attr.Name != null)
                {
                    string displayName = attr.Name == "Area" ? result.Resolution : attr.Name;
                    colMap.Add(new ClassMapColDefinition(attr.Name, displayName, null));
                }
            }

            ClassMapping  map    = new ClassMapping("csv", "csv", colMap, false);
            DictionaryDao csvDao = new DictionaryDao(new CsvDescriptor(writer, CsvQuoteLevel.QuoteAlways), map);

            List <CheckedDictionary <string, object> > list = new List <CheckedDictionary <string, object> >();

            if (result.ContextRows != null)
            {
                // Add context rows
                AddValuesToDictionary(result, list, result.ContextRows, valuesToStuff);
            }
            if (result.Values != null)
            {
                // Add value rows
                AddValuesToDictionary(result, list, result.Values, valuesToStuff);
            }

            // If there were no results, just give them nothing
            if (list.Count == 0)
            {
                return("");
            }
            // Add these values to the csv writer
            csvDao.Insert(list);

            // Return our result
            return(writer.ToString());
        }
Exemple #4
0
        public PlaceAPIHandler(Region region, string keyWord, DataGridView dataGridView = null, ISheet sheet = null)
        {
            // 外部参数
            this.region       = region;
            this.keyWord      = keyWord;
            this.dataGridView = dataGridView;
            this.sheet        = sheet;

            // 内部参数
            Dictionary dicAk = DictionaryDao.SelectByKey("ak");

            ak = dicAk.Value;
            Dictionary dicSk = DictionaryDao.SelectByKey("sk");

            sk       = dicSk.Value;
            url      = "/place/v2/search";
            totalNum = 0;
            getNum   = 0;
        }
 public ProductService()
 {
     ProductDao = new ProductDao<ProductInfo>();
     UnitDao = new DictionaryDao<Unit>();
     SpecificationDao = new SpecificationDao<Specification>();
 }
 public DictionaryService()
 {
     DictionaryDao = new DictionaryDao<SystemDictionary>();
 }
Exemple #7
0
 private static void AssertMissingColumns(ClassMapping mapping, string fieldName, object uninitVal)
 {
     FastDAO<CsvTestObj> dao = new FastDAO<CsvTestObj>(
         new CsvDescriptor(CsvConnectionType.Directory, "..\\..\\Tests\\"), mapping);
     DictionaryDao dictDao = new DictionaryDao(
         new CsvDescriptor(CsvConnectionType.Directory, "..\\..\\Tests\\"), mapping);
     IList<CsvTestObj> objs = dao.Get();
     IList<CheckedDictionary<string, object>> dicts = dictDao.Get();
     Assert.AreEqual(12, objs.Count, "Wrong number of real objects.");
     Assert.AreEqual(12, dicts.Count, "Wrong number of dictionaries.");
     for (int x = 0; x < objs.Count; x++)
     {
         object val;
         switch (fieldName)
         {
             case "One":
                 val = objs[x].One;
                 break;
             case "Two":
                 val = objs[x].Two;
                 break;
             case "Three":
                 val = objs[x].Three;
                 break;
             case "Four":
                 val = objs[x].Four;
                 break;
             case "Five":
                 val = objs[x].Five;
                 break;
             default:
                 throw new ArgumentException("Field " + fieldName + " isn't handled yet.", "fieldName");
         }
         Assert.AreEqual(uninitVal, val, "Field '" + fieldName + "' should be uninitialized because it is unmapped, but isn't.");
         Assert.IsFalse(dicts[x].ContainsKey(fieldName), "Field '" + fieldName + "' should not be in the dictionary because it is unmapped.");
     }
 }
Exemple #8
0
        public void TestWriteCsvWithQuotes()
        {
            StringWriter writer = new StringWriter();

            // This is testing to verify the CsvDescriptor constructor that takes a
            // Writer and a CVSQuoteLevel.
            CsvTestObj testObj1 = new CsvTestObj();
            CheckedDictionary<string, object> testDict1 = new CheckedDictionary<string, object>();
            testObj1.One = 50;
            testObj1.Two = -1.0;
            testObj1.Three = "Yo";
            testObj1.Four = new DateTime(2001, 1, 1, 1, 1, 1);
            testObj1.Five = null;
            testDict1["One"] = testObj1.One;
            testDict1["Two"] = testObj1.Two;
            testDict1["Three"] = testObj1.Three;
            testDict1["Four"] = testObj1.Four;
            testDict1["Five"] = testObj1.Five;

            CsvTestObj testObj2 = new CsvTestObj();
            CheckedDictionary<string, object> testDict2 = new CheckedDictionary<string, object>();
            testObj2.One = int.MaxValue;
            testObj2.Two = double.MinValue;
            testObj2.Three = null;
            testObj2.Four = DateTime.MinValue;
            testObj2.Five = "";
            testDict2["One"] = testObj2.One;
            testDict2["Two"] = testObj2.Two;
            testDict2["Three"] = testObj2.Three;
            testDict2["Four"] = testObj2.Four;
            testDict2["Five"] = testObj2.Five;

            ClassMapping mapping1 = MakeMapping("n/a", "WriteOne", true);
            CsvDescriptor desc1 = new CsvDescriptor(writer, CsvQuoteLevel.QuoteStrings);
            DictionaryDao dao1 = new DictionaryDao(desc1, mapping1);
            dao1.Insert(testDict1);
            dao1.Insert(testDict2);

            string csv = writer.ToString();
            Assert.IsNotEmpty(csv, "The writer should not return an empty string. ");
        }
Exemple #9
0
        public void TestWriteCsv()
        {
            CsvTestObj testObj1 = new CsvTestObj();
            CheckedDictionary<string, object> testDict1 = new CheckedDictionary<string, object>();
            testObj1.One = 50;
            testObj1.Two = -1.0;
            testObj1.Three = "Yo";
            testObj1.Four = new DateTime(2001, 1, 1, 1, 1, 1);
            testObj1.Five = null;
            testDict1["One"] = testObj1.One;
            testDict1["Two"] = testObj1.Two;
            testDict1["Three"] = testObj1.Three;
            testDict1["Four"] = testObj1.Four;
            testDict1["Five"] = testObj1.Five;

            CsvTestObj testObj2 = new CsvTestObj();
            CheckedDictionary<string, object> testDict2 = new CheckedDictionary<string, object>();
            testObj2.One = int.MaxValue;
            testObj2.Two = double.MinValue;
            testObj2.Three = null;
            testObj2.Four = DateTime.MinValue;
            testObj2.Five = "";
            testDict2["One"] = testObj2.One;
            testDict2["Two"] = testObj2.Two;
            testDict2["Three"] = testObj2.Three;
            testDict2["Four"] = testObj2.Four;
            testDict2["Five"] = testObj2.Five;

            ClassMapping mapping1 = MakeMapping("n/a", "WriteOne", true);
            CsvDescriptor desc1 = new CsvDescriptor("..\\..\\Tests");
            DictionaryDao dao1 = new DictionaryDao(desc1, mapping1);
            dao1.Truncate();
            dao1.Insert(testDict1);
            dao1.Insert(testDict2);

            ClassMapping mapping2 = MakeMapping("Azavea.Open.DAO.CSV.Tests.CsvTestObj,Azavea.Open.DAO.CSV", "Doesn'tMatter", true);
            CsvDescriptor desc2 = new CsvDescriptor(CsvConnectionType.FileName,
                                                    "..\\..\\Tests\\WriteTwo.csv");
            FastDAO<CsvTestObj> dao2 = new FastDAO<CsvTestObj>(desc2, mapping2);
            dao2.Truncate();
            dao2.Insert(testObj1);
            dao2.Insert(testObj2);

            ClassMapping mapping3 = MakeMapping("n/a", "AlsoDoesn'tMatter", true);
            using (StreamWriter sw = new StreamWriter("..\\..\\Tests\\WriteThree.csv", false))
            {
                CsvDescriptor desc3 = new CsvDescriptor(sw);
                DictionaryDao dao3 = new DictionaryDao(desc3, mapping3);
                // Can't truncate this one.
                dao3.Insert(testDict1);
                dao3.Insert(testDict2);
            }

            ClassMapping mapping4 = MakeMapping("n/a", "WriteFour", false);
            CsvDescriptor desc4 = new CsvDescriptor("..\\..\\Tests");
            DictionaryDao dao4 = new DictionaryDao(desc4, mapping4);
            dao4.Truncate();
            dao4.Insert(testDict1);
            dao4.Insert(testDict2);

            ClassMapping mapping5 = MakeMapping("Azavea.Open.DAO.CSV.Tests.CsvTestObj,Azavea.Open.DAO.CSV", "Doesn'tMatter", false);
            CsvDescriptor desc5 = new CsvDescriptor(CsvConnectionType.FileName,
                                                    "..\\..\\Tests\\WriteFive.csv");
            FastDAO<CsvTestObj> dao5 = new FastDAO<CsvTestObj>(desc5, mapping5);
            dao5.Truncate();
            dao5.Insert(testObj1);
            dao5.Insert(testObj2);

            ClassMapping mapping6 = MakeMapping("n/a", "AlsoDoesn'tMatter", false);
            using (StreamWriter sw = new StreamWriter("..\\..\\Tests\\WriteSix.csv", false))
            {
                CsvDescriptor desc6 = new CsvDescriptor(sw);
                DictionaryDao dao6 = new DictionaryDao(desc6, mapping6);
                // Can't truncate this one.
                dao6.Insert(testDict1);
                dao6.Insert(testDict2);
            }

            // Now, assert they are all correct.  1, 2, and 3 should be the same (they have headers)
            // and 4, 5, and 6 should be the same (without headers).
            AssertFileContentsSame("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteTwo.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteThree.csv");
            AssertFileGreater("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteFour.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteFour.csv", "..\\..\\Tests\\WriteFive.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteFour.csv", "..\\..\\Tests\\WriteFive.csv");
        }