public static Result IterateDirectoryRecursively(IFileSystem fs, U8Span rootPath, Span <byte> workPath, ref DirectoryEntry dirEntry, FsIterationTask onEnterDir, FsIterationTask onExitDir, FsIterationTask onFile) { Abort.DoAbortUnless(workPath.Length >= PathTool.EntryNameLengthMax + 1); // Get size of the root path. int rootPathLen = StringUtils.GetLength(rootPath, PathTool.EntryNameLengthMax + 1); if (rootPathLen > PathTool.EntryNameLengthMax) { return(ResultFs.TooLongPath.Log()); } // Copy root path in, add a / if necessary. rootPath.Value.Slice(0, rootPathLen).CopyTo(workPath); if (!PathTool.IsSeparator(workPath[rootPathLen - 1])) { workPath[rootPathLen++] = StringTraits.DirectorySeparator; } // Make sure the result path is still valid. if (rootPathLen > PathTool.EntryNameLengthMax) { return(ResultFs.TooLongPath.Log()); } workPath[rootPathLen] = StringTraits.NullTerminator; return(IterateDirectoryRecursivelyImpl(fs, workPath, ref dirEntry, onEnterDir, onExitDir, onFile)); }
public static bool IsMounted(this FileSystemClient fs, U8Span mountName) { Result rc; bool isMounted; Span <byte> logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledFileSystemAccessorAccessLog(mountName)) { Tick start = fs.Hos.Os.GetSystemTick(); rc = fs.Impl.IsMounted(out isMounted, mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); ReadOnlySpan <byte> boolString = AccessLogImpl.ConvertFromBoolToAccessLogBooleanValue(isMounted); sb.Append(LogName).Append(mountName).Append(LogIsMounted).Append(boolString).Append((byte)'"'); fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); } else { rc = fs.Impl.IsMounted(out isMounted, mountName); } fs.Impl.LogErrorMessage(rc); Abort.DoAbortUnless(rc.IsSuccess()); return(isMounted); }
protected virtual void Dispose(bool disposing) { if (!disposing) { return; } using (ScopedLock.Lock(ref _openListLock)) { Abort.DoAbortUnless(_openFiles.Count == 0, ResultFs.FileNotClosed.Value, "All files must be closed before unmounting."); Abort.DoAbortUnless(_openDirectories.Count == 0, ResultFs.DirectoryNotClosed.Value, "All directories must be closed before unmounting."); if (_isPathCacheAttached) { throw new NotImplementedException(); } } _saveDataAttributeGetter?.Dispose(); _saveDataAttributeGetter = null; _mountNameGenerator?.Dispose(); _mountNameGenerator = null; _fileSystem?.Dispose(); _fileSystem = null; }
public void RaiseAbortRequestReceived(Abort abort, Association asc) { if (AbortRequestReceived != null) { AbortRequestReceived(abort, asc); } }
public FileRegion(long offset, long size) { Offset = offset; Size = size; Abort.DoAbortUnless(size >= 0); }
public static bool IsAbortNeeded(this FileSystemClientImpl fs, Result result) { if (result.IsSuccess()) { return(false); } switch (fs.Fs.GetCurrentThreadFsContext().HandleResult(result)) { case AbortSpecifier.Default: if (fs.Globals.ResultHandlingUtility.IsResultHandledByApplication) { return(ResultFs.HandledByAllProcess.Includes(result)); } else { return(!(ResultFs.HandledByAllProcess.Includes(result) || ResultFs.HandledBySystemProcess.Includes(result))); } case AbortSpecifier.Abort: return(true); case AbortSpecifier.Return: return(false); default: Abort.UnexpectedDefault(); return(default); } }
public FileSystemAccessor(FileSystemClient fsClient, U8Span name, IMultiCommitTarget multiCommitTarget, IFileSystem fileSystem, ICommonMountNameGenerator mountNameGenerator, ISaveDataAttributeGetter saveAttributeGetter) { FsClient = fsClient; _fileSystem = fileSystem; _openFiles = new LinkedList <FileAccessor>(); _openDirectories = new LinkedList <DirectoryAccessor>(); _openListLock.Initialize(); _mountNameGenerator = mountNameGenerator; _saveDataAttributeGetter = saveAttributeGetter; _multiCommitTarget = multiCommitTarget; if (name.IsEmpty()) { Abort.DoAbort(ResultFs.InvalidMountName.Log()); } if (StringUtils.GetLength(name, PathTool.MountNameLengthMax + 1) > PathTool.MountNameLengthMax) { Abort.DoAbort(ResultFs.InvalidMountName.Log()); } StringUtils.Copy(_mountName.Name.Slice(0, PathTool.MountNameLengthMax), name); _mountName.Name[PathTool.MountNameLengthMax] = 0; }
public Result SetOpenType(OpenType type) { Assert.SdkRequires(type == OpenType.Normal || type == OpenType.Internal); switch (type) { case OpenType.Normal: if (_isNormalStorageOpened) { return(ResultFs.TargetLocked.Log()); } _isNormalStorageOpened = true; return(Result.Success); case OpenType.Internal: if (_isInternalStorageOpened) { return(ResultFs.TargetLocked.Log()); } _isInternalStorageOpened = true; _isInternalStorageInvalidated = false; return(Result.Success); default: Abort.UnexpectedDefault(); return(Result.Success); } }
/// <summary> /// if need, run this method for auto-login. /// </summary> /// <returns></returns> private async Task ClickSubmitButtonIfAuto() { Submit.IsEnabled = false; SubitRing.IsActive = true; var user = EmailBox.Text; var pass = PasswordBox.Password; PasswordAndUserEncryption(ref user, ref pass); // set the abort button with keybord-focus, so that the vitual keyboad in the mobile device with disappear. Abort.Focus(FocusState.Keyboard); //await InsertLoginMessage(user, pass); var loginReturn = await PostLNULoginCallback(MainPage.LoginClient, user, pass); if (loginReturn != null) { CheckIfLoginSucceed(loginReturn); } else { ReportHelper.ReportAttention(GetUIString("Internet_Failed")); Submit.IsEnabled = true; SubitRing.IsActive = false; } }
public void MergeFrom(HTTPFault other) { if (other == null) { return; } if (other.delay_ != null) { if (delay_ == null) { delay_ = new global::Envoy.Config.Filter.Fault.V2.FaultDelay(); } Delay.MergeFrom(other.Delay); } if (other.abort_ != null) { if (abort_ == null) { abort_ = new global::Envoy.Config.Filter.Http.Fault.V2.FaultAbort(); } Abort.MergeFrom(other.Abort); } if (other.UpstreamCluster.Length != 0) { UpstreamCluster = other.UpstreamCluster; } headers_.Add(other.headers_); downstreamNodes_.Add(other.downstreamNodes_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public static unsafe Result CopyDirectoryRecursively(IFileSystem destFileSystem, IFileSystem sourceFileSystem, U8Span destPath, U8Span sourcePath, Span <byte> workBuffer) { var destPathBuf = new FsPath(); int originalSize = StringUtils.Copy(destPathBuf.Str, destPath); Abort.DoAbortUnless(originalSize < Unsafe.SizeOf <FsPath>()); // Pin and recreate the span because C# can't use byref-like types in a closure int workBufferSize = workBuffer.Length; fixed(byte *pWorkBuffer = workBuffer) { // Copy the pointer to workaround CS1764. // IterateDirectoryRecursively won't store the delegate anywhere, so it should be safe byte *pWorkBuffer2 = pWorkBuffer; Result OnEnterDir(U8Span path, ref DirectoryEntry entry) { // Update path, create new dir. StringUtils.Concat(SpanHelpers.AsByteSpan(ref destPathBuf), entry.Name); StringUtils.Concat(SpanHelpers.AsByteSpan(ref destPathBuf), DirectorySeparator); return(destFileSystem.CreateDirectory(destPathBuf)); } Result OnExitDir(U8Span path, ref DirectoryEntry entry) { // Check we have a parent directory. int len = StringUtils.GetLength(SpanHelpers.AsByteSpan(ref destPathBuf)); if (len < 2) { return(ResultFs.InvalidPathFormat.Log()); } // Find previous separator, add null terminator int cur = len - 2; while (!PathTool.IsSeparator(SpanHelpers.AsByteSpan(ref destPathBuf)[cur]) && cur > 0) { cur--; } SpanHelpers.AsByteSpan(ref destPathBuf)[cur + 1] = StringTraits.NullTerminator; return(Result.Success); } Result OnFile(U8Span path, ref DirectoryEntry entry) { var buffer = new Span <byte>(pWorkBuffer2, workBufferSize); return(CopyFile(destFileSystem, sourceFileSystem, destPathBuf, path, ref entry, buffer)); } return(IterateDirectoryRecursively(sourceFileSystem, sourcePath, OnEnterDir, OnExitDir, OnFile)); } }
/// <summary> /// Constructor /// </summary> public TransferProgress() { Delegator = new ElapsedEventHandler(CalculateEstimated); Completion = 0; AbortTransfer = new Abort(this); Visibility = "Visible"; }
private void Write(ReadOnlySpan <byte> source) { // Bounds check. Abort.DoAbortUnless(_offset + source.Length <= _buffer.Length && _offset + source.Length > _offset); source.CopyTo(_buffer.Slice(_offset)); _offset += source.Length; }
public override int GetHashCode() { int hash = 1; if (delay_ != null) { hash ^= Delay.GetHashCode(); } if (abort_ != null) { hash ^= Abort.GetHashCode(); } if (UpstreamCluster.Length != 0) { hash ^= UpstreamCluster.GetHashCode(); } hash ^= headers_.GetHashCode(); hash ^= downstreamNodes_.GetHashCode(); if (maxActiveFaults_ != null) { hash ^= MaxActiveFaults.GetHashCode(); } if (responseRateLimit_ != null) { hash ^= ResponseRateLimit.GetHashCode(); } if (DelayPercentRuntime.Length != 0) { hash ^= DelayPercentRuntime.GetHashCode(); } if (AbortPercentRuntime.Length != 0) { hash ^= AbortPercentRuntime.GetHashCode(); } if (DelayDurationRuntime.Length != 0) { hash ^= DelayDurationRuntime.GetHashCode(); } if (AbortHttpStatusRuntime.Length != 0) { hash ^= AbortHttpStatusRuntime.GetHashCode(); } if (MaxActiveFaultsRuntime.Length != 0) { hash ^= MaxActiveFaultsRuntime.GetHashCode(); } if (ResponseRateLimitPercentRuntime.Length != 0) { hash ^= ResponseRateLimitPercentRuntime.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public HorizonClient CreatePrivilegedHorizonClient() { ulong processId = Interlocked.Increment(ref _currentInitialProcessId); Abort.DoAbortUnless(processId <= InitialProcessCountMax, "Created too many privileged clients."); // Todo: Register process with FS return(new HorizonClient(this, new ProcessId(processId))); }
public void Unlock() { Abort.DoAbortUnless(IsLockedByCurrentThread()); _recursiveCount--; if (_recursiveCount == 0) { _cs.Leave(); } }
/// <summary> /// Constructs a window /// </summary> public Window() { // Save UI thread's dispatcher. Dispatcher = Dispatcher.CurrentDispatcher; Dispatcher.ShutdownStarted += (object sender, EventArgs e) => { // Raise the abort flag to gracefully shutdown all background threads. Abort.Cancel(); }; }
/// <summary> /// Reevaluate condition and try to abort the tree if required /// </summary> /// <param name="abort">Abort type</param> protected void EvaluateConditionAndTryAbort(Abort abortType) { bool c = Check(); if (c != lastConditionCheckResult) { lastConditionCheckResult = c; TryAbort(abortType); } }
/// <summary> /// Handle Abort Rq /// </summary> /// <param name="abort"></param> public override void AfterHandlingAbort(Abort abort) { if (!IsMessageHandled) { StopResultsGathering(); StartResultsGathering(); IsMessageHandled = true; } }
public void Lock() { if (!IsLockedByCurrentThread()) { _cs.Enter(); } _recursiveCount++; Abort.DoAbortUnless(_recursiveCount != 0); }
/// <summary> /// if need, run this method for auto-login. /// </summary> /// <returns></returns> private async void ClickSubmitButtonIfAutoAsync() { Submit.IsEnabled = false; SubitRing.IsActive = true; var user = EmailBox.Text; var pass = PasswordBox.Password; PasswordAndUserEncryption(user, pass); // set the abort button with keybord-focus, so that the vitual keyboad in the mobile device with disappear. Abort.Focus(FocusState.Keyboard); var result = await DoubanWebProcess.PostDoubanResponseAsync( path : "https://frodo.douban.com/service/auth2/token", host : "frodo.douban.com", reffer : null, content : new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("client_id", "0dad551ec0f84ed02907ff5c42e8ec70"), new KeyValuePair <string, string>("client_secret", "9e8bb54dc3288cdf"), new KeyValuePair <string, string>("redirect_uri", "frodo://app/oauth/callback/"), new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", user), new KeyValuePair <string, string>("password", pass), //new KeyValuePair<string, string>("apiKey","0dad551ec0f84ed02907ff5c42e8ec70"), new KeyValuePair <string, string>("os_rom", "android"), }), isMobileDevice : true); var tokenReturn = default(APITokenReturn); try { JObject jo = JObject.Parse(result); tokenReturn = new APITokenReturn { AccessToken = jo["access_token"].Value <string>(), RefreshToken = jo["refresh_token"].Value <string>(), ExpiresIn = jo["expires_in"].Value <string>(), UserId = jo["douban_user_id"].Value <string>(), UserName = jo["douban_user_name"].Value <string>(), }; MainLoginPopup.IsOpen = false; try { await MainPage.SetUserStatusAsync(tokenReturn.UserId); //await MainPage.SetUserStatusAsync("155845973"); NavigateToBase?.Invoke( null, null, GetFrameInstance(FrameType.UserInfos), GetPageType(NavigateType.UserInfo)); } catch { /* Ignore. */ } } catch { ReportHelper.ReportAttentionAsync(GetUIString("LoginFailed")); } }
public static void SendAbort(Association asc, AbortSource abortSource = AbortSource.DICOM_UL_SERV_PROVIDER, AbortReason reason = AbortReason.REASON_NOT_SPECIFIED) { if (asc.Stream.CanWrite) { var abort = new Abort { Source = abortSource, Reason = reason }; var message = abort.Write(); asc.Stream.Write(message, 0, message.Length); } }
public void Dispose() { if (_lastResult.IsSuccess() && _writeState == WriteState.NeedsFlush) { Abort.DoAbort(ResultFs.NeedFlush.Log(), "File needs flush before closing."); } _parentFileSystem?.NotifyCloseFile(this); _file?.Dispose(); _file = null; }
public void ResetIndexer(SaveDataSpaceId spaceId) { if (spaceId != SaveDataSpaceId.Temporary) { Abort.UnexpectedDefault(); } // ReSharper disable once RedundantAssignment Result rc = _tempIndexer.Indexer.Reset(); Assert.SdkAssert(rc.IsSuccess()); }
/// <summary> /// Method to handle the workflow after receiving an Abort Request. /// </summary> /// <param name="abort">Abort Request message.</param> public override void AfterHandlingAbort(Abort abort) { // message has now been handled if (!IsMessageHandled) { StopResultsGathering(); StartResultsGathering(); IsMessageHandled = true; isAssociated = false; } }
public void MergeFrom(HTTPFault other) { if (other == null) { return; } if (other.delay_ != null) { if (delay_ == null) { Delay = new global::Envoy.Config.Filter.Fault.V3Alpha.FaultDelay(); } Delay.MergeFrom(other.Delay); } if (other.abort_ != null) { if (abort_ == null) { Abort = new global::Envoy.Config.Filter.Http.Fault.V3Alpha.FaultAbort(); } Abort.MergeFrom(other.Abort); } if (other.UpstreamCluster.Length != 0) { UpstreamCluster = other.UpstreamCluster; } headers_.Add(other.headers_); downstreamNodes_.Add(other.downstreamNodes_); if (other.maxActiveFaults_ != null) { if (maxActiveFaults_ == null || other.MaxActiveFaults != 0) { MaxActiveFaults = other.MaxActiveFaults; } } if (other.responseRateLimit_ != null) { if (responseRateLimit_ == null) { ResponseRateLimit = new global::Envoy.Config.Filter.Fault.V3Alpha.FaultRateLimit(); } ResponseRateLimit.MergeFrom(other.ResponseRateLimit); } if (other.DelayPercentRuntime.Length != 0) { DelayPercentRuntime = other.DelayPercentRuntime; } if (other.AbortPercentRuntime.Length != 0) { AbortPercentRuntime = other.AbortPercentRuntime; } if (other.DelayDurationRuntime.Length != 0) { DelayDurationRuntime = other.DelayDurationRuntime; } if (other.AbortHttpStatusRuntime.Length != 0) { AbortHttpStatusRuntime = other.AbortHttpStatusRuntime; } if (other.MaxActiveFaultsRuntime.Length != 0) { MaxActiveFaultsRuntime = other.MaxActiveFaultsRuntime; } if (other.ResponseRateLimitPercentRuntime.Length != 0) { ResponseRateLimitPercentRuntime = other.ResponseRateLimitPercentRuntime; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public static Message <Abort> ReadAbort(NetworkBinaryReader dr) { var abort = new Abort(); dr.Skip(1); //Skip null and header dr.Skip(4); //Skip length dr.Skip(2); //Skip null abort.Source = (AbortSource)dr.Take(1).First(); abort.Reason = (AbortReason)dr.Skip(1).Take(1).First(); return(new Message <Abort> { Payload = abort, Type = MessageType.PDU }); }
public static U8Span GetCustomStorageDirectoryName(CustomStorageId storageId) { switch (storageId) { case CustomStorageId.System: case CustomStorageId.SdCard: return(new U8Span(CustomStorageDirectoryName)); default: Abort.UnexpectedDefault(); return(default); } }
/// <summary> /// if need, run this method for auto-login. /// </summary> /// <returns></returns> private async void ClickSubmitButtonIfAutoAsync() { Submit.IsEnabled = false; SubitRing.IsActive = true; var user = EmailBox.Text; var pass = PasswordBox.Password; PasswordAndUserEncryption(user, pass); // set the abort button with keybord-focus, so that the vitual keyboad in the mobile device with disappear. Abort.Focus(FocusState.Keyboard); await InsertLoginMessageAsync(user, pass, VerificationCodeBorder.Visibility == Visibility.Visible?VerificationCodeBox.Text : null, isAuto.Value); }
/// <summary> /// if need, run this method for auto-login. /// </summary> /// <returns></returns> private async Task ClickSubmitButtonIfAuto() { Submit.IsEnabled = false; SubitRing.IsActive = true; var user = EmailBox.Text; var pass = PasswordBox.Password; SettingsHelper.SaveSettingsValue(SettingsConstants.Email, user); PasswordEncryption(pass); // set the abort button with keybord-focus, so that the vitual keyboad in the mobile device with disappear. Abort.Focus(FocusState.Keyboard); await InsertLoginMessage(user, pass); }