/// <summary> /// Starts a session for the user on the given server/instance. /// This in intended to be called with a using block. /// All AccessControllers used within will be automatically authenticated. /// The Dispose method will Logout the user when complete. /// </summary> /// <param name="server">Domain of the server to use, ex: cms.crownpeak.com</param> /// <param name="instance">Name of the instance to use, ex: CPQA</param> /// <param name="username">Username of a user with active account in the CMS</param> /// <param name="password">Password of user</param> /// <param name="apiKey">Public developer API key supplied by CrownPeak</param> /// <param name="apiSecret">(Optional)Developer API Secret Key, ideally this will come from a secure database. Do not store key within application. Supplying a secret key will trigger Signature authentication method</param> /// <param name="requestCache">(Optional)When set to true the Cache property will be populated with data that can be used to cache information that does not often change. Cache property will be null otherwise.</param> public AccessSession(string server, string instance, string username, string password, string apiKey, string apiSecret = "", bool requestCache = false) { Client = new cpHttpClient(server, instance, apiKey, apiSecret); Server = server; Instance = instance; Username = username; Password = password; Key = apiKey; Secret = apiSecret; authController = new AccessAuth(Client); Authenticate(requestCache); }
private static AccessAsset accessAsset; //for accessability, used in multiple methods 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(); }
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(); }