Inheritance: IDisposable
Esempio n. 1
0
 public static AccessSession CreateSession(string host, string instance, string userName, string password, string apiKey)
 {
     // Authenticate with sevices and start session
     var session = new AccessSession(host, instance, userName, password, apiKey);
     return session;
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
              {
            #region handle arguments and validation
            if (args.Length < 2)
            {
              Console.WriteLine("Usage: syncFolder [local folder to synchronize] [destination CMS folder]");
            }
            string localFolder = args[0];
            string destFolder = args[1];

            if (!Directory.Exists(localFolder))
            {
              Console.WriteLine("Could not find local folder: {0}", localFolder);
              return;
            }
            #endregion

            #region get password
            string username = ConfigurationSettings.AppSettings["username"];
            Console.Write("Enter pw for {0}: ", username);
            string pw = getSecuredString();
            Console.WriteLine("");
            Console.WriteLine("Authenticating: {0} ", username);
            #endregion

            Console.WriteLine("Communicating with {0}/{1}", ConfigurationSettings.AppSettings["host"], ConfigurationSettings.AppSettings["instance"]);
            var session = new AccessSession( ConfigurationSettings.AppSettings["host"],
                                         ConfigurationSettings.AppSettings["instance"],
                                         username,
                                         pw,
                                         ConfigurationSettings.AppSettings["apiKey"]);
              accessAsset = new AccessAsset(session.Client);
              processFolder(localFolder.ToLower(), destFolder);
              var accessAuth = new AccessAuth(session.Client);
              accessAuth.Logout();

              }
              catch (Exception ex)
              {
            Console.WriteLine("Error: {0}", ex.Message);
              }
              Console.Write("Press, almost, any key to continue...");
              Console.ReadLine();
        }
Esempio n. 3
0
        private void EnsureAccessApiSession()
        {
            lock (_threadLock)
            {
                var sessionMinutes = (DateTime.Now - _sessionRenewDate).TotalMinutes;

                if (_session == null || (sessionMinutes >= _maxSessionMinutes))
                {
                    _session = Authenticator.CreateSession(_settings.ApiHostUrl, _settings.ApiInstanceName, _settings.ApiUserName, _settings.ApiPassword, _settings.ApiKey);
                    _sessionRenewDate = DateTime.Now;
                    return;
                }
            }

            // Make test call to ensure session hasn't timed out
            try
            {
                var accessAsset = new AccessAsset(_session.Client);
                accessAsset.Exists(new AssetExistsRequest("/"));
            }
            catch
            {
                _session = null;
                EnsureAccessApiSession();
            }
        }