private void WriteToFile(string content, string filename)
        {
            try
            {
                // Get the local folder.
                System.IO.IsolatedStorage.IsolatedStorageFile local =
                    System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();

                // Create a new folder named DataFolder.
                if (!local.DirectoryExists("DataFolder"))
                {
                    local.CreateDirectory("DataFolder");
                }

                // Create a new file named DataFile.txt.
                using (var isoFileStream =
                           new System.IO.IsolatedStorage.IsolatedStorageFileStream(
                               "DataFolder\\" + filename,
                               System.IO.FileMode.Create,
                               local))
                {
                    // Write the data from the textbox.
                    using (var isoFileWriter = new System.IO.StreamWriter(isoFileStream))
                    {
                        isoFileWriter.WriteLine(content);
                    }
                }
            }
            catch { }
        }
Beispiel #2
0
        public void SaveIndex()
        {
            System.IO.IsolatedStorage.IsolatedStorageFile local = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
            if (!local.DirectoryExists("IndicesFolder"))
            {
                local.CreateDirectory("IndicesFolder");
            }

            using (var isoFileStream = new System.IO.IsolatedStorage.IsolatedStorageFileStream("IndicesFolder\\Index.txt", System.IO.FileMode.OpenOrCreate, local))
            {
                using (var isoFileWriter = new System.IO.StreamWriter(isoFileStream))
                {
                    foreach (var card in Index)
                    {
                        var cardAsString = string.Format("[[{0}]] {1} {2}{3}", card.Key.Trim("\n".ToCharArray()), card.Value.StartsAtByte, card.Value.Length, Environment.NewLine);
                        isoFileWriter.WriteLine(cardAsString);
                    }
                }
            }
        }
Beispiel #3
0
        //  public long LogCommand(byte[] command)
        //{
        //  return LogCommand(new EventCommand() { Command = command });
        //}

        private bool Init(bool isoperationslog = false)
        {
            FileName = Path.Combine(BasePath, DataBaseName);
            LogWriter.SeparationLine();
            LogWriter.LogInformation("Initializing Journal Writer", LogEntryType.Information);

            try
            {
#if WINDOWS_PHONE
                if (!iss.DirectoryExists(FileName))
                {
                    LogWriter.LogInformation("Directory for Journaling does not exists. creating it", LogEntryType.Warning);
                    iss.CreateDirectory(FileName);
                }
#else
                if (!Directory.Exists(FileName))
                {
                    LogWriter.LogInformation("Directory for Journaling does not exists. creating it", LogEntryType.Warning);
                    Directory.CreateDirectory(FileName);
                }
#endif
            }
            catch (Exception ex)
            {
                LogWriter.LogException(ex);
                return(false);
            }

            if (isoperationslog)
            {
                FileName = Path.Combine(FileName, "denso.log");
            }
            else
            {
                FileName = Path.Combine(FileName, "denso.jnl");
            }


            LogWriter.LogInformation("Completed", LogEntryType.SuccessAudit);
            return(OpenLogFile());
        }
Beispiel #4
0
        internal static void SaveCollection(string database, string collection)
        {
            var store = GetObjectStore(database, collection);

            if (store.ChangesFromLastSave > 0)
            {
                var fullpath = Path.Combine(Path.Combine(Configuration.BasePath, database), collection + ".coll");

#if WINDOWS_PHONE
                if (!iss.DirectoryExists(Path.GetDirectoryName(fullpath)))
                {
                    iss.CreateDirectory(Path.GetDirectoryName(fullpath));
                }
#else
                if (!Directory.Exists(Path.GetDirectoryName(fullpath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fullpath));
                }
#endif

                using (var file = File.Open(fullpath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
                {
                    using (var writer = new BinaryWriter(file))
                    {
                        foreach (var dstore in store._primarystore)
                        {
                            foreach (var item in dstore)
                            {
                                writer.Write((int)item.Value.Length); // Data Lenght
                                //writer.Write((byte)item.Key.Length);
                                writer.Write(item.Key);               // Database _id
                                writer.Write(item.Value);             // Data
                            }
                        }
                        writer.Flush();
                        file.Flush();
                        file.SetLength(file.Position);
                    }
                }
            }
        }
 public bool DirectoryExists(string path)
 {
     return(file.DirectoryExists(path));
 }