Ejemplo n.º 1
0
 public void Start()
 {
     windowToUpdate.DisplayMessage("Starting file write");
     if (controlThread == null)
     {
         throw new InvalidOperationException("Managed to start without creating control thread.");
     }
     controlThread.Start();
 }
Ejemplo n.º 2
0
        protected virtual void ParseFileDetail(string fName, ref IGraph targetGraph, IUriNode provAction, IFileController fileController, out List <Exception> Errors, IWindowWithProgress 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();
                            lock (fNumberLock)
                            {
                                fNumber++;
                            }
                            //Putting this bit in the critical section makes it way slower *and* doesn't solve the filenumber repeating problem
                            ThreadWrittenGraph toSave = new ThreadWrittenGraph(outputFormat, copied, fNumber);
                            writer.AddFileToWrite(toSave);
                        }
                    }
                    writer.Stop();
                }
        }