IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers)
        {
            var commandLineArgs = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs);

            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(libraryPath);
            foreach (var input in objectFiles)
            {
                rule.AddPrerequisite(input, C.ObjectFile.Key);
            }

            var tool    = sender.Tool as Bam.Core.ICommandLineTool;
            var command = new System.Text.StringBuilder();

            command.AppendFormat("{0} {1} $^ {2}",
                                 CommandLineProcessor.Processor.StringifyTool(tool),
                                 commandLineArgs.ToString(' '),
                                 CommandLineProcessor.Processor.TerminatingArgs(tool));
            rule.AddShellCommand(command.ToString());

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());

            meta.CommonMetaData.Directories.AddUnique(libraryFileDir);
            meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables);
        }
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers)
        {
            var commandLineArgs = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs);

            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();
            rule.AddTarget(libraryPath);
            foreach (var input in objectFiles)
            {
                rule.AddPrerequisite(input, C.ObjectFile.Key);
            }

            var tool = sender.Tool as Bam.Core.ICommandLineTool;
            var command = new System.Text.StringBuilder();
            command.AppendFormat("{0} {1} $^ {2}",
                CommandLineProcessor.Processor.StringifyTool(tool),
                commandLineArgs.ToString(' '),
                CommandLineProcessor.Processor.TerminatingArgs(tool));
            rule.AddShellCommand(command.ToString());

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());
            meta.CommonMetaData.Directories.AddUnique(libraryFileDir);
            meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables);
        }
        /// <summary>
        /// Update and save new OHLC data if needed
        /// </summary>
        /// <param name="cpts"></param>
        private void UpdateAndSaving(CurrencyPairTimeSeries cpts)
        {
            bool doSave = true;

            if (OHLCData.ContainsKey(cpts.GetTimeSeriesKey()))
            {
                DateTime lastDate = StaticLibrary.UnixTimeStampToDateTime(OHLCData[cpts.GetTimeSeriesKey()].Last().Time);
                if (DateTime.UtcNow.Subtract(lastDate).TotalSeconds > 2 * cpts.Freq.GetFrequency(inSecs: true))
                {
                    if (UseInternet)
                    {
                        UpdateData(cpts);
                    }
                }
                else
                {
                    doSave = false;
                }
            }
            else
            {
                throw new NotImplementedException("You should have loaded the data before you got there (readed from csv or downloaded)");
            }
            if (doSave && SaveableFrequency(cpts.Freq))
            {
                SaveOHLC(cpts);
            }
        }
        /// <summary>
        /// Read already downloaded OHLC data
        /// </summary>
        /// <param name="curPair"></param>
        /// <param name="freq"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private GetOHLCResult ReadOHLC(CurrencyPair curPair, Frequency freq, string item = "Close")
        {
            string        pathLib = GetOHLCLibraryPath(curPair, freq);
            GetOHLCResult res     = new GetOHLCResult
            {
                Pairs = new Dictionary <string, List <OHLC> > {
                    { curPair.GetRequestID(), new List <OHLC> {
                      } }
                }
            };
            List <string[]> csv       = StaticLibrary.LoadCsvFile(pathLib);
            bool            isHeaders = true;

            string[] headers = null;
            foreach (string[] array in csv)
            {
                if (isHeaders)
                {
                    headers = array; isHeaders = false;
                }
                else
                {
                    OHLC ohlc = DataLibraryStaticLibrary.ReadOHLCItems(array, headers);
                    res.Pairs[curPair.GetRequestID()].Add(ohlc);
                }
            }
            return(res);
        }
        public List <Tuple <DateTime, double> > GetTimeSeries(ITimeSeriesKey itsk, bool isIndex, DateTime startDate)
        {
            List <Tuple <DateTime, double> > res = new List <Tuple <DateTime, double> >();
            double value;
            double lastItemValue = Double.NaN;
            double lastTSValue   = 10000;

            foreach (OHLC item in GetOHLCTimeSeries(itsk, StaticLibrary.DateTimeToUnixTimeStamp(startDate)))
            {
                DateTime itemTime = StaticLibrary.UnixTimeStampToDateTime(item.Time);
                itemTime = itsk.GetFrequency().Add(itemTime);
                if (itemTime > DateTime.UtcNow)
                {
                    itemTime = new DateTime(9999, 1, 1);
                }
                if (itemTime > startDate)
                {
                    if (!isIndex)
                    {
                        value = (double)item.Close;
                    }
                    else
                    {
                        value         = Double.IsNaN(lastItemValue) ? lastTSValue : lastTSValue * (double)item.Close / lastItemValue;
                        lastItemValue = (double)item.Close;
                        lastTSValue   = value;
                    }
                    res.Add(new Tuple <DateTime, double>(itemTime, value));
                }
            }
            return(res);
        }
Exemple #6
0
        // C/C++ with cl.exe (MSVC) & GoLink.exe
        private static IAttack CCxxClGoLinkExample()
        {
            var samplesOutput = new SamplesOutput();
            var attackName    = "CCxxClGoLink";
            var attack        = new Attack(new IOutput[] {
                samplesOutput,
            }, name: attackName);

            var cmdline             = "notepad";
            var createProcessSource = new CreateProcess(cmdline);
            // The CRT entry points (mainCRTStartup, wmainCRTStartup, WinMainCRTStartup, wWinMainCRTStartup, _DllMainCRTStartup) don't work GoLink
            // So, we must define our own entrypoint
            var entryPoint = ((ICFunction)createProcessSource).Name;

            // GoLink is incompatiable with Whole Program Optimization (cl.exe's /GL option)
            var compilerConfig             = new MyWarez.Plugins.Msvc.Compiler.Config(GL: false);
            var createProcessStaticLibrary = ((ICCxxCompiler <Win64ObjectFile>) new MyWarez.Plugins.Msvc.Compiler(compilerConfig)).Compile(createProcessSource);
            // MSVC's /GS option needs code from libcmt.lib
            // GoLink can't use static library files (.lib), so a workaround is to unpack the .lib into its individual object (.obj) files
            var libraryObjectFiles = new StaticLibrary <Win64ObjectFile>(new[] { MyWarez.Plugins.Msvc.StaticLibraries.libcmtWin64() }).ObjectFiles;
            //var libraryObjectFiles = new StaticLibrary<Win64ObjectFile>(new[] { MyWarez.Plugins.Msvc.StaticLibraries.libcmtWin64(), MyWarez.Plugins.Msvc.StaticLibraries.libucrtWin64(), MyWarez.Plugins.Msvc.StaticLibraries.libvcruntimeWin64() }).ObjectFiles;
            // libucrt.lib and libvcruntime.lib are other parts of the MSVC C Run-Time static libraries
            //      they are omitted here, omitting them saves time since extract object files from .lib files takes a while.

            // Use GoLink as the linker instead of MSVC's linker (link.exe)
            // We must specify an entrypoint with GoLink since the default entrypoint is always "START"
            //      Meanwhile MSVC would default to the appropriate CRT entrypoint
            var linkerConfig     = new MyWarez.Plugins.GoDevTool.Linker.Config(ENTRY: entryPoint);
            var createProcessExe = ((ILinker <Win64ObjectFile, Executable>) new MyWarez.Plugins.GoDevTool.Linker(linkerConfig, importStaticLibraryObjects: libraryObjectFiles)).Link(createProcessStaticLibrary);

            samplesOutput.Add("CCxxClGoLinkNotepad.exe", createProcessExe); // Double click to confirm that notepad spawns

            attack.Generate();
            return(attack);
        }
        public BlockchainProvider(string path, string credPath = "", IView view = null, bool useInternet = true)
        {
            if (view != null)
            {
                AddLoggingLink(view.PublishLogMessage);
            }
            BlockchainPath = path + "\\BlockchainData\\";
            if (!Directory.Exists(BlockchainPath))
            {
                Directory.CreateDirectory(BlockchainPath);
            }
            UseInternet = useInternet;
            foreach (Currency ccy in AvailableCryptoCurrencies)
            {
                FeesMemory[ccy] = new SortedDictionary <DateTime, Tuple <string, BitcoinValue> >();
            }
            string apiKey = null;

            if (credPath != "")
            {
                List <string[]> credFile = StaticLibrary.LoadCsvFile(credPath + "BlockchainKeys.txt");
                apiKey = credFile[0][0];
            }
            BlockChainApi = new BlockchainApiHelper(apiKey);
            ReadFeesMemory();
            foreach (Currency ccy in AvailableCryptoCurrencies)
            {
                UpdateMemory[ccy] = false;
            }
        }
        public void WriteFXHistory(CurrencyPairTimeSeries cpts)
        {
            string pathLib = GetFXLibraryPath(cpts);

            this.PublishInfo($"Saving FX: {cpts.CurPair.ToString()}");
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Time,Close");
            IEnumerable <DateTime> DateList = Data.GetAllDates();

            //DateList = cpts.Freq.GetSchedule(DateList.First(), DateList.Last(), true);
            foreach (DateTime date in DateList)
            {
                double close    = Data.GetQuote(date, cpts.CurPair).Item2.Rate;
                Int64  dateUnix = StaticLibrary.DateTimeToUnixTimeStamp(date);
                //if (StaticLibrary.UnixTimeStampToDateTime(dateUnix + FXMinimunFrequency.GetFrequency(true)) < DateTime.UtcNow)
                if (StaticLibrary.UnixTimeStampToDateTime(dateUnix) < DateTime.UtcNow)
                {
                    sb.AppendLine($"{dateUnix},{close}");
                }
                else
                {
                    this.PublishInfo($"Stopped at line: {StaticLibrary.UnixTimeStampToDateTime(dateUnix)}");
                }
            }
            File.WriteAllText(pathLib, sb.ToString());
        }
Exemple #9
0
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers)
        {
            var commandLine = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());

            if (!System.IO.Directory.Exists(libraryFileDir))
            {
                System.IO.Directory.CreateDirectory(libraryFileDir);
            }

            foreach (var input in objectFiles)
            {
                commandLine.Add(input.GeneratedPaths[C.ObjectFile.Key].ToString());
            }

            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
        /// <summary>
        /// Read locally downloaded Ledger
        /// </summary>
        /// <returns></returns>
        private GetLedgerResult ReadLedger()
        {
            string          pathLib = GetLedgerLibraryPath();
            GetLedgerResult res     = new GetLedgerResult
            {
                Ledger = new Dictionary <string, LedgerInfo>()
            };

            if (File.Exists(pathLib))
            {
                List <string[]> csv       = StaticLibrary.LoadCsvFile(pathLib);
                bool            isHeaders = true;
                string[]        headers   = null;
                foreach (string[] array in csv)
                {
                    if (isHeaders)
                    {
                        headers = array; isHeaders = false;
                    }
                    else
                    {
                        Tuple <string, LedgerInfo> li = DataLibraryStaticLibrary.ReadLedgerItems(array, headers);
                        res.Ledger.Add(li.Item1, li.Item2);
                    }
                }
            }
            return(res);
        }
 private void ReadFeesMemory()
 {
     foreach (Currency ccy in AvailableCryptoCurrencies)
     {
         string pth_ccy = GetPath(ccy);
         if (File.Exists(pth_ccy))
         {
             List <string[]> csv       = StaticLibrary.LoadCsvFile(pth_ccy);
             bool            isHeaders = true;
             string[]        headers   = null;
             foreach (string[] array in csv)
             {
                 if (isHeaders)
                 {
                     headers = array; isHeaders = false;
                 }
                 else
                 {
                     DateTime     t_line  = StaticLibrary.UnixTimeStampToDateTime(Convert.ToDouble(array[0]));
                     BitcoinValue bv_line = new BitcoinValue(Convert.ToDecimal(array[2]));
                     FeesMemory[ccy][t_line] = new Tuple <string, BitcoinValue>(array[1], bv_line);
                 }
             }
         }
     }
 }
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers)
        {
            if (sender.ReasonToExecute.Reason == Bam.Core.ExecuteReasoning.EReason.DeferredEvaluation)
            {
                if (!DeferredEvaluationRequiresBuild(sender, objectFiles))
                {
                    return;
                }
            }

            var commandLine = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(libraryFileDir);

            foreach (var input in objectFiles)
            {
                if (!(input as C.ObjectFileBase).PerformCompilation)
                {
                    continue;
                }
                commandLine.Add(input.GeneratedPaths[C.ObjectFile.Key].ToString());
            }

            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Exemple #13
0
    public void Send_Armies()                                                                           // Send armies button
    {
        GameObject button       = EventSystem.current.currentSelectedGameObject;                        // The button that was clicked
        CityStats  buttonParent = button.transform.parent.parent.gameObject.GetComponent <CityStats>(); // Gets the parent from the button that was clicked, aka a City

        if (buttonParent.armySize > 0)                                                                  // Makes a new army object
        {
            // Make a new army
            GameObject newArmy = Instantiate(army, buttonParent.transform.position, Quaternion.identity);
            StaticLibrary.DeselectAll();                                      // All others all deselected

            newArmy.transform.parent = GameObject.Find("_Dynamic").transform; // Becomes a dynamic object
            newArmy.GetComponent <ArmyStats>().armySize     = buttonParent.armySize;
            newArmy.GetComponent <ArmyStats>().isSelected   = true;           // The city spawned is selected
            newArmy.GetComponent <ArmyStats>().spawnNumber  = StaticLibrary.spawnArmyCounter;
            newArmy.GetComponent <ArmyStats>().playerNumber = buttonParent.playerNumber;

            buttonParent.armySize = 0; // The city where the army spawned from now has 0 armies

            StaticLibrary.spawnArmyCounter++;

            Transform[] parameters = new Transform[2] {
                newArmy.transform, buttonParent.transform
            };
            StopCoroutine("DeleteArmy");
            StartCoroutine("DeleteArmy", parameters);
        }
    }
Exemple #14
0
    // Update is called once per frame
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetMouseButtonDown(0))
        {
            mouseDownPoint = Input.mousePosition;
            userIsDragging = true;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.tag == "Town")
                {
                    if (hit.transform.GetComponent <CityStats>().isSelected)
                    {
                        hit.transform.GetComponent <CityStats>().isSelected = false;
                    }
                    else
                    {
                        StaticLibrary.DeselectAll();
                        hit.transform.GetComponent <CityStats>().isSelected = true;
                    }
                    hit.transform.Find("CityCanvas").gameObject.SetActive(true); // ACtivates the canvas of the city hit
                }
                else if (hit.collider.tag == "Army")
                {
                    if (hit.transform.GetComponent <ArmyStats>().isSelected)
                    {
                        hit.transform.GetComponent <ArmyStats>().isSelected = false;
                    }
                    else
                    {
                        hit.transform.GetComponent <ArmyStats>().isSelected = true;
                        StaticLibrary.DeselectTown();
                    }
                }
                else if (hit.collider.name == "Ground")
                {
                    StaticLibrary.DeselectAll();
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            mouseUpPoint = Input.mousePosition;

            foreach (GameObject army in GameObject.FindGameObjectsWithTag("Army"))
            {
                Vector3 armyPosition = Camera.main.WorldToScreenPoint(army.transform.position);
                if (armyPosition.x >= mouseDownPoint.x && armyPosition.x <= mouseUpPoint.x && armyPosition.y <= mouseDownPoint.y && armyPosition.y >= mouseUpPoint.y)
                {
                    army.GetComponent <ArmyStats>().isSelected = true;
                }
            }
            userIsDragging = false;
        }
    }
Exemple #15
0
        public void TestToTimeAgo_ExpectTimeAgo_WhenInvalidDate()
        {
            // Assemble
            DateTime firstDate       = new DateTime(2000, 01, 01, 0, 0, 0);
            string   exptectedResult = "didn't happen yet";

            // Act
            string actualResult = StaticLibrary.ToTimeAgo(firstDate, DateTime.MinValue);

            // Assert
            Assert.Equal(exptectedResult, actualResult);
        }
Exemple #16
0
        public void TestToTimeAgo_ExpectTimeAgo_WhenSameDate()
        {
            // Assemble
            DateTime date            = new DateTime(2000, 01, 01, 0, 0, 0);
            string   exptectedResult = "right now";

            // Act
            string actualResult = StaticLibrary.ToTimeAgo(date, date);

            // Assert
            Assert.Equal(exptectedResult, actualResult);
        }
Exemple #17
0
        public void TestToTimeAgo_ExpectTimeAgo_When999MilisecondsAgo()
        {
            // Assemble
            DateTime firstDate       = new DateTime(2000, 01, 01, 0, 0, 0, 0, DateTimeKind.Local);
            DateTime secondDate      = new DateTime(2000, 01, 01, 0, 0, 0, 999, DateTimeKind.Local);
            string   exptectedResult = "right now";

            // Act
            string actualResult = StaticLibrary.ToTimeAgo(firstDate, secondDate);

            // Assert
            Assert.Equal(exptectedResult, actualResult);
        }
Exemple #18
0
        public void TestToTimeAgo_ExpectTimeAgo_When15MinuteAgo()
        {
            // Assemble
            DateTime firstDate       = new DateTime(2000, 01, 01, 0, 0, 0);
            DateTime secondDate      = new DateTime(2000, 01, 01, 0, 15, 0);
            string   exptectedResult = "15 minutes ago";

            // Act
            string actualResult = StaticLibrary.ToTimeAgo(firstDate, secondDate);

            // Assert
            Assert.Equal(exptectedResult, actualResult);
        }
Exemple #19
0
        public void TestToTimeAgo_ExpectTimeAgo_When23HourAgo()
        {
            // Assemble
            DateTime firstDate       = new DateTime(2000, 01, 01, 0, 0, 0);
            DateTime secondDate      = new DateTime(2000, 01, 01, 23, 59, 59);
            string   exptectedResult = "23 hours ago";

            // Act
            string actualResult = StaticLibrary.ToTimeAgo(firstDate, secondDate);

            // Assert
            Assert.Equal(exptectedResult, actualResult);
        }
Exemple #20
0
    IEnumerator InstantiateArmy(CityStats buttonParent) // Instantiates an army
    {
        bool    playerClicked       = false;            // Only instantiate when a player clickes to move it immediately
        Vector3 playerClickedTarget = Vector3.zero;
        float   armysize            = buttonParent.armySize;

        buttonParent.armySize = 0; // The city where the army spawned from now has 0 armies
        buttonParent.Update_Citystats();

        while (!playerClicked) // Waits untill the player clicks before instantiating unit
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                if (Input.GetMouseButtonDown(1))
                {
                    playerClicked       = true;
                    playerClickedTarget = new Vector3(hit.point.x, 0f, hit.point.z);
                }
            }
            yield return(null);
        }
        // Make a new army
        GameObject newArmy = Instantiate(army, buttonParent.transform.position, Quaternion.identity);

        ArmyStats newArmyStats = newArmy.GetComponent <ArmyStats>();

        newArmyStats.justSpawned  = true;                                  // So that it doesnt collide with the town immediately, used in Collide armies to not collide with a town
        newArmy.transform.parent  = GameObject.Find("_Dynamic").transform; // Becomes a dynamic object
        newArmyStats.armySize     = armysize;
        newArmyStats.isSelected   = true;                                  // The army spawned is selected
        newArmyStats.spawnNumber  = StaticLibrary.spawnArmyCounter;
        newArmyStats.playerNumber = buttonParent.playerNumber;

        newArmy.GetComponent <MoveArmies>().target = playerClickedTarget;
        newArmy.GetComponent <MoveArmies>().StartRoutine();

        StaticLibrary.DeselectTown();
        StaticLibrary.spawnArmyCounter++;

        playerClicked = false;
        yield return(new WaitForSeconds(0.5f)); // So that it doesnt collide with the town immediately

        newArmyStats.justSpawned = false;
    }
 public KrakenProvider(string path, string credPath = "", string userName = "", string key = "", IView view = null, bool useInternet = true)
 {
     if (view != null)
     {
         AddLoggingLink(view.PublishLogMessage);
     }
     Path = path + "Kraken\\";
     if (userName == "" || key == "")
     {
         string          keyPath = credPath + "KrakenKeys.txt";
         List <string[]> creds   = StaticLibrary.LoadCsvFile(keyPath);
         userName = creds[0][0];
         key      = creds[1][0];
     }
     KrakenApi   = new Kraken(userName, key);
     UseInternet = useInternet;
     //LoadDepositAddresses(Currency.XBT);
 }
        DeferredEvaluationRequiresBuild(
            StaticLibrary sender,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles)
        {
            var libWriteTime = System.IO.File.GetLastWriteTime(sender.GeneratedPaths[C.StaticLibrary.Key].Parse());

            foreach (var input in objectFiles)
            {
                if ((input.ReasonToExecute != null) && (input.ReasonToExecute.Reason == Bam.Core.ExecuteReasoning.EReason.DeferredEvaluation))
                {
                    var objectFileWriteTime = System.IO.File.GetLastWriteTime((input as C.ObjectFileBase).InputPath.Parse());
                    if (objectFileWriteTime > libWriteTime)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        private VisitorViewModel GetVisitorViewModel()
        {
            var userAgent    = Request.Headers["User-Agent"].ToString();
            var ipAddress    = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            var browserName  = StaticLibrary.GetBrowserName(userAgent);
            var osName       = StaticLibrary.GetOperationalSystemName(userAgent);
            var headers      = Request.Headers.Select(x => x.Key + ":" + x.Value);
            var headerString = string.Join(Environment.NewLine, headers.Select(x => x.ToString()));

            var visitor = new VisitorViewModel()
            {
                Ip              = ipAddress,
                ClientHeaders   = headerString,
                ClientBrowser   = browserName,
                ClientOS        = osName,
                ClientUserAgent = userAgent,
            };

            return(visitor);
        }
 public FXDataProvider(string path, string credPath = "", string key = "", IView view = null, bool useInternet = true)
 {
     if (view != null)
     {
         AddLoggingLink(view.PublishLogMessage);
     }
     FXPath = path + "\\FXData";
     if (!Directory.Exists(FXPath))
     {
         Directory.CreateDirectory(FXPath);
     }
     if (key == "")
     {
         string          credFXPath = credPath + "FXKeys.txt";
         List <string[]> FXcreds    = StaticLibrary.LoadCsvFile(credFXPath);
         key = FXcreds[0][0];
     }
     APIKey      = key;
     UseInternet = useInternet;
 }
        /// <summary>
        /// Write additional OHLC information locally
        /// </summary>
        /// <param name="cpts"></param>
        private void SaveOHLC(CurrencyPairTimeSeries cpts)
        {
            string pathLib = GetOHLCLibraryPath(cpts.CurPair, cpts.Freq);

            this.PublishInfo($"Saving OHLC: {cpts.CurPair.ToString()} {cpts.Freq.ToString()}");
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Time,Open,High,Low,Close,Volume,Vwap,Count");
            foreach (OHLC item in OHLCData[cpts.GetTimeSeriesKey()])
            {
                //Console.WriteLine($"Saving data: {UnixTimeStampToDateTime(item.Time)}");
                if (StaticLibrary.UnixTimeStampToDateTime(item.Time + cpts.Freq.GetFrequency(true)) < DateTime.UtcNow)
                {
                    sb.AppendLine($"{item.Time},{item.Open},{item.High},{item.Low},{item.Close},{item.Volume},{item.Vwap},{item.Count}");
                }
                else
                {
                    this.PublishInfo($"Stopped at line: {StaticLibrary.UnixTimeStampToDateTime(item.Time)}");
                }
            }
            File.WriteAllText(pathLib, sb.ToString());
        }
Exemple #26
0
        public void OnPost()
        {
            // Gets local information from user
            string postComments = Request.Form["postComments"];
            string userAgent    = Request.Headers["User-Agent"].ToString();
            string ipAddress    = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            string browserName  = StaticLibrary.GetBrowserName(userAgent);
            string osName       = StaticLibrary.GetOperationalSystemName(userAgent);

            // TODO: fix this
            // Gets IP-based information
            //string host = _configuration["IpApiService:Host"];
            //string resource = _configuration["IpApiService:Resource"];


            //WebClient2 webClient = new WebClient2(host);
            //string jsonData = webClient.HttpGet(resource + ipAddress).Result;

            //JObject jObject = JObject.Parse(jsonData);

            //POSTS post = new POSTS();
            //post.USER_POST = postComments;
            //post.USER_NAME = User.Identity.Name;
            //post.USER_MEDIA = User.Identity.AuthenticationType;
            //post.USER_IP = ipAddress;
            //post.USER_OS = osName;
            //post.USER_BROWSER = browserName;
            //post.USER_COUNTRY = (string)jObject["countryCode"];
            //post.CREATED_ON_UTC = DateTime.UtcNow;

            //var connectionString = GlobalSettings.Instance.ConnectionString;
            //var options = new DbContextOptionsBuilder<DatabaseContext>().UseSqlServer(connectionString).Options;
            //DatabaseContext context = new DatabaseContext(options);
            //Repository<POSTS> repository = new Repository<POSTS>(context);

            //repository.Add(post);
            //repository.Save();
            //repository.Dispose();
        }
Exemple #27
0
        FileType GetFileType(string path)
        {
            if (PathUtils.IsSymlink(path))
            {
                return(FileType.Symlink);
            }

            if (Directory.Exists(path))
            {
                return(FileType.Directory);
            }

            if (path.EndsWith(".exe", StringComparison.Ordinal) || path.EndsWith(".dll", StringComparison.Ordinal))
            {
                return(FileType.PEAssembly);
            }

            if (MachO.IsMachOFile(path))
            {
                return(FileType.MachO);
            }

            if (StaticLibrary.IsStaticLibrary(path))
            {
                return(FileType.MachO);
            }

            if (ArchitectureSpecificFiles != null)
            {
                var filename = Path.GetFileName(path);
                if (ArchitectureSpecificFiles.Any(v => v.ItemSpec == filename))
                {
                    return(FileType.ArchitectureSpecific);
                }
            }

            return(FileType.Other);
        }
 public void WriteFeesMemory()
 {
     foreach (Currency ccy in AvailableCryptoCurrencies)
     {
         if (UpdateMemory[ccy])
         {
             if (!IsAcceptedCryptoCurrency(ccy))
             {
                 throw new Exception($"This data provider does not access the data from his Blockchain: {ccy.ToFullName()}");
             }
             this.PublishInfo($"Writing Fees History {ccy.ToFullName()}");
             StringBuilder sb = new StringBuilder();
             sb.AppendLine("Time,RefId,Fees");
             foreach (DateTime tx_date in FeesMemory[ccy].Keys)
             {
                 var item = FeesMemory[ccy][tx_date];
                 sb.AppendLine($"{StaticLibrary.DateTimeToUnixTimeStamp(tx_date)},{item.Item1},{item.Item2.GetBtc()}");
             }
             File.WriteAllText(GetPath(ccy), sb.ToString());
             UpdateMemory[ccy] = false;
         }
     }
 }
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers)
        {
            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());
            if (!System.IO.Directory.Exists(libraryFileDir))
            {
                System.IO.Directory.CreateDirectory(libraryFileDir);
            }

            foreach (var input in objectFiles)
            {
                commandLine.Add(input.GeneratedPaths[C.ObjectFile.Key].ToString());
            }

            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
        public BitcoinValue GetTransactionFees(Transaction tx, List <string> depositAddresses)
        {
            Currency ccy     = tx.Received.Ccy;
            DateTime?timeKey = GetTransactionInMemory(tx);

            if (timeKey.HasValue)
            {
                return(FeesMemory[ccy][timeKey.Value].Item2);
            }
            UpdateMemory[ccy] = true;
            decimal  res         = 0;
            long     tx_date_ref = StaticLibrary.DateTimeToUnixTimeStamp(tx.Date);
            DateTime?tx_date     = null;

            foreach (string address in depositAddresses)
            {
                List <ApiTx> tx_add = GetAddressTransactions(address);
                foreach (ApiTx item in tx_add)
                {
                    if (item.GetAmountFromAddress(address).GetBtc() == (decimal)tx.Received.Amount)
                    {
                        if (StaticLibrary.DateTimeDistTest(tx.Date, item.Time, 4))
                        {
                            res     = item.GetFees().GetBtc();
                            tx_date = item.Time;
                        }
                    }
                }
            }
            BitcoinValue bv = new BitcoinValue(res);

            if (tx_date.HasValue)
            {
                FeesMemory[ccy][tx_date.Value] = new Tuple <string, BitcoinValue>(tx.ID, bv);
            }
            return(bv);
        }
Exemple #31
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Bullet"))
        {
            health--;

            Destroy(collision.gameObject);

            if (health == 0)
            {
                AudioManager.Play(DeadAudio);
                Director.AddToScore(ScoreValue);

                Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);

                if (StaticLibrary.RandomBool(PickupChance))
                {
                    PickupManager.PlaceRandomPickup(transform.position);
                }
                else
                {
                    Vector3    position = GameObject.Find("Camera").GetComponent <Camera>().WorldToScreenPoint(transform.position);
                    GameObject points   = Instantiate(TextPrefab, position, Quaternion.identity, GameObject.Find("Canvas").transform);
                    points.GetComponent <Text>().text = "" + ScoreValue;

                    Destroy(points, 2f);
                }

                Destroy(gameObject);
            }
            else
            {
                AudioManager.Play(HitAudio);
                UpdateColour();
            }
        }
    }
        private bool ReadFXHistory(CurrencyPairTimeSeries cpts)
        {
            string pathLib = GetFXLibraryPath(cpts);

            if (!File.Exists(pathLib))
            {
                cpts    = cpts.GetCloneWithInverseCcyPair();
                pathLib = GetFXLibraryPath(cpts);
            }
            if (!File.Exists(pathLib))
            {
                return(false);
            }
            if (ReadFiles.Contains(cpts.GetFullName()))
            {
                return(true);
            }
            ReadFiles.Add(cpts.GetFullName());
            List <string[]> csv       = StaticLibrary.LoadCsvFile(pathLib);
            bool            isHeaders = true;

            string[] headers = null;
            foreach (string[] array in csv)
            {
                if (isHeaders)
                {
                    headers = array; isHeaders = false;
                }
                else
                {
                    OHLC ohlc = DataLibraryStaticLibrary.ReadOHLCItems(array, headers);
                    Data.AddQuote(StaticLibrary.UnixTimeStampToDateTime(ohlc.Time), new XChangeRate((double)ohlc.Close, cpts.CurPair));
                }
            }
            return(false);
        }
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers)
        {
            if (0 == objectFiles.Count)
            {
                return;
            }

            var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution;
            var project = solution.EnsureProjectExists(sender);
            var config = project.GetConfiguration(sender);

            config.SetType(VSSolutionBuilder.VSProjectConfiguration.EType.StaticLibrary);
            config.SetOutputPath(libraryPath);
            config.EnableIntermediatePath();

            foreach (var header in headers)
            {
                config.AddHeaderFile(header as HeaderFile);
            }

            var compilerGroup = config.GetSettingsGroup(VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.Compiler);
            if (objectFiles.Count > 1)
            {
                var vsConvertParameterTypes = new Bam.Core.TypeArray
                {
                    typeof(Bam.Core.Module),
                    typeof(VSSolutionBuilder.VSSettingsGroup),
                    typeof(string)
                };

                var sharedSettings = C.SettingsBase.SharedSettings(
                    objectFiles,
                    typeof(VisualCCommon.VSSolutionImplementation),
                    typeof(VisualStudioProcessor.IConvertToProject),
                    vsConvertParameterTypes);
                (sharedSettings as VisualStudioProcessor.IConvertToProject).Convert(sender, compilerGroup);

                foreach (var objFile in objectFiles)
                {
                    var deltaSettings = (objFile.Settings as C.SettingsBase).CreateDeltaSettings(sharedSettings, objFile);
                    config.AddSourceFile(objFile, deltaSettings);
                }
            }
            else
            {
                (objectFiles[0].Settings as VisualStudioProcessor.IConvertToProject).Convert(sender, compilerGroup);
                foreach (var objFile in objectFiles)
                {
                    config.AddSourceFile(objFile, null);
                }
            }

            var vsSettingsGroup = config.GetSettingsGroup(VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.Librarian);
            (sender.Settings as VisualStudioProcessor.IConvertToProject).Convert(sender, vsSettingsGroup);

            // order only dependencies
            foreach (var required in sender.Requirements)
            {
                if (null == required.MetaData)
                {
                    continue;
                }

                var requiredProject = required.MetaData as VSSolutionBuilder.VSProject;
                if (null != requiredProject)
                {
                    project.RequiresProject(requiredProject);
                }
            }
        }
Exemple #34
0
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers)
        {
            if (0 == objectFiles.Count)
            {
                return;
            }

            var workspace = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta;
            var target = workspace.EnsureTargetExists(sender);
            target.EnsureOutputFileReferenceExists(
                sender.CreateTokenizedString("@filename($(0))", libraryPath),
                XcodeBuilder.FileReference.EFileType.Archive,
                XcodeBuilder.Target.EProductType.StaticLibrary);
            var configuration = target.GetConfiguration(sender);
            if (sender.Macros["OutputName"].Equals(sender.Macros["modulename"]))
            {
                configuration.SetProductName(Bam.Core.TokenizedString.CreateVerbatim("${TARGET_NAME}"));
            }
            else
            {
                configuration.SetProductName(sender.Macros["OutputName"]);
            }

            foreach (var header in headers)
            {
                target.EnsureHeaderFileExists((header as HeaderFile).InputPath);
            }

            if (objectFiles.Count > 1)
            {
                var xcodeConvertParameterTypes = new Bam.Core.TypeArray
                {
                    typeof(Bam.Core.Module),
                    typeof(XcodeBuilder.Configuration)
                };

                var sharedSettings = C.SettingsBase.SharedSettings(
                    objectFiles,
                    typeof(ClangCommon.XcodeCompilerImplementation),
                    typeof(XcodeProjectProcessor.IConvertToProject),
                    xcodeConvertParameterTypes);
                (sharedSettings as XcodeProjectProcessor.IConvertToProject).Convert(sender, configuration);

                foreach (var objFile in objectFiles)
                {
                    var buildFile = objFile.MetaData as XcodeBuilder.BuildFile;
                    var deltaSettings = (objFile.Settings as C.SettingsBase).CreateDeltaSettings(sharedSettings, objFile);
                    if (null != deltaSettings)
                    {
                        var commandLine = new Bam.Core.StringArray();
                        (deltaSettings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);
                        if (commandLine.Count > 0)
                        {
                            // Cannot set per-file-per-configuration settings, so blend them together
                            if (null == buildFile.Settings)
                            {
                                buildFile.Settings = commandLine;
                            }
                            else
                            {
                                buildFile.Settings.AddRangeUnique(commandLine);
                            }
                        }
                    }
                    configuration.BuildFiles.Add(buildFile);
                }
            }
            else
            {
                (objectFiles[0].Settings as XcodeProjectProcessor.IConvertToProject).Convert(sender, configuration);
                foreach (var objFile in objectFiles)
                {
                    var buildFile = objFile.MetaData as XcodeBuilder.BuildFile;
                    configuration.BuildFiles.Add(buildFile);
                }
            }

            // convert librarian settings to the Xcode project
            if (sender.Settings is XcodeProjectProcessor.IConvertToProject)
            {
                (sender.Settings as XcodeProjectProcessor.IConvertToProject).Convert(sender, configuration);
            }

            // order only dependents
            foreach (var required in sender.Requirements)
            {
                if (null == required.MetaData)
                {
                    continue;
                }
                if (required is HeaderLibrary)
                {
                    // the target for a HeaderLibrary has no FileReference output, and thus cannot be an order only dependency
                    continue;
                }

                var requiredTarget = required.MetaData as XcodeBuilder.Target;
                if (null != requiredTarget)
                {
                    target.Requires(requiredTarget);
                }
            }
        }