コード例 #1
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        public Groups(IHubConfigurator hubConfigurator) : base(hubConfigurator, HubNames.GroupsHub)
        {
            Proxy.On <DbChangeStatus, Group>(nameof(IGroupsHubEvents.OnChanged),
                                             (status, group) => OnChanged?.Invoke(status, group));

            Proxy.On(nameof(IGroupsHubEvents.GroupsImport), () => Imported?.Invoke());
        }
コード例 #2
0
        /// <summary>
        /// The function tries to merge possible updates from the deltaDB into
        /// the actual database. If there was made changes to the actualDB, then
        /// the function fires a event, which cause the KeePass UI to update and
        /// show the "save"-button.
        /// </summary>
        public void Import(object sender, SyncSource source)
        {
            Debug.Assert(source.DestinationDB != null && source.DestinationDB.RootGroup != null);
            //merge all updates in
            PwDatabase deltaDB = new PwDatabase();

            try {
                deltaDB.Open(IOConnectionInfo.FromPath(source.Location), source.Key, null);
            }
            catch (InvalidCompositeKeyException e) {
                Debug.WriteLine("Wrong key! exception was: " + e.Message);
                //brand this entry as a false one => red bg-color and "X" as group icon
                ShowErrorHighlight(source.DestinationDB, source.Uuid);
                if (Imported != null)
                {
                    Imported.Invoke(this, source.DestinationDB.RootGroup);
                }
                return;
            }
            catch (Exception e) {
                Debug.WriteLine("Standard exception was thrown during deltaDB.Open(): " + e.Message);
                //maybe the process has not finished writing to our file, but the filewtcher fires our event
                //sourceEntryUuid we have to ignore it and wait for the next one.
                return;
            }
            HideErrorHighlight(source.DestinationDB, source.Uuid);
            MergeIn(source.DestinationDB, deltaDB);
            deltaDB.Close();
        }
コード例 #3
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        public Students(IHubConfigurator hubConfigurator) : base(hubConfigurator, HubNames.StudentsHub)
        {
            Proxy.On <DbChangeStatus, Student>(nameof(IStudentsHubEvents.OnChanged),
                                               (status, student) => OnChanged?.Invoke(status, student));

            Proxy.On(nameof(IStudentsHubEvents.StudentsImported),
                     () => Imported?.Invoke());
        }
コード例 #4
0
        protected void MergeIn(PwDatabase target, PwDatabase source)
        {
            //remember stats of destDB to guess if we merged in something
            //maybe we only look for the lastChanged entry
            var clone = source.CloneDeep(target.RootGroup);

            clone.SetCustomAttribute(KeeShare.AttributeFlags.IsTemporaryDatabase, true);
            var cyclicEntries = new List <PwEntry>();

            foreach (var cloneEntry in clone.RootGroup.GetEntries(true).ToList())
            {
                if (cloneEntry.HasExportSource(target.RootGroup.Uuid.ToHexString()))
                {
                    cloneEntry.DeleteFrom(cloneEntry.ParentGroup);
                    cyclicEntries.Add(cloneEntry);
                }
            }

            Console.WriteLine("Prevent import of nodes which are exported from here: " + String.Join(",", cyclicEntries.Select(e => e.GetTitle()).ToArray()));

            DateTime lastChange = DateTime.MinValue;

            foreach (var entry in target.RootGroup.GetEntries(true))
            {
                if (entry.LastModificationTime.Ticks > lastChange.Ticks)
                {
                    lastChange = entry.LastModificationTime;
                }
            }
            target.MergeIn(clone, PwMergeMethod.Synchronize);
            foreach (var entry in source.RootGroup.GetEntries(true))
            {
                if (entry.LastModificationTime.Ticks > lastChange.Ticks)
                {
                    //set the modified flag of the database true, so the uiUpdate knows which tab should be marked as changed
                    target.Modified = true;
                }
            }
            if (Imported != null)
            {
                Imported.Invoke(this, target.RootGroup);
            }
        }
コード例 #5
0
 public Task <ISTrainingPartResponse <bool> > AddGroupsAsync(IEnumerable <Group> groups)
 {
     Imported?.Invoke();
     return(Task.FromResult(new ISTrainingPartResponse <bool>(ISTrainingPartResponseCode.Ok, true)));
 }
コード例 #6
0
 public Task <ISTrainingPartResponse <bool> > ImportStudentsAsync(IEnumerable <Student> students)
 {
     Imported?.Invoke();
     return(Task.FromResult(new ISTrainingPartResponse <bool>(ISTrainingPartResponseCode.Ok, true)));
 }
コード例 #7
0
 public Task RaiseStudentsImported()
 {
     Imported?.Invoke();
     return(Task.CompletedTask);
 }
コード例 #8
0
 private void OnImported(Type arg1, string arg2, FileStorageType arg3)
 {
     Imported?.Invoke(arg1, arg2, arg3);
     OnDataUpdated(arg1);
 }