예제 #1
0
        /// <summary>
        /// Standart constructor.
        /// </summary>
        /// <param name="local">Local change.</param>
        /// <param name="remote">Remote change.</param>
        internal SideChooseForm(Change local, Change remote)
        {
            this.Text = "Výběr: " + local.TimeEventHash;
            InitializeComponent();

            DialogResult = DialogResult.Cancel;

            labelHash.Text = local.TimeEventHash;

            TimeEvent localTe = local.TimeEvent;
            TimeEvent remoteTe = remote.TimeEvent;
           
            switch (local.Type)
            {
                case Change.ChangeType.Add:
                    labelLocalChange.Text = "Přidána událost:";
                    setLocaleValues(localTe);
                    break;
                case Change.ChangeType.Edit:
                    labelLocalChange.Text = "Editována událost:";
                    setLocaleValues(localTe);
                    break;
                case Change.ChangeType.Del:
                    labelLocalChange.Text = "Smazána událost:";
                    hideLocalValues();
                    break;
                default:
                    break;
            }

            switch (remote.Type)
            {
                case Change.ChangeType.Add:
                    labelRemoteChange.Text = "Přidána událost:";
                    setRemoteValues(remoteTe);
                    break;
                case Change.ChangeType.Edit:
                    labelRemoteChange.Text = "Editována událost:";
                    setRemoteValues(remoteTe);
                    break;
                case Change.ChangeType.Del:
                    labelRemoteChange.Text = "Smazána událost:";
                    hideRemoteValues();
                    break;
                default:
                    break;
            }

        }
예제 #2
0
        /// <summary>
        /// Write content of change cache into Database.
        /// </summary>
        public void WriteCaches(Queue<TimeEvent> newTimeEvents, Queue<Change> newChanges)
        {
            lock (newTimeEvents)
            {
                TimeEvent[] timeEvents = new TimeEvent[newTimeEvents.Count];
                int i = 0;
                while (true)
                {
                    if (newTimeEvents.Count == 0)
                        break;
                    timeEvents[i] = newTimeEvents.Dequeue();
                    i++;
                }
                lock (db)
                    if (timeEvents.Length != 0)
                        db.ExecuteAddEditChanges(timeEvents);
                newTimeEvents.Clear();
            }
            lock (newChanges)
            {
                Change[] changes = new Change[newChanges.Count];
                int i = 0;
                while (true)
                {
                    if (newChanges.Count == 0)
                        break;

                    Change c = newChanges.Dequeue();
                    c.ChangeDate = DateTime.Now;
                    changes[i] = c;
                    i++;
                }

                lock (db)
                    if (changes.Length != 0)
                        db.InsertChange(changes);
                newChanges.Clear();
            }
        }
예제 #3
0
 /// <summary>
 /// Execute new change in local.
 /// </summary>
 /// <param name="c">Change that should be executed.</param>
 /// <param name="te">TimeEvent that should be executed.</param>
 public void ExecuteChange(Change c, Queue<TimeEvent> newTimeEvents, Queue<Change> newChanges)
 {
     lock (db)
         switch (c.Type)
         {
             case Change.ChangeType.Add:
             case Change.ChangeType.Edit:
                 if (c.TimeEvent == null)
                     throw new NullReferenceException();
                 lock (newTimeEvents)
                     newTimeEvents.Enqueue(c.TimeEvent);
                 break;
             case Change.ChangeType.Del:
                 db.ExecuteDelChange(c.TimeEventHash);
                 break;
         }
     lock (newChanges)
         newChanges.Enqueue(c);
 }
예제 #4
0
 /// <summary>
 /// Add to result and change its side if it's necessary.
 /// </summary>
 /// <param name="local">Local change.</param>
 /// <param name="remote">Remote change.</param>
 /// <returns>True if it is neccesary to decide, False otherwise.</returns>
 public bool AddToResultsAndReturnIfItIsNecessary(Change local, Change remote)
 {
     lock (resultChanges)
         if (local.Type == Change.ChangeType.Del && (remote.Type == Change.ChangeType.Add || remote.Type == Change.ChangeType.Edit))
         {
             resultChanges[local.TimeEventHash] = ChangeSide.NotDecided;
             return true;
         }
         else if ((local.Type == Change.ChangeType.Add || local.Type == Change.ChangeType.Edit) && remote.Type == Change.ChangeType.Del)
         {
             resultChanges[local.TimeEventHash] = ChangeSide.NotDecided;
             return true;
         }
         else if (local.Type == Change.ChangeType.Del && remote.Type == Change.ChangeType.Del)
         {
             resultChanges[local.TimeEventHash] = ChangeSide.NotNecessaryUpdate;
             return false;
         }
         else if (local.TimeEvent.HasSameDataAs(remote.TimeEvent))
         {
             resultChanges[local.TimeEventHash] = ChangeSide.NotNecessaryUpdate;
             return false;
         }
         else
         {
             resultChanges[local.TimeEventHash] = ChangeSide.NotDecided;
             return true;
         }
 }
예제 #5
0
 /// <summary>
 /// Parse Record received by connection into Chnage and TimeEvent.
 /// </summary>
 /// <param name="record">String that should be parsed.</param>
 /// <param name="c">Change, that was parsed.</param>
 /// <param name="te">TimeEvent, that was parsed</param>
 public void ParseRecord(string record, out Change c, out TimeEvent te)
 {
     var items = record.Split('*');
     c = Change.Parse(items[0]);
     if (items[1] == "null")
         te = null;
     else
         te = TimeEvent.Parse(items[1]);
 }
예제 #6
0
 /// <summary>
 /// Send Changes to writer.
 /// </summary>
 /// <param name="writer">Where should be chnage send through.</param>
 /// <param name="c">Which change should be send.</param>
 /// <param name="te">Which TimeEvent should be send.</param>
 public void SendChange(TextWriter writer, Change c, TimeEvent te)
 {
     if (c.Type == Change.ChangeType.Del)
         writer.WriteLine(c.GetSynchronizationString() + "*" + "null" + "*?");
     else
         writer.WriteLine(c.GetSynchronizationString() + "*" + te.GetSynchronizationString() + "*?");
 }