Esempio n. 1
0
        public void FileSystem_Should_Check_My_File_System()
        {
            //arrange
            var notePadFile           = new File("notepad", ".exe", 241);
            var windowsSubDirectories = new List <Directory>()
            {
                new Directory("addins", new List <File>(), new List <Directory>())
            };
            var diskCDirectories = new List <Directory>()
            {
                new Directory("Intel", new List <File>(), new List <Directory>()),
                new Directory("Windows", new List <File>()
                {
                    notePadFile
                }, windowsSubDirectories)
            };
            var diskC = new LocalDisk("C", new List <File>(), diskCDirectories);

            var googleDriveFiles = new List <File>()
            {
                new File("CV, Sergiy Lichenko", "docx", 21200),
                new File("CV, Sergiy Lichenko", "pdf", 184000),
                new File("VladimirDorokhov_CV.doc", "doc", 18000)
            };
            var diskDDirectories = new List <Directory>()
            {
                new Directory("GoogleDrive", googleDriveFiles, new List <Directory>())
            };
            var diskD = new LocalDisk("D", new List <File>(), diskDDirectories);

            //act
            var fileSystem = new FileSystem(new List <LocalDisk>()
            {
                diskC, diskD
            });

            //assert
            fileSystem.LocalDisks.Count().ShouldBeEquivalentTo(2);
            fileSystem.LocalDisks.ElementAt(1).ShouldBeEquivalentTo(diskD);
            fileSystem.LocalDisks.ElementAt(0).ShouldBeEquivalentTo(diskC);

            fileSystem.LocalDisks.ElementAt(1).Directories.ShouldBeEquivalentTo(diskDDirectories);
            fileSystem.LocalDisks.ElementAt(1).Directories.ElementAt(0).Files.ShouldBeEquivalentTo(googleDriveFiles);
            fileSystem.LocalDisks.ElementAt(1).Directories.ElementAt(0).Directories.Count.ShouldBeEquivalentTo(0);

            fileSystem.LocalDisks.ElementAt(0).Directories.ShouldBeEquivalentTo(diskCDirectories);
            fileSystem.LocalDisks.ElementAt(0).Files.Count.ShouldBeEquivalentTo(0);
            fileSystem.LocalDisks.ElementAt(0).Directories.ElementAt(0).Directories.Count.ShouldBeEquivalentTo(0);
            fileSystem.LocalDisks.ElementAt(0).Directories.ElementAt(0).Files.Count.ShouldBeEquivalentTo(0);

            fileSystem.LocalDisks.ElementAt(0).Directories.ElementAt(1).Directories.ShouldBeEquivalentTo(windowsSubDirectories);
            fileSystem.LocalDisks.ElementAt(0).Directories.ElementAt(1).Files.ElementAt(0).ShouldBeEquivalentTo(notePadFile);
            fileSystem.LocalDisks.ElementAt(0).Directories.ElementAt(1).Files.Count.ShouldBeEquivalentTo(1);
        }
Esempio n. 2
0
        public void FileSystem_Should_Throw_LocalDisk_Find_By_Name_If_Null()
        {
            //arrange
            var localDisk = new LocalDisk(string.Empty, new List <File>(), new List <Directory>());

            //act
            Action act = () => localDisk.FindByName(null).ToArray();

            //assert
            act.ShouldThrow <ArgumentNullException>();
        }
Esempio n. 3
0
        public TransferBytes(TransferItem item, ItemsTransferManager GroupManager, object clientTo = null)
        {
            if (item.From.node.Info.Size == 0)
            {
                item.ErrorMsg = "File size zero."; Dispose();
            }
            this.item         = item;
            this.GroupManager = GroupManager;
            Type_root_to      = this.item.To.node.GetRoot.NodeType.Type;
            Type_root_from    = this.item.From.node.GetRoot.NodeType.Type;

            if (GroupManager.AreCut && (Type_root_to | CloudType.LocalDisk) == Type_root_from &&
                item.To.node.GetRoot.Info.Name == item.From.node.GetRoot.Info.Name)
            {
                LocalDisk.AutoCreateFolder(this.item.To.node.Parent);
                File.Move(item.From.node.GetFullPathString(), item.To.node.GetFullPathString());
                item.status = StatusTransfer.Moved;
                Dispose();
            }
            else
            {
                if (item.buffer == null)
                {
                    item.buffer = new byte[128 * 1024];
                }
                if (clientTo != null)
                {
                    this.clientTo = clientTo;
                }
                if (item.To.node.GetRoot.NodeType.Type == CloudType.Mega)
                {
                    InitUploadMega();                                                      //InitUploadMega
                }
                //Make Stream From
                item.From.stream = AppSetting.ManageCloud.GetFileStream(item.From.node, item.SaveSizeTransferSuccess,
                                                                        item.From.node.Info.Size - 1, item.To.node.GetRoot.NodeType.Type != CloudType.LocalDisk, item.dataCryptoMega);
                //Make Stream To
                if (item.ChunkUploadSize > 0)
                {
                    MakeNextChunkUploadInStreamTo(true);                          //upload to cloud
                }
                else
                {
                    this.item.To.stream = AppSetting.ManageCloud.GetFileStream(item.To.node, item.SizeWasTransfer); //download to disk
                }
                item.status = StatusTransfer.Running;
                item.From.stream.BeginRead(item.buffer, 0, item.buffer.Length, new AsyncCallback(GetFrom), 0);
            }
        }
Esempio n. 4
0
        public void FileSystem_Should_Create_LocalDisk()
        {
            //arrange
            var files       = new List <File>();
            var directories = new List <Directory>();
            var name        = string.Empty;

            //act
            var disk = new LocalDisk(name, files, directories);

            //assert
            disk.Files.ShouldBeEquivalentTo(files);
            disk.Directories.ShouldBeEquivalentTo(directories);
            disk.Name.ShouldBeEquivalentTo(name);
        }
Esempio n. 5
0
        public void FileSystem_Should_Find_By_Name_DirectoryAndFile_Multiple()
        {
            //arrange
            var notePadFileName       = "notepad";
            var notePadFile           = new File(notePadFileName, ".exe", 241);
            var windowsSubDirectories = new List <Directory>()
            {
                new Directory("addins", new List <File>(), new List <Directory>())
            };
            var diskCDirectories = new List <Directory>()
            {
                new Directory("Intel", new List <File>(), new List <Directory>()),
                new Directory("notepad", new List <File>()
                {
                    notePadFile
                }, windowsSubDirectories)
            };
            var diskC = new LocalDisk("C", new List <File>(), diskCDirectories);

            var googleDriveFiles = new List <File>()
            {
                new File("CV, Sergiy Lichenko", "docx", 21200),
                new File("CV, Sergiy Lichenko", "pdf", 184000),
                new File("VladimirDorokhov_CV.doc", "doc", 18000)
            };
            var diskDDirectories = new List <Directory>()
            {
                new Directory("GoogleDrive", googleDriveFiles, new List <Directory>())
            };
            var diskD      = new LocalDisk("D", new List <File>(), diskDDirectories);
            var fileSystem = new FileSystem(new List <LocalDisk>()
            {
                diskC, diskD
            });

            //act
            var result = fileSystem.FindByName("notepad").ToList();

            //assert
            result.Count.ShouldBeEquivalentTo(2);
            result[0].ShouldBeEquivalentTo(diskCDirectories[1]);
            result[1].ShouldBeEquivalentTo(notePadFile);
        }
Esempio n. 6
0
 public override Vector2 GetRandomLocalPoint()
 {
     return(LocalDisk.GetRandomPoint());
 }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            Stopwatch stopwatch = new Stopwatch();

            DateTime startDate;
            var      endDate = DateTime.Today.GetBusinessDay(-1);

            var options = new CommandLineOptions();

            if (!Parser.Default.ParseArguments(args, options))
            {
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            DateTime.TryParse(String.Join(".", options.startDate), out startDate);

            var logging = new Logging(options.LogFile);

            Trace.WriteLine(options.ToString());

            var config = new ConfigBase();

            config.Load(options.Settings);

            if (!options.NoDownload)
            {
                IDataSource dataSource = new Bloomberg();
                dataSource.Connect();

                HashSet <string> shareNames = new HashSet <string>();

                // get specifications
                var sheet = new Sheet();
                sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("shareNames") });
                var shareIDs = sheet.toShares();
                shareNames.UnionWith(
                    dataSource.GetFields(shareIDs.ToList(), "ID_BB_GLOBAL")
                    );

                sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("indices") });
                var indexNames = sheet.toShares();

                sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("fields") });
                var fields = new List <Field>();
                sheet.toFields <Field>(fields);

                //download index compositions
                if (indexNames != null && indexNames.Count() > 0)
                {
                    //obtain components of indices
                    var names = dataSource.DownloadMultipleComponents(indexNames.ToList(), "INDX_MEMBERS");

                    //convert tickers -> BB IDs
                    shareNames.UnionWith(dataSource.GetFields(names, "ID_BB_GLOBAL"));
                }

                LocalDisk disk = new LocalDisk();
                disk.SetPath(options.Dir);

                //delete data for shares-reload and shares-delete
                {
                    sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("shares-reload") });
                    var sharesReload = dataSource.GetFields(sheet.toShares().ToList(), "ID_BB_GLOBAL");

                    sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("shares-delete") });
                    var sharesDelete = dataSource.GetFields(sheet.toShares().ToList(), "ID_BB_GLOBAL");

                    foreach (var item in sharesDelete.Concat(sharesReload))
                    {
                        disk.DeleteDirectory(item.StripOfIllegalCharacters());
                    }

                    //delete shares-delete names from list of downloadable shares
                    foreach (var item in sharesDelete)
                    {
                        if (shareNames.Contains(item))
                        {
                            shareNames.Remove(item);
                        }
                    }
                }

                shareNames = new HashSet <string>(shareNames.Where(item => item.Contains("BBG") & !item.Contains(" ")));

                //roundtrip to tickers and back to bb_ids - as some bb_ids represent the same share
                var ticker      = dataSource.GetFields(shareNames.ToList(), "EQY_FUND_TICKER");
                var asset_class = dataSource.GetFields(shareNames.ToList(), "BPIPE_REFERENCE_SECURITY_CL_RT");
                var tickers     = ticker.Zip(asset_class, (first, last) => first + " " + last);
                HashSet <string> unique_tickers = new HashSet <string>(tickers);
                shareNames = new HashSet <string>(dataSource.GetFields(unique_tickers.ToList(), "ID_BB_GLOBAL").ToList());

                //download and save data
                stopwatch.Start();
                {
                    var shares = new SharesBatch(shareNames.ToList(), fields, dataSource, disk, startDate, endDate);
                    shares.PerformOperations();

                    Trace.Write("Processing Individual: ");
                    foreach (var shareName in shareNames)
                    {
                        Share share = new Share(name: shareName, fields: fields, dataSource: dataSource, fileAccess: disk, startDate: startDate, endDate: endDate);
                        share.DoWork();
                    }
                }
                dataSource.Disconnect();

                //download fieldInfo
                {
                    if (shareNames.Count() > 0)
                    {
                        dataSource.Connect(dataType: "//blp/apiflds");
                        disk.SetPath(options.FieldInfoDir);
                        Share share = new Share(name: shareNames.First(), fields: fields, dataSource: dataSource, fileAccess: disk, startDate: startDate, endDate: endDate);
                        share.DoWorkFieldInfo();
                        dataSource.Disconnect();
                    }
                }
                stopwatch.Stop();
                Trace.WriteLine("Time spent downloading from BB: " + stopwatch.Elapsed.ToString());
            }


            //upload data via SQL connection
            if (!options.NoUpload)
            {
                stopwatch.Restart();
                {
                    LocalDisk disk = new LocalDisk();
                    disk.SetPath(options.Dir);

                    var database = new MySQL(config.GetValue("sqlIP"), config.GetValue("sqlUser"), config.GetValue("sqlPass"), config.GetValue("sqlDB"), disk);
                    database.DoWork();
                }

                {
                    LocalDisk disk = new LocalDisk();
                    disk.SetPath(options.FieldInfoDir);

                    var database = new MySQL(config.GetValue("sqlIP"), config.GetValue("sqlUser"), config.GetValue("sqlPass"), config.GetValue("sqlDB"), disk);
                    database.DoWorkFieldInfo();
                }
                stopwatch.Stop();
                Trace.WriteLine("Time spent uploading: " + stopwatch.Elapsed.ToString());
                logging.Close();
            }
        }