Пример #1
0
        private static void ImportFiles(string uploadLocation)
        {
            // path
            var updates = new List <TransferData>();

            System.Console.WriteLine("Starting scan of directory");

            foreach (var directory in Directory.EnumerateDirectories(uploadLocation))
            {
                System.Console.WriteLine(directory);

                var firstFile = Directory.EnumerateFiles(directory).FirstOrDefault();
                if (firstFile != null)
                {
                    var filename = firstFile.Substring(firstFile.LastIndexOf('\\') + 1);

                    int  barcode, col;
                    char row;
                    ParseFileName(filename, out barcode, out row, out col);

                    updates.Add(new TransferData()
                    {
                        Barcode = barcode, Source = directory, Destination = string.Format("{0}\\{1}", _storageLocation, barcode)
                    });
                }
            }

            System.Console.WriteLine("Completed scan of directory");
            System.Console.WriteLine("{0} files processed", updates.Count);

            var db = new DataDataContext();

            var total   = updates.Count;
            var counter = 0;

            System.Console.WriteLine("Starting copy of data");
            // rename the folders
            foreach (var u in updates)
            {
                if (db.Barcodes.Any(a => a.Id == u.Barcode))
                {
                    // check for the destination
                    if (!Directory.Exists(u.Destination))
                    {
                        Directory.CreateDirectory(u.Destination);
                    }

                    foreach (var file in Directory.EnumerateFiles(u.Source))
                    {
                        try
                        {
                            var start    = file.LastIndexOf('\\') + 1;
                            var filename = file.Substring(start);

                            //System.Console.WriteLine(file);
                            //System.Console.WriteLine(filename);
                            //System.Console.WriteLine(u.Barcode);
                            //System.Console.WriteLine(string.Format("{0}\\{1}", u.Destination, filename));
                            //System.Console.WriteLine("-----------------------");

                            if (File.Exists(string.Format("{0}\\{1}", u.Destination, filename)))
                            {
                                File.Delete(string.Format("{0}\\{1}", u.Destination, filename));
                            }

                            File.Move(string.Format("{0}\\{1}", u.Source, filename), string.Format("{0}\\{1}", u.Destination, filename));

                            int  barcode, col;
                            char row;
                            ParseFileName(filename, out barcode, out row, out col);

                            var bf = db.BarcodeFiles.FirstOrDefault(a => a.BarcodeId == barcode && a.WellColumn == col && a.WellRow == row);
                            if (bf == null)
                            {
                                bf = new BarcodeFile()
                                {
                                    DateTimeUploaded = DateTime.Now, BarcodeId = barcode, Uploaded = true, Validated = false, WellColumn = col, WellRow = row
                                };
                                db.BarcodeFiles.InsertOnSubmit(bf);
                            }
                            else
                            {
                                bf.Uploaded         = true;
                                bf.Validated        = false;
                                bf.DateTimeUploaded = DateTime.Now;
                            }

                            counter++;
                            System.Console.Clear();
                            System.Console.WriteLine(string.Format("{0}% Completed File Import", counter / total));
                            System.Console.WriteLine(string.Format("Processed {0}", filename));
                        }
                        catch
                        {
                        }
                    }

                    Directory.Delete(u.Source);
                }
            }

            db.SubmitChanges();

            System.Console.WriteLine("Completed copy of data");
        }
Пример #2
0
 private void detach_BarcodeFiles(BarcodeFile entity)
 {
     this.SendPropertyChanging();
     entity.Barcode = null;
 }
Пример #3
0
 private void attach_BarcodeFiles(BarcodeFile entity)
 {
     this.SendPropertyChanging();
     entity.Barcode = this;
 }
Пример #4
0
 partial void DeleteBarcodeFile(BarcodeFile instance);
Пример #5
0
 partial void UpdateBarcodeFile(BarcodeFile instance);
Пример #6
0
 partial void InsertBarcodeFile(BarcodeFile instance);