Exemple #1
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="ioService"></param>
        /// <param name="uri"></param>
        /// <param name="accept"></param>
        public static XmlReader Create(IIOService ioService, Uri uri, MediaRangeList accept)
        {
            Contract.Requires <ArgumentNullException>(ioService != null);
            Contract.Requires <ArgumentNullException>(uri != null);

            // default acceptable media types
            accept = !accept.IsEmpty ? accept : XML_MEDIA_RANGES;

            // format request
            var request = new IORequest(uri, IOMethod.Get)
            {
                Accept = accept,
            };

            // get response
            var response = ioService.Send(request);

            if (response.Status != IOStatus.Success)
            {
                throw new XmlException();
            }

            // acceptable response?
            if (!response.ContentType.Matches(accept))
            {
                throw new XmlException();
            }

            return(new IOXmlReader(uri, response.Content));
        }
Exemple #2
0
            public Task <T> GetDataAsync <T>(IDataRequest <T> request)
            {
                IORequest <T> ir = new IORequest <T>(request);

                manager.ioRequested.OnNext(new Tuple <NodeJob, IIORequest>(this, ir));
                return(ir.WaitTask);
            }
        /*public void Open()
         *  => OpenFileDialogRequest.Raise(new OpenFileDialogInfo { Title = "Get Save Path" },
         *      FileInfoAction);*/

        public void Open()
        {
            var openInfo = new OpenFileDialogInfo {
                Title = "Get Save Path"
            };

            IORequest.Raise(openInfo, _ => FileInfoAction(openInfo));
        }
        /*public void Save()
         *  => SaveFileDialogRequest.Raise(new SaveFileDialogInfo { Title = "Get Save Path" },
         *      FileInfoAction);*/

        public void Save()
        {
            var saveInfo = new SaveFileDialogInfo {
                Title = "Get Save Path"
            };

            IORequest.Raise(saveInfo, _ => FileInfoAction(saveInfo));
        }
        /*public void Browse()
         *  => BrowseFolderDialogRequest.Raise(new BrowseFolderDialogInfo { Title = "Browse folder" },
         *      BrowseFolderInfoAction);*/

        public void Browse()
        {
            var browseInfo = new BrowseFolderDialogInfo {
                Title = "Browse folder"
            };

            IORequest.Raise(browseInfo, _ => BrowseFolderInfoAction(browseInfo));
        }
 public IORequest(IORequest request, byte[] payload, IoRequestProperties properties = 0)
 {
     Id = request.Id;
     RequestDirection    = request.RequestDirection;
     Address             = request.Address;
     Payload             = payload;
     IoRequestProperties = properties;
 }
Exemple #7
0
        public bool Process(HttpServer server, HttpRequest request, HttpResponse response)
        {
            SystemLogger.Log(SystemLogger.Module.CORE, " ############## " + this.GetType() + " -> " + request.Url);
            if (request.Url.StartsWith(REMOTE_RESOURCE_URI))
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "Remote resource protocol.");
                try {
                    string   commandParams      = request.Url.Substring(REMOTE_RESOURCE_URI.Length);
                    string[] commandParamsArray = commandParams.Split(new char[] { '/' });
                    if (commandParamsArray.Length > 0)
                    {
                        string ioServiceName = commandParamsArray [0];

                        Object unityIOService = serviceLocator.GetService(UNITY_IO_SERVICE_NAME);
                        if (unityIOService != null && ioServiceName != null)
                        {
                            IIo    io         = (IIo)unityIOService;
                            string parameters = commandParams.Substring(ioServiceName.Length + 1);

                            IORequest ioRequest = new IORequest();
                            ioRequest.Content = parameters;
                            IOResponse ioResponse = io.InvokeService(ioRequest, ioServiceName);
                            if (ioResponse != null)
                            {
                                response.ContentType = ioResponse.ContentType;
                                response.RawContent  = ioResponse.ContentBinary;
                            }
                        }
                    }

                    if (response.RawContent == null)
                    {
                        response.Content = "No content available.";
                        SystemLogger.Log(SystemLogger.Module.CORE, "No content available for request [" + request.Url + "," + request.Method + "]. Continue to next handler...");
                        return(false);
                    }

                    return(true);
                } catch (Exception e) {
                    SystemLogger.Log(SystemLogger.Module.CORE, "Exception when parsing request [" + request.Url + "]", e);
                    response.Content = "Malformed request.";
                    return(false);
                }
            }
            else
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "Non remote resource protocol. Continue to next handler...");
                return(false);
            }
        }
Exemple #8
0
        public override IOResponse Submit(IORequest request)
        {
            var stm = typeof(Ref).Assembly
                      .GetManifestResourceNames()
                      .Where(i => i.EndsWith("." + request.ResourceUri.LocalPath.Substring(1)))
                      .Select(i => typeof(Ref).Assembly.GetManifestResourceStream(i))
                      .FirstOrDefault();

            if (stm == null)
            {
                return(null);
            }

            return(new IOResponse(request, IOStatus.Success, stm, "application/xml"));
        }
Exemple #9
0
        /// <summary>
        /// Retrieves a <see cref="WebRequest"/> for the given <see cref="ModelRequest"/>.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        protected virtual IORequest WriteIORequest(ModelRequest request)
        {
            Contract.Requires <ArgumentNullException>(request != null);

            var mediaType = GetMediaType(request);

            if (mediaType == null)
            {
                return(null);
            }

            // obtain and build request parts
            var cnt = (string)null;
            var stm = new MemoryStream();
            var uri = request.ResourceUri;

            if (IsQuery(request) && request.Body != null)
            {
                // serialize body to string
                var u = new UriBuilder(uri);
                var s = new StringBuilder(u.Query);
                using (var w = new StringWriter(s))
                    Serialize(w, request.Body, mediaType);
                u.Query = s.ToString();

                // replace uri
                uri = u.Uri;
            }
            else if (request.Body != null)
            {
                // serialize data to body
                using (var w = new StreamWriter(stm, request.Encoding, 1024, true))
                    Serialize(w, request.Body, mediaType);

                // configure body
                cnt          = mediaType;
                stm.Position = 0;
            }

            // generate new web request
            var ioRequest = new IORequest(uri, GetMethod(request));

            ioRequest.ContentType = cnt;
            ioRequest.Headers.Add(request.Headers);
            ioRequest.Content = stm;

            return(ioRequest);
        }
        /// <summary>
        /// Server Requests Canceling an Operation
        /// this method was called by 3.1.5.7, and the scenario was in Scenario16_ByteRangeLock
        /// </summary>
        /// <param name="iorequest">An implementation-specific identifier that is unique for each
        /// outstanding IO operation. See [MS-CIFS] section 3.3.5.51.</param>
        /// <returns>An NTSTATUS code that specifies the result</returns>
        public static MessageStatus CancelinganOperation(IORequest iorequest)
        {
            //When a cancelation request is received, scan CancelableOperations.
            //CancelableOperationList looking for an operation CanceledOperation
            //that matches IORequest. If found,
            if (sequenceIORequest.Contains(iorequest))
            {
                Condition.IsTrue(sequenceIORequest.Contains(iorequest));
                sequenceIORequest.Remove(iorequest);
                Helper.CaptureRequirement(6527, @"[In Server Requests Canceling an Operation,If an operation CanceledOperation that matches IORequest. found,]
                    CanceledOperation MUST be failed with STATUS_CANCELED returned for the status of the canceled operation.");
                return(MessageStatus.CANCELLED);
            }

            return(MessageStatus.INVALID_PARAMETER);
        }
        public async Task <Guid> Write()
        {
            Guid guid = Guid.Empty;

            foreach (var i in Enumerable.Range(0, accessPattern[0].Length))
            {
                var b       = accessPattern[0][i];
                var p       = accessPattern[1][i];
                var request = IORequest.CreateWriteIoRequest(new Address(AddressScope.Page, (ushort)b, (ushort)p), array);
                var result  = await scheduler.ScheduleFileSystemRequest(request).ConfigureAwait(false);

                guid = result.Id;
            }

            return(guid);
        }
Exemple #12
0
        public async Task <IOResponse> ScheduleFileSystemRequest(IORequest request)
        {
            var writer = _responseChannel.Writer;

            while (await writer.WaitToWriteAsync())
            {
                TaskCompletionSource <IOResponse> source = new TaskCompletionSource <IOResponse>();
                ValueTuple <IORequest, TaskCompletionSource <IOResponse> > tuple = (request, source);
                await writer.WriteAsync(tuple);

                var response = await source.Task.ConfigureAwait(false);

                return(response);
            }

            return(default);
        public async Task <Guid> Read()
        {
            Guid guid = Guid.Empty;

            foreach (var i in Enumerable.Range(0, accessPattern[0].Length))
            {
                var b       = accessPattern[0][i];
                var p       = accessPattern[1][i];
                var request = IORequest.CreateReadRequest(new Address(AddressScope.Page, (ushort)b, (ushort)p));
                var result  = await scheduler.ScheduleFileSystemRequest(request).ConfigureAwait(false);

                guid = result.Id;
                ArrayPool <byte> .Shared.Return(result.Payload);
            }

            return(guid);
        }
Exemple #14
0
        /// <summary>
        /// Updates the or install module.
        /// </summary>
        /// <param name="module">Module.</param>
        public virtual bool UpdateOrInstallModule(Module module)
        {
            IOService service = this.GetServiceFromUrl(module.LoadUrl);
            IORequest request = this.GetRequestWithRequiredHeaders();

            String tempFile = this.GetIOService().InvokeServiceForBinary(request, service, "tmp.zip");

            if (tempFile != null)
            {
                return(this.StoreModuleZipFile(module, tempFile));
            }
            else
            {
                SystemLogger.Log(SystemLogger.Module.CORE, "It was not possible to get module data from url: " + module.LoadUrl);
            }

            return(false);
        }
Exemple #15
0
        /// <summary>
        /// Writes the data to the underlying stream
        /// </summary>
        /// <param name="writeRequest">The write request.</param>
        public async Task Write(IORequest writeRequest)
        {
            var pos = writeRequest.Address.ToPosition();

            _dataFileStream.Position = pos.offset;
            var length = pos.length;

            if ((writeRequest.IoRequestProperties & IoRequestProperties.OnlyHeader) == IoRequestProperties.OnlyHeader)
            {
                length = (uint)GetHeaderLengthForScope(writeRequest.Address.Scope);
            }

            await _dataFileStream.WriteAsync(writeRequest.Payload.Slice(0, (int)length)).ConfigureAwait(false);

            if ((writeRequest.IoRequestProperties & IoRequestProperties.Flush) == IoRequestProperties.Flush)
            {
                await _dataFileStream.FlushAsync().ConfigureAwait(false);
            }
        }
        public async Task AddAndWaitForResult()
        {
            using DefaultScheduler fileSystemScheduler = new DefaultScheduler(new MemoryFileSystemService(new DatatentSettings(), Constants.BLOCK_SIZE_INCL_HEADER * 2, new NullLogger <FileSystemServiceBase>()));
            var bytes = new byte[Constants.PAGE_SIZE_INCL_HEADER];

            UnitTestHelper.FillArray(ref bytes, 0x01);

            var       address      = new Address(AddressScope.Page, 1, 1);
            IORequest writeRequest = new IORequest(IORequestDirection.Write, address, bytes);

            var writeResponse = await fileSystemScheduler.ScheduleFileSystemRequest(writeRequest).ConfigureAwait(false);

            writeResponse.Id.Should().Be(writeRequest.Id);

            IORequest readRequest  = IORequest.CreateReadRequest(address);
            var       readResponse = await fileSystemScheduler.ScheduleFileSystemRequest(readRequest).ConfigureAwait(false);

            readResponse.Address.FullAddress.Should().Be(address.FullAddress);
            readResponse.Payload.Take(bytes.Length).Should().BeEquivalentTo(bytes);
        }
Exemple #17
0
        /// <summary>
        /// Method overrided, to start activity notification while invoking external service.
        /// </summary>
        /// <param name="request">
        /// A <see cref="IORequest"/>
        /// </param>
        /// <param name="service">
        /// A <see cref="IOService"/>
        /// </param>
        /// <returns>
        /// A <see cref="IOResponse"/>
        /// </returns>
        public override IOResponse InvokeService(IORequest request, IOService service)
        {
            this.IOUserAgent = IPhoneUtils.GetInstance().GetUserAgent();
            INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify");

            try {
                notificationService.StartNotifyActivity();
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Cannot StartNotifyActivity. Message: " + e.Message);
            }
            IOResponse response = base.InvokeService(request, service);

            try {
                notificationService.StopNotifyActivity();
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Cannot StopNotifyActivity. Message: " + e.Message);
            }

            return(response);
        }
Exemple #18
0
        public virtual IORequest GetRequestWithRequiredHeaders()
        {
            IORequest request = new IORequest();

            if (_context != null && _context.Credentials != null && _context.Credentials.Length > 0)
            {
                // Basic Authentication available
                // Credentials should be a base64 encoding for the "username:password" concatenation string
                // TODO  allow other authentication types in the future
                IOHeader authHeader = new IOHeader();
                authHeader.Name  = "Authorization";
                authHeader.Value = "Basic " + _context.Credentials;

                request.Headers = new IOHeader[] { authHeader };
            }

            // Accept header is needed to avoid "406 not acceptable" error, but should be set in the request final object
            // I/O Services use the request content type to set this value on the final request object
            request.ContentType = "*/*";

            return(request);
        }
Exemple #19
0
 public override Priority CanSend(IORequest request)
 {
     return(request.ResourceUri.Scheme == "nx-example" ? Priority.High : Priority.Ignore);
 }
        /// <summary>
        /// Server Requests Canceling an Operation
        /// this method was called by 3.1.5.7, and the scenario was in Scenario16_ByteRangeLock
        /// </summary>
        /// <param name="iorequest">An implementation-specific identifier that is unique for each 
        /// outstanding IO operation. See [MS-CIFS] section 3.3.5.51.</param>
        /// <returns>An NTSTATUS code that specifies the result</returns>
        public static MessageStatus CancelinganOperation(IORequest iorequest)
        {
            //When a cancelation request is received, scan CancelableOperations.
            //CancelableOperationList looking for an operation CanceledOperation
            //that matches IORequest. If found,
            if (sequenceIORequest.Contains(iorequest))
            {
                Condition.IsTrue(sequenceIORequest.Contains(iorequest));
                sequenceIORequest.Remove(iorequest);
                Helper.CaptureRequirement(6527, @"[In Server Requests Canceling an Operation,If an operation CanceledOperation that matches IORequest. found,]
                    CanceledOperation MUST be failed with STATUS_CANCELED returned for the status of the canceled operation.");
                return MessageStatus.CANCELLED;
            }

            return MessageStatus.INVALID_PARAMETER;
        }