コード例 #1
0
ファイル: Restore.cs プロジェクト: Jebik/SqlRestoreTool
 public void RestoreAtTime(string path, List <string> transactionFilesDestPath, DateTime time, string restore_name, RestoreOption restoreOption)
 {
     _transactions = transactionFilesDestPath;
     _time         = time;
     _mode         = RestoreMode.AtTime;
     RestoreBackup(path, restore_name, restoreOption);
 }
コード例 #2
0
        protected void Restore(RestoreMode restore)
        {
            // Auto-bound SmartRefs get bound first time value added/removed after they're queued
            if (_binder.hasRefsToBind)
            {
                _binder.AutoBind();
            }

            if (_hasDecorators)
            {
                for (int i = 0; i < _decorators.Length; ++i)
                {
                    ((SmartSetDecoratorBase <TData>)_decorators[i]).BeginRestore(restore);
                }
            }

            // Outer try-finally to allow throw within catch while still ensuring inner finally is executed.
            try {
                try {
                    SetAll(_set);
                } catch {
                    Debug.LogError("Exception thrown during " + name + ".Restore(). OnEndRestore will still be called on all decorators. Exception follows.");
                    throw;
                } finally {
                    // Ensure decorator state always reset correctly
                    for (int i = 0; i < _decorators.Length; ++i)
                    {
                        ((SmartSetDecoratorBase <TData>)_decorators[i]).EndRestore();
                    }
                }
            } finally {}
        }
コード例 #3
0
        private async Task ClientOnClickExecute(ServerAccess ba, string client, RestoreMode mode)
        {
            try
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
                {
                    Files.Clear();
                }));

                using (new NetworkConnection(ba.uri, new NetworkCredential(ba.username, ba.password)))
                {
                    string        path  = Path.Combine(ba.uri, ba.dailyfolder, client);
                    DirectoryInfo dir   = new DirectoryInfo(path);
                    FileInfo[]    files = dir.GetFiles("*.bak").OrderByDescending(p => p.CreationTime).ToArray();

                    if (files.Count() > 0)
                    {
                        await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
                        {
                            SelectedTime = DateTime.Now;
                            for (int i = 0; i < files.Count(); i++)
                            {
                                Files.Add(files[i]);
                            }
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
コード例 #4
0
 /// <summary>
 /// Safely try to restore to serialized value.
 /// </summary>
 /// <param name="init">Passed in OnEnable to set initial value without dispatching events or decorators.</summary>
 protected void Restore(RestoreMode restore)
 {
     try {
         OnRestore(restore);
     } catch {
         Debug.LogErrorFormat("Automatic reset behaviour for {0}/{1} failed. Please override {0}.OnRestore().", GetType().Name, this.name);
         throw;
     }
 }
コード例 #5
0
        public override float OnUpdated(float oldValue, float newValue, RestoreMode restoreMode, ref BlockFlags block)
        {
            float result = Mathf.Clamp(newValue, _min, _max);

            if (result != newValue)
            {
                _onRangeClamped.Dispatch(this, result, newValue);
            }
            return(result);
        }
コード例 #6
0
 public override TData OnUpdated(TData oldValue, TData newValue, RestoreMode restoreMode, ref BlockFlags block)
 {
     Send(newValue);
     // Stop event from being dispatched locally
     if (_networkOnlyDispatch)
     {
         block |= BlockFlags.DISPATCH;
     }
     // Stop data from being updated locally
     if (_networkOnlyValue)
     {
         block |= BlockFlags.DATA;
     }
     return(newValue);
 }
コード例 #7
0
        void SetValue(TData v, RestoreMode restore)
        {
            // When setting initial value, don't dispatch anything or use decorators
            if (restore == RestoreMode.INIT)
            {
                _runtimeValue = v;
                return;
            }

            // Auto-bound SmartRefs get bound first time value changes after they're queued
            if (_binder.hasRefsToBind)
            {
                _binder.AutoBind();
            }

            BlockFlags block = BlockFlags.NONE;

            if (_hasDecorators)
            {
                TData temp = v;
                temp = ExecuteDecoratorsOnUpdate(_decorators, _runtimeValue, temp, restore, ref block);
                // If decorators blocked, do not continue to other decorators
                if (!block.Contains(BlockFlags.DECORATORS) && _multiDecorators.Count > 0)
                {
                    foreach (var a in _multiDecorators)
                    {
                        temp = ExecuteDecoratorsOnUpdate(a.Value, _runtimeValue, temp, restore, ref block);
                    }
                }

                // If data blocked, do not update runtime value
                if (!block.Contains(BlockFlags.DATA))
                {
                    _runtimeValue = temp;
                }
            }
            else
            {
                _runtimeValue = v;
            }

            // If dispatch blocked, do not dispatch relay
            if (!block.Contains(BlockFlags.DISPATCH))
            {
                _relay.Dispatch(_runtimeValue);
            }
        }
コード例 #8
0
        /// <summary>
        /// Restore runtime value to default (serialized) value.
        /// <para />Override this to implement type-specific restore behaviour.
        /// </summary>
        /// <param name="init">Passed in OnEnable to set initial value without dispatching events or decorators.</summary>
        protected virtual void OnRestore(RestoreMode restore)
        {
            // Storing and restoring defaults are same action
            // Storing actually means writing existing value to runtime value
            switch (_dataType)
            {
            case DataType.STRUCT:
            case DataType.CLASS:
                SetValue(_value, restore);
                break;

            case DataType.ARRAY:
                SetValue((TData)(_value as System.Array).Clone(), restore);
                break;

            case DataType.DICTIONARY:
                var      dType    = typeof(TData);
                object[] argsDict = new object[] { _value };
                if (argsDict[0] != null)
                {
                    // Find Dictionary<T1,T1>(IDictionary<T1,T2>) copy constructor
                    if (_dictionaryConstructor == null)
                    {
                        var _iDictType = typeof(IDictionary <,>).MakeGenericType(
                            dType.GetGenericArguments()
                            );
                        _dictionaryConstructor = dType.GetConstructor(new System.Type[] { _iDictType });
                    }
                    SetValue((TData)_dictionaryConstructor.Invoke(argsDict), restore);
                }
                else
                {
                    // Empty dictionary - just create a new one
                    SetValue((TData)System.Activator.CreateInstance(dType), restore);
                }
                break;

            case DataType.COLLECTION:
                object[] argsCol = new object[] { _value };
                SetValue((TData)System.Activator.CreateInstance(typeof(TData), argsCol), restore);
                break;
            }
        }
コード例 #9
0
        private async Task SwitchExecute(ServerAccess ba, RestoreMode mode)
        {
            try
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
                {
                    Clients.Clear();
                }));

                using (new NetworkConnection(ba.uri, new NetworkCredential(ba.username, ba.password)))
                {
                    var listClientRemote = Directory.GetDirectories(ba.uri);

                    var path       = Path.Combine(ba.uri, ba.dailyfolder);
                    var listClient = Directory.GetDirectories(path);

                    var cleanList = new List <string>();
                    foreach (var c in listClient)
                    {
                        var substring = c.Remove(c.IndexOf(path), path.Length + 1);
                        cleanList.Add(substring);
                    }
                    var sortedList = cleanList.OrderBy(c => c).ToList();

                    await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
                    {
                        foreach (var c in sortedList)
                        {
                            Clients.Add(c);
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
コード例 #10
0
 TData ExecuteDecoratorsOnUpdate(SmartDecoratorBase[] decorators, TData oldValue, TData newValue, RestoreMode restore, ref BlockFlags block)
 {
     if (decorators != null && decorators.Length != 0)
     {
         for (int i = 0; i < decorators.Length; ++i)
         {
             var d = decorators[i];
             if (d.active)
             {
                 newValue = (decorators[i] as SmartDataDecoratorBase <TData>).OnUpdated(oldValue, newValue, restore, ref block);
                 // If decorators blocked, do not continue to other decorators
                 if (block.Contains(BlockFlags.DECORATORS))
                 {
                     break;
                 }
             }
         }
     }
     return(newValue);
 }
コード例 #11
0
 protected abstract void Send(SetEventData <TData> data, RestoreMode restoreMode);
コード例 #12
0
ファイル: Restore.cs プロジェクト: Jebik/SqlRestoreTool
 public void Restore(string path, string restore_name, RestoreOption restoreOption)
 {
     _mode = RestoreMode.AtDate;
     RestoreBackup(path, restore_name, restoreOption);
 }