Ejemplo n.º 1
0
        protected void MergePhase2(Object objectToMerge, Object objectToDelete, MergeHandle mergeHandle, ICUDResult cudResult, ProceedWithMergeHook proceedHook, MergeFinishedCallback mergeFinishedCallback, bool addNewEntitiesToCache)
        {
            List <Object> unpersistedObjectsToDelete = new List <Object>();

            RemoveUnpersistedDeletedObjectsFromCudResult(cudResult.AllChanges, cudResult.GetOriginalRefs(), unpersistedObjectsToDelete);
            if (objectToDelete != null)
            {
                IList <IObjRef> oriList = OriHelper.ExtractObjRefList(objectToDelete, mergeHandle);

                AppendDeleteContainers(objectToDelete, oriList, cudResult.AllChanges, cudResult.GetOriginalRefs(), unpersistedObjectsToDelete);
            }

            // Store the MergeFinishedCallback from this thread on the stack and set the property null (for following calls):
            if (GuiThreadHelper.IsInGuiThread())
            {
                GuiThreadHelper.InvokeOutOfGui(delegate()
                {
                    MergePhase3(objectToMerge, unpersistedObjectsToDelete, cudResult, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
                });
            }
            else
            {
                MergePhase3(objectToMerge, unpersistedObjectsToDelete, cudResult, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
            }
        }
Ejemplo n.º 2
0
        protected void MergePhase1(Object objectToMerge, Object objectToDelete, ProceedWithMergeHook proceedHook, MergeFinishedCallback mergeFinishedCallback, bool addNewEntitiesToCache)
        {
            ICUDResult       cudResult;
            MergeHandle      mergeHandle;
            IDisposableCache childCache = CacheFactory.Create(CacheFactoryDirective.NoDCE, false, false, "MergeProcess.ORIGINAL");

            try
            {
                mergeHandle = BeanContext.RegisterBean <MergeHandle>() //
                              .PropertyValue("Cache", childCache)      //
                              .Finish();
                cudResult         = MergeController.MergeDeep(objectToMerge, mergeHandle);
                mergeHandle.Cache = null;
            }
            finally
            {
                childCache.Dispose();
                childCache = null;
            }
            if (GuiThreadHelper.IsInGuiThread())
            {
                MergePhase2(objectToMerge, objectToDelete, mergeHandle, cudResult, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
            }
            else
            {
                GuiThreadHelper.InvokeInGui(delegate()
                {
                    MergePhase2(objectToMerge, objectToDelete, mergeHandle, cudResult, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
                });
            }
        }
Ejemplo n.º 3
0
 public void ApplyChangesToOriginals(ICUDResult cudResult, IOriCollection oriCollection, ICache cache)
 {
     if (GuiThreadHelper.IsInGuiThread())
     {
         ApplyChangesToOriginalsIntern(cudResult, oriCollection, cache);
         return;
     }
     GuiThreadHelper.InvokeInGuiAndWait(new IBackgroundWorkerDelegate(delegate()
     {
         ApplyChangesToOriginalsIntern(cudResult, oriCollection, cache);
     }));
 }
Ejemplo n.º 4
0
        public virtual void Populate()
        {
            var localRequest = new Object();

            lock (currentRequestLock)
            {
                currentRequest = localRequest;
            }
            if (GuiThreadHelper.IsInGuiThread())
            {
                IFilterDescriptor       filterDescriptor = GetFilterDescriptor();
                IList <ISortDescriptor> sortDescriptors  = GetSortDescriptors();
                IPagingRequest          pagingRequest    = GetPagingRequest();
                Object[] contextInformation = GetContextInformation();

                Model.IsBusy = true;
                ThreadPool.Queue((GenericViewModel <T> model) =>
                {
                    CacheContext.ExecuteWithCache <Object>(CacheProvider.GetCurrentCache(), delegate()
                    {
                        ConfigureCacheWithEagerLoads(Cache);
                        PopulateAsync(model, filterDescriptor, sortDescriptors, pagingRequest, contextInformation, Cache, localRequest);
                        return(null);
                    });
                }, Model);
            }
            else
            {
                IFilterDescriptor       filterDescriptor = null;
                IList <ISortDescriptor> sortDescriptors  = null;
                IPagingRequest          pagingRequest    = null;
                Object[] contextInformation = null;
                GuiThreadHelper.InvokeInGuiAndWait(delegate()
                {
                    filterDescriptor = GetFilterDescriptor();
                    sortDescriptors  = GetSortDescriptors();
                    pagingRequest    = GetPagingRequest();

                    contextInformation = GetContextInformation();

                    Model.IsBusy = true;
                });
                CacheContext.ExecuteWithCache <Object>(CacheProvider.GetCurrentCache(), delegate()
                {
                    ConfigureCacheWithEagerLoads(Cache);
                    PopulateAsync(Model, filterDescriptor, sortDescriptors, pagingRequest, contextInformation, Cache, localRequest);
                    return(null);
                });
            }
        }
Ejemplo n.º 5
0
 public void Process(Object objectToMerge, Object objectToDelete, ProceedWithMergeHook proceedHook, MergeFinishedCallback mergeFinishedCallback, bool addNewEntitiesToCache)
 {
     if (GuiThreadHelper.IsInGuiThread())
     {
         GuiThreadHelper.InvokeOutOfGui(delegate()
         {
             MergePhase1(objectToMerge, objectToDelete, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
         });
     }
     else
     {
         MergePhase1(objectToMerge, objectToDelete, proceedHook, mergeFinishedCallback, addNewEntitiesToCache);
     }
 }
Ejemplo n.º 6
0
 public virtual void OnCanExecuteChanged(Object sender, EventArgs e)
 {
     if (CanExecuteChanged != null)
     {
         if (GuiThreadHelper.IsInGuiThread())
         {
             CanExecuteChanged.Invoke(this, EventArgs.Empty);
         }
         else
         {
             SyncContext.Send((object state) =>
             {
                 CanExecuteChanged.Invoke(this, EventArgs.Empty);
             }, null);
         }
     }
 }
Ejemplo n.º 7
0
        protected override void InterceptIntern(IInvocation invocation)
        {
            Attribute annotation = GetMethodLevelBehavior(invocation.Method);

            if (annotation is NoProxyAttribute)
            {
                InvokeTarget(invocation);
                return;
            }
            String  methodName   = invocation.Method.Name.ToLower();
            Boolean?isAsyncBegin = null;

            if (methodName.StartsWith("begin"))
            {
                isAsyncBegin = true;
                methodName   = methodName.Substring(5);
            }
            else if (methodName.StartsWith("end"))
            {
                isAsyncBegin = false;
                methodName   = methodName.Substring(3);
            }
            if (GuiThreadHelper.IsInGuiThread())
            {
                if (!typeof(void).Equals(invocation.Method.ReturnType))
                {
                    throw new Exception("It is not allowed to call synchronuous methods from GUI thread. Please use '" + typeof(IThreadPool).FullName
                                        + "' to make this synchronuous call from a background thread");
                }
                ThreadPool.Queue(delegate()
                {
                    Intercept(invocation, methodName, annotation, isAsyncBegin);
                });
                return;
            }
            Object result = Intercept(invocation, methodName, annotation, isAsyncBegin);

            invocation.ReturnValue = result;
        }
Ejemplo n.º 8
0
        public void FilterValues()
        {
            if (DataSource == null)
            {
                return;
            }
            IList <T> readonlyDataSourceContext;

            if (DataSource is IModelMultiContainer <T> )
            {
                readonlyDataSourceContext = ((IModelMultiContainer <T>)DataSource).Values;
            }
            else if (DataSource is IModelSingleContainer <T> )
            {
                readonlyDataSourceContext = new List <T>(1);
                T value = ((IModelSingleContainer <T>)DataSource).Value;
                if (value != null)
                {
                    readonlyDataSourceContext.Add(value);
                }
            }
            else
            {
                throw new NotSupportedException(typeof(IModelContainer).Name + " of type '" + DataSource.GetType() + "' not supported");
            }
            SetBusy();
            if (GuiThreadHelper.IsInGuiThread())
            {
                // Create a 'safe copy' of the datasource from within gui thread
                IList <T> clonedDataSourceContext = new List <T>(readonlyDataSourceContext);
                ThreadPool.Queue(delegate()
                {
                    try
                    {
                        IList <T> values = ClientFilter.Filter(clonedDataSourceContext);

                        // This will not set the Values-IList<T> Pointer but will clear and reinit its content
                        // This assumption is important because our unmodifiableValues-Property depends on it
                        SyncContext.Send((object state) =>
                        {
                            base.Values = values;
                        }, null);
                    }
                    finally
                    {
                        SetUnbusy();
                    }
                });
            }
            else
            {
                try
                {
                    IList <T> clonedDataSourceContext = null;
                    SyncContext.Send((object state) =>
                    {
                        // Create a 'safe copy' of the datasource from within gui thread
                        clonedDataSourceContext = new List <T>(readonlyDataSourceContext);
                    }, null);

                    IList <T> values = ClientFilter.Filter(clonedDataSourceContext);

                    // This will not set the Values-IList<T> Pointer but will clear and reinit its content
                    // This assumption is important because our unmodifiableValues-Property depends on it
                    SyncContext.Send((object state) =>
                    {
                        base.Values = values;
                    }, null);
                }
                finally
                {
                    SetUnbusy();
                }
            }
        }
Ejemplo n.º 9
0
        protected override void InterceptIntern(IInvocation invocation)
        {
            if (GuiThreadHelper != null && GuiThreadHelper.IsInGuiThread())
            {
                throw new Exception("It is not allowed to call this interceptor from GUI thread");
            }
            lock (clientLock)
            {
                if (connectionChangePending)
                {
                    // Wait till the connection change finished
                    Monitor.Wait(clientLock);
                }
            }
            DateTime   m1     = DateTime.Now;
            MethodInfo method = invocation.Method;
            String     url    = ServiceBaseUrl + "/" + ServiceName + "/" + method.Name;

            HttpWebRequest webRequest;

#if SILVERLIGHT
            if (HttpUseClient)
            {
                webRequest = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(url));
            }
            else
            {
                webRequest = WebRequest.CreateHttp(url);
            }
#else
            webRequest           = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Proxy     = null;
            webRequest.KeepAlive = true;
#endif
            Object    result    = null;
            bool      hasResult = false;
            Exception ex        = null;

            lock (webRequest)
            {
                webRequest.Accept = "text/plain";
                if (HttpAcceptEncodingZipped)
                {
                    TryToSetHeader(HttpRequestHeader.AcceptEncoding, webRequest, "gzip");
                    webRequest.Headers["Accept-Encoding-Workaround"] = "gzip";
                }
                SetAuthorization(webRequest);

                if (invocation.Arguments.Length == 0)
                {
                    webRequest.Method = "GET";
                    webRequest.BeginGetResponse(delegate(IAsyncResult asyncResult2)
                    {
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asyncResult2);
                            using (Stream responseStream = response.GetResponseStream())
                                using (Stream memoryStream = new MemoryStream())
                                {
                                    int b;
                                    while ((b = responseStream.ReadByte()) != -1)
                                    {
                                        memoryStream.WriteByte((byte)b);
                                    }
                                    memoryStream.Position = 0;
                                    try
                                    {
                                        Stream deflateStream = GetResponseStream(response, memoryStream);
                                        result = CyclicXmlHandler.ReadFromStream(deflateStream);
                                    }
                                    catch (XmlTypeNotFoundException)
                                    {
                                        throw;
                                    }
                                    catch (Exception)
                                    {
                                        memoryStream.Position = 0;
                                        result = CyclicXmlHandler.ReadFromStream(memoryStream);
                                    }
                                }
                            hasResult = true;
                        }
                        catch (WebException e)
                        {
                            ex = ParseWebException(e);
                            using (HttpWebResponse response = (HttpWebResponse)e.Response)
                            {
                                HandleException(e, response);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error(e);
                            ex = e;
                        }
                        finally
                        {
                            lock (webRequest)
                            {
                                Monitor.PulseAll(webRequest);
                            }
                        }
                    }, null);
                }
                else
                {
                    webRequest.Method      = "POST";
                    webRequest.ContentType = "text/plain";
                    if (HttpContentEncodingZipped)
                    {
                        TryToSetHeader(HttpRequestHeader.ContentEncoding, webRequest, "gzip");
                        webRequest.Headers["Content-Encoding-Workaround"] = "gzip";
                    }
                    webRequest.BeginGetRequestStream(delegate(IAsyncResult asyncResult)
                    {
                        try
                        {
                            using (Stream stream = webRequest.EndGetRequestStream(asyncResult))
#if SILVERLIGHT
                                using (Stream deflateStream = HttpContentEncodingZipped ? new GZipStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression, false) : stream)
#else
                                using (Stream deflateStream = HttpContentEncodingZipped ? new GZipStream(stream, CompressionMode.Compress, false) : stream)
#endif
                                {
                                    CyclicXmlHandler.WriteToStream(deflateStream, invocation.Arguments);
                                }
                            webRequest.BeginGetResponse(delegate(IAsyncResult asyncResult2)
                            {
                                DateTime m4 = DateTime.Now;
                                try
                                {
                                    HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asyncResult2);
                                    DateTime m5 = DateTime.Now;
                                    using (Stream responseStream = response.GetResponseStream())
                                        using (Stream memoryStream = new MemoryStream())
                                        {
                                            int b;
                                            while ((b = responseStream.ReadByte()) != -1)
                                            {
                                                memoryStream.WriteByte((byte)b);
                                            }
                                            memoryStream.Position = 0;
                                            try
                                            {
                                                Stream deflateStream = GetResponseStream(response, memoryStream);
                                                result = CyclicXmlHandler.ReadFromStream(deflateStream);
                                            }
                                            catch (XmlTypeNotFoundException)
                                            {
                                                throw;
                                            }
                                            catch (Exception)
                                            {
                                                memoryStream.Position = 0;
                                                result = CyclicXmlHandler.ReadFromStream(memoryStream);
                                            }
                                        }
                                    hasResult = true;
                                }
                                catch (WebException e)
                                {
                                    ex = ParseWebException(e);
                                    using (HttpWebResponse response = (HttpWebResponse)e.Response)
                                    {
                                        HandleException(e, response);
                                    }
                                }
                                catch (Exception e)
                                {
                                    ex = e;
                                }
                                finally
                                {
                                    lock (webRequest)
                                    {
                                        Monitor.PulseAll(webRequest);
                                    }
                                }
                            }, null);
                        }
                        catch (Exception e)
                        {
                            ex = e;
                            lock (webRequest)
                            {
                                Monitor.PulseAll(webRequest);
                            }
                        }
                    }, null);
                }
                while (!hasResult && ex == null)
                {
                    Monitor.Wait(webRequest);
                }
            }
            if (result is AmbethServiceException)
            {
                ex = ParseServiceException((AmbethServiceException)result);
                throw new Exception("Error occured while calling " + webRequest.Method + " " + webRequest.RequestUri, ex);
            }
            if (ex != null)
            {
                if (ex is WebException)
                {
                    throw new Exception(ex.Message + "\r\rError occured while calling " + webRequest.Method + " " + webRequest.RequestUri + ". " + CyclicXmlHandler.Write(invocation.Arguments), ex);
                }
                throw new Exception("Error occured while calling " + webRequest.Method + " " + webRequest.RequestUri + ". " + CyclicXmlHandler.Write(invocation.Arguments), ex);
            }
            if (!hasResult)
            {
                throw new Exception("This must never happen");
            }
            invocation.ReturnValue = ConvertToExpectedType(method.ReturnType, result);
        }