Why is this collection keeps getting recreated everytime?

Jul 5, 2012 at 1:37 PM
        private void CreateQueries()
        {
            GridData =
                ExpressionObserver.Execute(() =>
                                               from o in _orders
                                               where o.State != OrderStateEnum.Canceled
                                               group o by o.Isin
                                               into g
                                               let germanSymbol = _referenceData.GetGermanSymbol(g.Key)
                                               let primarySymbol = _referenceData.GetPrimaryExchangeSymbol(g.Key)
                                               let name = _referenceData.GetInstrumentName(g.Key)
                                               orderby name ascending
                                               let primaryExchange = _referenceData.GetPrimaryExchangeId(g.Key)
                                               from q in _quotes
                                                   .Where(w => w.Isin == g.Key &&
                                                               w.Exchange == primaryExchange &&
                                                               w.Provider == ProviderEnum.Bloomberg).DefaultIfEmpty(
                                                                   new QuoteTickViewModel())
                                               select new ComplexRowViewModel()
                                                          {
                                                              Isin = g.Key,
                                                              Name = name,
                                                              GermanSymbol = germanSymbol,
                                                              PrimarySymbol = primarySymbol,
                                                              PrimaryExchange = new SimpleRowViewModel()
                                                                                    {
                                                                                        Ask = (decimal) q.Ask,
                                                                                        AskSize = q.AskSize,
                                                                                        Bid = (decimal) q.Bid,
                                                                                        BidSize = q.BidSize,
                                                                                        Exchange = q.Exchange,
                                                                                        Isin = q.Isin,
                                                                                        Last = (decimal) q.Last,
                                                                                        LastSize = q.LastSize,
                                                                                        LastTime = q.Time
                                                                                    },
                                                              Groupped =
                                                                  from qx in
                                                                      _quotes.Where(
                                                                          w =>
                                                                          w.Isin == g.Key &&
                                                                          w.Provider == ProviderEnum.Tradebase &&
                                                                          w.Exchange != primaryExchange)
                                                                  select new SimpleRowViewModel()
                                                                             {
                                                                                 Ask = (decimal) qx.Ask,
                                                                                 AskSize = qx.AskSize,
                                                                                 Bid = (decimal) qx.Bid,
                                                                                 BidSize = qx.BidSize,
                                                                                 Exchange = qx.Exchange,
                                                                                 Isin = qx.Isin,
                                                                                 Last = (decimal) qx.Last,
                                                                                 LastSize = qx.LastSize,
                                                                                 LastTime = qx.Time
                                                                             }
                                                          }
                        ).Cascade();
        }

As you see I got this query in my application. Top collection is orders which is almost static, but the nested Groupped collection is keeps getting updated. But insted of just updating the related properties, whole list getting recreated every update.

I was wondering if there is a solution for this ?
Coordinator
Jul 6, 2012 at 8:46 AM
Edited Jul 6, 2012 at 8:49 AM

I don't know which property is changing to cause the entire collection to update but what strikes me is that you seem to use an outer join between your grouped _orders and _quotes where you actually want to use an inner join.

With an outer join every group will need to be regarded when a relevant property of any _quote changes, as opposed to an inner join where only the associated groups will be checked.

Regs,

Thomas.

Jul 6, 2012 at 1:40 PM

Allright I've somehow fixed that problem but now I got a new one :)

 

Added item does not appear at given index '1'.

It is a typical threading problem but I really dont know what can I do about it.

'Pulse.UI.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'A first chance exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dllSystem.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>Pulse.UI.vshost.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Added item does not appear at given index '1'.</Message><StackTrace>   at MS.Internal.Data.EnumerableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)   at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)   at Obtics.NCToNCC.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(Object rawMessage)   at Obtics.Collections.Transformations.NotifyVpcTransformation`2.Notifier.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.Collections.Transformations.TranslucentTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(Object rawMessage)   at Obtics.Collections.Transformations.UnorderedCascadeTransformation`2.BufferNodeCC.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.Collections.Transformations.TranslucentTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(Object rawMessage)   at Obtics.Collections.Transformations.UnorderedNotifyVpcTransformation`2.Notifier.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.Values.Transformations.PropertyTransformation`2.Buffer_PropertyChanged(Object sender, EventArgs args)   at Obtics.Values.Transformations.PropertyTransformation`2.npc_PropertyChanged(Object sender, PropertyChangedEventArgs e)   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)   at GalaSoft.MvvmLight.ViewModelBase.RaisePropertyChanged(String propertyName) in D:\GalaSoft\mydotnet\GalaSoft MVVM Light Toolkit\Source\V3\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\ViewModelBase.cs:line 234   at Pulse.UI.ViewModels.OrderStatusViewModel.set_State(OrderStateEnum value) in C:\Serkan\Pulse Project\Pulse.UI\ViewModels\OrderStatusViewModel.cs:line 236   at Pulse.UI.ViewModels.OrderStatusViewModel.set_Status(OrderStatus value) in C:\Serkan\Pulse Project\Pulse.UI\ViewModels\OrderStatusViewModel.cs:line 80   at Pulse.UI.Common.MarketData.&amp;lt;MessageHandler&amp;gt;b__a(OrderStatusViewModel vm, OrderStatus m) in C:\Serkan\Pulse Project\Pulse.UI\Common\MarketData.cs:line 219   at Pulse.UI.Common.MarketData.&amp;lt;&amp;gt;c__DisplayClass20`2.&amp;lt;CollectionKeeper&amp;gt;b__1f() in C:\Serkan\Pulse Project\Pulse.UI\Common\MarketData.cs:line 333   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)   at System.Windows.Threading.DispatcherOperation.InvokeImpl()   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)   at System.Threading.ExecutionContext.runTryCode(Object userData)   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Windows.Threading.DispatcherOperation.Invoke()   at System.Windows.Threading.Dispatcher.ProcessQueue()   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp;amp; msg)   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)   at System.Windows.Application.RunDispatcher(Object ignore)   at System.Windows.Application.RunInternal(Window window)   at System.Windows.Application.Run(Window window)   at System.Windows.Application.Run()   at Pulse.UI.App.Main() in C:\Serkan\Pulse Project\Pulse.UI\obj\x86\Release\App.g.cs:line 0   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>System.InvalidOperationException: Added item does not appear at given index '1'.   at MS.Internal.Data.EnumerableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)   at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)   at Obtics.NCToNCC.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(Object rawMessage)   at Obtics.Collections.Transformations.NotifyVpcTransformation`2.Notifier.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.Collections.Transformations.TranslucentTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(Object rawMessage)   at Obtics.Collections.Transformations.UnorderedCascadeTransformation`2.BufferNodeCC.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.Collections.Transformations.TranslucentTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.Collections.Transformations.OpaqueTransformationBase`3.Release(INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(Object rawMessage)   at Obtics.Collections.Transformations.UnorderedNotifyVpcTransformation`2.Notifier.NotifyChanged(Object sender, INCEventArgs changeArgs)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.NCSourcedObject`1.NotifyChanged(Object sender, INCEventArgs args)   at Obtics.NotifyChangedReceiverTable.SendMessage(Object sender, INCEventArgs message)   at Obtics.NCObservableObjectBase`1.Release(INCEventArgs message)   at Obtics.NCSourcedObjectToVP`2.Release(INCEventArgs message)   at Obtics.Values.Transformations.PropertyTransformation`2.Buffer_PropertyChanged(Object sender, EventArgs args)   at Obtics.Values.Transformations.PropertyTransformation`2.npc_PropertyChanged(Object sender, PropertyChangedEventArgs e)   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)   at GalaSoft.MvvmLight.ViewModelBase.RaisePropertyChanged(String propertyName) in D:\GalaSoft\mydotnet\GalaSoft MVVM Light Toolkit\Source\V3\GalaSoft.MvvmLight\GalaSoft.MvvmLight (NET35)\ViewModelBase.cs:line 234   at Pulse.UI.ViewModels.OrderStatusViewModel.set_State(OrderStateEnum value) in C:\Serkan\Pulse Project\Pulse.UI\ViewModels\OrderStatusViewModel.cs:line 236   at Pulse.UI.ViewModels.OrderStatusViewModel.set_Status(OrderStatus value) in C:\Serkan\Pulse Project\Pulse.UI\ViewModels\OrderStatusViewModel.cs:line 80   at Pulse.UI.Common.MarketData.&amp;lt;MessageHandler&amp;gt;b__a(OrderStatusViewModel vm, OrderStatus m) in C:\Serkan\Pulse Project\Pulse.UI\Common\MarketData.cs:line 219   at Pulse.UI.Common.MarketData.&amp;lt;&amp;gt;c__DisplayClass20`2.&amp;lt;CollectionKeeper&amp;gt;b__1f() in C:\Serkan\Pulse Project\Pulse.UI\Common\MarketData.cs:line 333   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)   at System.Windows.Threading.DispatcherOperation.InvokeImpl()   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)   at System.Threading.ExecutionContext.runTryCode(Object userData)   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Windows.Threading.DispatcherOperation.Invoke()   at System.Windows.Threading.Dispatcher.ProcessQueue()   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp;amp; handled)   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp;amp; msg)   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)   at System.Windows.Application.RunDispatcher(Object ignore)   at System.Windows.Application.RunInternal(Window window)   at System.Windows.Application.Run(Window window)   at System.Windows.Application.Run()   at Pulse.UI.App.Main() in C:\Serkan\Pulse Project\Pulse.UI\obj\x86\Release\App.g.cs:line 0   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Threading.ThreadHelper.ThreadStart()</ExceptionString><DataItems><Data></Data></DataItems></Exception></TraceRecord>

Jul 9, 2012 at 2:15 PM

I am testing it for 3 days now. I've bumped my head to my desk several times because of this :) please help, I'm uploading my class which creates these queries.

http://www.4shared.com/file/ce_V8PPh/MarketData.html

Everything works fine until an OrderStatus gets a "Cancelled" state. I think it is because I filter the cancelled orders on top of the query. But how is this relevant I don't know. Anyway, the exception is:

InvalidOperationException, Added item does not appear at given index '0'.

But this totally makes no sense since the item is already there.

I'd be really glad if anyone can help me.

Jul 9, 2012 at 8:34 PM

As far as I understand, obtics engine is still searching for the order with active state but at that time the object already got the cancelled state. so if not an equal object returns i get an error.

 

but the solutions is to keep a list with every orderstate which kind of impossible

Coordinator
Jul 10, 2012 at 1:43 PM

It is probably the same issue as mentioned in this thread: http://obtics.codeplex.com/discussions/360575

The engine does not maintain a list with conversions. It uses your lambda function to find a conversion it needs for adding AND removing. So your lambda needs to return an equal result (not necessairily referentially equal) when it gets called with equal parameters. So:

X x = value;

Func<X,Y> yourLambda = <stuff>;

Assert.IsTrue(EqualityComparer<Y>.Default.Equals(yourLambda(x),yourLambda(x)));

Jul 10, 2012 at 2:32 PM
Edited Jul 10, 2012 at 2:33 PM

For other programmers who are having problems with this kind of exception, I ended up having this code.

 

 

        private void CreateQueries()
        {
            var query = ExpressionObserver.Execute(() => (from o in _orders
                                                          where o.State != OrderStateEnum.Canceled
                                                          group o by o.Isin
                                                              into g
                                                              let name = _referenceData.GetInstrumentName(g.Key)
                                                              orderby name ascending
                                                              select GetComplexRowViewModel(
                                                                                            g.First()
                                                                                            ,
                                                                                            (from p in _quotes
                                                                                             where
                                                                                                 p.Isin == g.Key &&
                                                                                                 p.Exchange == _referenceData.GetPrimaryExchangeId(g.Key) &&
                                                                                                 p.Provider == ProviderEnum.Bloomberg
                                                                                             select GetSimpleRowViewModel(p))
                                                                                             ,
                                                                                             (from q in _quotes
                                                                                              where
                                                                                                  q.Isin == g.Key &&
                                                                                                  q.Provider == ProviderEnum.Tradebase &&
                                                                                                  g.Select(s => s.Exchange).Contains(q.Exchange)
                                                                                              select GetSimpleRowViewModel(q))
                                                                                              ,
                                                                                              (from o in _orders
                                                                                               where o.Isin == g.Key
                                                                                               && o.State != OrderStateEnum.Canceled
                                                                                               group o by new { o.LimitPrice, o.OrderSide } into x
                                                                                               select GetCompressedRowViewModel
                                                                                               (
                                                                                                   x.Key.OrderSide == OrderSideEnum.Sell ? (decimal?)x.Key.LimitPrice : (decimal?)null,
                                                                                                   x.Key.OrderSide == OrderSideEnum.Sell ? x.Select(s => s.Quantity).Aggregate((c, n) => c + n) : 0,
                                                                                                   x.Key.OrderSide == OrderSideEnum.Buy ? (decimal?)x.Key.LimitPrice : (decimal?)null,
                                                                                                   x.Key.OrderSide == OrderSideEnum.Buy ? x.Select(s => s.Quantity).Aggregate((c, n) => c + n) : 0,
                                                                                                   string.Join(", ", x.Select(s => s.Exchange)),
                                                                                                   x.First().Isin.ToString(),
                                                                                                   x.Key.OrderSide == OrderSideEnum.Buy ? x.Count() : 0,
                                                                                                   x.Key.OrderSide == OrderSideEnum.Sell ? x.Count() : 0,
                                                                                                   x.Key.OrderSide == OrderSideEnum.Sell ? RowSide.Sell : RowSide.Buy
                                                                                               ))
                                                                   ,
                                                                   (from o in _orders
                                                                    where o.Isin == g.Key
                                                                    && o.State != OrderStateEnum.Canceled
                                                                    select GetUncompressedRowViewModel(o))
                                                                  
                                                                                             ))).Cascade();
            GridData = query;
        }


        // Obtics 
        private ConcurrentDictionary<string, ComplexRowViewModel> _complexRowViewModels = new ConcurrentDictionary<string, ComplexRowViewModel>();
        private ComplexRowViewModel GetComplexRowViewModel(OrderStatusViewModel model, IEnumerable<SimpleRowViewModel> primaryExchanges, IEnumerable<SimpleRowViewModel> groupped
            , IEnumerable<CompressedRowViewModel> compressed, IEnumerable<UncompressedRowViewModel> uncompressed)
        {
            if (model == null)
                return _complexRowViewModels.GetOrAdd("", s2 => new ComplexRowViewModel());

            return _complexRowViewModels.GetOrAdd(model.Isin,
                                                  s2 =>
                                                  new ComplexRowViewModel(_referenceData) { UnderlyingOrder = model, PrimaryExchange = primaryExchanges.First(), Groupped = groupped, Compressed = compressed, Uncompressed = uncompressed });
        }

        private ConcurrentDictionary<string, SimpleRowViewModel> _simpleRowViewModels = new ConcurrentDictionary<string, SimpleRowViewModel>();
        private SimpleRowViewModel GetSimpleRowViewModel(QuoteTickViewModel model)
        {
            if (model == null)
                return _simpleRowViewModels.GetOrAdd("", s2 => new SimpleRowViewModel());

            return _simpleRowViewModels.GetOrAdd(model.Isin + model.Exchange,
                                                                s2 =>
                                                                new SimpleRowViewModel() { UnderlyingQuote = model });
        }

        private ConcurrentDictionary<string, UncompressedRowViewModel> _uncompressedRowViewModels = new ConcurrentDictionary<string, UncompressedRowViewModel>();
        private UncompressedRowViewModel GetUncompressedRowViewModel(OrderStatusViewModel model)
        {
            if (model == null)
                return _uncompressedRowViewModels.GetOrAdd("", s2 => new UncompressedRowViewModel());

            return _uncompressedRowViewModels.GetOrAdd(model.InternalId,
                                                                s2 =>
                                                                new UncompressedRowViewModel() { UnderlyingOrder = model });
        }

        private ConcurrentDictionary<string, CompressedRowViewModel> _compressedRowViewModels = new ConcurrentDictionary<string, CompressedRowViewModel>();
        private CompressedRowViewModel GetCompressedRowViewModel(decimal? Ask, int AskSize, decimal? Bid, int BidSize, string Exchange, string Isin, int OrderBuyCount, int OrderSellCount, RowSide RowSide)
        {

            return new CompressedRowViewModel()
                       {
                           Ask = Ask,
                           AskSize = AskSize,
                           Bid = Bid,
                           BidSize = BidSize,
                           Exchange = Exchange,
                           Isin = Isin,
                           OrderBuyCount = OrderBuyCount,
                           OrderSellCount = OrderSellCount,
                           RowSide = RowSide
                       };
        }

 

So basically we what we can say is, Obtics is not entirely compatible with lambda and linq.

If you want to shape your viewmodels into another format or use surrogate classes or having aggregation with creating new classes on the fly, Obtics is not for you.

Thanks anyway.