コード例 #1
0
        internal Byte[] TryEncodePacket(LdapMessage message)
        {
            OperationMapper mapper  = SingletonContainer.GetOperationMapper();
            Type            encoder = mapper.GetEncoderForTag(message.ProtocolOp.GetTag());

            AsnWriter writer = new AsnWriter(AsnEncodingRules.BER);

            object?result = null;

            using (writer.PushSequence())
            {
                writer.WriteInteger(message.MessageId);

                var    parameters     = new object[] { writer, message.ProtocolOp };
                object?invokableClass = FormatterServices.GetUninitializedObject(encoder);

                if (invokableClass != null)
                {
                    MethodInfo?method = encoder.GetMethod("TryEncode");
                    if (method != null)
                    {
                        result = method.Invoke(invokableClass, parameters);
                    }
                }
            }

            if (result != null)
            {
                Byte[] data = writer.Encode();
                return(data);
            }

            throw new NotImplementedException("The encoder for " + message.ProtocolOp.GetTag() + " is not implemented.");
        }
コード例 #2
0
        /// <summary>
        /// 查找电脑信息
        /// </summary>
        /// <param name="javascriptCallback"></param>
        public NettojsResponse RegisterNettojs(string jsonNettojsParameters)
        {
            List <NettojsParameter> nettojsParameters = JsonConvert.DeserializeObject <List <NettojsParameter> >(jsonNettojsParameters);

            try {
                nettojsParameters.ForEach(nettojsParameter =>
                {
                    if (nettojsParameter.Parameters != null && nettojsParameter.Parameters.Count > 0)
                    {
                        SingletonContainer.Get <JavascriptContent>().NettojsMap.Add(nettojsParameter.ShortName,
                                                                                    nettojsParameter.Parameters.ToObject(Type.GetType(nettojsParameter.FullName)));
                    }
                    else
                    {
                        SingletonContainer.Get <JavascriptContent>().NettojsMap.Add(nettojsParameter.ShortName,
                                                                                    Activator.CreateInstance(Type.GetType(nettojsParameter.FullName)));
                    }
                });
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                return(new NettojsResponse()
                {
                    Code = NettojsResponse.EXCEPTION, Message = e.ToString()
                });
            }

            return(new NettojsResponse());
        }
コード例 #3
0
        public AOPAttribute(params Type[] InterceptorTypes)
        {
            if (InterceptorTypes is null)
            {
                throw new ArgumentNullException(nameof(InterceptorTypes));
            }

            var Interceptors = new List <AOPInterceptor>();

            foreach (var InterceptorType in InterceptorTypes)
            {
                if (!typeof(AOPInterceptor).IsAssignableFrom(InterceptorType))
                {
                    throw new AOPException($"{InterceptorType.FullName}is not an AOP type");
                }

                AOPInterceptor interceptor = SingletonContainer.Get(InterceptorType.FullName,
                                                                    () => (AOPInterceptor)Activator.CreateInstance(InterceptorType));

                Interceptors.Add(interceptor);
                //Interceptors.Add((AOPInterceptor)Activator.CreateInstance(InterceptorType));
            }

            this.Interceptors = Interceptors.ToArray();
        }
コード例 #4
0
 public void SutIsCommerceServiceContainer(SingletonContainer sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <ICommerceServiceContainer>(sut);
     // Teardown
 }
コード例 #5
0
    public T GetInstance(params object[] @params)
    {
        if (!SingletonContainer.ContainsType(typeof(T)))
        {
            SingletonContainer.CreateInstance(typeof(T), @params);
        }

        return((T)SingletonContainer.GetInstance(typeof(T)));
    }
コード例 #6
0
        public void ResolveWillReturnCorrectType(SingletonContainer sut)
        {
            // Fixture setup
            // Exercise system
            var result = sut.ResolveProductManagementService();

            // Verify outcome
            Assert.IsAssignableFrom <ProductManagementService>(result);
            // Teardown
        }
コード例 #7
0
        public void ResolveWillReturnResultWithCorrectRepository(SingletonContainer sut)
        {
            // Fixture setup
            // Exercise system
            var result = (ProductManagementService)sut.ResolveProductManagementService();

            // Verify outcome
            Assert.IsAssignableFrom <InMemoryProductRepository>(result.Repository);
            // Teardown
        }
コード例 #8
0
        public void ResolveTwiceWillReturnDifferentInstances(SingletonContainer sut)
        {
            // Fixture setup
            var unexpected = sut.ResolveProductManagementService();
            // Exercise system
            var result = sut.ResolveProductManagementService();

            // Verify outcome
            Assert.NotSame(unexpected, result);
            // Teardown
        }
コード例 #9
0
        internal void StartReceiving()
        {
            Task networkTask = new Task(async() =>
            {
                NetworkStream unencryptedStream = Client.GetStream();
                SslStream sslStream             = new SslStream(unencryptedStream);

                IPEndPoint?endpoint = (IPEndPoint?)Client.Client.RemoteEndPoint;
                if (endpoint == null)
                {
                    throw new Exception("IP address is null");
                }

                ClientContext clientContext = new ClientContext(endpoint.Address);
                DecisionEngine engine       = new DecisionEngine(clientContext);

                bool _initializedTls = false;

                while (_clientIsConnected)
                {
                    Stream rawOrSslStream = (_useStartTls) ? sslStream : unencryptedStream;

                    try
                    {
                        if (_useStartTls && !_initializedTls)
                        {
                            await sslStream.AuthenticateAsServerAsync(new SslServerAuthenticationOptions
                            {
                                ServerCertificate = SingletonContainer.GetCertificate(),
                            });
                            _initializedTls = true;
                        }

                        Byte[] data = await ReadFullyAsync(rawOrSslStream);

                        await HandleAsync(data, rawOrSslStream, engine);
                    }
                    catch (Exception e)
                    {
                        ILogger?logger = SingletonContainer.GetLogger();
                        if (logger != null)
                        {
                            logger.LogException(e);
                        }

                        break;
                    }
                }

                Client.Close();
            });

            networkTask.Start();
        }
コード例 #10
0
        public void MapperIsShared(SingletonContainer sut)
        {
            // Fixture setup
            var other = (ProductManagementService)sut.ResolveProductManagementService();
            // Exercise system
            var result = (ProductManagementService)sut.ResolveProductManagementService();

            // Verify outcome
            Assert.Same(other.ContractMapper, result.ContractMapper);
            // Teardown
        }
コード例 #11
0
        internal async Task <List <LdapMessage> > GenerateReply(LdapPacketParserLibrary.Models.LdapMessage message)
        {
            // Authentication check
            List <Type> publicOperations = new List <Type> {
                typeof(BindRequest),
                typeof(UnbindRequest),
                typeof(ExtendedRequest),
            };

            if (!_clientContext.IsAuthenticated && !publicOperations.Contains(message.ProtocolOp.GetType()))
            {
                return(new List <LdapMessage>()
                {
                    new LdapMessage(message.MessageId, new BindResponse(new LdapResult(LdapResult.ResultCodeEnum.InappropriateAuthentication, null, null)))
                });
            }

            LdapEvents eventListener = SingletonContainer.GetLdapEventListener();

            Type protocolType = message.ProtocolOp.GetType();
            Type handlerType  = SingletonContainer.GetHandlerMapper().GetHandlerForType(protocolType);

            var    parameters     = new object[] { _clientContext, eventListener, message.ProtocolOp };
            object?invokableClass = FormatterServices.GetUninitializedObject(handlerType);

            if (invokableClass != null)
            {
                MethodInfo?method = handlerType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Single(x => x.Name.EndsWith("Handle"));

                if (method != null)
                {
                    Task         resultTask = (Task)method.Invoke(invokableClass, parameters);
                    await        resultTask;
                    PropertyInfo?propertInfo = resultTask.GetType().GetProperty("Result");
                    object       result      = propertInfo.GetValue(resultTask);

                    if (result != null)
                    {
                        List <LdapMessage> messages = new List <LdapMessage>();

                        HandlerReply handlerReply = (HandlerReply)result;
                        foreach (IProtocolOp op in handlerReply._protocolOps)
                        {
                            messages.Add(new LdapMessage(message.MessageId, op));
                        }

                        return(messages);
                    }
                }
            }

            throw new System.Exception();
        }
コード例 #12
0
        async Task <HandlerReply> IRequestHandler <ExtendedRequest> .Handle(ClientContext context, LdapEvents eventListener, ExtendedRequest operation)
        {
            if (operation.RequestName == StartTLS && SingletonContainer.GetCertificate() != null)
            {
                context.HasEncryptedConnection = true;
                return(new HandlerReply(new List <IProtocolOp> {
                    new ExtendedOperationResponse(
                        new LdapResult(LdapResult.ResultCodeEnum.Success, null, null),
                        StartTLS,
                        null
                        ),
                }));
            }

            LdapResult   ldapResult   = new LdapResult(LdapResult.ResultCodeEnum.ProtocolError, null, null);
            BindResponse bindResponse = new BindResponse(ldapResult);

            return(new HandlerReply(new List <IProtocolOp> {
                bindResponse
            }));
        }
コード例 #13
0
        private IProtocolOp DecodeApplicationData(int tagValue, AsnReader reader)
        {
            OperationMapper mapper  = SingletonContainer.GetOperationMapper();
            Type            decoder = mapper.GetDecoderForTag(tagValue);

            var    parameters     = new object[] { reader };
            object?invokableClass = FormatterServices.GetUninitializedObject(decoder);

            if (invokableClass != null)
            {
                MethodInfo?method = decoder.GetMethod("TryDecode");
                if (method != null)
                {
                    object result = method.Invoke(invokableClass, parameters);
                    if (result != null)
                    {
                        return((IProtocolOp)result);
                    }
                }
            }

            throw new NotImplementedException("The decoder for " + tagValue + " is not implemented.");
        }
コード例 #14
0
 public NettojsResponse SetProperty(string objName, string propertyName, string json)
 {
     return(SingletonContainer.Get <JavascriptContent>().Set(objName, propertyName, json));
 }
コード例 #15
0
 public NettojsResponse InvokeNettojs(string objName, string methodName, string json)
 {
     return(SingletonContainer.Get <JavascriptContent>().Invoke(objName, methodName, json));
 }
コード例 #16
0
 protected override void RegisterTypes(IContainerRegistry containerRegistry)
 {
     SingletonContainer.RegisterTypes(containerRegistry);
 }
コード例 #17
0
 public SingletonController(SingletonContainer singletonContainer)
 {
     SingletonContainer = singletonContainer;
 }
コード例 #18
0
 public MochouCache()
 {
     config = SingletonContainer.Get <CacheConfig>();
 }
コード例 #19
0
 public SchoolPrincipal(string token)
 {
     _token = token;
     _container=SingletonContainer.Instance;
 }