Ejemplo n.º 1
0
        void WaitOnline_timer_Tick(object sender, EventArgs e)
        {
            waitOnline_timer.Stop();

            if (Internet.CheckInternetAndProcess(m_Guid, m_Storage, m_Process, m_Site, m_PlacePath, "wait_timer") != "")
            {
                return;
            }

            MessageBox.Show(String.Format(MMUtils.GetString("internet.maponline.message"), doc.Name),
                            MMUtils.GetString("internet.maponline.caption"));

            string _lastfile     = Directory.GetFiles(m_PlacePath, "*.mmap").Last().ToString();
            long   placemap_time = Convert.ToInt64(Path.GetFileNameWithoutExtension(_lastfile));

            DocumentStorage.closeMap = true;
            doc.Close();

            File.SetAttributes(m_LocalPath, System.IO.FileAttributes.Normal);

            // Get last copy from Place
            if (placemap_time > m_FrozenTime)
            {
                File.Copy(_lastfile, m_LocalPath, true);
            }
            // Or return frozen file
            else
            {
                File.Copy(m_FrozenPath, m_LocalPath, true);
            }

            DocumentStorage.openMap = true;
            MMUtils.MindManager.AllDocuments.Open(m_LocalPath);
            doc = MMUtils.ActiveDocument;

            m_Status = "online";
            GetOnlineUsers();

            DocumentStorage.Sync(doc, true, m_PlacePath);                      // subscribe map

            Watchers WW = new Watchers(m_PlacePath + "share", m_PlacePath, "") // TODO project path!
            {
                doc      = doc,
                aMapGuid = m_Guid
            };

            Maps.MapsGroup.WATCHERS.Add(WW);

            SUtils.GetChanges(doc);

            saveMap_timer.Start();
            checkOnlineUsers_timer.Start();
            refreshIndicator_timer.Start();

            if (doc == MMUtils.ActiveDocument)
            {
                refresh = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_doc">Map to process</param>
        /// <returns>fail</returns>
        public static string ProcessMap(Document _doc)
        {
            string _guid = SUtils.SynergyMapGuid(_doc);
            string _storage = "", _process = "", _site = "",
                   _placemapfolderpath = "", // full path to map folder in its Place
                   _placename          = "", // place name - for Frozen Path
                   _projectname        = "", // place name - for Frozen Path
                   _projectpath        = "",
                   _mapblocker         = "", // who blocks the map
                   _unlocktime         = "", // hh:mm when map will be unlocked
                   fail = "";

            int _secToSaveMap = 105, _secToWait = 100, _minLockTime = 1;

            string   _docName       = _doc.Name;
            FileInfo file           = new FileInfo(_doc.FullName);
            float    fileMBytesSize = file.Length / 1048576;

            file = null;

            _secToSaveMap = _secToSaveMap + Convert.ToInt32(fileMBytesSize * 15);
            _secToWait    = _secToSaveMap + Convert.ToInt32(fileMBytesSize * 20);

            GetMapData(_guid, ref _storage, ref _process, ref _site, ref _placemapfolderpath,
                       ref _placename, ref _projectname, ref _projectpath);

            if (_placemapfolderpath == "" || _placename == "")
            {
                return("nomap");
            }

            // TODO check if map is locked
            string blockerPath = _placemapfolderpath + "info.locker";

            if (File.Exists(blockerPath))
            {
                string       _datetime;
                StreamReader sr = new StreamReader(blockerPath);
                _mapblocker  = sr.ReadLine().Trim();
                _datetime    = sr.ReadLine();
                _minLockTime = Convert.ToInt32(sr.ReadLine().Trim());
                sr.Close();

                // TODO UTC??
                DateTime.TryParse(_datetime, out DateTime _lockedtime);
                TimeSpan timeleft = _lockedtime.AddMinutes(_minLockTime) - DateTime.UtcNow;
                _minLockTime = timeleft.Minutes;
                _unlocktime  = DateTime.UtcNow.AddMinutes(_minLockTime).ToLocalTime().ToString(); // hh:mm

                if (_minLockTime < 0)                                                             // время блокировки истекло
                {
                    _minLockTime = 1;
                    _mapblocker  = "";
                    File.Delete(blockerPath);
                }
            }

            string _frozenPath = MMUtils.m_SynergyTempPath + _placename + "\\";

            try
            {
                Directory.CreateDirectory(_frozenPath);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show(
                    "Невозможно создать папку\n\n" + _frozenPath, "Очень плохо. Прекратить работу");
                return("path");
            }

            if (_projectname == "")
            {
                _frozenPath = _frozenPath + _docName;
            }
            else
            {
                Directory.CreateDirectory(_frozenPath + _projectname);
                _frozenPath = _frozenPath + _projectname + "\\" + _docName;
            }

            Timers timer = new Timers(_secToSaveMap, _secToWait, _minLockTime)
            {
                doc          = _doc,
                m_Guid       = _guid,
                m_Storage    = _storage,
                m_Process    = _process,
                m_Site       = _site,
                m_PlacePath  = _placemapfolderpath,
                m_LocalPath  = _doc.FullName,
                m_FrozenPath = _frozenPath,
                MapBlocker   = _mapblocker,
                unLockTime   = _unlocktime,
                refresh      = false
            };

            Maps.MapsGroup.TIMERS.Add(timer);

            DocumentStorage.Sync(_doc, true, _placemapfolderpath);

            if (_mapblocker != "")
            {
                fail = "locked";
            }
            else
            {
                fail = Internet.CheckInternetAndProcess(_guid, _storage, _process, _site, _placemapfolderpath, "SUtils");
            }

            timer.refreshIndicator_timer.Start();
            timer.IP_timer.Start();

            if (fail == "")
            {
                timer.m_Status = "online";
                timer.GetOnlineUsers();
                timer.IP_timer.Start(); // start watching for Internet & Process
                timer.saveMap_timer.Start();
                timer.checkOnlineUsers_timer.Start();
            }
            else
            {
                if (fail == "sitefail")
                {
                    timer.m_Status = "offline";
                }

                if (fail == "processfail")
                {
                    timer.m_Status = "offline";
                }

                if (fail == "locked")
                {
                    timer.lock_timer.Start();
                    timer.m_Status = "locked";
                }
            }

            Watchers WW = new Watchers(_placemapfolderpath + "share", _placemapfolderpath, _projectpath)
            {
                doc      = _doc,
                aMapGuid = _guid
            };

            Maps.MapsGroup.WATCHERS.Add(WW);

            if (_doc == MMUtils.ActiveDocument && skipActiveMap == false)
            {
                Maps.MapUsersDlg.status = timer.m_Status;

                if (timer.m_Status == "online")
                {
                    if (timer.UsersOnline.Count > 0)
                    {
                        Maps.MapUsersDlg.users = timer.UsersOnline;
                    }
                }

                //if (timer.m_Status == "offline")
                //{
                //    // передать причину
                //}

                if (timer.m_Status == "locked")
                {
                    Maps.MapUsersDlg.blocker = _mapblocker;
                    // передать время окончания блокировки
                }

                Maps.MapsGroup.dlgUsersOnline.Show(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd));
            }

            skipActiveMap = false;

            return(fail);
        }