コード例 #1
0
ファイル: PersistenceService.cs プロジェクト: fdieulle/XShell
        public void Persist(string name, IPersistable persistable)
        {
            if (persistable == null)
            {
                return;
            }

            try
            {
                var folder = GetFolder();

                // Process the persistence in 2 times to avoid to corrupt persisted files.
                using (var ms = new MemoryStream())
                {
                    persistable.Persist(ms);

                    var buffer = ms.GetBuffer();
                    var length = (int)ms.Length;
                    if (length == 0)
                    {
                        return;
                    }

                    var filePath = GetFilePath(folder, name);
                    using (var writer = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                        writer.Write(buffer, 0, length);
                }
            }
            catch (Exception e)
            {
                WriteException(name, "Exception happens during persist", e);
            }
        }
コード例 #2
0
        protected override void ExecuteImpl(object parameter)
        {
            var path = Path.Combine(BasePath, "Declarations");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            foreach (var tree in _state.BuiltInDeclarationTrees)
            {
                System.Diagnostics.Debug.Assert(path != null, "project path isn't supposed to be null");

                var filename = string.Format("{0}.{1}.{2}", tree.Node.QualifiedMemberName.QualifiedModuleName.ProjectName, tree.MajorVersion, tree.MinorVersion) + ".xml";
                _service.Persist(Path.Combine(path, filename), tree);
            }
        }
        protected override void OnExecute(object parameter)
        {
            var path = Path.Combine(BasePath, "Declarations");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            foreach (var project in _state.DeclarationFinder.BuiltInDeclarations(DeclarationType.Project).OfType <ProjectDeclaration>())
            {
                System.Diagnostics.Debug.Assert(path != null, "project path isn't supposed to be null");

                var tree         = _serializableProjectBuilder.SerializableProject(project);
                var filename     = $"{tree.Node.QualifiedMemberName.QualifiedModuleName.ProjectName}.{tree.MajorVersion}.{tree.MinorVersion}.xml";
                var fullFilename = Path.Combine(path, filename);
                _service.Persist(fullFilename, tree);
            }
        }
コード例 #4
0
 public void Write(IPersistable value)
 {
     value.Persist(this);
 }