Exemplo n.º 1
0
        /* public static void StartProcessingList(List<ThreadWrittenGraph> graphsToSave, IWindowWithProgress toUpdate)
         * {
         *   //No concurrancy issue here: it gets call once
         *   ThreadController = new FileWritingThread(graphsToSave, toUpdate);
         *   ThreadController.Start();
         * }
         */

        public void AddFileToWrite(ThreadWrittenGraph toAdd)
        {
            lock (toWrite)
            {
                toWrite.Add(toAdd);
            }
        }
Exemplo n.º 2
0
        protected virtual void ParseFileDetail(string fName, ref IGraph targetGraph, IUriNode provAction, IFileController fileController, out List <Exception> Errors, MainWindowViewModel toUpdate, string outputFormat)
        {
            FileWritingThread writer = new FileWritingThread(toUpdate);

            using (MemoryStream memStream = new MemoryStream(File.ReadAllBytes(fName))) //Do the processing in Memory for speedier access
                using (StreamReader sr = new StreamReader(memStream))
                {
                    if (!sr.EndOfStream)
                    {
                        toUpdate.DisplayMessage("Loading in to memory");
                        fileController.ProcessHeader(sr, ref targetGraph, provAction, fName);
                    }
                    toUpdate.DisplayMessage("Converting Items");
                    IEnumerable <IImportedItem> parsedElments = fileController.ConvertItems(sr, out Errors);
                    writer.Start();

                    long nElements             = parsedElments.LongCount();
                    long elmentNumber          = 0;
                    List <IImportedItem> chunk = new List <IImportedItem>();
                    foreach (IImportedItem element in parsedElments)
                    {
                        chunk.Add(element);
                        elmentNumber++;
                        if (elmentNumber % saveFreq == 0)
                        {
                            List <IImportedItem> copied = new List <IImportedItem>();
                            copied.AddRange(chunk);
                            chunk.Clear();
                            chunk = new List <IImportedItem>();
                            lock (fNumberLock)
                            {
                                fNumber++;
                            }
                            ThreadWrittenGraph toSave = new ThreadWrittenGraph(outputFormat, copied, fNumber);
                            writer.AddFileToWrite(toSave);
                        }
                    }
                    writer.Stop();
                }
        }