Exemple #1
0
        public static Project CreateEmpty(ILocalizationContext context, FileInfo path, INodeFactory conversationNodeFactory, INodeFactory domainNodeFactory, ISerializer <TData> serializer, ISerializer <TConversationData> conversationSerializer, ConversationSerializerDeserializerFactory conversationSerializerDeserializer, ISerializer <TDomainData> domainSerializer, PluginsConfig pluginsConfig, Func <IAudioProviderCustomization> audioCustomization, UpToDateFile.BackEnd backEnd)
        {
            using (MemoryStream m = new MemoryStream())
            {
                //Create the new conversation file stream, fill with essential content and close
                FileInfo conversationFile = ConversationFile.GetAvailableConversationPath(path.Directory, Enumerable.Empty <ISaveableFileProvider>());
                using (FileStream conversationStream = Util.LoadFileStream(conversationFile, FileMode.CreateNew, FileAccess.Write))
                {
                    conversationSerializer.Write(SerializationUtils.MakeConversationData(Enumerable.Empty <ConversationNode>(), new ConversationEditorData()), conversationStream);
                }

                //Create the new project
                GetFilePath getFilePath = null; //Should never need this as all the FileId lists are empty
                Write(getFilePath, Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <Id <FileInProject> >(), Enumerable.Empty <TData.LocalizerSetData>(), m, serializer);
                using (FileStream projectfile = Util.LoadFileStream(path, FileMode.Create, FileAccess.Write))
                {
                    m.Position = 0;
                    m.CopyTo(projectfile);
                    m.Position = 0;
                }

                TData data = new TData(Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.FileIdAndPath>(), Enumerable.Empty <TData.LocalizerSetData>());

                Project result = new Project(context, data, conversationNodeFactory, domainNodeFactory, m, path, serializer, conversationSerializer, conversationSerializerDeserializer, domainSerializer, pluginsConfig, audioCustomization, backEnd);
                return(result);
            }
        }
Exemple #2
0
        public static ConversationFile CreateEmpty(DirectoryInfo directory, Project project, INodeFactory nodeFactory,
                                                   GenerateAudio generateAudio, Func <IDynamicEnumParameter, object, DynamicEnumParameter.Source> getDocumentSource, IAudioLibrary audioProvider, UpToDateFile.BackEnd backEnd, DirectoryInfo origin)
        {
            var file = GetAvailableConversationPath(directory, project.Elements);

            var nodes  = Enumerable.Empty <GraphAndUI <NodeUIData> >();
            var groups = new List <NodeGroup>();

            //Fill the stream with the essential content
            using (MemoryStream m = new MemoryStream())
            {
                using (FileStream stream = Util.LoadFileStream(file, FileMode.CreateNew, FileAccess.Write))
                {
                    project.ConversationSerializer.Write(SerializationUtils.MakeConversationData(nodes, new ConversationEditorData(groups)), m);
                    m.Position = 0;
                    m.CopyTo(stream);
                }

                var result = new ConversationFile(Id <FileInProject> .New(), nodes, groups, m, DocumentPath.FromPath(file, origin), project.ConversationSerializer, new ReadOnlyCollection <LoadError>(new LoadError[0]), nodeFactory, generateAudio, getDocumentSource, audioProvider, backEnd);
                result.m_file.Save(); //Make sure the file starts life as a valid xml document
                return(result);
            }
        }
        private static void CopyToStream(IEnumerable <ConversationNode> nodes, IEnumerable <NodeGroup> groups, Stream m)
        {
            var serializer = SerializationUtils.ConversationSerializer;

            serializer.Write(SerializationUtils.MakeConversationData(nodes.Cast <ConversationNode>(), new ConversationEditorData(groups)), m);
        }
Exemple #4
0
 private void SaveTo(Stream file)
 {
     file.Position = 0;
     m_serializer.Write(SerializationUtils.MakeConversationData(Nodes, new ConversationEditorData(Groups)), file);
 }