public ECUConnection(string fileName, string friendlyName)
        {
            DriverPath      = fileName;
            InternalTimeout = 2000;

            if (!IsSimulation())
            {
                // apparently AVDI embeds their hardware identifier in the device's name and path, which might be regarded as sensitive when sharing
                // this redacts it (somewhat) to help save some time for testers
                if (DriverIsAVDI())
                {
                    FriendlyName = "AVDI-PT";
                    Console.WriteLine($"Initializing new connection to {friendlyName}");
                }
                else
                {
                    FriendlyName = friendlyName;
                    Console.WriteLine($"Initializing new connection to {friendlyName} using {fileName}");
                }
                ConnectionAPI = APIFactory.GetAPI(fileName);
            }
            else
            {
                FriendlyName  = "Simulation";
                ConnectionAPI = null;
            }

            SetConnectionDefaults();
            State = ConnectionState.PendingDeviceSelection;
            ConnectionUpdateState();
            TesterPresentTimer.Elapsed += TesterPresentTimer_Elapsed;
            TesterPresentTimer.Start();
        }
        private void DoUpdatePrices(object state)
        {
            long lPeriod = 60000;

            try
            {
                if (FCurrencyWatchInventory.Any() || FTokenWatchInventory.Any())
                {
                    var lUpdated         = new ConcurrentBag <string>();
                    var lPriceSourceAPIs = APIFactory.GetPriceAPIs();
                    foreach (var lPriceSource in lPriceSourceAPIs)
                    {
                        var lCurrencyPriceTask = lPriceSource.Item2.GetPrices(FCurrencyWatchInventory.Values.Select(lCurrency => lCurrency.Ticker));
                        var lTokenPriceTask    = lPriceSource.Item2.GetTokenPrices(FTokenWatchInventory.Keys);
                        var lOperationTasks    = new Task[]
                        {
                            lCurrencyPriceTask.ContinueWith((lTask) => ProcessNewPrices(lTask, FCurrencyPrices, lUpdated)),
                            lTokenPriceTask.ContinueWith((lTask) => ProcessNewPrices(lTask, FTokenPrices, lUpdated))
                        };
                        Task.WaitAll(lOperationTasks, FCancelTokenSource.Token);
                    }
                    OnPricesUpdated?.BeginInvoke(this, null, null);
                }
            }
            catch (Exception ex)
            {
                Log.Write(LogLevel.Error, $"DoUpdatePrices: Exception thrown: {ex}");
                lPeriod = 15000;
            }
            finally
            {
                FCoreUpdaterTimer.Change(lPeriod, Timeout.Infinite);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        private static void Main(string[] args)
        {
            var    t = new Test();
            Action a = t.Bar();

            a();

            TimeSpan warmup = Measure(() => ClassicObjectModel(new TfsTeamProjectCollection(new Uri("*****"))));  // TODO Put in appropriate value, then refactor

            TimeSpan classic = Measure(() => ClassicObjectModel(new TfsTeamProjectCollection(new Uri("*****")))); // TODO Put in appropriate value, then refactor

            Console.WriteLine("==========================");
            Console.WriteLine("======   WRAPPED  ========");
            Console.WriteLine("==========================");
            TimeSpan wrapped = Measure(() => TfsVSOApi(APIFactory.Connect(new Uri("*****")))); // TODO Put in appropriate value, then refactor


            RestClientManager.BasicAuthorizationUsername = "******"; // TODO Put in appropriate value, then refactor
            RestClientManager.BasicAuthorizationPassword = "******"; // TODO Put in appropriate value, then refactor
            VSOClientManager.VsoCollection = "*****";               // TODO Put in appropriate value, then refactor
            Console.WriteLine("==========================");
            Console.WriteLine("=======   REST  ==========");
            Console.WriteLine("==========================");
            TimeSpan rest = Measure(() => TfsVSOApi(new TfsTeamProjectCollectionImpl(new Uri("*****")))); // TODO Put in appropriate value, then refactor


            //    Console.WriteLine("Warm-Up={0}Sec       Classic={1}Sec    ", warmup.TotalSeconds, classic.TotalSeconds);
            // Console.WriteLine(" Wrapped={0}Sec      ReST={1}Sec", wrapped.TotalSeconds, rest.TotalSeconds);
            Console.WriteLine("Done!");
            Console.ReadLine();
        }
Beispiel #4
0
    public static void Main(string[] args)
    {
        APIFactory          factory;
        IConceptAPI         api;
        IConceptConcreteMix concreteMixToRemove;

        try
        {
            //Create the factory.
            factory = new APIFactory();

            //Cycle through the attached apis.
            Console.WriteLine("Attaching...");
            foreach (IConceptAPI attachedAPI in factory.conceptAPIs)
            {
                Console.WriteLine("File Path = " + attachedAPI.filePath);
            }

            //Create an API.
            Console.WriteLine("Creating...");
            api = factory.createConceptAPI();
            Console.WriteLine("File Path = " + api.filePath);

            //Print the concrete mixes.
            Console.WriteLine("Getting Concrete Mixes...");
            concreteMixToRemove = null;
            foreach (IConceptConcreteMix concreteMix in api.criteria.concreteMixes)
            {
                if (concreteMixToRemove == null)
                {
                    concreteMixToRemove = concreteMix;
                }
                Console.WriteLine("Concrete Mix: name = " + concreteMix.name + ", f'c = " + concreteMix.fprimec.ToString());
            }

            //Add a concrete mix, and print again.
            Console.WriteLine("Adding Concrete Mix...");
            api.criteria.concreteMixes.add("7000 psi", 7000);
            foreach (IConceptConcreteMix concreteMix in api.criteria.concreteMixes)
            {
                Console.WriteLine("Concrete Mix: name = " + concreteMix.name + ", f'c = " + concreteMix.fprimec.ToString());
            }

            //Remove a concrete mix and print again.
            Console.WriteLine("Removing Concrete Mix...");
            api.criteria.concreteMixes.remove(concreteMixToRemove.guid);
            foreach (IConceptConcreteMix concreteMix in api.criteria.concreteMixes)
            {
                Console.WriteLine("Concrete Mix: name = " + concreteMix.name + ", f'c = " + concreteMix.fprimec.ToString());
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("There was an error: " + e.Message);
        }

        //Don't close the application right away.
        Console.ReadLine();
    }
        /// <summary>
        /// Home page
        /// </summary>
        /// <returns></returns>
        public IActionResult ViewMovie(long movieId)
        {
            //fetch al movies and query single movie by ID
            var movie = new APIFactory().GetAllMovies(new AppKey().FetchAllMoviesUrl).Result.ToList()
                        .SingleOrDefault(n => n.id == movieId);

            return(View(movie));
        }
        public override void UpdateProviderFromPropertyValues()
        {
            selectedMarketQuoteItem = prop["QuoteItem"];
            ezInstrumentKey instrumentKey = APIFactory.InstrumentKeyFromString(prop["InstrumentKey"]);

            currentInstrument = APIMain.InstrumentFromKey(instrumentKey);
            //api.SubscribeToInstrument(instrument.Key);
            api.OnInsideMarketUpdate += api_OnInsideMarketUpdate;
            api_OnInsideMarketUpdate(currentInstrument);
        }
        /// <summary>
        /// Home page
        /// </summary>
        /// <returns></returns>
        public IActionResult Index(int page = 1)
        {
            //fetch all movies from json object
            var movies = new APIFactory().GetAllMovies(new AppKey().FetchAllMoviesUrl).Result.ToList();

            //paginate movies
            var model = PagingList.Create(movies, 10, page);

            return(View(model));
        }
        public static List <Tuple <string, string> > GetAvailableJ2534NamesAndDrivers()
        {
            List <Tuple <string, string> > result = new List <Tuple <string, string> >();

            foreach (APIInfo apiInfo in APIFactory.GetAPIList())
            {
                result.Add(new Tuple <string, string>(apiInfo.Name, apiInfo.Filename));
            }
#if DEBUG
            result.Add(new Tuple <string, string>("Simulation", "SIMULATION"));
#endif
            return(result);
        }
Beispiel #9
0
 public static void Connect()
 {
     try
     {
         A.Channel = APIFactory.GetAPI(A.DllFileName).GetDevice().GetChannel(Protocol.CAN, Baud.CAN, ConnectFlag.CAN_29BIT_ID);
         A.Channel.StartMsgFilter(new MessageFilter(UserFilterType.PASSALL, new byte[] { 0x00, 0x00, 0x07, 0xE8 }));
         A.Channel.DefaultTxTimeout = 350;
         A._isconnected             = true;
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception Error source: {0}", e.Source);
         Console.WriteLine("Press any key to exit.");
         Console.ReadKey();
         Environment.Exit(0); // Exit(0);
     }
 }
Beispiel #10
0
        private void j2534InterfacesToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            j2534InterfacesToolStripMenuItem.DropDownItems.Clear();
            ToolStripItem defaultItem = j2534InterfacesToolStripMenuItem.DropDownItems.Add("(No devices found)");

            defaultItem.Enabled = false;

            foreach (APIInfo apiInfo in APIFactory.GetAPIList())
            {
                defaultItem.Visible = false;
                // Console.WriteLine($"Found {apiInfo.Name} from {apiInfo.Filename}");
                ToolStripItem newItem = j2534InterfacesToolStripMenuItem.DropDownItems.Add(apiInfo.Name);
                newItem.Tag    = apiInfo.Filename;
                newItem.Click += J2534InterfaceItem_Click;
            }

            // Console.WriteLine("Completed enumeration of J2534 devices");
        }
Beispiel #11
0
        public IActionResult Index(int page = 1)
        {
            //get user ID from session
            var userId = Convert.ToInt64(HttpContext.Session.GetString("MovieDemoLoggedInUserId"));

            //get favorite data from DB
            var userFavMovies = _databaseConnection.UserFavouriteMovies.Where(n => n.AppUserId == userId);

            //get all movies
            var movies     = new APIFactory().GetAllMovies(new AppKey().FetchAllMoviesUrl).Result.ToList();
            var userMovies = from a in movies
                             join b in userFavMovies on a.id equals b.MovieId
                             where b.AppUserId == userId
                             select a;

            //paginate movies
            var model = PagingList.Create(userMovies, 10, page);

            return(View(model));
        }
Beispiel #12
0
        public override void UpdateProviderFromPropertyValues()
        {
            //selectedMarketData = prop["QuoteItem"];
            ezInstrumentKey instrumentKey = APIFactory.InstrumentKeyFromString(prop["InstrumentKey"]);

            // Get historical data for 1-hour "bars".
            EZInstrument   instrument = APIMain.InstrumentFromKey(instrumentKey);
            zChartInterval interval   = zChartInterval.Hour;
            int            period     = 1;

            // TODO analyze different time periods (ex: different hours of the trading session) to
            // get a better "AverageVolumePerTimePeriod" calculation.
            EZChartDataSeries historicalData = api.RequestHistoricalData(instrument, interval, period);

            if (historicalData == null)
            {
                averageVolumePerTimePeriod = prop["AverageVolumePerTimePeriod"] ?? 0;
                timePeriodLength           = prop["TimePeriodLengthMinutes"] ?? 0.0;
            }
            else
            {
                int totalVolume = 0;
                int volumeCount = 0;
                foreach (ezBarDataPoint dp in historicalData.TradeBars)
                {
                    totalVolume += dp.Volume;
                    ++volumeCount;
                }
                double averageVolumePerHour = (double)totalVolume / (double)volumeCount;

                timePeriodLength           = 5.0; // five minutes
                averageVolumePerTimePeriod = (int)Math.Round(averageVolumePerHour / 20.0);
            }

            currentInstrument = APIMain.InstrumentFromKey(instrumentKey);
            //api.SubscribeToInstrument(instrument.Key);
            api.OnInsideMarketUpdate += api_OnInsideMarketUpdate;
            api_OnInsideMarketUpdate(currentInstrument);
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("E38 unlocker ");
            Console.WriteLine("Enter key to start with. 0x0000 for full range ");
            keystring = Console.ReadLine();
            if (keystring == "")
            {
                keystring = "0000";
            }
            key = Convert.ToInt32(keystring, 16);
            if (key < 0x0000 || key > 0xffff)
            {
                Console.WriteLine("please enter a key between 0x0000 and 0xffff");
                Main(args);
            }
            Console.WriteLine($"Starting brute force with {key:X4}");  //Console.WriteLine($"{i:X4}");
            Channel Channel = APIFactory.GetAPI(DllFileName).GetDevice().GetChannel(Protocol.ISO15765, Baud.ISO15765, ConnectFlag.CAN_29BIT_ID);

            Channel.StartMsgFilter(new MessageFilter(UserFilterType.STANDARDISO15765, new byte[] { 0x00, 0x00, 0x07, 0xE0 }));
            System.Threading.Thread.Sleep(50);
            Channel.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xE0, 0x09, 0x02 });
            GetMessageResults Response = Channel.GetMessages(3, 500);

            Vin = HexStringToString(BitConverter.ToString(Response.Messages[2].Data).Replace("-", "").Substring(14, 34));
            Console.WriteLine($"Vin is {Vin}");
            if (Vin.Length != 17)
            {
                Console.WriteLine("Vin is not correct, problem.. exiting");
                Main(args);
            }
            Console.WriteLine("please make note of last key tried if you need to stop, then start with last key tried to continue");
            for (int trykey = key; trykey < 0x10000; trykey++)
            {
                Channel.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xE0, 0x27, 0x01 });
                GetMessageResults Seedrequest = Channel.GetMessages(2);
                message = (BitConverter.ToString(Seedrequest.Messages[1].Data).Replace("-", ""));
                Console.WriteLine($"Response from Seed request is {message}");
                if (message.Contains("6701"))
                {
                    Console.WriteLine("Seed request response OK");   // key = 0x1234

                    keystring = trykey.ToString("X4");
                    byte key1 = Convert.ToByte(keystring.Substring(0, 2), 16);
                    byte key2 = Convert.ToByte(keystring.Substring(2, 2), 16);

                    Channel.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xE0, 0x27, 0x02, key1, key2 });
                    GetMessageResults Unlocked = Channel.GetMessages(2);
                    message = (BitConverter.ToString(Unlocked.Messages[1].Data).Replace("-", ""));
                    if (!message.Contains("670"))
                    {
                        Console.WriteLine($"Error!! Unlock failed using {key1:X2} {key2:X2} for key, Response was {message}");
                        System.Threading.Thread.Sleep(9980);
                    }
                    else
                    {
                        Console.WriteLine("!!!!! Unlocked- OK");
                        Console.WriteLine($"Key used to unlock was  0x{trykey:X4}");
                        File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\" + "key.txt", $"Key used to unlock was  0x{trykey:X4}");
                        Console.WriteLine("Press any key to close, make sure you note the key used!!! ");
                        Console.WriteLine("Key is also saved as key.txt");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                }

                else
                {
                    Console.WriteLine($"Error!! Response from Seed request is {message}");
                    System.Threading.Thread.Sleep(9980);
                    trykey--; // try the same key again
                              // do we quit or keep on going??
                }
            }

            APIFactory.StaticDispose();
            // Channel.ClearMsgFilters();

            Console.WriteLine("Press any key to end ");
            Console.ReadKey();
        }
Beispiel #14
0
        static void Logdata()
        {
            Connect();
            //  System.Threading.Thread.Sleep(40);
            //// now its connected.. now what?? Can I read messages and wait to see a certain message? then read and log all messages?
            var filePath = string.Empty;

            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.InitialDirectory = "c:\\";
                saveFileDialog.Filter           = "txt files (*.txt)|*.txt";
                saveFileDialog.FilterIndex      = 2;
                saveFileDialog.RestoreDirectory = true;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath = saveFileDialog.FileName;
                    File.Delete(filePath);
                    using (StreamWriter w = File.AppendText(filePath))
                    {
                        int l = 0;
                        Console.WriteLine("Press any key to stop logging");
                        Console.WriteLine("starting log in 2 seconds");
                        System.Threading.Thread.Sleep(1000);
                        Console.WriteLine("starting log in 1 second");
                        System.Threading.Thread.Sleep(1000);
                        Console.WriteLine("Starting log");

                        while (Console.KeyAvailable == false)
                        {
                            GetMessageResults Logdata = A.Channel.GetMessage();
                            if (Logdata.Result == 0)
                            {
                                String line = BitConverter.ToString(Logdata.Messages[0].Data).Replace("-", "").Remove(0, 5);
                                switch (filter)
                                {
                                case 0:

                                {
                                    w.WriteLine(line);
                                    if (Debug)
                                    {
                                        Console.WriteLine(line);
                                    }
                                    Console.WriteLine(l);
                                    break;
                                }

                                case 1:
                                {
                                    if (line.StartsWith("7E0") || line.StartsWith("7E8") || line.StartsWith("7DF") || line.StartsWith("101"))
                                    {
                                        w.WriteLine(line);
                                        if (Debug)
                                        {
                                            Console.WriteLine(line);
                                        }
                                        Console.WriteLine(l);
                                    }
                                    break;
                                }

                                case 2:
                                {
                                    if (line.StartsWith("7E2") || line.StartsWith("7EA") || line.StartsWith("7DF") || line.StartsWith("101"))
                                    {
                                        w.WriteLine(line);
                                        if (Debug)
                                        {
                                            Console.WriteLine(line);
                                        }
                                        Console.WriteLine(l);
                                    }
                                    break;
                                }

                                case 3:
                                {
                                    if (line.StartsWith("7E0") || line.StartsWith("7E8") || line.StartsWith("7E2") || line.StartsWith("7EA") || line.StartsWith("7DF") || line.StartsWith("101"))
                                    {
                                        w.WriteLine(line);
                                        if (Debug)
                                        {
                                            Console.WriteLine(line);
                                        }
                                        Console.WriteLine(l);
                                    }
                                    break;
                                }

                                case 4:
                                {
                                    if (line.StartsWith("7DF") || line.StartsWith("101") || line.StartsWith("7EB") || line.StartsWith("641"))
                                    {
                                        w.WriteLine(line);
                                        if (Debug)
                                        {
                                            Console.WriteLine(line);
                                        }
                                        Console.WriteLine(l);
                                    }
                                    break;
                                }
                                }

                                l++;
                            }
                        }
                        Console.WriteLine("finished, your file was saved to " + filePath);
                        Console.WriteLine("Press any key to exit program, please note your log file location");

                        w.Close();
                        Console.ReadKey();        // delay

                        APIFactory.StaticDispose();
                    }
                }
            }
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            //以下是调用的例子,请你自己替换为相关的对象,谢谢

            //获取数据库实例,超级简单工厂
            DBInstance   dbmgr = DBFactory.GetInstance();
            List <Param> list  = new List <Param>();


            //获取远程API实例
            APIInstance api = APIFactory.GetInstance();

            //api.SetToken("TOKEN","id");   //设置token,防止私密信息暴露
            //api.SetLang("LANG");   //设置多语言ID

            #region 列表数据搜索


            list.Add(new Param("category_id", DbType.Int32, 1));
            //list.Add(new Param("lang_code_name", DbType.String, "简体%"));
            //DataTable dt=AppLink.api.BlogMgr.list(dbmgr, list);
            //Console.WriteLine("blog/list" );
            //printDataTable(dt);

            //同步返回列表数据
            //object blogjson = BlogMgr.list(api, list);
            //printJsonReturn("blog/list", null, blogjson);

            //异步返回列表数据
            //BlogMgr.list(api, list, printJsonReturn);


            #endregion


            #region 单条数据获取
            //Console.WriteLine("blog/get");
            //int blogid =Convert.ToInt32( dt.Rows[0]["id"]);
            //Dictionary<string, object> info = AppLink.api.BlogMgr.get(dbmgr, blogid);
            //printJson(info);
            #endregion


            #region 更新存在数据
            //list.Clear();
            //list.Add(new Param("category_id", 1));
            //list.Add(new Param("name", "test csharp in name"));
            //list.Add(new Param("summary", "test csharp in summary"));
            //list.Add(new Param("published_date", "2011-11-11"));
            //list.Add(new Param("content", "test csharp in content"));
            //list.Add(new Param("status", "A"));
            //list.Add(new Param("lang_code", "1"));
            //Console.WriteLine("blog/update");
            //AppLink.api.BlogMgr.update(dbmgr, list,blogid);
            #endregion

            #region 新增数据
            //list.Clear();
            //list.Add(new Param("category_id",1));
            //list.Add(new Param("name","test csharp in name +"));
            //list.Add(new Param("summary", "test csharp in summary +"));
            //list.Add(new Param("published_date", "2011-11-11"));
            //list.Add(new Param("content", "test csharp in content +"));
            //list.Add(new Param("status", "A"));
            //list.Add(new Param("lang_code", "1"));
            //Console.WriteLine("blog/update");
            //int newblogid = AppLink.api.BlogMgr.update(dbmgr, list);
            //Console.WriteLine("new id is "+ newblogid.ToString());
            #endregion


            Console.Read();
        }