Exemple #1
0
 public IEnumerable<Account> FindAccountsForService(string serviceId)
 {
     if (_keyStore == null)
     {
         InitializeStore();
     }
     
     var accounts = new List<Account>();
     string postfix = "-" + serviceId;
     IEnumeration aliases = _keyStore.Aliases();
     while(aliases.HasMoreElements)
     {
         string alias = aliases.NextElement().ToString();
         if(alias.EndsWith(postfix))
         {
             var entry = _keyStore.GetEntry(alias, _prot) as KeyStore.SecretKeyEntry;
             if(entry != null)
             {
                 byte[] bytes = entry.SecretKey.GetEncoded();
                 string serialized = Encoding.UTF8.GetString(bytes);
                 Account account = Account.Deserialize(serialized);
                 accounts.Add(account);
             }
         }
     }
     return accounts;
 }
Exemple #2
0
        /// <summary>
        /// 解压文件
        /// </summary>
        /// <param name="inputZip"></param>
        /// <param name="destinationDirectory"></param>
        public static void UnzipFile(string inputZip, string destinationDirectory)
        {
            int           buffer         = 2048;
            List <string> zipFiles       = new List <string>();
            File          sourceZipFile  = new File(inputZip);
            File          unzipDirectory = new File(destinationDirectory);

            CreateDir(unzipDirectory.AbsolutePath);

            ZipFile zipFile;

            zipFile = new ZipFile(sourceZipFile, ZipFile.OpenRead);
            IEnumeration zipFileEntries = zipFile.Entries();

            while (zipFileEntries.HasMoreElements)
            {
                ZipEntry entry        = (ZipEntry)zipFileEntries.NextElement();
                string   currentEntry = entry.Name;
                File     destFile     = new File(unzipDirectory, currentEntry);

                if (currentEntry.EndsWith(Constant.SUFFIX_ZIP))
                {
                    zipFiles.Add(destFile.AbsolutePath);
                }

                File destinationParent = destFile.ParentFile;
                CreateDir(destinationParent.AbsolutePath);

                if (!entry.IsDirectory)
                {
                    if (destFile != null && destFile.Exists())
                    {
                        continue;
                    }

                    BufferedInputStream inputStream = new BufferedInputStream(zipFile.GetInputStream(entry));
                    int currentByte;
                    // buffer for writing file
                    byte[] data = new byte[buffer];

                    var fos = new System.IO.FileStream(destFile.AbsolutePath, System.IO.FileMode.OpenOrCreate);
                    BufferedOutputStream dest = new BufferedOutputStream(fos, buffer);

                    while ((currentByte = inputStream.Read(data, 0, buffer)) != -1)
                    {
                        dest.Write(data, 0, currentByte);
                    }
                    dest.Flush();
                    dest.Close();
                    inputStream.Close();
                }
            }
            zipFile.Close();

            foreach (var zipName in zipFiles)
            {
                UnzipFile(zipName, destinationDirectory + File.SeparatorChar
                          + zipName.Substring(0, zipName.LastIndexOf(Constant.SUFFIX_ZIP)));
            }
        }
Exemple #3
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21DEC2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * get all records based on given rectangle.
         * @param rectGeo the boundary..
         * @return a hashtable of all matched record.the key is the mapInfo ID.
         */
        public Hashtable SearchMapObjectsInRect(GeoLatLngBounds rectGeo)
        {
            Point pt1, pt2;

            pt1 = new Point(new[] {
                (int)(rectGeo.X * DOUBLE_PRECISION + 0.5),
                (int)(rectGeo.Y * DOUBLE_PRECISION + 0.5)
            });
            pt2 = new Point(new int[] {
                (int)((rectGeo.X + rectGeo.Width) * DOUBLE_PRECISION + 0.5),
                (int)((rectGeo.Y + rectGeo.Height) * DOUBLE_PRECISION + 0.5)
            });
            HyperCube h1 = new HyperCube(pt1, pt2);
            Hashtable retArrayList = new Hashtable();
            Point     p11, p12;

            for (IEnumeration e1 = _tree.Intersection(h1); e1.HasMoreElements();)
            {
                AbstractNode node = (AbstractNode)(e1.NextElement());
                if (node.IsLeaf())
                {
                    int         index = 0;
                    HyperCube[] data  = node.GetHyperCubes();
                    HyperCube   cube;
                    for (int cubeIndex = 0; cubeIndex < data.Length; cubeIndex++)
                    {
                        cube = data[cubeIndex];
                        if (cube.Intersection(h1))
                        {
                            p11 = cube.GetP1();
                            p12 = cube.GetP2();
                            int             mapinfoId = ((Leaf)node).GetDataPointer(index);
                            int             mapInfoId = mapinfoId;
                            GeoLatLngBounds mbr       = new GeoLatLngBounds();
                            mbr.X      = p11.GetFloatCoordinate(0) / DOUBLE_PRECISION;
                            mbr.Y      = p11.GetFloatCoordinate(1) / DOUBLE_PRECISION;
                            mbr.Width  = ((p12.GetFloatCoordinate(0) - p11.GetFloatCoordinate(0))) / DOUBLE_PRECISION;
                            mbr.Height = ((p12.GetFloatCoordinate(1) - p11.GetFloatCoordinate(1))) / DOUBLE_PRECISION;
                            if (!retArrayList.Contains(mapInfoId))
                            {
                                retArrayList.Add(mapInfoId, mbr);
                            }
                        }
                        index++;
                    }
                }
            }
            return(retArrayList);
        }
Exemple #4
0
        /// <summary>
        /// 写配置文件
        /// </summary>
        /// <param name="context"></param>
        /// <param name="propertyKey"></param>
        /// <param name="propertyValue"></param>
        public static void changeValueByPropertyName(Context context, string propertyKey, string propertyValue)
        {
            // 实例化Properties对象
            Properties prop = new Properties();

            try
            {
                // 读取文件流
                Stream ins = context.Assets.Open("Config.properties", Access.Random);
                // 装载Properties对象
                prop.Load(ins);
                // 打开流
                Stream       fos = context.OpenFileOutput("Config.properties", FileCreationMode.Private);
                IEnumeration ie  = prop.PropertyNames();
                // 循环每一个节点
                while (ie.HasMoreElements)
                {
                    // 取出值
                    string s = ie.NextElement().ToString();
                    // 发是否是指定修改值得名称
                    if (!s.Equals(propertyKey))
                    {
                        // 设置值
                        prop.SetProperty(s, prop.GetProperty(s));
                    }
                }
                // 设置值
                prop.SetProperty(propertyKey, propertyValue);
                // 保存配置文件
                prop.Store(fos, "");
                ins.Close();
                // 关闭Properties对象
                fos.Close();
            }
            catch (FileNotFoundException e)
            {
                Log.Error(LOG_FLAG, e.ToString());
                LogUtil.SaveLogInfoToFile(e.ToString());
            }
            catch (IOException e)
            {
                Log.Error(LOG_FLAG, e.ToString());
                LogUtil.SaveLogInfoToFile(e.ToString());
            }
        }
Exemple #5
0
 private static IEnumerable <ZipEntry> GetBitmapEntries(ZipFile file)
 {
     using (IEnumeration entries = file.Entries())
     {
         while (entries.HasMoreElements)
         {
             var entry = (ZipEntry)entries.NextElement();
             if (!entry.IsDirectory &&
                 (entry.Name.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
                  entry.Name.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) ||
                  entry.Name.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) ||
                  entry.Name.EndsWith(".png", StringComparison.OrdinalIgnoreCase)))
             {
                 yield return(entry);
             }
         }
     }
 }
Exemple #6
0
        public IEnumerable <string> FindAccountsForService(string serviceId)
        {
            List <string> r       = new List <string>();
            string        postfix = "-" + serviceId;
            IEnumeration  aliases = _keyStore.Aliases();

            while (aliases.HasMoreElements)
            {
                string alias = aliases.NextElement().ToString();
                if (alias.EndsWith(postfix))
                {
                    KeyStore.SecretKeyEntry e = _keyStore.GetEntry(
                        alias,
                        _passProtection) as KeyStore.SecretKeyEntry;
                    if (e != null)
                    {
                        byte[] bytes    = e.SecretKey.GetEncoded();
                        string password = System.Text.Encoding.UTF8.GetString(bytes);
                        r.Add(password);
                    }
                }
            }
            return(r);
        }
Exemple #7
0
 public T Next()
 {
     return(_enum.NextElement());
 }