Beispiel #1
0
        /// <summary>
        /// load list of links from file
        /// </summary>
        /// <returns></returns>
        public static void LoadLinks()
        {
            if (AnySyncRunning)
            {
                throw new ApplicationException("Cannot load Links while any sync is running!");
            }

            _links = new List <SyncLink>();

            if (CreateDataFileIfNotExist())
            {
                return;
            }

            List <string> lines      = new List <string>(File.ReadAllLines(LinksDataFilePath));
            List <int>    errorLines = new List <int>();
            bool          linkSec    = false;

            int i = 0;

            foreach (string line in lines)
            {
                if (line.Trim().Equals("<links>"))
                {
                    linkSec = true;
                }
                else if (line.Trim().Equals("</links>"))
                {
                    break;
                }
                else if (linkSec)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    Link l = Link.CreateFromLine(line);
                    if (l != null)
                    {
                        SyncLink sl = new SyncLink(l);
                        _links.Add(sl);
                        LinkChanged(0, sl);
                    }
                    else
                    {
                        errorLines.Add(i);
                    }
                }

                i++;
            }
            if (errorLines.Count > 0)
            {
                MessageBox.Show($"Please check links.dat. \nBad format detected in lines: {string.Join(", ", errorLines)}",
                                @"Bad Format in Data-File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
        /// <summary>
        /// select LinkRow and unselect others
        /// start updating detail stats afterwards
        /// </summary>
        /// <param name="l">associated SyncLink</param>
        void SelectLinkRow(SyncLink l)
        {
            //deselect others
            foreach (LinkRow lr in _linkRows.Where(x => x.Link != l))
            {
                lr.Selected = false;
            }

            _selectedLink = l;

            StartUpdatingSelectedSyncLinkInfo();
        }
Beispiel #3
0
 void RemoveLinkRow(SyncLink link)
 {
     for (int i = 0; i < _linkRows.Count; i++)
     {
         if (_linkRows[i].Link == link)
         {
             _linkRows.RemoveAt(i);
             dataTable.Controls.RemoveAt(i);
             break;
         }
     }
 }
        /// <summary>
        /// create SyncDetailInfoForm2 that displays all details of a synchronisation process
        /// </summary>
        /// <param name="l">link that contains the synchronisation information</param>
        public SyncDetailInfoForm2(SyncLink l)
        {
            _l = l;

            InitializeComponent();

            statusProgressBar1.StatusTitles = SyncStatus.GetGroupedTitles();
            statusProgressBar1.ActivateStatus("fetching files/dirs");

            SyncStatusFormHelper.Init(this);

            tabControl_left1.SelectedIndex = 1;
            label_title.Text          = _l.Title;
            label_link_folder1.Text   = _l.Path1;
            label_link_folder2.Text   = _l.Path2;
            label_link_direction.Text = _l.Direction.ToString();

            if (SI != null)
            {
                //build tree (pause sync while building)
                bool running = _l.IsRunning;
                if (running)
                {
                    _l.PauseSync();
                }
                int ct = 0;
                int i  = 0;
                while (_l.SyncTask != null && _l.SyncTask.TasksRunning() > 0 && i < 5)
                {
                    if (ct == _l.SyncTask.TasksRunning())
                    {
                        i++;
                    }
                    else
                    {
                        ct = _l.SyncTask.TasksRunning();
                        i  = 0;
                    }
                    Thread.Sleep(300);
                }
                if (_l.SyncTask != null)
                {
                    BuildTreeBase(_l.SyncInfo.DirTree);
                    SI.SetListener(this);
                    if (running)
                    {
                        _l.ResumeSync();
                    }
                }
            }

            Load += delegate { StartUpdateRoutine(); };
        }
Beispiel #5
0
        /// <summary>
        /// create a LinkRow that displays information and controls for a Link and its synchronisation
        /// </summary>
        public LinkRow(SyncLink link)
        {
            InitializeComponent();

            Link = link;
            UpdateData();

            //add on-click-listener to inner panel and its children
            inner.MouseClick += OnInnerClick;
            foreach (Control c in inner.Controls)
            {
                c.MouseClick += OnInnerClick;
            }
        }
Beispiel #6
0
        /// <summary>
        /// add Link and update file
        /// </summary>
        /// <param name="link"></param>
        public static void AddLink(Link link)
        {
            if (LinkExists(link.Title))
            {
                throw BadInputException.LinkAlreadyExists;
            }

            SyncLink sl = new SyncLink(link);

            Links.Add(sl);
            LinkChanged(0, sl);

            SaveLinksToFile();
        }
Beispiel #7
0
        /// <summary>
        /// start synchronisation of link and update button
        /// </summary>
        /// <param name="l"></param>
        void StartSync(SyncLink l)
        {
            label_p.Visible           = true;
            label_p.Text              = @"0";
            progressBar_total.Visible = true;
            progressBar_total.Value   = 0;

            l.Sync(null);

            StartUpdatingSyncInfo();
            if (_selectedLink == l)
            {
                StartUpdatingSelectedSyncLinkInfo();
            }
        }
Beispiel #8
0
        /// <summary>
        /// remove Link and update file
        /// </summary>
        /// <param name="title">the title of the Link</param>
        public static void RemoveLink(string title)
        {
            int      pos = GetLinkPosByTitle(title);
            SyncLink sl  = Links[pos];

            if (Links[pos].IsRunning)
            {
                throw new ApplicationException("Cannot remove Link while its sync is running!");
            }

            Links.RemoveAt(pos);
            LinkChanged(2, sl);

            SaveLinksToFile();
        }
Beispiel #9
0
        void AddLinkRow(SyncLink link)
        {
            LinkRow ll = new LinkRow(link);

            ll.LinkDeletionRequested     += delegate { DataManager.RemoveLink(link.Title); };
            ll.EditLinkRequested         += delegate { new LinkDataForm(link).ShowDialog(); };
            ll.LinkRowSelected           += delegate { SelectLinkRow(link); };
            ll.SyncStartRequested        += delegate { StartSync(link); };
            ll.SyncCancellationRequested += delegate { CancelSync(link); };

            ll.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
            ll.Width  = dataTable.Width;

            _linkRows.Add(ll);
            dataTable.Controls.Add(ll, 0, _linkRows.Count);
        }
Beispiel #10
0
        /// <summary>
        /// create SyncDetailInfoForm1 that displays all details of a synchronisation process
        /// </summary>
        /// <param name="l">link that contains the synchronisation information</param>
        public SyncDetailInfoForm1(SyncLink l, MainForm mainForm)
        {
            _l        = l;
            _mainForm = mainForm;
            InitializeComponent();

            label_title.Text     = _l.Title;
            label_folder1.Text   = _l.Path1;
            label_folder2.Text   = _l.Path2;
            label_direction.Text = _l.Direction.ToString();

            if (_l.SyncInfo != null)
            {
                //build tree (pause sync while building)
                bool running = _l.IsRunning;
                if (running)
                {
                    _l.PauseSync();
                }
                int ct = 0;
                int i  = 0;
                while (_l.SyncTask != null && _l.SyncTask.TasksRunning() > 0 && i < 5)
                {
                    if (ct == _l.SyncTask.TasksRunning())
                    {
                        i++;
                    }
                    else
                    {
                        ct = _l.SyncTask.TasksRunning();
                        i  = 0;
                    }
                    Thread.Sleep(300);
                }
                if (_l.SyncTask != null)
                {
                    BuildTreeRecursively(treeView1.Nodes, _l.SyncInfo.DirTree);
                    _l.SyncInfo.SetListener(this);
                    if (running)
                    {
                        _l.ResumeSync();
                    }
                }
            }
            StartUpdateRoutine();
        }
Beispiel #11
0
        private void OnLinkDataChanged(int changeType, SyncLink l)
        {
            switch (changeType)
            {
            case 0:
                //Link added
                AddLinkRow(l);
                break;

            case 1:
                //Link changed
                GetLinkRow(l).UpdateData();
                break;

            case 2:
                //Link removed
                RemoveLinkRow(l);
                break;
            }
        }
Beispiel #12
0
 /// <summary>
 /// cancel synchronisation of link
 /// </summary>
 /// <param name="l"></param>
 void CancelSync(SyncLink l)
 {
     l.CancelSync();
 }
Beispiel #13
0
 LinkRow GetLinkRow(SyncLink l)
 {
     return(_linkRows.FirstOrDefault(x => x.Link == l));
 }
Beispiel #14
0
 public SyncLogReplicaInfo SourcePrepare(SyncLink link)
 {
     return(sync_db.SourcePrepare(link));
 }
 public SyncLogReplicaInfo SourcePrepare(SyncLink link)
 {
     return(Channel.SourcePrepare(link));
 }