コード例 #1
0
 /// <summary>
 /// 从配置容器集合中移除所有配置容器。
 /// </summary>
 public void Clear()
 {
     _values.Clear();
     _contents.Clear();
     _contentSuperior.RemoveNodes();
     _declarations.Clear();
     _declarationSuperior.RemoveNodes();
     if (_savable.AutoSave)
     {
         _savable.Save();
     }
 }
コード例 #2
0
        private void Save()
        {
            while (true)
            {
                lock (_queue) {
#if DEBUG
                    ParallelUtility.countLocks("_queue");
#endif

                    if (_queue.Count == 0 && !_shutdown)
                    {
                        Monitor.Wait(_queue);
                    }

                    if (_queue.Count > 0)
                    {
                        ISavable item = _queue.Dequeue();

                        item.Save();
                    }
                    else if (_shutdown)
                    {
                        break;
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Save specified ISavable object to stream
 /// </summary>
 /// <param name="savable">ISavable to save</param>
 /// <param name="stream">Stream to save</param>
 public static void SaveToStream(ISavable savable, PCBinarySaveStream stream)
 {
     if (savable == null)
     {
         throw new ArgumentNullException("Invalid ISavable object.");
     }
     savable.Save(stream);
 }
コード例 #4
0
 public static void Save()
 {
     foreach (PluginPair plugin in AllPlugins)
     {
         ISavable savable = plugin.Plugin as ISavable;
         savable?.Save();
     }
 }
コード例 #5
0
        /// <summary>
        /// Create an instance of XmlSaveStream and save given ISavable
        /// </summary>
        /// <param name="savable">ISavable to save</param>
        public XmlSaveStream(ISavable savable)
        {
            Document = new XmlDocument();
            XmlElement rootNode = new XmlElement("SaveData");

            savable.Save(rootNode, this);
            Document.AppendChild(rootNode);
        }
コード例 #6
0
        public void SaveAs(ISavable savable, string fileName, string extension, string fileTypeName, string title)
        {
            var fileDialog = GetSaveFileDialog(fileName, extension, fileTypeName, title);

            if (fileDialog.ShowDialog() != true)
            {
                return;
            }

            savable.Save(fileDialog.FileName);
        }
コード例 #7
0
 /// <summary>
 /// 设置配置容器的串联内容。
 /// </summary>
 /// <param name="value">配置容器的串联内容。</param>
 /// <returns></returns>
 ///
 public void SetValue(string value)
 {
     if (value is null || value.Length == 0)
     {
         if (_content.Value.Length != 0)
         {
             _content.SetValue(string.Empty);
             if (_savable.AutoSave)
             {
                 _savable.Save();
             }
         }
     }
コード例 #8
0
        /// <summary>
        /// Save specified ISavable object to xml content
        /// </summary>
        /// <param name="savable">ISavable to save</param>
        /// <returns>Saved data as string in xml format</returns>
        public static string SaveToXmlContent(ISavable savable)
        {
            if (savable == null)
            {
                throw new ArgumentNullException("Invalid ISavable object.");
            }

            XmlSaveStream SaveStream = new XmlSaveStream();
            XmlElement    root       = new XmlElement(RootXmlElementName);

            savable.Save(root, SaveStream);
            SaveStream.Document.AppendChild(root);
            return(SaveStream.Document.OuterXml);
        }
コード例 #9
0
        //----------------------------------------------------------------------------------------------------------------------
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            var viewModel = new PlayerViewModel();

            DataContext = viewModel;

            IPlayerActionQueriable playerAction = DataContext as IPlayerActionQueriable;

            if (playerAction != null)
            {
                playerAction.PlayQuery             += Play;
                playerAction.PauseQuery            += Pause;
                playerAction.StopQuery             += Stop;
                playerAction.ListChangeQuery       += PlayerActionOnListChangeQuery;
                playerAction.FolderDialogQuery     += playerAction_FolderDialogQuery;
                playerAction.ChangePathDialogQuery += playerAction_ChangePathDialogQuery;
            }
            ISavable saveModel = DataContext as ISavable;

            if (saveModel != null)
            {
                this.Closing += (s, ev) => saveModel.Save();;
            }
//            workPlayer.Stretch = Stretch.;
            workPlayer.StretchDirection = StretchDirection.Both;


            Binding bindingCurrentTrackDeletePressCommand = new Binding("CurrentTrackDeletePressCommand");

            bindingCurrentTrackDeletePressCommand.Source = DataContext;
            BindingOperations.SetBinding(this, PlayerWindow.CurrentTrackDeletePressCommandProperty, bindingCurrentTrackDeletePressCommand);

            Binding bindingCurrentTrackDoubleClickCommand = new Binding("CurrentTrackDoubleClickCommand");

            bindingCurrentTrackDoubleClickCommand.Source = DataContext;
            BindingOperations.SetBinding(this, PlayerWindow.CurrentTrackDoubleClickCommandProperty, bindingCurrentTrackDoubleClickCommand);

            IScrollIntoViewAction scrollIntoViewAction = (IScrollIntoViewAction)DataContext;

            scrollIntoViewAction.MainGridScrollIntoView += i =>
            {
                ScrollIntoView();
            };
            playerAction.OnLoad();
            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick    += timer_Tick;
            timer.Start();
        }
コード例 #10
0
            public void Intercept(IInvocation invocation)
            {
                invocation.Proceed();
                if (invocation.Method.Name.StartsWith("set_", StringComparison.Ordinal))
                {
                    var propname = invocation.Method.Name.Substring(4);
                    if (_jsonSettingsAbstractionVirtuals.Any(av => av == propname))
                    {
                        return;
                    }

                    //save.
                    _settings.Save();
                }
            }
コード例 #11
0
        public void SaveFile(Symbol musicData)
        {
            if (saveFileDialog.ShowDialog() == true)
            {
                string extension = Path.GetExtension(saveFileDialog.FileName);

                ISavable saver = converterGetter.GetSaver(extension);

                if (saver == null)
                {
                    MessageBox.Show($"Extension {extension} is not supported.");
                    return;
                }
                saver.Save(saveFileDialog.FileName, musicData);
            }
        }
コード例 #12
0
        internal void SaveFile(Symbol musicData, string extension)
        {
            ISavable saver = converterGetter.GetSaver(extension);

            if (saver == null)
            {
                MessageBox.Show($"Extension {extension} is not supported.");
                return;
            }

            string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            string newpath  = Path.GetFullPath(Path.Combine(path, @"..\..\"));
            string Filename = newpath + "/Files/autogenerated_pdf_" + DateTime.Now.Ticks.ToString();

            saver.Save(Filename, musicData);
        }
コード例 #13
0
        public void XmlSaveToFileTest()
        {
            Assert.AreEqual(nodeCount, sGraph.Node.Count);
            Assert.AreEqual(edgeCount, sGraph.Edge.Count);

            fileNameExtension = ".xml";

            saveToFile = new XmlSaveToFile <int, int>(filePath);
            saveToFile.Save(sGraph);

            sGraph.Node.Clear();
            sGraph.Edge.Clear();

            sGraph = saveToFile.Load();

            Assert.AreEqual(nodeCount, sGraph.Node.Count);
            Assert.AreEqual(edgeCount, sGraph.Edge.Count);
        }
コード例 #14
0
        void Example()
        {
            // ** Inicjalize graph
            graph.AddNode(51);
            graph.AddNode(12);

            graph.AddEdge(graph[0], graph[1]);
            // ** End inicjalize

            converter = new SerializableGraphConverter <int, int>(graph);

            serializableGraph = converter.GetSerializableGraph();

            saver = new BinarySaveToFile <int, int>(filePath + ".bin"); // bin file or
            saver = new JsonSaveToFile <int, int>(filePath + ".json");  // json text file or
            saver = new XmlSaveToFile <int, int>(filePath + ".xml");    // xml file

            saver.Save(serializableGraph);                              // Save to file.

            serializableGraph = saver.Load();                           // Load from file.
        }
コード例 #15
0
        //-------------------------------------------------------------------------------------------------------------------
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var viewModel = new Fb2PlayerViewModel.Fb2PlayerViewModel();

            DataContext = viewModel;

            ISavable saveModel = DataContext as ISavable;

            if (saveModel != null)
            {
                this.Closing += (s, ev) => saveModel.Save();;
            }
            IScrollIntoViewAction scrollIntoViewAction = (IScrollIntoViewAction)DataContext;

            if (scrollIntoViewAction != null)
            {
                scrollIntoViewAction.SpeechPhraseScrollIntoView += () =>
                {
                    SpeechPhraseScrollIntoView();
                };
            }
        }
コード例 #16
0
ファイル: JObjectArray.cs プロジェクト: bonahona/BonaJson
 public override JObject Add(object element)
 {
     if (element == null)
     {
         return(Add(new JNullObject()));
     }
     else if (element is bool)
     {
         return(Add(new JBoolObject((bool)element)));
     }
     else if (element is float)
     {
         return(Add(new JValueObject((float)element)));
     }
     else if (element is int)
     {
         return(Add(new JIntObject((int)element)));
     }
     else if (element is string)
     {
         return(Add(new JStringObject((string)element)));
     }
     else if (element is JObject)
     {
         return(Add((JObject)element));
     }
     else if (element is ISavable)
     {
         ISavable tmpObject = (ISavable)element;
         return(Add(tmpObject.Save()));
     }
     else
     {
         throw new InvalidCastException();
     }
 }
コード例 #17
0
 public void Execute()
 {
     savable.Save();
 }
コード例 #18
0
        private bool ExecuteSaveAction(ISavable savableObject, ITrackStatus trackableObject, CslaActionExtenderProperties props)
        {
            var  result       = true;
            bool okToContinue = true;

            BusinessBase businessObject = null;
            bool         savableObjectIsBusinessBase = savableObject is BusinessBase;

            if (savableObjectIsBusinessBase)
            {
                businessObject = savableObject as BusinessBase;
            }

            if (savableObjectIsBusinessBase)
            {
                if (!businessObject.IsValid)
                {
                    HasBrokenRulesEventArgs argsHasBrokenRules = new HasBrokenRulesEventArgs(
                        props.CommandName,
                        businessObject.GetBrokenRules().ErrorCount > 0,
                        businessObject.GetBrokenRules().WarningCount > 0,
                        businessObject.GetBrokenRules().InformationCount > 0,
                        _autoShowBrokenRules);

                    OnHasBrokenRules(argsHasBrokenRules);

                    okToContinue = !argsHasBrokenRules.Cancel;
                    //in case the client changed it
                    _autoShowBrokenRules = argsHasBrokenRules.AutoShowBrokenRules;
                }
            }

            if (okToContinue)
            {
                if (savableObjectIsBusinessBase)
                {
                    if (_autoShowBrokenRules && !businessObject.IsValid)
                    {
                        // todo: add child broken rules
                        string brokenRules = string.Empty;
                        foreach (var brokenRule in businessObject.GetBrokenRules())
                        {
                            var lambdaBrokenRule = brokenRule;
                            var friendlyName     =
                                PropertyInfoManager.GetRegisteredProperties(businessObject.GetType()).Find(
                                    c => c.Name == lambdaBrokenRule.Property).FriendlyName;
                            brokenRules += string.Format("{0}: {1}{2}", friendlyName, brokenRule, Environment.NewLine);
                        }
                        MessageBox.Show(brokenRules, Resources.ActionExtenderErrorCaption,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                if (trackableObject.IsValid)
                {
                    CslaActionCancelEventArgs savingArgs = new CslaActionCancelEventArgs(false, props.CommandName);
                    OnObjectSaving(savingArgs);

                    if (!savingArgs.Cancel)
                    {
                        _bindingSourceTree.Apply();
                        ISavable objectToSave;

                        if (Csla.ApplicationContext.AutoCloneOnUpdate == false)
                        {
                            objectToSave = ((ICloneable)savableObject).Clone() as ISavable;// if not AutoClone, clone manually
                        }
                        else
                        {
                            objectToSave = savableObject;
                        }

                        if (objectToSave != null)
                        {
                            try
                            {
                                RemoveEventHooks(savableObject);
                                savableObject = savableObject.Save() as ISavable;

                                OnObjectSaved(new CslaActionEventArgs(props.CommandName));

                                switch (props.PostSaveAction)
                                {
                                case PostSaveActionType.None:

                                    if (props.RebindAfterSave)
                                    {
                                        _bindingSourceTree.Bind(savableObject);
                                        AddEventHooks(savableObject);
                                    }
                                    break;

                                case PostSaveActionType.AndClose:

                                    CloseForm();
                                    break;

                                case PostSaveActionType.AndNew:

                                    OnSetForNew(new CslaActionEventArgs(props.CommandName));
                                    AddEventHooks(savableObject);
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                _bindingSourceTree.Bind(objectToSave);
                                AddEventHooks(objectToSave);
                                OnErrorEncountered(new ErrorEncounteredEventArgs(props.CommandName, new ObjectSaveException(ex)));
                                // there was some problem
                                result = false;
                            }
                        }
                        else
                        {
                            // did not find bound object so don't bother raising the Clicked event
                            result = false;
                        }

                        _bindingSourceTree.SetEvents(true);
                    }
                }
                else
                {
                    OnBusinessObjectInvalid(new CslaActionEventArgs(props.CommandName));
                    // object not valid or has broken rules set to invalidate it due to this control's properties
                    result = false;
                }
            }
            else
            {
                // process was canceled from the HasBrokenRules event (okToContinue = false)
                result = false;
            }

            return(result);
        }
    private bool ExecuteSaveAction(ISavable savableObject, ITrackStatus trackableObject, CslaActionExtenderProperties props)
    {
      var result = true;
      bool okToContinue = true;

      BusinessBase businessObject = null;
      bool savableObjectIsBusinessBase = savableObject is BusinessBase;
      if (savableObjectIsBusinessBase)
        businessObject = savableObject as BusinessBase;

      if (savableObjectIsBusinessBase)
      {
        if (!businessObject.IsValid)
        {
          HasBrokenRulesEventArgs argsHasBrokenRules = new HasBrokenRulesEventArgs(
            props.CommandName,
            businessObject.GetBrokenRules().ErrorCount > 0,
            businessObject.GetBrokenRules().WarningCount > 0,
            businessObject.GetBrokenRules().InformationCount > 0,
            _autoShowBrokenRules);

          OnHasBrokenRules(argsHasBrokenRules);

          okToContinue = !argsHasBrokenRules.Cancel;
          //in case the client changed it
          _autoShowBrokenRules = argsHasBrokenRules.AutoShowBrokenRules;
        }
      }

      if (okToContinue)
      {
        if (savableObjectIsBusinessBase)
        {
          if (_autoShowBrokenRules && !businessObject.IsValid)
          {
            // todo: add child broken rules
            string brokenRules = string.Empty;
            foreach (var brokenRule in businessObject.GetBrokenRules())
            {
              var lambdaBrokenRule = brokenRule;
              var friendlyName =
                PropertyInfoManager.GetRegisteredProperties(businessObject.GetType()).Find(
                  c => c.Name == lambdaBrokenRule.Property).FriendlyName;
              brokenRules += string.Format("{0}: {1}{2}", friendlyName, brokenRule, Environment.NewLine);
            }
#if !WEBGUI
            MessageBox.Show(brokenRules, Resources.ActionExtenderErrorCaption,
              MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
            MessageBox.Show(brokenRules, Resources.ActionExtenderErrorCaption,
              MessageBoxButtons.OK, MessageBoxIcon.Error,
              messageBoxClosedHandler, false);
#endif
          }
        }

        if (trackableObject.IsValid)
        {
          CslaActionCancelEventArgs savingArgs = new CslaActionCancelEventArgs(false, props.CommandName);
          OnObjectSaving(savingArgs);

          if (!savingArgs.Cancel)
          {
            _bindingSourceTree.Apply();
            ISavable objectToSave;

            if (Csla.ApplicationContext.AutoCloneOnUpdate == false)
              objectToSave = ((ICloneable)savableObject).Clone() as ISavable;// if not AutoClone, clone manually
            else
              objectToSave = savableObject;

            if (objectToSave != null)
            {
              try
              {
                RemoveEventHooks(savableObject);
                savableObject = savableObject.Save() as ISavable;

                OnObjectSaved(new CslaActionEventArgs(props.CommandName));

                switch (props.PostSaveAction)
                {
                  case PostSaveActionType.None:

                    if (props.RebindAfterSave)
                    {
                      _bindingSourceTree.Bind(savableObject);
                      AddEventHooks(savableObject);
                    }
                    break;

                  case PostSaveActionType.AndClose:

                    CloseForm();
                    break;

                  case PostSaveActionType.AndNew:

                    OnSetForNew(new CslaActionEventArgs(props.CommandName));
                    AddEventHooks(savableObject);
                    break;
                }
              }
              catch (Exception ex)
              {
                _bindingSourceTree.Bind(objectToSave);
                AddEventHooks(objectToSave);
                OnErrorEncountered(new ErrorEncounteredEventArgs(props.CommandName, new ObjectSaveException(ex)));
                // there was some problem
                result = false;
              }
            }
            else
            {
              // did not find bound object so don't bother raising the Clicked event
              result = false;
            }

            _bindingSourceTree.SetEvents(true);
          }
        }
        else
        {
          OnBusinessObjectInvalid(new CslaActionEventArgs(props.CommandName));
          // object not valid or has broken rules set to invalidate it due to this control's properties
          result = false;
        }
      }
      else
      {
        // process was canceled from the HasBrokenRules event (okToContinue = false)
        result = false;
      }

      return result;
    }
コード例 #20
0
 public void Save(double meony)
 {
     _savable.Save(meony);
 }