Ejemplo n.º 1
0
 public bool Save()
 {
     if (item.Name == null || item.Name.Length == 0)
     {
         MessageBox.Show("Unable to save without a name");
         return(false);
     }
     try
     {
         bool saved = item.Save(false);
         if (!saved && MessageBox.Show("File exists! Overwrite?", "File exists", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             saved = item.Save(true);
         }
         if (saved)
         {
             UnsavedChanges = 0;
             Saved?.Invoke(this, item.Name + " " + ConfigManager.SourceSeperator + " " + item.Source);
         }
         return(saved);
     } catch (Exception e)
     {
         MessageBox.Show(e.Message);
         return(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Сохранение данных
        /// </summary>
        /// <returns>True если сохранение произошло успешно</returns>
        public bool Save()
        {
            bool result = SaveSessionData(null);

            Saved?.Invoke(null, EventArgs.Empty);
            return(result);
        }
Ejemplo n.º 3
0
 public bool Save()
 {
     if (Pack.Name == null || Pack.Name.Length == 0)
     {
         MessageBox.Show("Unable to save without a name");
         return(false);
     }
     Pack.Weight = 0;
     foreach (string i in Pack.Contents)
     {
         Pack.Weight += Program.Context.GetItem(i, Pack.Source).Weight;
     }
     try
     {
         bool saved = Pack.Save(false);
         if (!saved && MessageBox.Show("File exists! Overwrite?", "File exists", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             saved = Pack.Save(true);
         }
         if (saved)
         {
             UnsavedChanges = 0;
             Saved?.Invoke(this, Pack.Name + " " + ConfigManager.SourceSeperator + " " + Pack.Source);
         }
         return(saved);
     } catch (Exception e)
     {
         MessageBox.Show(e.Message);
         return(false);
     }
 }
Ejemplo n.º 4
0
        private static void Save(Pattern pattern)
        {
            if (!Directory.Exists(DIRECTORY))
            {
                Directory.CreateDirectory(DIRECTORY);
            }

            var path = GetPath(pattern.name);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (var stream = new FileStream(path, FileMode.CreateNew))
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(pattern.ToJson());
                }
            }

            pattern.UpdateLastWriteTime();

            Saved?.Invoke(pattern);
        }
Ejemplo n.º 5
0
        private async Task CoreHandler()
        {
            var canEnter = await once.WaitAsync(BindSettings.DelayTime);

            if (canEnter && Interlocked.CompareExchange(ref notify, 0, 1) == 1)
            {
                try
                {
                    var infos = ChangeWatcher.ChangeInfos;
                    ChangeWatcher.Clear();
                    var repo  = ChangeReport.FromChanges(GetConfiguration(), infos);
                    var saver = new ChangeSaver(repo, BindSettings.Conditions);
                    saver.EmitAndSave();
                    OnConfigChanged(infos);
                    Saved?.Invoke(this, infos);
                }
                catch (Exception ex)
                {
                    SaveException?.Invoke(this, ex);
                }
                finally
                {
                    Interlocked.Exchange(ref notify, 1);
                }
            }
        }
Ejemplo n.º 6
0
        public void SaveAll()
        {
            CheckDescriptionUpdate();

            Context.UnsavedChanges = false;
            Saved?.Invoke(this, null);
        }
Ejemplo n.º 7
0
        private void Save()
        {
            Source.Source = CodeSource.Text;

            Context.UnsavedChanges = true;
            Saved?.Invoke(this, null);
        }
Ejemplo n.º 8
0
 private void OnSaved(Object dataObject)
 {
     if (Saving != null)
     {
         Saved.Invoke(dataObject, EventArgs.Empty);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Saves the surface to bytes. Performs also modified child surfaces saving before.
        /// </summary>
        /// <remarks>
        /// Assume this method does not throw exceptions but uses return value as a error code.
        /// </remarks>
        /// <returns>True if failed, otherwise false.</returns>
        public bool Save()
        {
            // Save all children modified before saving the current surface
            for (int i = 0; i < Children.Count; i++)
            {
                if (Children[i].IsModified && Children[i].Save())
                {
                    return(true);
                }
            }

            _meta.Release();

            Saving?.Invoke(this);

            // Save surface meta
            _meta.AddEntry(10, Utils.StructureToByteArray(ref CachedSurfaceMeta));

            // Save all nodes meta
            VisjectSurface.Meta11 meta11;
            for (int i = 0; i < Nodes.Count; i++)
            {
                var node = Nodes[i];
                meta11.Position = node.Location;
                meta11.Selected = false; // don't save selection to prevent stupid binary diffs on asset
                node.Meta.Release();
                // TODO: reuse byte[] array for all nodes to reduce dynamic memory allocations
                node.Meta.AddEntry(11, Utils.StructureToByteArray(ref meta11));
            }

            // Save graph
            try
            {
                // Save graph
                using (var stream = new MemoryStream())
                    using (var writer = new BinaryWriter(stream))
                    {
                        // Save graph to bytes
                        SaveGraph(writer);
                        var bytes = stream.ToArray();

                        // Send data to the container
                        Context.SurfaceData = bytes;

                        Saved?.Invoke(this);

                        // Clear modification flag
                        _isModified = false;
                    }
            }
            catch (Exception ex)
            {
                // Error
                Editor.LogWarning("Saving Visject Surface data failed.");
                Editor.LogWarning(ex);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        public async Task <bool> SaveAsync()
        {
            Log.Debug($"[{Scope}] Saving snapshots");

            var savingAsync = SavingAsync;

            if (savingAsync is not null)
            {
                var cancelEventArgs = new CancelEventArgs();
                await savingAsync(this, cancelEventArgs);

                if (cancelEventArgs.Cancel)
                {
                    Log.Info("Saving canceled by SavingAsync event");
                    return(false);
                }
            }

            var snapshots = new List <ISnapshot>();

            lock (_snapshots)
            {
                snapshots.AddRange(_snapshots);
            }

            await _snapshotStorageService.SaveSnapshotsAsync(snapshots);

            Saved?.Invoke(this, EventArgs.Empty);

            Log.Info($"[{Scope}] Saved '{snapshots.Count}' snapshots");

            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Сохранение данных в указанный файл
        /// </summary>
        /// <param name="newFileName">Имя файла</param>
        /// <returns>True если сохранение произошло успешно</returns>
        public bool SaveAs(string newFileName)
        {
            bool result = SaveSessionData(newFileName);

            Saved?.Invoke(null, EventArgs.Empty);
            return(result);
        }
Ejemplo n.º 12
0
        public void Save()
        {
            AssetDatabase.CreateAsset(Obj, AssetPath);
            AssetDatabase.SaveAssets();

            Saved?.Invoke(this, new ObjectSavedEventArgs(Obj));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Make sure all entries are filled, then save the new donor to the database
        /// </summary>
        public void Save(object sender, EventArgs e)
        {
            bool allEntriesFilled = Utilities.AllEntriesFilled(this);

            if (allEntriesFilled == true)
            {
                var bloodGroup = BloodBankManager.Utilities.GetBloodGroup(this);
                var donor      = new Donor
                {
                    Name          = donor_name.Text,
                    Age           = donor_age.Text,
                    BloodGroup    = bloodGroup.Text,
                    Sex           = donor_sex.SelectedItem.ToString(),
                    StreetAddress = donor_street_address.Text,
                    City          = donor_city.Text,
                    State         = donor_state.SelectedItem.ToString(),
                    Date          = DateTime.Parse(donor_date.Text),
                    PhoneNumber   = donor_phonenumber.Text,
                    Email         = donor_email.Text,
                    Rh            = donor_rh.SelectedItem.ToString(),

                    //This is a dummy value for @responseMessage to be assigned to if no error occurs
                    Error = "No Error"
                };
                donor.Save();
                Saved.Invoke(this, EventArgs.Empty);
                MessageBox.Show(donor.Name + " has been saved");
                Utilities.ResetAllControls(this);
            }
            else
            {
                MessageBox.Show("Please fill out all entries before saving");
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Saves the Model
        /// </summary>
        /// <returns></returns>
        public async Task SaveAsync()
        {
            Exception          = null;
            ViewModelErrorText = null;
            if (Model is Core.ITrackStatus obj && !obj.IsSavable)
            {
                ViewModelErrorText = ModelErrorText;
                return;
            }
            try
            {
                Model = await DoSaveAsync();

                Saved?.Invoke();
            }
            catch (DataPortalException ex)
            {
                Exception          = ex;
                ViewModelErrorText = ex.BusinessExceptionMessage;
            }
            catch (Exception ex)
            {
                Exception          = ex;
                ViewModelErrorText = ex.Message;
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Raises the <see cref = "E:Saved"/> event.
 /// </summary>
 /// <param name = "e">The <see cref = "SaveEventArgs"/> instance containing the event data.</param>
 protected internal virtual void OnSaved(SaveEventArgs e)
 {
     InvalidateCachedReferences();
     Saved?.Invoke(this, e);
     EntityManager.RaiseStaticOnSaved(this, e);
     InvalidateCachedReferences();
 }
Ejemplo n.º 16
0
 internal void OnSave(object saver)
 {
     if (Saved != null)
     {
         Saved.Invoke(saver, EventArgs.Empty);
     }
 }
        private void SaveClick(object sender, RoutedEventArgs e)
        {
            var feedInfos = new List <FeedInfo>();

            foreach (CheckBox cb in pnlFeedSelection.Children.Cast <CheckBox>())
            {
                var feedInfo = cb.Tag as FeedInfo;

                feedInfo.IsSelected = cb.IsChecked.Value;
                feedInfos.Add(feedInfo);
            }

            // Set default opening behavior
            Options.Instance.OpenInDefaultBrowser = cbOpenInVS.IsChecked.Value;

            // Set selected feeds
            DeveloperNewsPackage.Store.FeedInfos = feedInfos;

            // Save selection and Options
            DeveloperNewsPackage.Store.SaveSelection();

            CancelClick(sender, e);

            Saved?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Saves all files that have been modified.
        /// </summary>
        /// <param name="m">The monitor.</param>
        /// <returns>True on success, false on error.</returns>
        public bool Save(IActivityMonitor m)
        {
            bool saved = false;

            if (_isDirtyProjectFiles)
            {
                foreach (var p in MSProjects)
                {
                    if (!p.ProjectFile.Save(m, FileSystem))
                    {
                        return(false);
                    }
                }
                CheckDirtyProjectFiles(false);
                saved = true;
            }
            if (_isDirtyStructure)
            {
                using (var w = new System.IO.StringWriter())
                {
                    Write(w);
                    FileSystem.CopyTo(m, w.ToString(), FilePath);
                }
                saved = true;
            }
            if (saved)
            {
                Saved?.Invoke(this, new EventMonitoredArgs(m));
            }
            return(true);
        }
Ejemplo n.º 19
0
        public void Save()
        {
            if (LogEntries.Count == 0)
            {
                return;
            }

            lock (_logEntriesLock)
            {
                var serializer =
                    new Serializer(new[]
                {
                    typeof(List <KeyLogEntry>), typeof(NormalText), typeof(SpecialKey),
                    typeof(StandardKey),
                    typeof(WindowChanged)
                });

                Directory.CreateDirectory(Path.GetDirectoryName(_fileName));

                using (var fs = new FileStream(_fileName, FileMode.Append))
                    using (var sw = new StreamWriter(fs))
                        sw.WriteLine(Convert.ToBase64String(serializer.Serialize(LogEntries)));

                LogEntries.Clear();
                Saved?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 20
0
 public bool UpdateObject(N2.Edit.Workflow.CommandContext value)
 {
     try
     {
         BinderContext = value;
         EnsureChildControls();
         if (ZoneName != null && ZoneName != value.Content.ZoneName)
         {
             value.Content.ZoneName = ZoneName;
         }
         foreach (string key in AddedEditors.Keys)
         {
             BinderContext.GetDefinedDetails().Add(key);
         }
         var modifiedDetails = EditAdapter.UpdateItem(value.Definition, value.Content, AddedEditors, Page.User);
         if (modifiedDetails.Length == 0)
         {
             return(false);
         }
         foreach (string detailName in modifiedDetails)
         {
             BinderContext.GetUpdatedDetails().Add(detailName);
         }
         BinderContext.RegisterItemToSave(value.Content);
         if (Saved != null)
         {
             Saved.Invoke(this, new ItemEventArgs(value.Content));
         }
         return(true);
     }
     finally
     {
         BinderContext = null;
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Saves the properties to the registry asyncronously.
        /// </summary>
        public virtual async Task SaveAsync()
        {
            ShellSettingsManager manager = await _settingsManager.GetValueAsync();

            WritableSettingsStore settingsStore = manager.GetWritableSettingsStore(SettingsScope.UserSettings);

            if (!settingsStore.CollectionExists(CollectionName))
            {
                settingsStore.CreateCollection(CollectionName);
            }

            foreach (PropertyInfo property in GetOptionProperties())
            {
                var output = SerializeValue(property.GetValue(this));
                settingsStore.SetString(CollectionName, property.Name, output);
            }

            T liveModel = await GetLiveInstanceAsync();

            if (this != liveModel)
            {
                await liveModel.LoadAsync();
            }

            Saved?.Invoke(this, liveModel);
        }
Ejemplo n.º 22
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            Grf.Resource.Subtype = (ResourceSubtype)SubtypeBox.SelectedIndex;

            Saved?.Invoke(this, null);
            Context.Djn.Rename(Grf.Resource.ID, Grf.Resource.Name); // this is kinda hacky
            Close();
        }
Ejemplo n.º 23
0
        public virtual async Task SaveAsync(string fileName = null)
        {
            fileName = GetFileName(fileName);

            await _filterSerializationService.SaveFiltersAsync(fileName, FilterSchemes);

            Saved?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 24
0
 public void Save()
 {
     Saved.Invoke();
     for (int i = 0; i < _datas.Count; i++)
     {
         _saver.Save(_datas[i], _folderPath);
     }
 }
Ejemplo n.º 25
0
        public void Save()
        {
            string json = JsonConvert.SerializeObject(MainSession);
            string key  = MainSession.GetType().ToString();

            mProperties[key] = json;
            Saved?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 26
0
 void IConfiguration.Save()
 {
     Settings.Default.AutoStart              = AutoStart;
     Settings.Default.AutoClose              = AutoClose;
     Settings.Default.ForceClose             = ForceClose;
     Settings.Default.ConnectionInformations = _connections.ToArray();
     Settings.Default.Save();
     Saved?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 27
0
        private void SaveCommandAction(object obj)
        {
            doctorAppointment.Date = Date;
            doctorAppointment.INR  = INR;

            DatabaseManager.UpdateAppointment(doctorAppointment);

            Saved.Invoke(this, null);
        }
        /// <summary>
        /// Saves settings data, if available.
        /// </summary>
        /// <remarks>
        /// <see cref="CanSave"/> determines whether settings can be saved.
        /// </remarks>
        /// <param name="force">The value that determines whether to force data serialization.</param>
        public void SaveSettings(bool force = true)
        {
            if (CanSave() && IsLoaded)
            {
                OnSaveSettings(m_data, force);

                Saved?.Invoke(m_data);
            }
        }
Ejemplo n.º 29
0
 internal bool Save()
 {
     if (LastSavedValue != Value)
     {
         LastSavedValue = Value;
         Saved?.Invoke(this, EventArgs.Empty);
         return(true);
     }
     return(false);
 }
        public async Task SaveAsync()
        {
            Log.Debug("Saving feature toggle values");

            await _featureToggleSerializationService.SaveAsync(_featureToggles.Values.Select(x => new FeatureToggleValue(x)).ToList());

            Saved?.Invoke(this, EventArgs.Empty);

            Log.Debug($"Saved '{_featureToggles.Count}' feature toggle values");
        }