Пример #1
0
        private static void OpenDataBase(string databasename)
        {
            lock (_eventStore)
                if (!_eventStore.ContainsKey(databasename))
                {
                    var filename = Path.Combine(Path.Combine(Configuration.BasePath, databasename), "denso.trn");

                    long eventcommandsn = 0;
#if WINDOWS_PHONE
                    if (iss.FileExists(filename))
                    {
                        using (var fs = iss.OpenFile(Path.Combine(Path.Combine(Configuration.BasePath, databasename), "denso.trn"), FileMode.Open, FileAccess.Read))
#else
                    if (File.Exists(filename))
                        using (var fs = File.Open(Path.Combine(Path.Combine(Configuration.BasePath, databasename), "denso.trn"), FileMode.Open, FileAccess.Read, FileShare.Read))
#endif
                            if (fs.Length > 0)
                            {
                                using (var br = new BinaryReader(fs))
                                    eventcommandsn = br.ReadInt64();
                            }
                    }

                    _eventStore.Add(databasename, new EventStore(databasename, eventcommandsn));
                }
        }
Пример #2
0
        private string ReadFile(string filename)
        {
            try
            {
                // Obtain a virtual store for the application.
                System.IO.IsolatedStorage.IsolatedStorageFile local =
                    System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();

                if (local.FileExists("DataFolder\\" + filename))
                {
                    // Specify the file path and options.
                    using (var isoFileStream = new System.IO.IsolatedStorage.IsolatedStorageFileStream
                                                   ("DataFolder\\" + filename, System.IO.FileMode.Open, local))
                    {
                        // Read the data.
                        using (var isoFileReader = new System.IO.StreamReader(isoFileStream))
                        {
                            return(isoFileReader.ReadLine());
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch { return(null); }
        }
Пример #3
0
        public void DeleteRemovesFileFromStorage()
        {
            var file = new IsolatedStorageFile("~/exists.js", storage, directory);

            file.Delete();
            storage.FileExists("exists.js").ShouldBeFalse();
        }
Пример #4
0
        internal static bool FileExists(string dbpath, string typeName, bool useElevatedTrust)
        {
            string extension = ".sqo";

            if (SiaqodbConfigurator.EncryptedDatabase)
            {
                extension = ".esqo";
            }
            string fileName = dbpath + Path.DirectorySeparatorChar + typeName + extension;

            #if SILVERLIGHT
            if (!useElevatedTrust)
            {
                System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();

                return(isf.FileExists(fileName));
            }
            else
            {
                return(File.Exists(fileName));
            }
#elif MONODROID
            return(File.Exists(fileName));
#else
            return(File.Exists(fileName));
#endif
        }
Пример #5
0
        public void DeleteIndex()
        {
            System.IO.IsolatedStorage.IsolatedStorageFile local = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();

            if (local.FileExists("IndicesFolder\\Index.txt"))
            {
                local.DeleteFile("IndicesFolder\\Index.txt");
            }
        }
Пример #6
0
 void PhotoTask_Completed(object sender, PhotoResult e)
 {
     if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
     {
         System.Windows.Media.Imaging.WriteableBitmap  bmp = Microsoft.Phone.PictureDecoder.DecodeJpeg(e.ChosenPhoto);
         System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
         if (isf.FileExists("back_temp.jpg"))
         {
             isf.DeleteFile("back_temp.jpg");
         }
         System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.CreateFile("back_temp.jpg");
         System.Windows.Media.Imaging.Extensions.SaveJpeg(bmp, PhotoStream, 1024, 768, 0, 100); //这里设置保存后图片的大小、品质
         PhotoStream.Close();                                                                   //写入完毕,关闭文件流
     }
 }
Пример #7
0
 private void Bcakground_Click(object sender, RoutedEventArgs e)
 {
     if ((bool)checkBoxSetting.IsChecked)
     {
         takePhote();
         NavigationService.GoBack();
     }
     else
     {
         System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
         if (isf.FileExists("back_temp.jpg"))
         {
             isf.DeleteFile("back_temp.jpg");
         }
     }
 }
Пример #8
0
        internal void ShrinkToSN(long commandsn)
        {
            LogWriter.LogInformation("File Shrink requested", LogEntryType.Warning);
            //return;

            CloseFile();
            lock (_filelock)
            {
#if WINDOWS_PHONE
                if (iss.FileExists(FileName))
                {
                    using (var readerfs = iss.OpenFile(FileName, FileMode.Open, FileAccess.Read, FileShare.Write))
                        using (var writerfs = iss.OpenFile(FileName, FileMode.Open, FileAccess.Write, FileShare.Read))
#else
                if (File.Exists(FileName))
                    using (var readerfs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Write))
                        using (var writerfs = File.Open(FileName, FileMode.Open, FileAccess.Write, FileShare.Read))
#endif

                            using (var br = new BinaryReader(readerfs))
                                using (var bw = new BinaryWriter(writerfs))
                                {
                                    LogWriter.LogInformation("Compressing file", LogEntryType.Information);
                                    while (readerfs.Position < readerfs.Length)
                                    {
                                        var cmd = ReadCommand(br);
                                        if (cmd != null)
                                        {
                                            if (cmd.CommandSN > commandsn)
                                            {
                                                WriteCommand(bw, cmd);
                                            }
                                        }
                                    }

                                    LogWriter.LogInformation("File shrink completed", LogEntryType.SuccessAudit);
                                    readerfs.Close();
                                    writerfs.Flush();
                                    LogWriter.LogInformation("Free empty space", LogEntryType.SuccessAudit);
                                    writerfs.SetLength(writerfs.Position);
                                    writerfs.Close();

                                    LogWriter.LogInformation("Shringk completed", LogEntryType.SuccessAudit);
                                }
                }
            }
        }
Пример #9
0
        public bool LoadIndex()
        {
            System.IO.IsolatedStorage.IsolatedStorageFile local = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
            var newIndex = new Dictionary <string, FileTextBlock>();

            if (!local.FileExists("IndicesFolder\\Index.txt"))
            {
                return(false);
            }

            using (var isoFileStream = new System.IO.IsolatedStorage.IsolatedStorageFileStream("IndicesFolder\\Index.txt", System.IO.FileMode.Open, local))
            {
                using (var isoFileReader = new System.IO.StreamReader(isoFileStream))
                {
                    var line = isoFileReader.ReadLine();
                    while (!isoFileReader.EndOfStream)
                    {
                        if (!string.IsNullOrEmpty(line))
                        {
                            var firstSpace = line.IndexOf(" ", line.IndexOf("]]"));
                            if (firstSpace > 0)
                            {
                                var secondSpace = line.IndexOf(" ", firstSpace + 1);
                                var wordKey     = line.Substring(2, line.IndexOf("]]") - 2);
                                var startsAt    = long.Parse(line.Substring(firstSpace + 1, secondSpace - firstSpace).Trim(' '));
                                var length      = int.Parse(line.Substring(secondSpace + 1).Trim(' '));
                                newIndex.Add(wordKey, new FileTextBlock()
                                {
                                    Length = length, StartsAtByte = startsAt
                                });
                            }
                        }
                        line = isoFileReader.ReadLine();
                    }
                }
            }

            Index = newIndex;
            return(true);
        }
 public bool FileExists(string path)
 {
     return(file.FileExists(path));
 }