コード例 #1
0
ファイル: App.xaml.cs プロジェクト: clovett/FoscamExplorer
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            Log.WriteLine("App OnSuspending");

            var deferral = e.SuspendingOperation.GetDeferral();

            if (Window.Current != null)
            {
                Frame frame = Window.Current.Content as Frame;
                if (frame != null && frame.Content != null)
                {
                    Log.WriteLine("Frame content found: " + frame.Content.GetType().FullName);

                    ISuspendable sus = frame.Content as ISuspendable;
                    if (sus != null)
                    {
                        sus.OnSuspending();
                    }
                }
                else
                {
                    Log.WriteLine("no frame or no frame content");
                }
            }

            Log.CloseLog();

            deferral.Complete();
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Suspender"/> class.
 /// </summary>
 /// <param name="instance">The instance.</param>
 public Suspender(ISuspendable instance)
 {
     suspendable = instance;
     if (suspendable != null)
     {
         suspendable.Suspend();
     }
 }
コード例 #3
0
        /// <summary>
        /// Registers a suspendable item with the <see cref="SuspensionManager"/>.
        /// </summary>
        /// <param name="item">
        /// The suspendable item to register.
        /// </param>
        public void Register(ISuspendable item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            this.suspendableCache.Add(new WeakReference <ISuspendable>(item));
        }
コード例 #4
0
        /// <inheritdoc />
        public void Add(ISuspendable suspendable)
        {
            if (suspendable == null)
            {
                throw new ArgumentNullException(nameof(suspendable));
            }

            this.items.Add(new WeakReference <ISuspendable>(suspendable));
        }
コード例 #5
0
ファイル: SuspensionManager.cs プロジェクト: Branchie/Gypo
 public static void Unregister(ISuspendable suspendable, params string[] keys)
 {
     foreach (string key in keys)
     {
         if (suspendables.TryGetValue(key, out List <SuspendableObject> result))
         {
             result.RemoveAll(s => s.Equals(suspendable));
         }
     }
 }
コード例 #6
0
ファイル: SuspensionManager.cs プロジェクト: Branchie/Gypo
        public static void Register(ISuspendable suspendable, params string[] keys)
        {
            foreach (string key in keys)
            {
                if (!suspendables.TryGetValue(key, out List <SuspendableObject> result))
                {
                    result = new List <SuspendableObject>();
                    suspendables.Add(key, result);
                }

                result.Add(new SuspendableObject(suspendable));
            }
        }
コード例 #7
0
        private void TransportInterrupted(ITransport sender)
        {
            ISuspendable service = this.discoveryAgent as ISuspendable;

            if (service != null)
            {
                try
                {
                    service.Resume();
                }
                catch (Exception e)
                {
                    Tracer.WarnFormat("Caught error while resuming service: {0} - {1}", service, e.Message);
                }
            }

            if (this.Interrupted != null)
            {
                this.Interrupted(sender);
            }
        }
コード例 #8
0
        /// <summary>
        /// Unregisters a suspendable item from the <see cref="SuspensionManager"/>.
        /// </summary>
        /// <param name="item">
        /// The suspendable item to unregister.
        /// </param>
        public void Unregister(ISuspendable item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var cacheItem = this.suspendableCache.FirstOrDefault(
                x =>
            {
                ISuspendable cache;
                var exists = x.TryGetTarget(out cache);

                if (exists)
                {
                    return(cache == item);
                }

                return(false);
            });

            this.suspendableCache.Remove(cacheItem);
        }
コード例 #9
0
        /// <inheritdoc />
        public void Remove(ISuspendable suspendable)
        {
            if (suspendable == null)
            {
                throw new ArgumentNullException(nameof(suspendable));
            }

            var existingItem = this.items.FirstOrDefault(
                x =>
            {
                ISuspendable s;
                var exists = x.TryGetTarget(out s);

                if (exists)
                {
                    return(s == suspendable);
                }

                return(false);
            });

            this.items.Remove(existingItem);
        }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Suspender"/> class.
 /// </summary>
 /// <param name="instance">The instance.</param>
 public Suspender(ISuspendable instance)
 {
     suspendable = instance;
     if (suspendable != null) suspendable.Suspend();
 }
コード例 #11
0
 public static void SetPassSurfaceToViewModel(DependencyObject element, ISuspendable value)
 {
     element.SetValue(PassSurfaceToViewModelProperty, value);
 }
コード例 #12
0
 public SuspendScope(ISuspendable suspender)
 {
     _suspendable = suspender;
     _suspendable.Suspend();
 }
コード例 #13
0
ファイル: SuspensionManager.cs プロジェクト: Branchie/Gypo
 public bool Equals(ISuspendable suspendable) => Equals(this.suspendable, suspendable);
コード例 #14
0
ファイル: SuspensionManager.cs プロジェクト: Branchie/Gypo
 public SuspendableObject(ISuspendable suspendable)
 {
     this.suspendable = suspendable;
 }