示例#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 bool OpenLogFile()
        {
            try
            {
#if WINDOWS_PHONE
                _logfile = iss.OpenFile(FileName, FileMode.Append, FileAccess.Write, FileShare.Read);
#else
                _logfile = new FileStream(FileName,
                                          FileMode.OpenOrCreate,
                                          System.Security.AccessControl.FileSystemRights.Read,
                                          FileShare.ReadWrite, 4096,
                                          FileOptions.None);
#endif
                _reader = new BinaryReader(_logfile);

                if (_logfile != null)
                {
                    LogWriter.LogMessage(string.Format("Log File ready: {0}", FileName), LogEntryType.Information);
                }
                else
                {
                    LogWriter.LogMessage(string.Format("Unable to open logfile: {0}", FileName), LogEntryType.Error);
                }

                JournalWriter.Closing += (s, e) => CloseFile();
            }
            catch (Exception ex)
            {
                LogWriter.LogException(ex);
                return(false);
            }
            return(true);
        }
示例#3
0
        private bool OpenLogFile()
        {
            try
            {
                if (_logfile == null)
                {
#if WINDOWS_PHONE
                    _logfile = iss.OpenFile(FileName, FileMode.Append, FileAccess.Write, FileShare.Read);
#else
                    _logfile = new FileStream(FileName,
                                              FileMode.Append,
                                              System.Security.AccessControl.FileSystemRights.AppendData,
                                              FileShare.ReadWrite, 4096,
                                              FileOptions.None);
                    //_logfile = File.Open(FileName, FileMode.Append, FileAccess.Write, FileShare.Read);
#endif
                    //IncreaseFileSize();
                    _logbuffer = new MemoryStream();
                    _writer    = new BinaryWriter(_logbuffer);

                    if (_logfile != null)
                    {
                        LogWriter.LogMessage(string.Format("Log File ready: {0}", FileName), LogEntryType.Information);
                    }
                    else
                    {
                        LogWriter.LogMessage(string.Format("Unable to open logfile: {0}", FileName), LogEntryType.Error);
                        //Server.EmergencyShutdown();
                    }

                    JournalWriter.Closing += (s, e) => CloseFile();
                }
            }
            catch (Exception ex)
            {
                LogWriter.LogException(ex);
                //Server.EmergencyShutdown();
                return(false);
            }
            return(true);
        }
示例#4
0
        /// <summary>
        /// 尝试读取数据流
        /// </summary>
        /// <param name="resName"></param>
        /// <returns></returns>
        public static System.IO.Stream OpenStream(string @resName)
        {
            Stream resource = StrRes(resName);

            if (resource != null)
            {
                return(resource);
            }
            //尝试读取XAP中文件(Content类型)
            System.IO.Stream stream = null;
            try
            {
                stream = TitleContainer.OpenStream(resName);
            }
            catch
            {
                if (stream == null)
                {
                    //尝试读取DLL中文件(Resource类型)
                    Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute);
                    stream = ApplicationResourceStream(pathUri);
                }
            }
            if (stream == null)
            {
                //尝试读取标准路径数据
                try
                {
                    stream = new System.IO.FileStream(resName, System.IO.FileMode.Open);
                }
                catch
                {
                    //尝试读取封闭空间中数据
                    try
                    {
                        System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                        stream = store.OpenFile(resName, System.IO.FileMode.Open);
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        Log.DebugWrite("\n" + resName + " file not found !");
                    }
                }
            }
            return(stream);
        }
示例#5
0
        /// <summary>
        /// 尝试读取数据流
        /// </summary>
        /// <param name="resName"></param>
        /// <returns></returns>
        public static System.IO.Stream OpenStream(string resName)
        {
            if (resName.IndexOf("/") == -1 && FileUtils.GetExtension(resName).Length == 0)
            {
                resName = "Content/" + resName;
            }
            Stream resource = StrRes(resName);

            if (resource != null)
            {
                return(resource);
            }
            //尝试读取XAP中文件(Content类型)
            System.IO.Stream stream = null;
            try
            {
                stream = TitleContainer.OpenStream(resName);
            }
            catch
            {
                try
                {
                    if (stream == null)
                    {
                        stream = XNAConfig.LoadStream(resName);
                    }
                }
                catch (Exception)
                {
                    if (stream == null)
                    {
                        //尝试读取DLL中文件(Resource类型)
                        Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute);
                        stream = ApplicationResourceStream(pathUri);
                    }
                }
            }
            if (stream == null)
            {
                //尝试读取标准路径数据
                try
                {
                    stream = new System.IO.FileStream(resName, System.IO.FileMode.Open);
                }
                catch
                {
                    //尝试读取封闭空间中数据
                    try
                    {
                        System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                        stream = store.OpenFile(resName, System.IO.FileMode.Open);
                    }
                    catch (Exception ex)
                    {
                        Loon.Utils.Debugging.Log.Exception(ex);
                        Loon.Utils.Debugging.Log.DebugWrite('\n' + resName + " file not found !");
                    }
                }
            }
            return(stream);
        }
 public System.IO.Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share)
 {
     return(file.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access, (System.IO.FileShare)share));
 }
示例#7
0
 public Stream Open(FileMode mode, FileAccess access, FileShare fileShare)
 {
     return(storage.OpenFile(systemFilename, mode, access, fileShare));
 }