private static WatchItemViewModel CreateModel(WatchItem watchItem)
        {
            var model   = new WatchItemViewModel();
            var contact = watchItem.Contacts.First();

            if (contact != null)
            {
                model.ContactId        = contact.ContactID;
                model.ContactFirstName = contact.FirstName;
                model.ContactLastName  = contact.Surname;
                model.ContactEmail     = contact.Email;
            }

            model.WatchItemId   = watchItem.WatchItemID;
            model.WatchItemName = watchItem.WatchItemName;
            model.URL           = watchItem.WebsiteUrl;
            model.ItemPath      = watchItem.ItemPath;
            return(model);
        }
示例#2
0
 public void Start(string name)
 {
     if (mStopWatch == null)
     {
         mFirstItem = new WatchItem(name, 0);
         mStopWatch = new Stopwatch();
         mStopWatch.Start();
         mCurrentItem           = mFirstItem;
         mCurrentItem.StartTime = mStopWatch.Elapsed.TotalMilliseconds;
     }
     else
     {
         WatchItem item = new WatchItem(name, 0);
         item.StartTime = mStopWatch.Elapsed.TotalMilliseconds;
         mCurrentItem.Childs.Add(item);
         item.Parent  = mCurrentItem;
         mCurrentItem = item;
     }
 }
        private List <WatchItem> MapWatchItemsOfTitles(List <string> distinctTitles, WatchGroup watchGroup, WatchItem[] watchGroupItems)
        {
            var watchItems = new List <WatchItem>();

            for (int i = 0; i < distinctTitles.Count; i++)
            {
                var watchItem = new WatchItem
                {
                    Title        = distinctTitles[i],
                    WatchGroupId = watchGroup.Id,
                };
                if (watchGroupItems.Contains(watchItem) == false)
                {
                    watchItems.Add(watchItem);
                }
            }

            return(watchItems);
        }
示例#4
0
        public async Task GetValue(WatchItem watchItem, CancellationToken cancellationToken)
        {
            SetupGetValueCommandParameters(watchItem.Name);
            await _debuggerSessionCommand.ExecuteNonQueryAsynchronous(cancellationToken);

            var result = (ValueInfoStatus)GetValueFromOracleDecimal(_debuggerSessionCommand.Parameters["RESULT"]);
            var value  = GetValueFromOracleString(_debuggerSessionCommand.Parameters["VALUE"]);

            TraceLog.WriteLine($"Get value '{watchItem.Name}' result: {result}; value={value}");

            if (result != ValueInfoStatus.ErrorIndexedTable)
            {
                watchItem.Value      = result == ValueInfoStatus.ErrorNullValue ? "NULL" : FormatIfCursorValue(value);
                watchItem.ChildItems = null;
                return;
            }

            var indexes = await GetCollectionIndexes(OracleObjectIdentifier.Create(_runtimeInfo.SourceLocation.Owner, _runtimeInfo.SourceLocation.Name), watchItem.Name, cancellationToken);

            watchItem.Value = $"collection ({indexes.Count} items)";

            var watchItems = new ObservableCollection <WatchItem>();

            foreach (var index in indexes)
            {
                var collectionItemExpression = $"{watchItem.Name}({index.Value})";
                SetupGetValueCommandParameters(collectionItemExpression);
                await _debuggerSessionCommand.ExecuteNonQueryAsynchronous(cancellationToken);

                var childItem =
                    new WatchItem
                {
                    Name  = collectionItemExpression,
                    Value = GetValueFromOracleString(_debuggerSessionCommand.Parameters["VALUE"])
                };

                watchItems.Add(childItem);
            }

            watchItem.ChildItems = watchItems;
        }
示例#5
0
        private async void Add_Clicked(object sender, EventArgs e)
        {
            PromptConfig config = new PromptConfig
            {
                Title       = "Add",
                Message     = "Add your watch item",
                Placeholder = "Watch Item",
                OkText      = "Save"
            };
            var dialog = await UserDialogs.Instance.PromptAsync(config);

            var       itemName = dialog.Value;
            WatchItem addItem  = new WatchItem
            {
                Id   = new Random().ToString(),
                Name = itemName
            };
            await viewModel.WatchItemStore.AddItemAsync(addItem);

            //TODO: add INotify
        }
        public IActionResult AddWatchItem(string itemNameInput, string urlInput, string itemPathInput, string contactFirstNameInput, string contactLastNameInput, string contactEmailInput)
        {
            Console.WriteLine($"Name: {itemNameInput}");
            var watchItem = new WatchItem
            {
                WatchItemName = itemNameInput,
                WebsiteUrl    = urlInput,
                ItemPath      = itemPathInput,
                Contacts      = new HashSet <Contact>()
            };

            var contact = new Contact
            {
                FirstName = contactFirstNameInput,
                Surname   = contactLastNameInput,
                Email     = contactEmailInput
            };

            _watchItemManager.AddWatchItem(watchItem, contact);
            return(RedirectToAction("Index"));
        }
示例#7
0
        public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous,
                                              "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            // Retrieve the model id from the query string
            string model = req.Query["model"];

            // If the user specified a model id, find the details of the model
            // of watch
            if (model != null)
            {
                WatchItem watchInfo =
                    _watchInfoProvider.ProvideWatchItem(model);

                return(new OkObjectResult(
                           $"Watch Details: {watchInfo.Manufacturer}, " +
                           $"{watchInfo.CaseType}, {watchInfo.Bezel}, " +
                           $"{watchInfo.Dial}, {watchInfo.CaseFinish}, " +
                           $"{watchInfo.Jewels}"));
            }
            return(new BadRequestObjectResult(
                       "Please provide a watch model in the query string"));
        }
示例#8
0
        private void DebuggerSessionAttachedHandler(object sender, EventArgs eventArgs)
        {
            try
            {
                var debuggerSession = (OracleDebuggerSession)sender;

                debuggerSession.ActiveLine.ShouldBe(1);

                const int breakPointLine = 6;
                var       breakpointTask = debuggerSession.SetBreakpoint(OracleObjectIdentifier.Empty, breakPointLine, CancellationToken.None);
                breakpointTask.Wait();
                breakpointTask.Result.IsSuccessful.ShouldBeTrue();
                var breakpointIdentifier = breakpointTask.Result.BreakpointIdentifier;

                debuggerSession.Continue(CancellationToken.None).Wait();

                debuggerSession.ActiveLine.ShouldBe(breakPointLine);

                var watchItemVar1 = new WatchItem {
                    Name = "var1"
                };
                debuggerSession.GetValue(watchItemVar1, CancellationToken.None).Wait();

                watchItemVar1.Value.ShouldBe("1");

                debuggerSession.StepInto(CancellationToken.None).Wait();

                debuggerSession.ActiveLine.ShouldBe(breakPointLine + 1);

                debuggerSession.GetValue(watchItemVar1, CancellationToken.None).Wait();

                watchItemVar1.Value.ShouldBe("2");

                watchItemVar1.Value = 999;
                debuggerSession.SetValue(watchItemVar1, CancellationToken.None).Wait();
                debuggerSession.GetValue(watchItemVar1, CancellationToken.None).Wait();
                watchItemVar1.Value.ShouldBe("999");

                var watchItemVar3 = new WatchItem {
                    Name = "var3"
                };
                debuggerSession.GetValue(watchItemVar3, CancellationToken.None).Wait();
                watchItemVar3.ChildItems.ShouldNotBeNull();
                watchItemVar3.ChildItems.Count.ShouldBe(2);

                /*watchItemVar3.ChildItems[0].Name.ShouldBe("var3(1)");
                 * watchItemVar3.ChildItems[0].Value.ShouldBe("value 1");
                 * watchItemVar3.ChildItems[1].Name.ShouldBe("var3(2)");
                 * watchItemVar3.ChildItems[1].Value.ShouldBe("value 2");*/

                breakpointTask = debuggerSession.DisableBreakpoint(breakpointIdentifier, CancellationToken.None);
                breakpointTask.Wait();
                breakpointTask.Result.IsSuccessful.ShouldBeTrue();

                breakpointTask = debuggerSession.DeleteBreakpoint(breakpointIdentifier, CancellationToken.None);
                breakpointTask.Wait();
                breakpointTask.Result.IsSuccessful.ShouldBeTrue();

                debuggerSession.Continue(CancellationToken.None).Wait();
            }
            finally
            {
                _resetEvent.Set();
            }
        }
 public void AddWatchItem(WatchItem watchItem)
 => _watchItemSession.SafeSaveAsync(watchItem).Wait();
示例#10
0
		private void DebuggerSessionAttachedHandler(object sender, EventArgs eventArgs)
		{
			try
			{
				var debuggerSession = (OracleDebuggerSession)sender;

				debuggerSession.ActiveLine.ShouldBe(1);

				const int breakPointLine = 6;
				var breakpointTask = debuggerSession.SetBreakpoint(OracleObjectIdentifier.Empty, breakPointLine, CancellationToken.None);
				breakpointTask.Wait();
				breakpointTask.Result.IsSuccessful.ShouldBe(true);
				var breakpointIdentifier = breakpointTask.Result.BreakpointIdentifier;

				debuggerSession.Continue(CancellationToken.None).Wait();

				debuggerSession.ActiveLine.ShouldBe(breakPointLine);

				var watchItemVar1 = new WatchItem { Name = "var1" };
				debuggerSession.GetValue(watchItemVar1, CancellationToken.None).Wait();

				watchItemVar1.Value.ShouldBe("1");

				debuggerSession.StepInto(CancellationToken.None).Wait();

				debuggerSession.ActiveLine.ShouldBe(breakPointLine + 1);

				debuggerSession.GetValue(watchItemVar1, CancellationToken.None).Wait();

				watchItemVar1.Value.ShouldBe("2");

				watchItemVar1.Value = 999;
				debuggerSession.SetValue(watchItemVar1, CancellationToken.None).Wait();
				debuggerSession.GetValue(watchItemVar1, CancellationToken.None).Wait();
				watchItemVar1.Value.ShouldBe("999");

				var watchItemVar3 = new WatchItem { Name = "var3" };
				debuggerSession.GetValue(watchItemVar3, CancellationToken.None).Wait();
				watchItemVar3.ChildItems.ShouldNotBe(null);
				watchItemVar3.ChildItems.Count.ShouldBe(2);
				/*watchItemVar3.ChildItems[0].Name.ShouldBe("var3(1)");
				watchItemVar3.ChildItems[0].Value.ShouldBe("value 1");
				watchItemVar3.ChildItems[1].Name.ShouldBe("var3(2)");
				watchItemVar3.ChildItems[1].Value.ShouldBe("value 2");*/

				breakpointTask = debuggerSession.DisableBreakpoint(breakpointIdentifier, CancellationToken.None);
				breakpointTask.Wait();
				breakpointTask.Result.IsSuccessful.ShouldBe(true);

				breakpointTask = debuggerSession.DeleteBreakpoint(breakpointIdentifier, CancellationToken.None);
				breakpointTask.Wait();
				breakpointTask.Result.IsSuccessful.ShouldBe(true);

				debuggerSession.Continue(CancellationToken.None).Wait();
			}
			finally
			{
				_resetEvent.Set();
			}
		}
示例#11
0
        public static DynValue getinfo(ScriptExecutionContext executionContext, CallbackArguments args)
        {
            Coroutine cor      = executionContext.GetCallingCoroutine();
            int       vfArgIdx = 0;

            if (args[0].Type == DataType.Thread)
            {
                cor = args[0].Coroutine;
                vfArgIdx++;
            }

            DynValue vf    = args[vfArgIdx + 0];
            DynValue vwhat = args[vfArgIdx + 1];

            if (vf.Type == DataType.Void || vf.Type == DataType.Nil)
            {
                vf = DynValue.NewNumber(1);
            }

            args.AsType(vfArgIdx + 1, "getinfo", DataType.String, true);

            string what = vwhat.CastToString() ?? "nfSlu";

            DynValue vt = DynValue.NewTable(executionContext.GetScript());

            if (vf.Type == DataType.Number)
            {
                WatchItem[] stacktrace = cor.GetStackTrace((int)vf.Number, executionContext.CallingLocation);
                if (stacktrace.Length == 0)
                {
                    return(DynValue.NewNil());
                }
                WatchItem wi = stacktrace[0];

                if (what.Contains("n"))
                {
                    vt.Table.Set("name", DynValue.NewString(wi.Name ?? ""));
                }
                if (what.Contains("f"))
                {
                    vt.Table.Set("func", wi.Value ?? DynValue.NewNil());
                }
                if (what.Contains("S"))
                {
                    string source = (wi.Value != null && wi.Value.Type == DataType.Function) ? executionContext.GetScript().GetSourceCode(executionContext.CallingLocation.SourceIdx).Name : "[C]";
                    vt.Table.Set("source", DynValue.NewString("=" + source));
                    vt.Table.Set("short_src", DynValue.NewString(source.Length >= 60 ? source.Substring(0, 60) : source));
                    vt.Table.Set("what", DynValue.NewString(wi.Name == null ? "main" : ((wi.Value != null && wi.Value.Type == DataType.Function) ? "Lua" : "C")));
                }
                if (what.Contains("l"))
                {
                    vt.Table.Set("currentline", DynValue.NewNumber(wi.Location != null ? wi.Location.FromLine : executionContext.CallingLocation.FromLine));
                }
                if (what.Contains("u"))
                {
                    vt.Table.Set("nups", DynValue.NewNumber((wi.Value != null && wi.Value.Type == DataType.Function) ? wi.Value.Function.GetUpvaluesCount() : 0));
                }
            }
            else
            {
                args.AsType(vfArgIdx + 0, "getinfo", DataType.Number, true);
            }

            return(vt);
        }
 public WatchItemAddMessage(int Transaction, WatchItem newWatchItem)
     : base(Endpoint.StandardV3)
 {
     this.Transaction  = Transaction;
     this.newWatchItem = newWatchItem;
 }
示例#13
0
		public async Task SetValue(WatchItem watchItem, CancellationToken cancellationToken)
		{
			_debuggerSessionCommand.CommandText = OracleDatabaseCommands.DebuggerSetValue;
			_debuggerSessionCommand.Parameters.Clear();
			_debuggerSessionCommand.AddSimpleParameter("RESULT", null, TerminalValues.Number);
			var statement = $"{watchItem.Name} := {watchItem.Value};";
			_debuggerSessionCommand.AddSimpleParameter("ASSIGNMENT_STATEMENT", statement, TerminalValues.Varchar2);

			await _debuggerSessionCommand.ExecuteNonQueryAsynchronous(cancellationToken);

			var result = (ValueInfoStatus)GetValueFromOracleDecimal(_debuggerSessionCommand.Parameters["RESULT"]);
			Trace.WriteLine($"Set value '{statement}' result: {result}");
		}
示例#14
0
        public Watch(DebugView view)
            : base(view)
        {
            _window = new Window(25, 25, 80, 25, "Watch");
            _window.Visible = false;
            View.Desktop.Add(_window);

            _watchView = new ListView<WatchItem>(1, 1, 76, 19);
            _watchView.Columns.Add(new ListView<WatchItem>.Column("Name", 14, w => w.Name));
            _watchView.Columns.Add(new ListView<WatchItem>.Column("Expression", 40, w => w.Expression, false));
            _watchView.Columns.Add(new ListView<WatchItem>.Column("Value", 20, null, false, w =>
            {
                if (Target == null)
                    return "No Target";

                if (w.Error != null)
                    return w.Error;

                try
                {
                    var value = w.Function(Target);
                    return string.Format("{0:X8} {0,11}", value);
                }
                catch (WatchException e)
                {
                    return e.Message;
                }
                catch
                {
                    return "Error";
                }
            }));

            _watchView.Clicked += (item, button) =>
            {
                if (button == Mouse.Button.Right)
                {
                    _watchView.Items.Remove(item);
                }
                else if (button == Mouse.Button.Middle)
                {
                    _editing = item;
                    _name.Value = _editing.Name;
                    _expression.Value = _editing.Expression;
                }
            };

            _window.Add(_watchView);

            _name = new TextBox(1, 21, 13);
            _window.Add(_name);

            _expression = new TextBox(15, 21, 50);
            _window.Add(_expression);

            _button = new Button(66, 21, 11, "Add");
            _button.Clicked += () =>
            {
                if (_expression.Value.Length == 0)
                    return;

                WatchItem item;

                if (_editing == null)
                {
                    item = new WatchItem();
                    _watchView.Items.Add(item);
                }
                else
                {
                    item = _editing;
                }

                item.Name = _name.Value;
                item.Expression = _expression.Value;

                try
                {
                    item.Function = WatchExpression.Compile(item.Expression);
                    item.Error = null;
                }
                catch (WatchException e)
                {
                    item.Error = e.Message;
                }

                _name.Value = "";
                _expression.Value = "";
                _editing = null;
            };
            _window.Add(_button);
        }
示例#15
0
 protected void OnWatchAdded(WatchItem item)
 {
     if (WatchAdded != null) WatchAdded(item);
 }
        /// <summary>
        /// Reset the watch / timeline
        /// </summary>
        /// <returns></returns>
        public async Task <bool> Wipe()
        {
            try
            {
                if (await _pc.IsBackgroundTaskRunning())
                {
                    _Log.Add("Stop current activities");

                    _pc.StopBackgroundTask(PebbleConnector.Initiator.Manual);

                    await _pc.WaitBackgroundTaskStopped(5);
                }

                await Connect();

                String Message;

                //Get current watch face ID
                //WatchFaceMessage _wfm = new WatchFaceMessage();
                Guid      CurrentWatchFace     = _pc.Pebble.CurrentWatchFace; //await _pc.Pebble.RequestWatchFaceMessageAsync(_wfm);
                WatchItem CurrentWatchFaceItem = _pc.WatchItems.Get(CurrentWatchFace);
                System.Diagnostics.Debug.WriteLine(String.Format("Current watch face: {0}", CurrentWatchFace));

                if (CurrentWatchFaceItem != null)
                {
                    _Log.Add(String.Format("Current watch face: {0}", CurrentWatchFaceItem.Name));
                }
                else
                {
                    _Log.Add(String.Format("Current watch face: {0}", CurrentWatchFace));
                }


                _pc.StartReceivingMessages();
                _pc.Pebble._protocol.MessageReceived += AppMessageReceived;

                //Set the watch face
                byte[] TicTocByte = new byte[16] {
                    0x8F, 0x3C, 0x86, 0x86, 0x31, 0xA1, 0x4F, 0x5F, 0x91, 0xF5, 0x01, 0x60, 0x0C, 0x9B, 0xDC, 0x59
                };
                Guid TicTocGuid = new Guid(TicTocByte);

                if (CurrentWatchFace != Guid.Empty && CurrentWatchFace != TicTocGuid)
                {
                    WatchFaceSelectMessage _wsm = new WatchFaceSelectMessage(CurrentWatchFace, TicTocGuid);
                    await _pc.Pebble.WriteMessageAsync(_wsm);

                    System.Diagnostics.Debug.WriteLine(String.Format("TicToc Watch fase set as current"));
                }

                StandardV3Message _SV3M;

                for (int i = 1; i <= 9; i++)
                {
                    _SV3M = new StandardV3Message(_pc.Pebble.GetNextMessageIdentifier(), (byte)i);
                    await _pc.Pebble._protocol.WriteMessage(_SV3M);
                    await WaitForMessage(_SV3M.Identifier);
                }


                /*Message = "00:04:b1:db:05:d0:11:01";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("d0:11");
                 *
                 * Message = "00:04:b1:db:05:65:54:02";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("65:54");
                 *
                 * Message = "00:04:b1:db:05:8c:b5:03";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:b5");
                 *
                 * Message = "00:04:b1:db:05:8c:b6:04";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:b6");
                 *
                 * Message = "00:04:b1:db:05:8c:b7:05";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:b7");
                 *
                 * Message = "00:04:b1:db:05:8c:b8:06";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:b8");
                 *
                 * Message = "00:04:b1:db:05:8c:b9:07";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:b9");
                 *
                 * Message = "00:04:b1:db:05:8c:ba:08";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:ba");
                 *
                 * Message = "00:04:b1:db:05:8c:b0:09";
                 * await _pc.WriteMessage(Message);
                 * await WaitForMessage("8c:b0");*/

                _Log.Add("Pebble Time wiped.");

                System.Diagnostics.Debug.WriteLine("Pebble Time wiped.");

                foreach (var item in _pc.Pebble.WatchItems)
                {
                    WatchItemAddMessage _waam = new WatchItemAddMessage(_pc.Pebble.GetNextMessageIdentifier(), item);
                    await _pc.Pebble._protocol.WriteMessage(_waam);
                    await WaitForMessage(_waam.Transaction);

                    switch (item.Type)
                    {
                    case WatchItemType.WatchFace:

                        _Log.Add(String.Format("Watch face {0} added.", item.Name));
                        System.Diagnostics.Debug.WriteLine(String.Format("Watch face {0} added.", item.Name));

                        break;

                    case WatchItemType.WatchApp:

                        _Log.Add(String.Format("Watch app {0} added.", item.Name));
                        System.Diagnostics.Debug.WriteLine(String.Format("Watch app {0} added.", item.Name));

                        break;
                    }
                }

                _Log.Add("Watch items restored");
                System.Diagnostics.Debug.WriteLine("Watch items restored");

                //Clear caches
                Weather.ClearCache();
                await Calender.ClearCache();

                _Log.Add("Cache cleared on phone");
                System.Diagnostics.Debug.WriteLine("Cache cleared on phone");

                //Update timeline
                await _TimeLineSynchronizer.Synchronize();

                //Set the watch face
                if (CurrentWatchFace != Guid.Empty && CurrentWatchFace != TicTocGuid)
                {
                    WatchFaceSelectMessage _wsm = new WatchFaceSelectMessage(TicTocGuid, CurrentWatchFace);
                    await _pc.Pebble.WriteMessageAsync(_wsm);

                    _Log.Add(String.Format("Selected watch face: {0}", CurrentWatchFace));
                    if (CurrentWatchFaceItem != null)
                    {
                        _Log.Add(String.Format("Current watch face: {0}", CurrentWatchFaceItem.Name));
                    }
                    else
                    {
                        _Log.Add(String.Format("Current watch face: {0}", CurrentWatchFace));
                    }

                    System.Diagnostics.Debug.WriteLine(String.Format("Selected watch face: {0}", CurrentWatchFace));

                    _pc.Pebble.ItemSend += Pebble_ItemSend;
                }
                else
                {
                    Disconnect();
                }

                return(true);
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(String.Format("Wipe exception: {0}", exp.Message));
                Disconnect();
            }

            return(false);
        }
示例#17
0
        public static AlgoTraderOverview buildOverviewObject()
        {
            AlgoTraderOverview result = new AlgoTraderOverview();


            /* ###################### SYMBOLS ###################### */

            AlgoTraderDataTable symbolsDataTable = new AlgoTraderDataTable();

            symbolsDataTable.Name = "overview-symbols";

            if (String.IsNullOrEmpty(SelectedSymbol))
            {
                symbolsDataTable.HideColumn = (!String.IsNullOrEmpty(SelectedStrategyId) ? 1 : -1);
                symbolsDataTable.Show       = true;
                symbolsDataTable.Title      = "Symbols (" + AlgoTraderShared.WatchList.Count.ToString() + ")";

                StringBuilder sb = new StringBuilder();

                // name, strategies, positions, orders, actions, realized, unrealized

                List <DataTableItem> dataTableItems = new List <DataTableItem>();
                for (int n = 0; n < AlgoTraderShared.WatchList.Count; n++)
                {
                    WatchItem wi = AlgoTraderShared.WatchList[n];

                    string symbol = wi.Symbol;

                    DataTableItem dataTableItem = new DataTableItem();

                    dataTableItem.ColumnValues.Add("symbol", wi.Symbol);
                    dataTableItem.ColumnValues.Add("strategies", wi.Strategies.Count);



                    //dataTableItem.Name = wi.Symbol;
                    //dataTableItem.SubItems = wi.Strategies.Count;

                    dataTableItem.ColumnValues.Add("orders", AlgoTraderShared.Orders.FindAll(o => o.Symbol == symbol).Count);
                    dataTableItem.ColumnValues.Add("actions", AlgoTraderShared.StrategyActions.FindAll(a => a.Symbol == symbol).Count);

                    List <Position> positions = AlgoTraderShared.Positions.FindAll(p => p.Symbol == symbol);

                    dataTableItem.ColumnValues.Add("positions", positions.Count);

                    // do realized
                    List <Position> closedPositions = positions.FindAll(p => p.Status == PositionStatus.Closed);
                    decimal         netRealized     = 0M;
                    for (int m = 0; m < closedPositions.Count; m++)
                    {
                        netRealized += closedPositions[m].SoldAt - closedPositions[m].BoughtAt;
                    }
                    dataTableItem.ColumnValues.Add("realized", netRealized);

                    // do unrealized
                    List <Position> openPositions  = positions.FindAll(p => p.Status == PositionStatus.Open);
                    decimal         latestAskPrice = -1M;
                    decimal         latestBidPrice = -1M;
                    if (openPositions.Count > 0)
                    {
                        List <Node> nodes = AlgoTraderShared.NodesData[symbol].Nodes;
                        latestAskPrice = nodes[nodes.Count - 1].AskPrice;
                        latestBidPrice = nodes[nodes.Count - 1].BidPrice;
                    }
                    decimal netUnrealized = 0M;


                    for (int m = 0; m < openPositions.Count; m++)
                    {
                        Position p         = openPositions[m];
                        decimal  sellPrice = 0M;
                        decimal  buyPrice  = 0M;

                        if (p.Side == PositionSide.Long)
                        {
                            // if long, find the sell price by getting the latest bid price
                            sellPrice = latestBidPrice;
                            buyPrice  = p.BoughtAt;
                        }
                        else if (p.Side == PositionSide.Short)
                        {
                            // if short, find the buy price by getting the latest ask price
                            buyPrice  = latestAskPrice;
                            sellPrice = p.SoldAt;
                        }
                        else
                        {
                            throw new Exception("a what?");
                        }
                        netUnrealized += sellPrice - buyPrice;
                    }
                    dataTableItem.ColumnValues.Add("unrealized", netUnrealized);

                    dataTableItems.Add(dataTableItem);
                }


                TrySortDataTable(ref dataTableItems, "overview-symbols", "symbol");

                // // name, strategies, positions, orders, actions, realized, unrealized
                // <tr><td></td><td class=\"sub-items-col\"></td><td></td><td></td><td></td><td></td><td></td></tr>
                for (int n = 0; n < dataTableItems.Count; n++)
                {
                    sb.Append("<tr>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["symbol"] + "</td>");
                    sb.Append("<td class=\"sub-items-col\">" + dataTableItems[n].ColumnValues["strategies"] + "</td>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["positions"] + "</td>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["orders"] + "</td>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["actions"] + "</td>");
                    sb.Append("<td data-sort-value=\"" + dataTableItems[n].ColumnValues["realized"] + "\">" + UC.DecimalToUSD((decimal)dataTableItems[n].ColumnValues["realized"], 4) + "</td>");
                    sb.Append("<td data-sort-value=\"" + dataTableItems[n].ColumnValues["unrealized"] + "\">" + UC.DecimalToUSD((decimal)dataTableItems[n].ColumnValues["unrealized"], 4) + "</td>");
                    sb.Append("</tr>");
                }

                symbolsDataTable.TBodyHtml = sb.ToString();
            }

            result.DataTables.Add(symbolsDataTable);

            /* ###################### STRATEGIES ###################### */

            AlgoTraderDataTable strategiesDataTable = new AlgoTraderDataTable();

            strategiesDataTable.Name = "overview-strategies";

            if (String.IsNullOrEmpty(SelectedStrategyId))
            {
                strategiesDataTable.HideColumn = (!String.IsNullOrEmpty(SelectedSymbol) ? 1 : -1);
                strategiesDataTable.Show       = true;

                string[] usableStrategiesKeys = Global.State.UsableStrategies.Keys.ToArray();

                strategiesDataTable.Title = "Strategies (" + usableStrategiesKeys.Length.ToString() + ")";

                StringBuilder sb = new StringBuilder();

                // name, strategies, positions, orders, actions, realized, unrealized

                List <DataTableItem> dataTableItems = new List <DataTableItem>();
                if (AlgoTraderShared.WatchList.Count > 0)
                {
                    for (int n = 0; n < usableStrategiesKeys.Length; n++)
                    {
                        string strategy = Global.State.UsableStrategies[usableStrategiesKeys[n]];

                        DataTableItem dataTableItem = new DataTableItem();

                        dataTableItem.ColumnValues.Add("strategy", strategy);

                        // probably super inefficient
                        dataTableItem.ColumnValues.Add("symbols", AlgoTraderShared.WatchList.Count(w => w.Strategies.Exists(s => s.GetType().Name == strategy)));



                        //dataTableItem.Name = wi.Symbol;
                        //dataTableItem.SubItems = wi.Strategies.Count;

                        dataTableItem.ColumnValues.Add("orders", AlgoTraderShared.Orders.FindAll(o => o.StrategyName == strategy && (String.IsNullOrEmpty(SelectedSymbol) || o.Symbol == SelectedSymbol)).Count);
                        dataTableItem.ColumnValues.Add("actions", AlgoTraderShared.StrategyActions.FindAll(a => a.StrategyName == strategy && (String.IsNullOrEmpty(SelectedSymbol) || a.Symbol == SelectedSymbol)).Count);

                        List <Position> positions = AlgoTraderShared.Positions.FindAll(p => p.StrategyName == strategy && (String.IsNullOrEmpty(SelectedSymbol) || p.Symbol == SelectedSymbol));

                        dataTableItem.ColumnValues.Add("positions", positions.Count);

                        // do realized
                        List <Position> closedPositions = positions.FindAll(p => p.Status == PositionStatus.Closed);
                        decimal         netRealized     = 0M;
                        for (int m = 0; m < closedPositions.Count; m++)
                        {
                            netRealized += closedPositions[m].SoldAt - closedPositions[m].BoughtAt;
                        }
                        dataTableItem.ColumnValues.Add("realized", netRealized);

                        // do unrealized
                        List <Position> openPositions = positions.FindAll(p => p.Status == PositionStatus.Open);

                        decimal netUnrealized = 0M;


                        for (int m = 0; m < openPositions.Count; m++)
                        {
                            Position p         = openPositions[m];
                            decimal  sellPrice = 0M;
                            decimal  buyPrice  = 0M;

                            List <Node> nodes = AlgoTraderShared.NodesData[p.Symbol].Nodes;

                            if (p.Side == PositionSide.Long)
                            {
                                // if long, find the sell price by getting the latest bid price
                                sellPrice = nodes[nodes.Count - 1].BidPrice;
                                buyPrice  = p.BoughtAt;
                            }
                            else if (p.Side == PositionSide.Short)
                            {
                                // if short, find the buy price by getting the latest ask price
                                buyPrice  = nodes[nodes.Count - 1].AskPrice;
                                sellPrice = p.SoldAt;
                            }
                            else
                            {
                                throw new Exception("a what?");
                            }
                            netUnrealized += sellPrice - buyPrice;
                        }
                        dataTableItem.ColumnValues.Add("unrealized", netUnrealized);

                        dataTableItems.Add(dataTableItem);
                    }
                }
                TrySortDataTable(ref dataTableItems, "overview-strategies", "strategy");

                for (int n = 0; n < dataTableItems.Count; n++)
                {
                    sb.Append("<tr>");
                    sb.Append("<td style=\"text-align:left;\">" + dataTableItems[n].ColumnValues["strategy"] + "</td>");
                    sb.Append("<td class=\"sub-items-col\">" + dataTableItems[n].ColumnValues["symbols"] + "</td>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["positions"] + "</td>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["orders"] + "</td>");
                    sb.Append("<td>" + dataTableItems[n].ColumnValues["actions"] + "</td>");
                    sb.Append("<td data-sort-value=\"" + dataTableItems[n].ColumnValues["realized"] + "\">" + UC.DecimalToUSD((decimal)dataTableItems[n].ColumnValues["realized"], 4) + "</td>");
                    sb.Append("<td data-sort-value=\"" + dataTableItems[n].ColumnValues["unrealized"] + "\">" + UC.DecimalToUSD((decimal)dataTableItems[n].ColumnValues["unrealized"], 4) + "</td>");
                    sb.Append("</tr>");
                }

                strategiesDataTable.TBodyHtml = sb.ToString();
            }

            result.DataTables.Add(strategiesDataTable);

            return(result);
        }
示例#18
0
 void AddWatch(string symbol, float Price, string WatchDate)
 {
     WatchItem Item = null;
     WatchList.TryGetValue(symbol, out Item);
     if (Item == null)
     {
         Item = new WatchItem();
         WatchList.Add(symbol, Item);
     }
     Item.Price = Price;
     Item.WatchDate = WatchDate;
 }
示例#19
0
		public async Task GetValue(WatchItem watchItem, CancellationToken cancellationToken)
		{
			SetupGetValueCommandParameters(watchItem.Name);
			await _debuggerSessionCommand.ExecuteNonQueryAsynchronous(cancellationToken);

			var result = (ValueInfoStatus)GetValueFromOracleDecimal(_debuggerSessionCommand.Parameters["RESULT"]);
			var value = GetValueFromOracleString(_debuggerSessionCommand.Parameters["VALUE"]);
			Trace.WriteLine($"Get value '{watchItem.Name}' result: {result}; value={value}");

			if (result != ValueInfoStatus.ErrorIndexedTable)
			{
				watchItem.Value = result == ValueInfoStatus.ErrorNullValue ? "NULL" : FormatIfCursorValue(value);
				watchItem.ChildItems = null;
				return;
			}

			var indexes = await GetCollectionIndexes(OracleObjectIdentifier.Create(_runtimeInfo.SourceLocation.Owner, _runtimeInfo.SourceLocation.Name), watchItem.Name, cancellationToken);
			watchItem.Value = $"collection ({indexes.Count} items)";

			var watchItems = new ObservableCollection<WatchItem>();
			foreach (var index in indexes)
			{
				var collectionItemExpression = $"{watchItem.Name}({index.Value})";
				SetupGetValueCommandParameters(collectionItemExpression);
				await _debuggerSessionCommand.ExecuteNonQueryAsynchronous(cancellationToken);

				var childItem =
					new WatchItem
					{
						Name = collectionItemExpression,
						Value = GetValueFromOracleString(_debuggerSessionCommand.Parameters["VALUE"])
					};

				watchItems.Add(childItem);
			}

			watchItem.ChildItems = watchItems;
		}
示例#20
0
        /// <summary>
        /// Creates and adds a new watch item using the specified name and type.
        /// </summary>
        /// <param name="name">The watch item name.</param>
        /// <param name="type">The type name.</param>
        public void AddNewWatch(string name, string type)
        {
            var li = new ListViewItem(name);
            li.SubItems.Add("?");
            li.SubItems.Add(type);
            var watchItem = new WatchItem(li);
            WatchItems.Add(watchItem);
            listView.Items.Add(li);

            OnWatchAdded(watchItem);
        }
示例#21
0
        internal WatchItem ProcessThing(object value, string tag, bool showRawData = true)
        {
            var node = new WatchItem(value.ToString(), tag);

            return(node);
        }
示例#22
0
 protected void OnWatchValueEdited(WatchItem item, long value)
 {
     if (WatchValueEdited != null)WatchValueEdited(item, value);
 }
示例#23
0
 public Task <int> DeleteItemAsync(WatchItem item)
 {
     return(Database1.DeleteAsync(item));
 }