//Refresh issues!! public override IList LoadObjects(IQuery query, IList listToFill) { if (this.url.Length < 1) { throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); } RemotingService rs = new RemotingService(this.Context, url); IMarshalingTransformer transformer = new MarshalingTransformer(Context); MarshalQuery mq = transformer.FromQuery(query); string xmlQuery = (string)Formatter.Serialize(mq); if (useCompression && this.compressor != null) { xmlQuery = this.compressor.Compress(xmlQuery); } bool doUseCompression = this.useCompression; if (this.compressor == null) { doUseCompression = false; } string result = rs.LoadObjects(xmlQuery, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) { result = this.compressor.Decompress(result); } MarshalObjectList mol = (MarshalObjectList)Formatter.Deserialize(result, typeof(MarshalObjectList)); transformer.ToObjectList(mol, query.RefreshBehavior, listToFill); return(listToFill); }
private static void CallRunningInstance(string[] args) { RemotingService service = (RemotingService)RemotingServices.Connect(typeof(RemotingService), "ipc://" + channelName + "/service.rem"); String firstArg = args[0]; if (firstArg == null || !_validArgs.Contains(firstArg)) { return; } if (firstArg == Arguments.About) { service.ShowAbout(); } else if (firstArg == Arguments.Check) { service.CheckMail(); } else if (firstArg == Arguments.Settings) { service.OpenSettingsWindow(); } else if (firstArg == Arguments.Help) { Utilities.UrlHelper.Launch(null, "https://github.com/shellscape/Gmail-Notifier-Plus/wiki"); } }
//Should have no refresh issues public override void LoadObject(ref object obj) { if (this.url.Length < 1) { throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); } RemotingService rs = new RemotingService(this.Context, url); IClassMap classMap = Context.DomainMap.MustGetClassMap(obj.GetType()); string id = Context.ObjectManager.GetObjectIdentity(obj); bool doUseCompression = this.useCompression; if (this.compressor == null) { doUseCompression = false; } string result = rs.LoadObject(classMap.GetName(), id, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) { result = this.compressor.Decompress(result); } MarshalObject mo = (MarshalObject)Formatter.Deserialize(result, typeof(MarshalObject)); IMarshalingTransformer transformer = new MarshalingTransformer(Context); Context.IdentityMap.RegisterLoadedObject(obj); transformer.ToObject(mo, ref obj); }
public override void Commit(bool recursive) { if (this.url.Length < 1) { throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); } MarshalUnitOfWork muow = GetUnitOfWork(); RemotingService rs = new RemotingService(this.Context, url); string xmlUoW = (string)Formatter.Serialize(muow); if (useCompression && this.compressor != null) { xmlUoW = this.compressor.Compress(xmlUoW); } bool doUseCompression = this.useCompression; if (this.compressor == null) { doUseCompression = false; } string result = rs.CommitUnitOfWork(xmlUoW, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) { result = this.compressor.Decompress(result); } MarshalObjectList mol = (MarshalObjectList)Formatter.Deserialize(result, typeof(MarshalObjectList)); UpdateSourceAssigned(mol); ClearUnitOfWork(); }
public IDomainMap GetMap() { if (this.url.Length < 1) { throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); } RemotingService rs = new RemotingService(this.Context, url); bool doUseCompression = this.useCompression; if (this.compressor == null) { doUseCompression = false; } string result = rs.GetMap(this.domainKey, doUseCompression); if (useCompression && this.compressor != null) { result = this.compressor.Decompress(result); } return(DomainMap.LoadFromXml(result, new DefaultMapSerializer())); }
public static int PublishService() { RemotingService.RegisterRemotingChannel(); TcpChannel ch = (TcpChannel)ChannelServices.GetChannel("tcp"); Uri u = new Uri(ch.GetUrlsForUri("test")[0]); publicPort = u.Port; InstrumentationServiceBackend backend = new InstrumentationServiceBackend(); System.Runtime.Remoting.RemotingServices.Marshal(backend, "InstrumentationService"); return(publicPort); }
static void Main(String[] arguments) { if (_program == null) { _remoting = new RemotingService(); _program = new Shellscape.Program(){ RemotingServiceType = typeof(RemotingService) }; _program.MainInstanceStarted += program_MainInstanceStarted; _program.RemoteCall += program_RemoteCall; } _program.Run<Forms.Main>(arguments); }
public void ProcessRequest(HttpContext context) { context.Server.ScriptTimeout = 3600; string configurationName = context.Request.QueryString["c"]; string timestamp = context.Request.QueryString["ts"]; DateTime lastUpdated; if (timestamp == null || !DateTime.TryParse(timestamp, out lastUpdated)) { context.Response.StatusCode = 400; context.Response.Write("Invalid timestamp."); context.Response.End(); return; } if (configurationName.IsNullOrEmpty()) { context.Response.StatusCode = 400; context.Response.Write("Missing configuration."); context.Response.End(); } /*if (!Authorization.IsAllowed) * { * context.Response.StatusCode = 403; * context.Response.Write("Access denied."); * context.Response.End(); * } * else*/ { // this securitydisabler allows the control panel to execute unfettered when debug compilation is enabled but you are not signed into Sitecore using (new SecurityDisabler()) { // TODO: check security (HMAC) using (var package = new RemotingService().CreateRemotingPackage(configurationName, lastUpdated)) { package.WriteToHttpResponse(new HttpResponseWrapper(context.Response)); } } } }
public void ProcessRequest(HttpContext context) { context.Server.ScriptTimeout = 3600; string configurationName = context.Request.QueryString["c"]; string timestamp = context.Request.QueryString["ts"]; DateTime lastUpdated; if (timestamp == null || !DateTime.TryParse(timestamp, out lastUpdated)) { context.Response.StatusCode = 400; context.Response.Write("Invalid timestamp."); context.Response.End(); return; } if (configurationName.IsNullOrEmpty()) { context.Response.StatusCode = 400; context.Response.Write("Missing configuration."); context.Response.End(); } /*if (!Authorization.IsAllowed) { context.Response.StatusCode = 403; context.Response.Write("Access denied."); context.Response.End(); } else*/ { // this securitydisabler allows the control panel to execute unfettered when debug compilation is enabled but you are not signed into Sitecore using (new SecurityDisabler()) { // TODO: check security (HMAC) using (var package = new RemotingService().CreateRemotingPackage(configurationName, lastUpdated)) { package.WriteToHttpResponse(new HttpResponseWrapper(context.Response)); } } } }
public override void Invoke(AMFContext context) { MessageOutput messageOutput = context.MessageOutput; for (int i = 0; i < context.AMFMessage.BodyCount; i++) { AMFBody amfBody = context.AMFMessage.GetBodyAt(i); ResponseBody responseBody = null; //Check for Flex2 messages and skip if (amfBody.IsEmptyTarget) { continue; } if (amfBody.IsDebug) { continue; } if (amfBody.IsDescribeService) { responseBody = new ResponseBody(); responseBody.IgnoreResults = amfBody.IgnoreResults; responseBody.Target = amfBody.Response + AMFBody.OnResult; responseBody.Response = null; DescribeService describeService = new DescribeService(amfBody); responseBody.Content = describeService.GetDescription(); messageOutput.AddBody(responseBody); continue; } //Check if response exists. responseBody = messageOutput.GetResponse(amfBody); if (responseBody != null) { continue; } try { MessageBroker messageBroker = _endpoint.GetMessageBroker(); RemotingService remotingService = messageBroker.GetService(RemotingService.RemotingServiceId) as RemotingService; if (remotingService == null) { string serviceNotFound = __Res.GetString(__Res.Service_NotFound, RemotingService.RemotingServiceId); responseBody = new ErrorResponseBody(amfBody, new FluorineException(serviceNotFound)); messageOutput.AddBody(responseBody); if (log.IsErrorEnabled) { log.Error(serviceNotFound); } continue; } Destination destination = null; if (destination == null) { destination = remotingService.GetDestinationWithSource(amfBody.TypeName); } if (destination == null) { destination = remotingService.DefaultDestination; } //At this moment we got a destination with the exact source or we have a default destination with the "*" source. if (destination == null) { string destinationNotFound = __Res.GetString(__Res.Destination_NotFound, amfBody.TypeName); responseBody = new ErrorResponseBody(amfBody, new FluorineException(destinationNotFound)); messageOutput.AddBody(responseBody); if (log.IsErrorEnabled) { log.Error(destinationNotFound); } continue; } try { remotingService.CheckSecurity(destination); } catch (UnauthorizedAccessException exception) { responseBody = new ErrorResponseBody(amfBody, exception); if (log.IsDebugEnabled) { log.Debug(exception.Message); } continue; } //Cache check string source = amfBody.TypeName + "." + amfBody.Method; IList parameterList = amfBody.GetParameterList(); string key = FluorineFx.Configuration.CacheMap.GenerateCacheKey(source, parameterList); if (FluorineConfiguration.Instance.CacheMap.ContainsValue(key)) { object result = FluorineFx.Configuration.FluorineConfiguration.Instance.CacheMap.Get(key); if (result != null) { if (log != null && log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.Cache_HitKey, source, key)); } responseBody = new ResponseBody(amfBody, result); messageOutput.AddBody(responseBody); continue; } } object instance; FactoryInstance factoryInstance = destination.GetFactoryInstance(); lock (factoryInstance) { factoryInstance.Source = amfBody.TypeName; if (FluorineContext.Current.ActivationMode != null)//query string can override the activation mode { factoryInstance.Scope = FluorineContext.Current.ActivationMode; } instance = factoryInstance.Lookup(); } if (instance != null) { try { bool isAccessible = TypeHelper.GetTypeIsAccessible(instance.GetType()); if (!isAccessible) { string msg = __Res.GetString(__Res.Type_InitError, amfBody.TypeName); if (log.IsErrorEnabled) { log.Error(msg); } responseBody = new ErrorResponseBody(amfBody, new FluorineException(msg)); messageOutput.AddBody(responseBody); continue; } MethodInfo mi = null; if (!amfBody.IsRecordsetDelivery) { mi = MethodHandler.GetMethod(instance.GetType(), amfBody.Method, parameterList); } else { //will receive recordsetid only (ignore) mi = instance.GetType().GetMethod(amfBody.Method); } if (mi != null) { object[] roleAttributes = mi.GetCustomAttributes(typeof(RoleAttribute), true); if (roleAttributes != null && roleAttributes.Length == 1) { RoleAttribute roleAttribute = roleAttributes[0] as RoleAttribute; string[] roles = roleAttribute.Roles.Split(','); bool authorized = messageBroker.LoginManager.DoAuthorization(roles); if (!authorized) { throw new UnauthorizedAccessException(__Res.GetString(__Res.Security_AccessNotAllowed)); } } #region Invocation handling PageSizeAttribute pageSizeAttribute = null; MethodInfo miCounter = null; object[] pageSizeAttributes = mi.GetCustomAttributes(typeof(PageSizeAttribute), true); if (pageSizeAttributes != null && pageSizeAttributes.Length == 1) { pageSizeAttribute = pageSizeAttributes[0] as PageSizeAttribute; miCounter = instance.GetType().GetMethod(amfBody.Method + "Count"); if (miCounter != null && miCounter.ReturnType != typeof(System.Int32)) { miCounter = null; //check signature } } ParameterInfo[] parameterInfos = mi.GetParameters(); //Try to handle missing/optional parameters. object[] args = new object[parameterInfos.Length]; if (!amfBody.IsRecordsetDelivery) { if (args.Length != parameterList.Count) { string msg = __Res.GetString(__Res.Arg_Mismatch, parameterList.Count, mi.Name, args.Length); if (log != null && log.IsErrorEnabled) { log.Error(msg); } responseBody = new ErrorResponseBody(amfBody, new ArgumentException(msg)); messageOutput.AddBody(responseBody); continue; } parameterList.CopyTo(args, 0); if (pageSizeAttribute != null) { PagingContext pagingContext = new PagingContext(pageSizeAttribute.Offset, pageSizeAttribute.Limit); PagingContext.SetPagingContext(pagingContext); } } else { if (amfBody.Target.EndsWith(".release")) { responseBody = new ResponseBody(amfBody, null); messageOutput.AddBody(responseBody); continue; } string recordsetId = parameterList[0] as string; string recordetDeliveryParameters = amfBody.GetRecordsetArgs(); byte[] buffer = System.Convert.FromBase64String(recordetDeliveryParameters); recordetDeliveryParameters = System.Text.Encoding.UTF8.GetString(buffer); if (recordetDeliveryParameters != null && recordetDeliveryParameters != string.Empty) { string[] stringParameters = recordetDeliveryParameters.Split(new char[] { ',' }); for (int j = 0; j < stringParameters.Length; j++) { if (stringParameters[j] == string.Empty) { args[j] = null; } else { args[j] = stringParameters[j]; } } //TypeHelper.NarrowValues(argsStore, parameterInfos); } PagingContext pagingContext = new PagingContext(System.Convert.ToInt32(parameterList[1]), System.Convert.ToInt32(parameterList[2])); PagingContext.SetPagingContext(pagingContext); } TypeHelper.NarrowValues(args, parameterInfos); try { InvocationHandler invocationHandler = new InvocationHandler(mi); object result = invocationHandler.Invoke(instance, args); if (FluorineConfiguration.Instance.CacheMap != null && FluorineConfiguration.Instance.CacheMap.ContainsCacheDescriptor(source)) { //The result should be cached CacheableObject cacheableObject = new CacheableObject(source, key, result); FluorineConfiguration.Instance.CacheMap.Add(cacheableObject.Source, cacheableObject.CacheKey, cacheableObject); result = cacheableObject; } responseBody = new ResponseBody(amfBody, result); if (pageSizeAttribute != null) { int totalCount = 0; string recordsetId = null; IList list = amfBody.GetParameterList(); string recordetDeliveryParameters = null; if (!amfBody.IsRecordsetDelivery) { //fist call paging object[] argsStore = new object[list.Count]; list.CopyTo(argsStore, 0); recordsetId = System.Guid.NewGuid().ToString(); if (miCounter != null) { //object[] counterArgs = new object[0]; totalCount = (int)miCounter.Invoke(instance, args); } string[] stringParameters = new string[argsStore.Length]; for (int j = 0; j < argsStore.Length; j++) { if (argsStore[j] != null) { stringParameters[j] = argsStore[j].ToString(); } else { stringParameters[j] = string.Empty; } } recordetDeliveryParameters = string.Join(",", stringParameters); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(recordetDeliveryParameters); recordetDeliveryParameters = System.Convert.ToBase64String(buffer); } else { recordsetId = amfBody.GetParameterList()[0] as string; } if (result is DataTable) { DataTable dataTable = result as DataTable; dataTable.ExtendedProperties["TotalCount"] = totalCount; dataTable.ExtendedProperties["Service"] = recordetDeliveryParameters + "/" + amfBody.Target; dataTable.ExtendedProperties["RecordsetId"] = recordsetId; if (amfBody.IsRecordsetDelivery) { dataTable.ExtendedProperties["Cursor"] = Convert.ToInt32(list[list.Count - 2]); dataTable.ExtendedProperties["DynamicPage"] = true; } } } } catch (UnauthorizedAccessException exception) { responseBody = new ErrorResponseBody(amfBody, exception); if (log.IsDebugEnabled) { log.Debug(exception.Message); } } catch (Exception exception) { if (exception is TargetInvocationException && exception.InnerException != null) { responseBody = new ErrorResponseBody(amfBody, exception.InnerException); } else { responseBody = new ErrorResponseBody(amfBody, exception); } if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.Invocation_Failed, mi.Name, exception.Message)); } } #endregion Invocation handling } else { responseBody = new ErrorResponseBody(amfBody, new MissingMethodException(amfBody.TypeName, amfBody.Method)); } } finally { factoryInstance.OnOperationComplete(instance); } } else { responseBody = new ErrorResponseBody(amfBody, new TypeInitializationException(amfBody.TypeName, null)); } } catch (Exception exception) { if (log != null && log.IsErrorEnabled) { log.Error(exception.Message + String.Format(" (Type: {0}, Method: {1})", amfBody.TypeName, amfBody.Method), exception); } responseBody = new ErrorResponseBody(amfBody, exception); } messageOutput.AddBody(responseBody); } }
public override Task Invoke(AMFContext context) { MessageOutput messageOutput = context.MessageOutput; for (int i = 0; i < context.AMFMessage.BodyCount; i++) { AMFBody amfBody = context.AMFMessage.GetBodyAt(i); ResponseBody responseBody = null; //Check for Flex2 messages and skip if (amfBody.IsEmptyTarget) { continue; } //Check if response exists. responseBody = messageOutput.GetResponse(amfBody); if (responseBody != null) { continue; } try { MessageBroker messageBroker = _endpoint.GetMessageBroker(); RemotingService remotingService = messageBroker.GetService(RemotingService.RemotingServiceId) as RemotingService; if (remotingService == null) { string serviceNotFound = __Res.GetString(__Res.Service_NotFound, RemotingService.RemotingServiceId); responseBody = new ErrorResponseBody(amfBody, new AMFException(serviceNotFound)); messageOutput.AddBody(responseBody); continue; } Destination destination = null; if (destination == null) { destination = remotingService.GetDestinationWithSource(amfBody.TypeName); } if (destination == null) { destination = remotingService.DefaultDestination; } //At this moment we got a destination with the exact source or we have a default destination with the "*" source. if (destination == null) { string destinationNotFound = __Res.GetString(__Res.Destination_NotFound, amfBody.TypeName); responseBody = new ErrorResponseBody(amfBody, new AMFException(destinationNotFound)); messageOutput.AddBody(responseBody); continue; } //Cache check string source = amfBody.TypeName + "." + amfBody.Method; IList parameterList = amfBody.GetParameterList(); FactoryInstance factoryInstance = destination.GetFactoryInstance(); factoryInstance.Source = amfBody.TypeName; object instance = factoryInstance.Lookup(); if (instance != null) { bool isAccessible = TypeHelper.GetTypeIsAccessible(instance.GetType()); if (!isAccessible) { string msg = __Res.GetString(__Res.Type_InitError, amfBody.TypeName); responseBody = new ErrorResponseBody(amfBody, new AMFException(msg)); messageOutput.AddBody(responseBody); continue; } MethodInfo mi = null; if (!amfBody.IsRecordsetDelivery) { mi = MethodHandler.GetMethod(instance.GetType(), amfBody.Method, amfBody.GetParameterList()); } else { //will receive recordsetid only (ignore) mi = instance.GetType().GetMethod(amfBody.Method); } if (mi != null) { #region Invocation handling ParameterInfo[] parameterInfos = mi.GetParameters(); //Try to handle missing/optional parameters. object[] args = new object[parameterInfos.Length]; if (!amfBody.IsRecordsetDelivery) { if (args.Length != parameterList.Count) { string msg = __Res.GetString(__Res.Arg_Mismatch, parameterList.Count, mi.Name, args.Length); responseBody = new ErrorResponseBody(amfBody, new ArgumentException(msg)); messageOutput.AddBody(responseBody); continue; } parameterList.CopyTo(args, 0); } else { if (amfBody.Target.EndsWith(".release")) { responseBody = new ResponseBody(amfBody, null); messageOutput.AddBody(responseBody); continue; } string recordsetId = parameterList[0] as string; string recordetDeliveryParameters = amfBody.GetRecordsetArgs(); byte[] buffer = System.Convert.FromBase64String(recordetDeliveryParameters); recordetDeliveryParameters = System.Text.Encoding.UTF8.GetString(buffer); if (recordetDeliveryParameters != null && recordetDeliveryParameters != string.Empty) { string[] stringParameters = recordetDeliveryParameters.Split(new char[] { ',' }); for (int j = 0; j < stringParameters.Length; j++) { if (stringParameters[j] == string.Empty) { args[j] = null; } else { args[j] = stringParameters[j]; } } //TypeHelper.NarrowValues(argsStore, parameterInfos); } } TypeHelper.NarrowValues(args, parameterInfos); try { InvocationHandler invocationHandler = new InvocationHandler(mi); object result = invocationHandler.Invoke(instance, args); responseBody = new ResponseBody(amfBody, result); } catch (UnauthorizedAccessException exception) { responseBody = new ErrorResponseBody(amfBody, exception); } catch (Exception exception) { if (exception is TargetInvocationException && exception.InnerException != null) { responseBody = new ErrorResponseBody(amfBody, exception.InnerException); } else { responseBody = new ErrorResponseBody(amfBody, exception); } } #endregion Invocation handling } else { responseBody = new ErrorResponseBody(amfBody, new MissingMethodException(amfBody.TypeName, amfBody.Method)); } } else { responseBody = new ErrorResponseBody(amfBody, new TypeInitializationException(amfBody.TypeName, null)); } } catch (Exception exception) { responseBody = new ErrorResponseBody(amfBody, exception); } messageOutput.AddBody(responseBody); } return(Task.FromResult <object>(null)); }
public RemotingServiceProxy() { remotingServiceObject = new RemotingService(); }
public override void LoadProperty(object obj, string propertyName) { if (this.url.Length < 1) { throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); } RemotingService rs = new RemotingService(this.Context, url); IMarshalingTransformer transformer = new MarshalingTransformer(Context); IObjectManager om = Context.ObjectManager; IClassMap classMap = Context.DomainMap.MustGetClassMap(obj.GetType()); IPropertyMap propertyMap = classMap.MustGetPropertyMap(propertyName); MarshalReference mr = transformer.FromObjectAsReference(obj); string xmlObject = (string)Formatter.Serialize(mr); if (useCompression && this.compressor != null) { xmlObject = this.compressor.Compress(xmlObject); } bool doUseCompression = this.useCompression; if (this.compressor == null) { doUseCompression = false; } string result = rs.LoadProperty(xmlObject, propertyName, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) { result = this.compressor.Decompress(result); } if (propertyMap.IsCollection) { if (propertyMap.ReferenceType == ReferenceType.None) { } else { //Refresh issues!!! (the objects in the list being deserialized may exist in the cache!!) MarshalObjectList mol = (MarshalObjectList)Formatter.Deserialize(result, typeof(MarshalObjectList)); IList freshList = transformer.ToObjectList(mol, RefreshBehaviorType.DefaultBehavior, new ArrayList()); //Context.IdentityMap.RegisterLoadedObject(obj); IList orgList = (IList)om.GetPropertyValue(obj, propertyName); LoadReferenceList(freshList, orgList, om, obj, propertyMap); this.Context.InverseManager.NotifyPropertyLoad(obj, propertyMap, orgList); } } else { if (propertyMap.ReferenceType == ReferenceType.None) { MarshalProperty mp = (MarshalProperty)Formatter.Deserialize(result, typeof(MarshalProperty)); transformer.ToProperty(obj, mp, propertyMap, RefreshBehaviorType.DefaultBehavior); } else { if (result.Length > 0) { MarshalObject mo = (MarshalObject)Formatter.Deserialize(result, typeof(MarshalObject)); string identity = transformer.GetIdentity(mo); IClassMap refClassMap = Context.DomainMap.MustGetClassMap(mo.Type); Type refType = Context.AssemblyManager.MustGetTypeFromClassMap(refClassMap); object refObject = Context.GetObjectById(identity, refType, true); if (om.GetObjectStatus(refObject) == ObjectStatus.NotLoaded) { transformer.ToObject(mo, ref refObject); } // object refObject = Context.TryGetObjectById(identity, refType, true); // if (refObject == null) // { // refObject = Context.GetObjectById(identity, refType, true); // transformer.ToObject(mo, ref refObject); // } om.SetPropertyValue(obj, propertyName, refObject); om.SetOriginalPropertyValue(obj, propertyName, refObject); om.SetNullValueStatus(obj, propertyName, false); this.Context.InverseManager.NotifyPropertyLoad(obj, propertyMap, refObject); } else { om.SetPropertyValue(obj, propertyName, null); om.SetOriginalPropertyValue(obj, propertyName, null); om.SetNullValueStatus(obj, propertyName, true); } } } }