예제 #1
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="returnObject">Object to return as part
 /// of the result.</param>
 /// <param name="globalContext">  Global context delivered via current reuest from the server
 /// </param>
 public DataPortalResult(object returnObject, ContextDictionary globalContext)
 {
     ReturnObject  = returnObject;
     GlobalContext = globalContext;
 }
예제 #2
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 public DataPortalResult()
 {
     GlobalContext = ApplicationContext.ContextManager.GetGlobalContext();
 }
예제 #3
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="returnObject">Object to return as part
 /// of the result.</param>
 public DataPortalResult(object returnObject)
 {
     ReturnObject  = returnObject;
     GlobalContext = ApplicationContext.ContextManager.GetGlobalContext();
 }
예제 #4
0
 /// <summary>
 /// Sets the client context.
 /// </summary>
 /// <param name="clientContext">Client context.</param>
 public void SetClientContext(ContextDictionary clientContext)
 {
     HttpContext.Items[_clientContextName] = clientContext;
 }
예제 #5
0
 /// <summary>
 /// Sets the global context.
 /// </summary>
 /// <param name="globalContext">Global context.</param>
 public void SetGlobalContext(ContextDictionary globalContext)
 {
     HttpContext.Items[_globalContextName] = globalContext;
 }
 public ContextAddressHeader(IDictionary<string, string> context)
 {
     this.context = new ContextDictionary(context);
 }
예제 #7
0
        private static ThemeStyle ProcessStyle(string name, string content, StringDictionary variables, ContextDictionary context)
        {
            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(content))
            {
                return(null);
            }

            StringDictionary values = new StringDictionary();

            content.ParseKeyValuePair((t1, t2) => values.Add(t1, t2));

            string             module       = null;
            ThemeParserContext styleContext = ThemeParserContext.Default;

            if (values.TryGetValue("$module", out module))
            {
                context.TryGetValue(module, out styleContext);
                values.Remove("$module");
            }

            ThemeStyle style = new ThemeStyle(styleContext, name);

            style.UpdateProperties(values);

            return(style);
        }
예제 #8
0
파일: TestContext.cs 프로젝트: ajj7060/csla
 public void SetClientContext(ContextDictionary clientContext)
 {
     _myContext[_clientContextName] = clientContext;
 }
예제 #9
0
파일: TestContext.cs 프로젝트: ajj7060/csla
 public void SetGlobalContext(ContextDictionary globalContext)
 {
     _myContext[_globalContextName] = globalContext;
 }
예제 #10
0
 /// <summary>
 /// Creates a new DataPortalContext object.
 /// </summary>
 /// <param name="principal">The current Principal object.</param>
 /// <param name="isRemotePortal">Indicates whether the DataPortal is remote.</param>
 /// <param name="clientContext">Client context.</param>
 /// <param name="clientCulture">Client culture.</param>
 /// <param name="clientUICulture">Client UI culture.</param>
 /// <param name="globalContext">Global context.</param>
 public DataPortalContext(IPrincipal principal, bool isRemotePortal, string clientCulture, string clientUICulture, ContextDictionary clientContext, ContextDictionary globalContext)
 {
     _principal       = principal;
     _clientContext   = clientContext;
     _clientCulture   = clientCulture;
     _clientUICulture = clientUICulture;
     _globalContext   = globalContext;
     _remotePortal    = isRemotePortal;
 }
예제 #11
0
파일: TestContext.cs 프로젝트: ajj7060/csla
 public void SetLocalContext(ContextDictionary localContext)
 {
     _myContext[_localContextName] = localContext;
 }
예제 #12
0
        /// <summary>
        /// Called by <see cref="DataPortal" /> to delete a
        /// business object.
        /// </summary>
        /// <param name="objectType">Type of business object to create.</param>
        /// <param name="criteria">Criteria object describing business object.</param>
        /// <param name="context">
        /// <see cref="Server.DataPortalContext" /> object passed to the server.
        /// </param>
        /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
#pragma warning disable 1998
        public async Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
#pragma warning restore 1998
        {
#if !(ANDROID || IOS) && !NETFX_CORE
            ChannelFactory <IWcfPortal> cf = GetChannelFactory();
            var         proxy    = GetProxy(cf);
            WcfResponse response = null;
#if NET40
            try
            {
                var request = new DeleteRequest(objectType, criteria, context);
                if (isSync)
                {
                    response = proxy.Delete(request);
                }
                else
                {
                    var worker = new Csla.Threading.BackgroundWorker();
                    var tcs    = new TaskCompletionSource <WcfResponse>();
                    worker.RunWorkerCompleted += (o, e) =>
                    {
                        tcs.SetResult((WcfResponse)e.Result);
                    };
                    worker.DoWork += (o, e) =>
                    {
                        e.Result = proxy.Delete(request);
                    };
                    worker.RunWorkerAsync();
                    response = await tcs.Task;
                }
                if (cf != null)
                {
                    cf.Close();
                }
                object result = response.Result;
                if (result is Exception)
                {
                    throw (Exception)result;
                }
                return((DataPortalResult)result);
            }
            catch
            {
                cf.Abort();
                throw;
            }
#else
            try
            {
                var request = new DeleteRequest(objectType, criteria, context);
                if (isSync)
                {
                    response = proxy.Delete(request);
                }
                else
                {
                    response = await proxy.DeleteAsync(request);
                }
                if (cf != null)
                {
                    cf.Close();
                }
            }
            catch
            {
                cf.Abort();
                throw;
            }
            object result = response.Result;
            if (result is Exception)
            {
                throw (Exception)result;
            }
            return((DataPortalResult)result);
#endif
#else
            var request = GetBaseCriteriaRequest();
            request.TypeName = objectType.AssemblyQualifiedName;
            if (!(criteria is IMobileObject))
            {
                criteria = new PrimitiveCriteria(criteria);
            }
            request.CriteriaData = MobileFormatter.Serialize(criteria);
            request = ConvertRequest(request);

            var proxy = GetProxy();
            DataPortalResult result = null;
#if !NETFX_CORE && !(IOS || ANDROID)
            var tcs = new TaskCompletionSource <DataPortalResult>();
            proxy.DeleteCompleted += (s, e) =>
            {
                try
                {
                    Csla.WcfPortal.WcfResponse response = null;
                    if (e.Error == null)
                    {
                        response = ConvertResponse(e.Result);
                    }
                    ContextDictionary globalContext = null;
                    if (response != null)
                    {
                        globalContext = (ContextDictionary)MobileFormatter.Deserialize(response.GlobalContext);
                    }
                    if (e.Error == null && response != null && response.ErrorData == null)
                    {
                        result = new DataPortalResult(null, null, globalContext);
                    }
                    else if (response != null && response.ErrorData != null)
                    {
                        var ex = new DataPortalException(response.ErrorData);
                        result = new DataPortalResult(null, ex, globalContext);
                    }
                    else
                    {
                        result = new DataPortalResult(null, e.Error, globalContext);
                    }
                }
                catch (Exception ex)
                {
                    result = new DataPortalResult(null, ex, null);
                }
                finally
                {
                    tcs.SetResult(result);
                }
            };
            proxy.DeleteAsync(request);
            var finalresult = await tcs.Task;
            if (finalresult.Error != null)
            {
                throw finalresult.Error;
            }
            return(finalresult);
#else
            try
            {
                var response = await proxy.DeleteAsync(request);

                response = ConvertResponse(response);
                if (response == null)
                {
                    throw new DataPortalException("null response", null);
                }
                var globalContext = (ContextDictionary)MobileFormatter.Deserialize(response.GlobalContext);
                if (response.ErrorData == null)
                {
                    result = new DataPortalResult(null, null, globalContext);
                }
                else
                {
                    var ex = new DataPortalException(response.ErrorData);
                    result = new DataPortalResult(null, ex, globalContext);
                }
            }
            catch (Exception ex)
            {
                result = new DataPortalResult(null, ex, null);
            }
            if (result.Error != null)
            {
                throw result.Error;
            }
            return(result);
#endif
#endif
        }
예제 #13
0
 internal void SetContext(ContextDictionary clientContext)
 {
     lock (_syncContext)
         ContextManager.SetClientContext(clientContext, ExecutionLocation);
 }
예제 #14
0
        /// <summary>
        /// Called by <see cref="DataPortal" /> to update a
        /// business object.
        /// </summary>
        /// <param name="obj">The business object to update.</param>
        /// <param name="context">
        /// <see cref="Server.DataPortalContext" /> object passed to the server.
        /// </param>
        /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
#pragma warning disable 1998
        public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
#pragma warning restore 1998
        {
#if !SILVERLIGHT && !NETFX_CORE
            ChannelFactory <IWcfPortal> cf = GetChannelFactory();
            var         proxy    = GetProxy(cf);
            WcfResponse response = null;
      #if NET40
            try
            {
                var request = new UpdateRequest(obj, context);
                if (isSync)
                {
                    response = proxy.Update(request);
                }
                else
                {
                    var worker = new Csla.Threading.BackgroundWorker();
                    var tcs    = new TaskCompletionSource <WcfResponse>();
                    worker.RunWorkerCompleted += (o, e) =>
                    {
                        tcs.SetResult((WcfResponse)e.Result);
                    };
                    worker.DoWork += (o, e) =>
                    {
                        e.Result = proxy.Update(request);
                    };
                    worker.RunWorkerAsync();
                    response = await tcs.Task;
                }
                if (cf != null)
                {
                    cf.Close();
                }
                object result = response.Result;
                if (result is Exception)
                {
                    throw (Exception)result;
                }
                return((DataPortalResult)result);
            }
            catch
            {
                cf.Abort();
                throw;
            }
#else
            try
            {
                var request = new UpdateRequest(obj, context);
                if (isSync)
                {
                    response = proxy.Update(request);
                }
                else
                {
                    response = await proxy.UpdateAsync(request);
                }
                if (cf != null)
                {
                    cf.Close();
                }
            }
            catch
            {
                cf.Abort();
                throw;
            }
            object result = response.Result;
            if (result is Exception)
            {
                throw (Exception)result;
            }
            return((DataPortalResult)result);
#endif
#else
            var request = GetBaseUpdateCriteriaRequest();
            request.ObjectData = MobileFormatter.Serialize(obj);
            request            = ConvertRequest(request);

            var proxy = GetProxy();
            DataPortalResult result = null;
#if !NETFX_CORE
            var tcs = new TaskCompletionSource <DataPortalResult>();
            proxy.UpdateCompleted += (s, e) =>
            {
                try
                {
                    Csla.WcfPortal.WcfResponse response = null;
                    if (e.Error == null)
                    {
                        response = ConvertResponse(e.Result);
                    }
                    ContextDictionary globalContext = null;
                    if (response != null)
                    {
                        globalContext = (ContextDictionary)MobileFormatter.Deserialize(response.GlobalContext);
                    }
                    if (e.Error == null && response != null && response.ErrorData == null)
                    {
                        var newobj = MobileFormatter.Deserialize(response.ObjectData);
                        result = new DataPortalResult(newobj, null, globalContext);
                    }
                    else if (response != null && response.ErrorData != null)
                    {
                        var ex = new DataPortalException(response.ErrorData);
                        result = new DataPortalResult(null, ex, globalContext);
                    }
                    else
                    {
                        result = new DataPortalResult(null, e.Error, globalContext);
                    }
                }
                catch (Exception ex)
                {
                    result = new DataPortalResult(null, ex, null);
                }
                finally
                {
                    tcs.SetResult(result);
                }
            };
            proxy.UpdateAsync(request);
            var finalresult = await tcs.Task;
            if (finalresult.Error != null)
            {
                throw finalresult.Error;
            }
            return(finalresult);
#else
            try
            {
                var response = await proxy.UpdateAsync(request);

                response = ConvertResponse(response);
                if (response == null)
                {
                    throw new DataPortalException("null response", null);
                }
                var globalContext = (ContextDictionary)MobileFormatter.Deserialize(response.GlobalContext);
                if (response.ErrorData == null)
                {
                    var newobj = MobileFormatter.Deserialize(response.ObjectData);
                    result = new DataPortalResult(newobj, null, globalContext);
                }
                else
                {
                    var ex = new DataPortalException(response.ErrorData);
                    result = new DataPortalResult(null, ex, globalContext);
                }
            }
            catch (Exception ex)
            {
                result = new DataPortalResult(null, ex, null);
            }
            if (result.Error != null)
            {
                throw result.Error;
            }
            return(result);
#endif
#endif
        }
예제 #15
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="returnObject">Object to return as part
 /// of the result.</param>
 /// <param name="ex">
 /// Error that occurred during the DataPotal call.
 /// This will be null if no errors occurred.
 /// </param>
 /// <param name="globalContext">  Global context delivered via current reuest from the server
 /// </param>
 public DataPortalResult(object returnObject, Exception ex, ContextDictionary globalContext)
 {
     ReturnObject  = returnObject;
     Error         = ex;
     GlobalContext = globalContext;
 }
 /// <summary>
 /// Sets the client context.
 /// </summary>
 /// <param name="clientContext">Client context.</param>
 /// <param name="executionLocation"></param>
 public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
 {
     HttpContext.Items[_clientContextName] = clientContext;
 }
예제 #17
0
        /// <summary>
        /// Sets the local context.
        /// </summary>
        /// <param name="localContext">Local context.</param>
        public void SetLocalContext(ContextDictionary localContext)
        {
            LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_localContextName);

            Thread.SetData(slot, localContext);
        }
예제 #18
0
 /// <summary>
 /// Sets the local context.
 /// </summary>
 /// <param name="localContext">Local context.</param>
 public void SetLocalContext(ContextDictionary localContext)
 {
     HttpContext.Items[_localContextName] = localContext;
 }
 public ContextAddressHeader(IDictionary<string, string> context)
     : base()
 {
     Fx.Assert(context != null, "caller must validate");
     this.context = new ContextDictionary(context);
 }
예제 #20
0
        private static void ProcessInstruction(string name, string content,
                                               ThemeList styles, StringDictionary variables, ContextDictionary context)
        {
            switch (name)
            {
            case "@vals":
                ParseVariables(variables, content);
                break;

            case "@include":
                break;

            case "@modules":
                ParseContext(content, context);
                break;
            }
        }