示例#1
0
        public MainWindowViewModel(ISynchronizationContext synchronizationContext, LocalDirectory localDirectory)
        {
            this.synchronizationContext = synchronizationContext;
            this.localDirectory         = localDirectory;

            localDirectory.FileFinded += (sender, e) =>
            {
                synchronizationContext.Invoke(() =>
                {
                    searchResults.Add(new FileViewModel(e.FileEntry));
                });
            };

            localDirectory.SearchStarted += (sender, e) =>
            {
                synchronizationContext.Invoke(() =>
                {
                    SearchInProcess = true;
                });
            };

            localDirectory.SearchFinished += (sender, e) =>
            {
                synchronizationContext.Invoke(() =>
                {
                    SearchInProcess = false;
                });
            };

            localDirectory.SearchPaused += (sender, e) =>
            {
                synchronizationContext.Invoke(() =>
                {
                    SearchIsPaused = true;
                });
            };

            localDirectory.SearchResumed += (sender, e) =>
            {
                synchronizationContext.Invoke(() =>
                {
                    SearchIsPaused = false;
                });
            };

            searchCommand = new DelegateCommand(Search, () => CanSearch);
            pauseCommand  = new DelegateCommand(() => localDirectory.PauseSearch(), () => CanPause);
            resumeCommand = new DelegateCommand(() => localDirectory.ResumeSearch(), () => CanResume);
            stopCommand   = new DelegateCommand(() => localDirectory.StopSearch(), () => CanStop);
        }
示例#2
0
 NetworkCredential Preprocessing.ICredentialsCache.QueryCredentials(Uri uri, string authType)
 {
     lock (credentialCacheLock)
     {
         if (credentialCache == null)
         {
             credentialCache = new NetworkCredentialsStorage(credentialsCacheStorage, new Persistence.SystemDataProtection());
         }
         var cred = credentialCache.GetCredential(uri);
         if (cred != null)
         {
             return(cred);
         }
         var ret = uiInvoke.Invoke <NetworkCredential>(() =>
                                                       NetworkCredentialsDialogController.ShowSheet(parentWindow,
                                                                                                    NetworkCredentialsStorage.GetRelevantPart(uri).ToString(),
                                                                                                    authType == "protected-archive")).Result;
         if (ret == null)
         {
             return(null);
         }
         credentialCache.Add(uri, ret);
         credentialCache.StoreSecurely();
         return(ret);
     }
 }
示例#3
0
 NetworkCredential Preprocessing.ICredentialsCache.QueryCredentials(Uri uri, string authType)
 {
     lock (credentialCacheLock)
     {
         if (credentialCache == null)
         {
             credentialCache = new NetworkCredentialsStorage(credentialsCacheStorage);
         }
         var cred = credentialCache.GetCredential(uri);
         if (cred != null)
         {
             return(cred);
         }
         var ret = uiInvokeSynchronization.Invoke <NetworkCredential>(() =>
                                                                      CredUIUtils.ShowCredentialsDialog(appWindow.Handle,
                                                                                                        NetworkCredentialsStorage.GetRelevantPart(uri).ToString(),
                                                                                                        authType == "protected-archive")).Result;
         if (ret == null)
         {
             return(null);
         }
         credentialCache.Add(uri, ret);
         credentialCache.StoreSecurely();
         return(ret);
     }
 }
 public void GetUrl(NSAppleEventDescriptor evt, NSAppleEventDescriptor withReplyEvent)
 {
     passedUrl = evt.ParamDescriptorForKeyword(FourCC("----")).StringValue;
     if (isLoaded)
     {
         invoke.Invoke(LoadPassedUrl);
     }
 }
示例#5
0
        async Task IPreprocessingStep.Execute(IPreprocessingStepCallback callback)
        {
            await callback.BecomeLongRunning();

            callback.SetStepDescription("Opening workspace " + source.FullPath);
            callback.SetOption(PreprocessingOptions.Silent, true);

            foreach (var entry in await await invoke.Invoke(() => workspacesManager.LoadWorkspace(source.Location, callback.Cancellation)).WithCancellation(callback.Cancellation))
            {
                callback.YieldChildPreprocessing(entry.Log, entry.IsHiddenLog);
            }
        }
示例#6
0
            public async Task <ResultCode> MoveToDateBound(DateTime d, bool reversedMode)
            {
                using (trace.NewFrame)
                {
                    trace.Info("Moving to the date {0} than '{1}' by sending 'get {2} bound' request to all readers",
                               reversedMode ? "less (or eq)" : "greater (or eq)", d, reversedMode ? "lower (rev)" : "lower");

                    ResultCode resultCode;

                    if (reversedMode)
                    {
                        currentDate = MessageTimestamp.MinValue;
                    }
                    else
                    {
                        currentDate = MessageTimestamp.MaxValue;
                    }

                    Task <DateBoundPositionResponseData> getBoundsTask = null;

                    for (int iteration = 0; ; ++iteration)
                    {
                        trace.Info("it's iteration {0} of trying to send the 'get date bound' request to reader", iteration);
                        var modelThreadCall = invoke.Invoke(() =>
                        {
                            // This code must be executing in the model thread
                            using (trace.NewFrame)
                            {
                                if (source.IsDisposed)
                                {
                                    trace.Warning("reader is disposed");
                                    // This TimeGapsDetector is probably disposed too or will be soon.
                                    // Returning null will make the main algorithm wait.
                                    // During waiting it'll detect stop condition.
                                    return(null);
                                }
                                trace.Info("the reader is idling. Getting date bound.");
                                return(source.GetDateBoundPosition(d,
                                                                   reversedMode ?  ValueBound.LowerReversed : ValueBound.Lower,
                                                                   CancellationToken.None
                                                                   )); // todo: cancellation
                            }
                        });

                        trace.Info("waiting the completion of 'get date bound' request scheduler");
                        if (IsStopOrInvalidate(resultCode = await owner.WaitEvents(Timeout.Infinite, modelThreadCall)))
                        {
                            return(resultCode);
                        }

                        getBoundsTask = await modelThreadCall;

                        if (getBoundsTask != null)
                        {
                            trace.Info("the 'get date bound' request was successfully sent to reader.");
                            break;
                        }

                        trace.Info("reader is not handled. Waiting...");

                        if (IsStopOrInvalidate(resultCode = await owner.WaitEvents(1000, null)))
                        {
                            return(resultCode);
                        }
                    }

                    trace.Info("waiting for the response from the reader");
                    if (IsStopOrInvalidate(resultCode = await owner.WaitEvents(30000, getBoundsTask)))
                    {
                        return(resultCode);
                    }
                    if (resultCode != ResultCode.UserEvent)
                    {
                        trace.Warning("reader didn't respond. Giving up by invalidating current progress.");
                        return(ResultCode.Invalidate);
                    }

                    bool ret = HandleResponse(await getBoundsTask, reversedMode);

                    trace.Info("returning {0}", ret);

                    return(ret ? ResultCode.Ok : ResultCode.None);
                }
            }
示例#7
0
 /// <summary>
 /// Calls the <paramref name="action"/> function in the synchronization context
 /// and returns the Task that is complete when passed function returned.
 /// </summary>
 public static Task Invoke(this ISynchronizationContext sync, Action action)
 {
     return(sync.Invoke(() => { action(); return 0; }));
 }