示例#1
0
        private void LaunchApp()
        {
            Process launchHelixMFA = new Process();

            launchHelixMFA.StartInfo.Arguments = port + " " + user;
            launchHelixMFA.StartInfo.FileName  = path;
            string msg = string.Format("==>{0} {1}", path, launchHelixMFA.StartInfo.Arguments);

            FileLogger.LogMessage(3, string.Empty, msg);
            launchHelixMFA.StartInfo.CreateNoWindow = true;
            launchHelixMFA.EnableRaisingEvents      = true;
            launchHelixMFA.Start();
            launchHelixMFA.Exited += (sender, e) => { exitCode = launchHelixMFA.ExitCode; closeBtn_Click(sender, e); };
        }
示例#2
0
        public bool RefreshPath(String basePath, bool force)
        {
            // if the list of paths is large (configurable?), try to expire some paths
            if (expirationList.Count > 100)
            {
                ClearExpiredPaths();
            }

            // first check if basePath is under the client's root.  if not, don't bother
            if (!connected || !IsUnderClientRoot(basePath))
            {
                return(false);
            }

            PathCache pc       = (pathCache.ContainsKey(basePath) ? pathCache[basePath] : null);
            bool      useCache = (pc != null);

            if (pc != null)
            {
                useCache = !pc.IsExpired();
            }

            if (force)
            {
                useCache = false;
            }

            if (useCache)
            {
                return(true);
            }

            FileLogger.LogMessage(3, Properties.Resources.FileLogger_RepoStorage, string.Format(Properties.Resources.FileLogger_RefreshingPath, basePath));

            if (pc != null)
            {
                // remove from the lists
                pathCache.Remove(basePath);
                expirationList.Remove(pc);
                pc = null;
            }

            // TODO: configurable expiration
            pc = new PathCache(basePath, DateTime.Now.AddMinutes(5));

            // is it better to do a local dir call to build a list of fstat targets, or to
            // do a fstat path/* ?
            // the answer from the performance lab is that passing the wildcard to the server should be more performant
            FileSpec[]           specs = new FileSpec[] { new FileSpec(null, null, new LocalPath(Path.Combine(basePath, "*")), null) };
            IList <FileMetaData> fds   = null;

            try
            {
                fds = rep.GetFileMetaData(null, specs);
            }
            catch (P4Exception e)
            {
                // add it anyway or we get lots of retries
                if (fds != null)
                {
                    pc.AddFiles(fds);
                }

                pathCache[basePath] = pc;
                expirationList.Add(pc);

                // alaways throw here?  display an error message?
                if (P4EXPProgram.IsLoginException(e.ErrorCode))
                {
                    throw;
                }
                FileLogger.LogException(Properties.Resources.FileLogger_P4EXPProgram, e);
            }
            catch (Exception e)
            {
                FileLogger.LogException(Properties.Resources.FileLogger_P4EXPProgram, e);
            }

            // add it anyway
            if (fds != null)
            {
                pc.AddFiles(fds);
            }

            pathCache[basePath] = pc;
            expirationList.Add(pc);

            return(true);
        }
示例#3
0
        private void RefreshClientData(bool force = false)
        {
            lock (this)
            {
                if (!connected)
                {
                    return;
                }

                DateTime now = DateTime.Now;
                if (now.CompareTo(clientFailed) < 0)
                {
                    return; // give up for a bit, there was a client error
                }
                if (roots.Count > 0 && !force && now.CompareTo(clientExpire) < 0)
                {
                    return; // no need to refresh
                }
                FileLogger.LogMessage(3, Properties.Resources.FileLogger_RepoStorage,
                                      String.Format(Properties.Resources.FileLogger_RefreshingClient, clientName));

                // re-initializing this RepoStorage
                roots.Clear();

                // set the client again, forcing a refresh
                try
                {
                    // Check for valid Client
                    IList <Client> clients = rep.GetClients(new ClientsCmdOptions(ClientsCmdFlags.None,
                                                                                  null, clientName, 1, null));
                    if (clients == null || clients.Count <= 0)
                    {
                        // If P4CLIENT is non-existent or a client that does not exist on the
                        // server, make sure the Client itself is set to null.
                        rep.Connection.Client = null;
                    }
                    else
                    {
                        rep.Connection.Client = clients[0];
                    }
                }
                catch (P4Exception e)
                {
                    if (e.ErrorCode == P4ClientError.MsgServer_LoginExpired ||
                        e.ErrorCode == P4ClientError.MsgServer_BadPassword ||
                        e.ErrorCode == P4ClientError.MsgServer_PasswordExpired)
                    {
                        clientFailed = now.AddSeconds(15);
                        throw;  // throw it out, someone should handle with a Login call
                    }
                }
                catch (Exception e)
                {
                    FileLogger.LogException(Properties.Resources.FileLogger_RefreshClientData, e);
                    rep.Connection.Client = null;
                }

                // we failed for some reason, record the failure so that we
                // don't launch a retry attack
                if (rep.Connection.Client == null || rep.Connection.Client.Root == null)
                {
                    FileLogger.LogMessage(1, Properties.Resources.FileLogger_RefreshClientData, Properties.Resources.FileLogger_FailedToSetClientDelay15);
                    clientFailed = now.AddSeconds(15);
                    return;
                }

                // now read the roots into our root array
                // convert to lower case, reverse the path indicators
                roots.Add(cleanRoot(rep.Connection.Client.Root));
                if (rep.Connection.Client.AltRoots != null)
                {
                    foreach (String root in rep.Connection.Client.AltRoots)
                    {
                        roots.Add(cleanRoot(root));
                    }
                }

                // TODO: make this configurable
                clientExpire = now.AddMinutes(5);
            }
        }