コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceResponse"/> class.
 /// </summary>
 /// <param name="soapFaultDetails">The SOAP fault details.</param>
 internal ServiceResponse(SoapFaultDetails soapFaultDetails)
 {
     this.result = ServiceResult.Error;
     this.errorCode = soapFaultDetails.ResponseCode;
     this.errorMessage = soapFaultDetails.FaultString;
     this.errorDetails = soapFaultDetails.ErrorDetails;
 }
コード例 #2
0
 /// <summary>
 /// Constructor for Confirmed ServiceError.
 /// </summary>
 internal GXDLMSException(ConfirmedServiceError service, ServiceError type, byte value)
     : base("ServiceError " + GetConfirmedServiceError(service) + " exception. " + GetServiceError(type) + " " + GetServiceErrorValue(type, value))
 {
     ConfirmedServiceError = service;
     ServiceError = type;
     ServiceErrorValue = value;
 }
コード例 #3
0
ファイル: ServiceWrapper.cs プロジェクト: Jabe/procstub
        public static bool CreateService(string serviceName, string displayName, ServiceAccess access,
            ServiceTypes type, ServiceStart start, ServiceError error, string path,
            string orderGroup, string tagId, string dep, string username, string password, string server = null)
        {
            IntPtr manager = IntPtr.Zero;
            IntPtr service = IntPtr.Zero;

            try
            {
                manager = OpenSCManager(server, null, ScmAccess.ScManagerAllAccess);

                if (manager != IntPtr.Zero)
                {
                    service = CreateService(manager, serviceName, displayName, (uint) access, (uint) type, (uint) start,
                        (uint) error, path, orderGroup, tagId, dep, username, password);

                    if (service != IntPtr.Zero)
                    {
                        return true;
                    }
                }
            }
            finally
            {
                if (service != IntPtr.Zero) CloseServiceHandle(service);
                if (manager != IntPtr.Zero) CloseServiceHandle(manager);
            }

            return false;
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceResponse"/> class.
 /// This is intended to be used by unit tests to create a fake service error response
 /// </summary>
 /// <param name="responseCode">Response code</param>
 /// <param name="errorMessage">Detailed error message</param>
 internal ServiceResponse(ServiceError responseCode, string errorMessage)
 {
     this.result = ServiceResult.Error;
     this.errorCode = responseCode;
     this.errorMessage = errorMessage;
     this.errorDetails = null;
 }
コード例 #5
0
ファイル: Controller.cs プロジェクト: webappsuk/CoreLibraries
 private static extern IntPtr CreateService(
     IntPtr hSCManager,
     string lpServiceName,
     string lpDisplayName,
     ServiceAccessRights dwDesiredAccess,
     int dwServiceType,
     ServiceBootFlag dwStartType,
     ServiceError dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     IntPtr lpdwTagId,
     string lpDependencies,
     string lp,
     string lpPassword);
コード例 #6
0
        /// <summary>
        /// Creates the specified service.
        /// </summary>
        /// <param name="ServiceName">Name of the service.</param>
        /// <param name="DisplayName">The display name.</param>
        /// <param name="ServiceAccess">The service access.</param>
        /// <param name="ServiceType">Type of the service.</param>
        /// <param name="ServiceStart">The service start.</param>
        /// <param name="ServiceError">The service error.</param>
        /// <param name="File">The file.</param>
        public static IntPtr Create(string ServiceName, string DisplayName, ServiceAccess ServiceAccess, ServiceType ServiceType, ServiceStart ServiceStart, ServiceError ServiceError, FileInfo File)
        {
            IntPtr ServiceManager = WinApi.OpenSCManager(null, null, (uint)ScmAccess.ScManagerAllAccess);

            if (ServiceManager == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            IntPtr Service = WinApi.CreateService(
                ServiceManager,
                ServiceName,
                DisplayName,
                (uint)ServiceAccess,
                (uint)ServiceType,
                (uint)ServiceStart,
                (uint)ServiceError,
                File.FullName,
                null, null, null, null, null
                );

            WinApi.CloseServiceHandle(ServiceManager);

            if (Service == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            return(Service);
        }
コード例 #7
0
        private static void OnBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, 
            string serviceName, string regtype, string replyDomain, IntPtr context)
        {
            var handle = GCHandle.FromIntPtr(context);
            var serviceBrowser = handle.Target as ServiceBrowser;
            BrowseService service = new BrowseService();
            service.Flags = flags;
            service.Name = serviceName;
            service.RegType = regtype;
            service.ReplyDomain = replyDomain;
            service.InterfaceIndex = interfaceIndex;
            service.AddressProtocol = serviceBrowser.address_protocol;

            Log.To.Discovery.V(TAG, "{0} (0x{1}) entered OnBrowseReply (found={2} flags={3})", 
                serviceBrowser, sdRef.Raw.ToString("X"), service, flags);
            
            ServiceBrowseEventArgs args = new ServiceBrowseEventArgs(
                service, (flags & ServiceFlags.MoreComing) != 0);
            
            if((flags & ServiceFlags.Add) != 0) {
                lock (serviceBrowser.service_table) {
                    if (serviceBrowser.service_table.ContainsKey (serviceName)) {
                        serviceBrowser.service_table[serviceName] = service;
                    } else {
                        serviceBrowser.service_table.Add (serviceName, service);
                    }
                }
                
                ServiceBrowseEventHandler handler = serviceBrowser._serviceAdded;
                if(handler != null) {
                    handler(serviceBrowser, args);
                }
            } else {
                lock (serviceBrowser.service_table) {
                    if (serviceBrowser.service_table.ContainsKey (serviceName)) {
                        serviceBrowser.service_table.Remove (serviceName);
                    }
                }
                
                ServiceBrowseEventHandler handler = serviceBrowser._serviceRemoved;
                if(handler != null) {
                    handler(serviceBrowser, args);
                }

                service.Dispose();
            }
        }
コード例 #8
0
 private static void OnRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode,
     string name, string regtype, string domain, IntPtr context)
 {
     var handle = GCHandle.FromIntPtr(context);
     var registerService = handle.Target as RegisterService;
     RegisterServiceEventArgs args = new RegisterServiceEventArgs();
     
     args.Service = registerService;
     args.IsRegistered = false;
     args.ServiceError = (ServiceErrorCode)errorCode;
     
     if(errorCode == ServiceError.NoError) {
         registerService.Name = name;
         registerService.RegType = regtype;
         registerService.ReplyDomain = domain;
         args.IsRegistered = true;
     }
     
     RegisterServiceEventHandler handler = registerService.Response;
     if(handler != null) {
         handler(registerService, args);
     }
 }
コード例 #9
0
        /// <summary>
        /// Helper method executing the REST request.
        /// </summary>
        /// <typeparam name="TRequest">Type of request.</typeparam>
        /// <typeparam name="TResponse">Type of response.</typeparam>
        /// <param name="faceRectangles">Optional list of face rectangles.</param>
        /// <param name="requestBody">Content of the HTTP request.</param>
        /// <returns></returns>
        private async Task <TResponse> SendRequestAsync <TRequest, TResponse>(Rectangle[] faceRectangles, TRequest requestBody)
        {
            var httpMethod = HttpMethod.Post;
            var requestUri = new StringBuilder();

            requestUri.AppendFormat("{0}/{1}", ServiceHost, RecognizeQuery);
            requestUri.Append('?');
            if (faceRectangles != null)
            {
                requestUri.Append(FaceRectangles);
                requestUri.Append('=');
                foreach (var rectangle in faceRectangles)
                {
                    requestUri.AppendFormat("{0},{1},{2},{3};",
                                            rectangle.Left,
                                            rectangle.Top,
                                            rectangle.Width,
                                            rectangle.Height);
                }
                requestUri.Remove(requestUri.Length - 1, 1); // drop last comma
                requestUri.Append('&');
            }
            requestUri.AppendFormat("{0}={1}",
                                    SubscriptionKeyName,
                                    _subscriptionKey);

            var request = new HttpRequestMessage(httpMethod, ServiceHost);

            request.RequestUri = new Uri(requestUri.ToString());

            if (requestBody != null)
            {
                if (requestBody is Stream)
                {
                    request.Content = new StreamContent(requestBody as Stream);
                    request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                }
                else
                {
                    request.Content = new StringContent(JsonConvert.SerializeObject(requestBody, s_settings), Encoding.UTF8, JsonHeader);
                }
            }

            HttpResponseMessage response = await _httpClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                string responseContent = null;
                if (response.Content != null)
                {
                    responseContent = await response.Content.ReadAsStringAsync();
                }

                if (!string.IsNullOrWhiteSpace(responseContent))
                {
                    return(JsonConvert.DeserializeObject <TResponse>(responseContent, s_settings));
                }

                return(default(TResponse));
            }
            else
            {
                if (response.Content != null && response.Content.Headers.ContentType.MediaType.Contains(JsonHeader))
                {
                    var errorObjectString = await response.Content.ReadAsStringAsync();

                    ServiceError errorCollection = JsonConvert.DeserializeObject <ServiceError>(errorObjectString);
                    if (errorCollection != null)
                    {
                        throw new ClientException(errorCollection.Error, response.StatusCode);
                    }
                }

                response.EnsureSuccessStatusCode();
            }

            return(default(TResponse));
        }
コード例 #10
0
        private void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
            ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, 
            IntPtr rdata, uint ttl, IntPtr context)
        {
            switch(rrtype) {
                case ServiceType.A:
                    IPAddress address;

                    if(rdlen == 4) {   
                        // ~4.5 times faster than Marshal.Copy into byte[4]
                        uint address_raw = (uint)(Marshal.ReadByte (rdata, 3) << 24);
                        address_raw |= (uint)(Marshal.ReadByte (rdata, 2) << 16);
                        address_raw |= (uint)(Marshal.ReadByte (rdata, 1) << 8);
                        address_raw |= (uint)Marshal.ReadByte (rdata, 0);

                        address = new IPAddress(address_raw);
                    } else if(rdlen == 16) {
                        byte [] address_raw = new byte[rdlen];
                        Marshal.Copy(rdata, address_raw, 0, rdlen);
                        address = new IPAddress(address_raw, interfaceIndex);
                    } else {
                        break;
                    }

                    if(hostentry == null) {
                        hostentry = new IPHostEntry();
                        hostentry.HostName = hosttarget;
                    }
                    
                    if(hostentry.AddressList != null) {
                        ArrayList list = new ArrayList(hostentry.AddressList);
                        list.Add(address);
                        hostentry.AddressList = list.ToArray(typeof(IPAddress)) as IPAddress [];
                    } else {
                        hostentry.AddressList = new IPAddress [] { address };
                    }
                    
                    ServiceResolvedEventHandler handler = Resolved;
                    if(handler != null) {
                        handler(this, new ServiceResolvedEventArgs(this));
                    }
                    
                    break;
                case ServiceType.TXT:
                    if(TxtRecord != null) {
                        TxtRecord.Dispose();
                    }
            
                    TxtRecord = new TxtRecord(rdlen, rdata);
                    break;
                default:
                    break;
            }
            
            sdRef.Deallocate();
        }
コード例 #11
0
 public static BabelException FromServiceError(ServiceError error, ErrorKind kind)
 {
     BabelException res;
     switch(kind)
     {
         //case ErrorKind.InvalidArgument: res = new BabelIllegalArgException(error.Details, error.Inner == null ? null : FromServiceError(error.Inner)); break;
         case ErrorKind.InvalidRequest: res = new BabelApplicationException(error.Details, error.Inner == null ? null : FromServiceError(error.Inner, ErrorKind.Unknown)); break; //Inner errors are unknown kind
         default: res = new BabelException(error.Details, error.Inner == null ? null : FromServiceError(error.Inner, ErrorKind.Unknown)); break; //Inner errors are unknown kind
     }
     if(error.Context != null)
     {
         foreach(var kv in error.Context)
         {
             res.Context.Add(kv.Key, kv.Value);
         }
     }
     if(error.Errors != null)
     {
         res.m_errors.AddRange(error.Errors);
     }
     return res;
 }
コード例 #12
0
        /// <summary>
        /// Creates or opens the specified service.
        /// </summary>
        /// <param name="ServiceName">Name of the service.</param>
        /// <param name="DisplayName">The display name.</param>
        /// <param name="ServiceAccess">The service access.</param>
        /// <param name="ServiceType">Type of the service.</param>
        /// <param name="ServiceStart">The service start.</param>
        /// <param name="ServiceError">The service error.</param>
        /// <param name="File">The file.</param>
        public static IntPtr CreateOrOpen(string ServiceName, string DisplayName, ServiceAccess ServiceAccess, ServiceType ServiceType, ServiceStart ServiceStart, ServiceError ServiceError, FileInfo File)
        {
            var Handle = Service.Create(ServiceName, DisplayName, ServiceAccess, ServiceType, ServiceStart, ServiceError, File);

            if (Handle == IntPtr.Zero)
            {
                return(Service.Open(ServiceName, ServiceAccess));
            }

            return(Handle);
        }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceException"/> class.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="message">The message.</param>
 public ServiceException(ServiceError error, string message)
     : base(message)
 {
     this.ServiceError = error;
 }
コード例 #14
0
        /// <summary>
        /// Sends the request asynchronous.
        /// </summary>
        /// <typeparam name="TRequest">The type of the request.</typeparam>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="httpMethod">The HTTP method.</param>
        /// <param name="requestUrl">The request URL.</param>
        /// <param name="requestBody">The request body.</param>
        /// <returns>The response.</returns>
        /// <exception cref="OxfordAPIException">The client exception.</exception>
        private async Task <TResponse> SendRequestAsync <TRequest, TResponse>(HttpMethod httpMethod, string requestUrl, TRequest requestBody)
        {
            var request = new HttpRequestMessage(httpMethod, ServiceHost);

            request.RequestUri = new Uri(requestUrl);
            if (requestBody != null)
            {
                if (requestBody is Stream)
                {
                    request.Content = new StreamContent(requestBody as Stream);
                    request.Content.Headers.ContentType = new MediaTypeHeaderValue(StreamContentTypeHeader);
                }
                else
                {
                    request.Content = new StringContent(JsonConvert.SerializeObject(requestBody, s_settings), Encoding.UTF8, JsonContentTypeHeader);
                }
            }

            HttpResponseMessage response = await _httpClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                string responseContent = null;
                if (response.Content != null)
                {
                    responseContent = await response.Content.ReadAsStringAsync();
                }

                if (!string.IsNullOrWhiteSpace(responseContent))
                {
                    return(JsonConvert.DeserializeObject <TResponse>(responseContent, s_settings));
                }

                return(default(TResponse));
            }
            else
            {
                if (response.Content != null && response.Content.Headers.ContentType.MediaType.Contains(JsonContentTypeHeader))
                {
                    var errorObjectString = await response.Content.ReadAsStringAsync();

                    ClientError ex = JsonConvert.DeserializeObject <ClientError>(errorObjectString);
                    if (ex.Error != null)
                    {
                        throw new FaceAPIException(ex.Error.ErrorCode, ex.Error.Message, response.StatusCode);
                    }
                    else
                    {
                        ServiceError serviceEx = JsonConvert.DeserializeObject <ServiceError>(errorObjectString);
                        if (ex != null)
                        {
                            throw new FaceAPIException(serviceEx.ErrorCode, serviceEx.Message, response.StatusCode);
                        }
                        else
                        {
                            throw new FaceAPIException("Unknown", "Unknown Error", response.StatusCode);
                        }
                    }
                }

                response.EnsureSuccessStatusCode();
            }

            return(default(TResponse));
        }
コード例 #15
0
 public static bool IsError(this ServiceError value)
 {
     return(value != ServiceError.Success);
 }
コード例 #16
0
 public Task SendToRemote(ServiceError error)
 {
     return(SendToRemote(BitConverter.GetBytes(ServiceMessage.HostToNetworkOrder((uint)error))));
 }
コード例 #17
0
ファイル: ServiceInstaller.cs プロジェクト: dvchinh/HTQLNHCS
 private static extern IntPtr CreateService(IntPtr hSCManager, string
                                            lpServiceName, string lpDisplayName, ServiceRights dwDesiredAccess, int
                                            dwServiceType, ServiceBootFlag dwStartType, ServiceError dwErrorControl,
                                            string lpBinaryPathName, string lpLoadOrderGroup, IntPtr lpdwTagId, string
                                            lpDependencies, string lp, string lpPassword);
コード例 #18
0
        private void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
                                        ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen,
                                        IntPtr rdata, uint ttl, IntPtr context)
        {
            switch (rrtype)
            {
            case ServiceType.A:
                IPAddress address;

                if (rdlen == 4)
                {
                    // ~4.5 times faster than Marshal.Copy into byte[4]
                    uint address_raw = (uint)(Marshal.ReadByte(rdata, 3) << 24);
                    address_raw |= (uint)(Marshal.ReadByte(rdata, 2) << 16);
                    address_raw |= (uint)(Marshal.ReadByte(rdata, 1) << 8);
                    address_raw |= (uint)Marshal.ReadByte(rdata, 0);

                    address = new IPAddress(address_raw);
                }
                else if (rdlen == 16)
                {
                    byte [] address_raw = new byte[rdlen];
                    Marshal.Copy(rdata, address_raw, 0, rdlen);
                    address = new IPAddress(address_raw, interfaceIndex);
                }
                else
                {
                    break;
                }

                if (hostentry == null)
                {
                    hostentry          = new IPHostEntry();
                    hostentry.HostName = hosttarget;
                }

                if (hostentry.AddressList != null)
                {
                    ArrayList list = new ArrayList(hostentry.AddressList);
                    list.Add(address);
                    hostentry.AddressList = list.ToArray(typeof(IPAddress)) as IPAddress [];
                }
                else
                {
                    hostentry.AddressList = new IPAddress [] { address };
                }

                ServiceResolvedEventHandler handler = Resolved;
                if (handler != null)
                {
                    handler(this, new ServiceResolvedEventArgs(this));
                }

                break;

            case ServiceType.TXT:
                if (TxtRecord != null)
                {
                    TxtRecord.Dispose();
                }

                TxtRecord = new TxtRecord(rdlen, rdata);
                break;

            default:
                break;
            }

            sdRef.Deallocate();
        }
コード例 #19
0
 internal OwaServiceFaultException(ServiceError serviceError, LocalizedException serviceException) : base(new FaultReason(serviceException.Message))
 {
     this.ServiceError     = serviceError;
     this.ServiceException = serviceException;
 }
コード例 #20
0
        private static void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
            ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, 
            IntPtr rdata, uint ttl, IntPtr context)
        {
            var handle = GCHandle.FromIntPtr(context);
            var browseService = handle.Target as BrowseService;
            switch(rrtype) {
                case ServiceType.A:
                    IPAddress address;

                    if(rdlen == 4) {   
                        // ~4.5 times faster than Marshal.Copy into byte[4]
                        uint address_raw = (uint)(Marshal.ReadByte (rdata, 3) << 24);
                        address_raw |= (uint)(Marshal.ReadByte (rdata, 2) << 16);
                        address_raw |= (uint)(Marshal.ReadByte (rdata, 1) << 8);
                        address_raw |= (uint)Marshal.ReadByte (rdata, 0);

                        address = new IPAddress(address_raw);
                    } else if(rdlen == 16) {
                        byte [] address_raw = new byte[rdlen];
                        Marshal.Copy(rdata, address_raw, 0, rdlen);
                        address = new IPAddress(address_raw, interfaceIndex);
                    } else {
                        break;
                    }

                    if(browseService.hostentry == null) {
                        browseService.hostentry = new IPHostEntry();
                        browseService.hostentry.HostName = browseService.hosttarget;
                    }
                    
                    if(browseService.hostentry.AddressList != null) {
                        ArrayList list = new ArrayList(browseService.hostentry.AddressList);
                        list.Add(address);
                        browseService.hostentry.AddressList = list.ToArray(typeof(IPAddress)) as IPAddress [];
                    } else {
                        browseService.hostentry.AddressList = new IPAddress [] { address };
                    }

                    Log.To.Discovery.V(Tag, "Query record reply received for {0} (0x{1})", browseService, sdRef.Raw.ToString("X"));
                    ServiceResolvedEventHandler handler = browseService._resolved;
                    if(handler != null) {
                        handler(browseService, new ServiceResolvedEventArgs(browseService));
                    }
                    
                    break;
                case ServiceType.TXT:
                    if(browseService.TxtRecord != null) {
                        browseService.TxtRecord.Dispose();
                    }
            
                    browseService.TxtRecord = new TxtRecord(rdlen, rdata);
                    break;
                default:
                    break;
            }
            
            sdRef.Deallocate();
        }
コード例 #21
0
        /// <summary>
        /// Loads response from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="xmlElementName">Name of the XML element.</param>
        internal void LoadFromXml(EwsServiceXmlReader reader, string xmlElementName)
        {
            if (!reader.IsStartElement(XmlNamespace.Messages, xmlElementName))
            {
                reader.ReadStartElement(XmlNamespace.Messages, xmlElementName);
            }

            this.result = reader.ReadAttributeValue<ServiceResult>(XmlAttributeNames.ResponseClass);

            if (this.result == ServiceResult.Success || this.result == ServiceResult.Warning)
            {
                if (this.result == ServiceResult.Warning)
                {
                    this.errorMessage = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.MessageText);
                }
                else
                {
                    reader.ReadElementValue();
                    if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.MessageText))
                    {
                        this.errorMessage = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.MessageText);
                    }
                }

                this.errorCode = reader.ReadElementValue<ServiceError>(XmlNamespace.Messages, XmlElementNames.ResponseCode);

                if (this.result == ServiceResult.Warning)
                {
                    reader.ReadElementValue<int>(XmlNamespace.Messages, XmlElementNames.DescriptiveLinkKey);
                }

                // If batch processing stopped, EWS returns an empty element. Skip over it.
                if (this.BatchProcessingStopped)
                {
                    do
                    {
                        reader.Read();
                    }
                    while (!reader.IsEndElement(XmlNamespace.Messages, xmlElementName));
                }
                else
                {
                    this.ReadElementsFromXml(reader);

                    reader.ReadEndElementIfNecessary(XmlNamespace.Messages, xmlElementName);
                }
            }
            else
            {
                this.errorMessage = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.MessageText);
                this.errorCode = reader.ReadElementValue<ServiceError>(XmlNamespace.Messages, XmlElementNames.ResponseCode);
                reader.ReadElementValue<int>(XmlNamespace.Messages, XmlElementNames.DescriptiveLinkKey);

                while (!reader.IsEndElement(XmlNamespace.Messages, xmlElementName))
                {
                    reader.Read();

                    if (reader.IsStartElement())
                    {
                        if (!this.LoadExtraErrorDetailsFromXml(reader, reader.LocalName))
                        {
                            reader.SkipCurrentElement();
                        }
                    }
                }
            }

            this.MapErrorCodeToErrorMessage();

            this.Loaded();
        }
コード例 #22
0
 internal ServiceErrorEventArgs(string stage, ServiceError errorCode)
 {
     Stage = stage;
     ErrorCode = errorCode;
 }
コード例 #23
0
ファイル: GXDLMSServer.cs プロジェクト: Gurux/Gurux.DLMS.Net
 /// <summary>
 /// Generate confirmed service error.
 /// </summary>
 /// <param name="service">Confirmed service error.</param>
 /// <param name="type">Service error.</param>
 /// <param name="code">code</param>
 /// <returns></returns>
 internal static byte[] GenerateConfirmedServiceError(ConfirmedServiceError service, ServiceError type, byte code)
 {
     return new byte[] { (byte)Command.ConfirmedServiceError, (byte)service, (byte)type, code };
 }
コード例 #24
0
ファイル: ServiceWrapper.cs プロジェクト: Jabe/procstub
        public static bool SetServiceConfig(
            string serviceName,
            ServiceTypes? type = null,
            ServiceStart? startMode = null,
            ServiceError? error = null,
            string binaryPathName = null,
            string loadOrderGroup = null,
            IntPtr tagId = default(IntPtr),
            string dependencies = null,
            string startName = null,
            string password = null,
            string displayName = null,
            string server = null)
        {
            IntPtr manager = IntPtr.Zero;
            IntPtr service = IntPtr.Zero;

            try
            {
                manager = OpenSCManager(server, null, ScmAccess.ScManagerAllAccess);

                if (manager != IntPtr.Zero)
                {
                    service = OpenService(manager, serviceName, ServiceAccess.ServiceChangeConfig);

                    if (service != IntPtr.Zero)
                    {
                        return ChangeServiceConfig(
                            service,
                            type.HasValue ? (uint) type.Value : ServiceNoChange,
                            startMode.HasValue ? (uint) startMode.Value : ServiceNoChange,
                            error.HasValue ? (uint) error.Value : ServiceNoChange,
                            binaryPathName,
                            loadOrderGroup,
                            tagId,
                            dependencies,
                            startName,
                            password,
                            displayName);
                    }
                }
            }
            finally
            {
                if (service != IntPtr.Zero) CloseServiceHandle(service);
                if (manager != IntPtr.Zero) CloseServiceHandle(manager);
            }

            return false;
        }
コード例 #25
0
ファイル: ErrorException.cs プロジェクト: LorenVS/bacstack
 /// <summary>
 /// Constructs a new error exception instance
 /// </summary>
 /// <param name="error">The error</param>
 public ErrorException(ServiceError error)
 {
     this.Error = error;
 }
コード例 #26
0
ファイル: ServiceException.cs プロジェクト: dropio/rmb-csharp
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceException"/> class.
 /// </summary>
 /// <param name="error">The error.</param>
 public ServiceException(ServiceError error)
 {
     this.serviceError = error;
 }
コード例 #27
0
 public ServiceResponse <T> Error(ServiceError error)
 {
     return(new ServiceResponse <T>(error));
 }
コード例 #28
0
ファイル: ServiceException.cs プロジェクト: dropio/rmb-csharp
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceException"/> class.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="message">The message.</param>
 public ServiceException(ServiceError error, string message)
     : base(message)
 {
     this.serviceError = error;
     this.serviceMessage = message;
 }
 internal ServiceErrorException(ServiceError error) : base(error.ToString())
 {
 }
コード例 #30
0
        private void OnBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, 
            string serviceName, string regtype, string replyDomain, IntPtr context)
        {
            BrowseService service = new BrowseService();
            service.Flags = flags;
            service.Name = serviceName;
            service.RegType = regtype;
            service.ReplyDomain = replyDomain;
            service.InterfaceIndex = interfaceIndex;

            ServiceBrowseEventArgs args = new ServiceBrowseEventArgs();
            args.Service = service;
            args.MoreComing = (flags & ServiceFlags.MoreComing) != 0;

            if((flags & ServiceFlags.Add) != 0) {
                lock(service_table.SyncRoot) {
                    service_table[serviceName] = service;
                }
                ServiceBrowseEventHandler handler = ServiceAdded;
                if(handler != null) {
                    handler(this, args);
                }
            } else {
                lock(service_table.SyncRoot) {
                    service_table.Remove(serviceName);
                }
                ServiceBrowseEventHandler handler = ServiceRemoved;
                if(handler != null) {
                    handler(this, args);
                }
            }
        }
コード例 #31
0
        private static string ParseResponseErrorXML(AstoriaResponse response, bool inStream)
        {
            string payloadString = response.Payload;

            ServiceError serviceError = new ServiceError();

            XmlNode error = null;
            if (inStream)
            {
                Match match = XmlInStreamErrorRegex.Match(payloadString);
                if (!match.Success)
                {
                    AstoriaTestLog.TraceLine(payloadString);
                    AstoriaTestLog.FailAndThrow("Payload did not contain expected in-stream error");
                }
                payloadString = match.Groups[1].Value;

                // if there was a namespace prefix, we need to inject a wrapping element with the namespace defined
                //
                if (!string.IsNullOrEmpty(match.Groups[2].Value))
                {
                    payloadString = "<wrapper xmlns:" + match.Groups[2].Value + "=\"" + AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace + "\">" +
                        payloadString +
                        "</wrapper>";
                }
                else
                {
                    // just for consistency later when we pull out the <error> tag
                    //
                    payloadString = "<wrapper>" + payloadString + "</wrapper>";
                }
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(payloadString);
                }
                catch (XmlException ex)
                {
                    AstoriaTestLog.FailAndContinue(ex);
                    return null;
                }

                // pull out the <error> tag, assuming that there is a <wrapper> tag around it
                //
                error = xmlDoc.FirstChild.FirstChild;
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(payloadString);
                }
                catch (XmlException ex)
                {
                    AstoriaTestLog.FailAndContinue(ex);
                    return null;
                }

                error = xmlDoc.FirstChild.NextSibling;
            }

            if (error != null)
            {
                XmlNode code = error.FirstChild;
                XmlNode message = code.NextSibling;
                XmlNode innerError = message.NextSibling;

                serviceError.code = code.InnerXml;
                serviceError.message = message.InnerXml;
                if (message.Attributes["xml:lang"] != null)
                    serviceError.language = message.Attributes["xml:lang"].Value;
                else
                    serviceError.language = null;

                if (innerError != null)
                {
                    XmlNode innerMessage = null;
                    XmlNode innerType = null;
                    XmlNode innerStackTrace = null;

                    innerMessage = innerError.FirstChild;
                    if (innerMessage != null)
                    {
                        serviceError.InnerServiceError.message = innerMessage.InnerXml;
                        innerType = innerMessage.NextSibling;
                        if (innerType != null)
                        {
                            serviceError.InnerServiceError.type = innerType.InnerXml;
                            innerStackTrace = innerType.NextSibling;
                            if (innerStackTrace != null)
                            {
                                serviceError.InnerServiceError.stacktrace = innerStackTrace.InnerXml;
                            }
                        }
                    }
                }
            }

            return serviceError.message;
        }
コード例 #32
0
 /// <summary>
 /// Notifies the handle that the transaction
 /// has errored out
 /// </summary>
 /// <param name="error">The error that occured</param>
 public abstract void FeedError(ServiceError error);
コード例 #33
0
        private static string ParseResponseErrorJSON(AstoriaResponse response, bool inStream)
        {
            // error should be something like
            //{
            //  "error": {
            //    "code": "", "message":  "Error message"
            //  }
            //}
            ServiceError serviceError = new ServiceError();
            string payloadString = response.Payload;

            CommonPayload payload;
            if (inStream)
            {
                Match match = JsonInStreamErrorRegex.Match(payloadString);
                if (!match.Success)
                {
                    AstoriaTestLog.TraceLine(payloadString);
                    AstoriaTestLog.FailAndThrow("Payload did not contain expected in-stream error");
                }
                response.Payload = match.Groups[1].Value;
            }
            payload = response.CommonPayload;

            PayloadProperty prop;
            PayloadComplexProperty complex = payload.Resources as PayloadComplexProperty;

            if (complex != null)
            {
                if (complex.PayloadProperties.TryGetValue("message", out prop))
                {
                    if (prop is PayloadComplexProperty)
                    {
                        if ((prop as PayloadComplexProperty).PayloadProperties.TryGetValue("value", out prop))
                        {
                            serviceError.message = (prop as PayloadSimpleProperty).Value;
                        }
                    }
                }
            }

            return serviceError.message;
        }
コード例 #34
0
        private void OnResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
            ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, 
            IntPtr txtRecord, IntPtr contex)
        {
            is_resolved = true;
            resolve_pending = false;
            
            InterfaceIndex = interfaceIndex;
            FullName = fullname;
			this.port = (ushort)IPAddress.NetworkToHostOrder((short)port);
            TxtRecord = new TxtRecord(txtLen, txtRecord);

            sdRef.Deallocate();
            
            // Run an A query to resolve the IP address
            ServiceRef sd_ref;
            
            if (AddressProtocol == AddressProtocol.Any || AddressProtocol == AddressProtocol.IPv4) {
                ServiceError error = Native.DNSServiceQueryRecord(out sd_ref, ServiceFlags.None, interfaceIndex,
                    hosttarget, ServiceType.A, ServiceClass.IN, query_record_reply_handler, IntPtr.Zero);
                
                if(error != ServiceError.NoError) {
                    throw new ServiceErrorException(error);
                }
            
                sd_ref.Process();
            }
            
            if (AddressProtocol == AddressProtocol.Any || AddressProtocol == AddressProtocol.IPv6) {
                ServiceError error = Native.DNSServiceQueryRecord(out sd_ref, ServiceFlags.None, interfaceIndex,
                    hosttarget, ServiceType.A6, ServiceClass.IN, query_record_reply_handler, IntPtr.Zero);
                
                if(error != ServiceError.NoError) {
                    throw new ServiceErrorException(error);
                }
            
                sd_ref.Process();
            }
        }
コード例 #35
0
ファイル: RegisterService.cs プロジェクト: hacxman/zeroshare
        private void OnRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode,
            string name, string regtype, string domain, IntPtr context)
        {
            RegisterServiceEventArgs args = new RegisterServiceEventArgs();

            args.Service = this;
            args.IsRegistered = false;
            args.ServiceError = (ServiceErrorCode)errorCode;

            if(errorCode == ServiceError.NoError) {
                Name = name;
                RegType = regtype;
                ReplyDomain = domain;
                args.IsRegistered = true;
            }

            RegisterServiceEventHandler handler = Response;
            if(handler != null) {
                handler(this, args);
            }
        }
コード例 #36
0
 public static extern SafeServiceHandle CreateService(
     SafeServiceHandle hSCManager,
     string lpServiceName,
     string lpDisplayName,
     ServiceAccessRights dwDesiredAccess,
     ServiceType dwServiceType,
     ServiceStart dwStartType,
     ServiceError dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     string lpdwTagId,
     string lpDependencies,
     string lpServiceStartName,
     string lpPassword);
コード例 #37
0
        private void OnResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
            ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, 
            IntPtr txtRecord, IntPtr contex)
        {
            is_resolved = true;
            resolve_pending = false;

            InterfaceIndex = interfaceIndex;
            FullName = fullname;
            HostTarget = hosttarget;
            this.port = (short)port;
            TxtRecord = new TxtRecord(txtLen, txtRecord);

            EventHandler handler = Resolved;
            if(handler != null) {
                handler(this, new EventArgs());
            }

            sdRef.Deallocate();
        }
コード例 #38
0
 protected BlogServiceException(ServiceError serviceError)
 {
     Error = serviceError;
 }
コード例 #39
0
 private static void OnResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
     ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, 
     IntPtr txtRecord, IntPtr context)
 {
     var handle = GCHandle.FromIntPtr(context);
     var browseService = handle.Target as BrowseService;
     Log.To.Discovery.V(Tag, "Resolve reply received for {0} (0x{1}), entering DNSServiceQueryRecord next", 
         browseService, sdRef.Raw.ToString("X"));
     browseService.is_resolved = true;
     browseService.resolve_pending = false;
     
     browseService.InterfaceIndex = interfaceIndex;
     browseService.FullName = fullname;
     browseService.Port = (ushort)IPAddress.NetworkToHostOrder((short)port);
     browseService.TxtRecord = new TxtRecord(txtLen, txtRecord);
     sdRef.Deallocate();
     
     // Run an A query to resolve the IP address
     ServiceRef sd_ref;
     
     if (browseService.AddressProtocol == AddressProtocol.Any || browseService.AddressProtocol == AddressProtocol.IPv4) {
         
         ServiceError error = Native.DNSServiceQueryRecord(out sd_ref, ServiceFlags.None, interfaceIndex,
             hosttarget, ServiceType.A, ServiceClass.IN, browseService.query_record_reply_handler, context);
         
         if(error != ServiceError.NoError) {
             Log.To.Discovery.W(Tag, "Error in DNSServiceQueryRecord {0}", error);
             browseService.Error(browseService, new ServiceErrorEventArgs("ResolveReply (IPv4)", error));
             sd_ref.Deallocate();
             return;
         }
     
         sd_ref.ProcessSingle(ServiceParams.Timeout);
     }
     
     if (browseService.AddressProtocol == AddressProtocol.Any || browseService.AddressProtocol == AddressProtocol.IPv6) {
         ServiceError error = Native.DNSServiceQueryRecord(out sd_ref, ServiceFlags.None, interfaceIndex,
             hosttarget, ServiceType.AAAA, ServiceClass.IN, browseService.query_record_reply_handler, context);
         
         if(error != ServiceError.NoError) {
             if(error != ServiceError.NoError) {
                 Log.To.Discovery.W(Tag, "Error in DNSServiceQueryRecord {0}", error);
                 browseService.Error(browseService, new ServiceErrorEventArgs("ResolveReply (IPv6)", error));
                 sd_ref.Deallocate();
                 return;
             }
         }
     
         sd_ref.ProcessSingle(ServiceParams.Timeout);
     }
 }
コード例 #40
0
ファイル: ServiceBrowser.cs プロジェクト: hacxman/zeroshare
        private void OnBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, 
            string serviceName, string regtype, string replyDomain, IntPtr context)
        {
            BrowseService service = new BrowseService();
            service.Flags = flags;
            service.Name = serviceName;
            service.RegType = regtype;
            service.ReplyDomain = replyDomain;
            service.InterfaceIndex = interfaceIndex;
            service.AddressProtocol = address_protocol;

            ServiceBrowseEventArgs args = new ServiceBrowseEventArgs(
                service, (flags & ServiceFlags.MoreComing) != 0);

            if((flags & ServiceFlags.Add) != 0) {
                lock (service_table) {
                    if (service_table.ContainsKey (serviceName)) {
                        service_table[serviceName] = service;
                    } else {
                        service_table.Add (serviceName, service);
                    }
                }

                ServiceBrowseEventHandler handler = ServiceAdded;
                if(handler != null) {
                    handler(this, args);
                }
            } else {
                lock (service_table) {
                    if (service_table.ContainsKey (serviceName)) {
                        service_table.Remove (serviceName);
                    }
                }

                ServiceBrowseEventHandler handler = ServiceRemoved;
                if(handler != null) {
                    handler(this, args);
                }
            }
        }
 public FinalizeShoppingResponseWrapper(ShoppingCart shoppingCart, bool hasError, ServiceError serviceError)
 {
     ShoppingCart = shoppingCart;
     HasError     = hasError;
     ServiceError = serviceError;
 }