Exemple #1
0
 public void After(Session s) {
     foreach (string fileName in rollbacks.Keys) {
         try {
             byte[] data = rollbacks[fileName];
             if (data == null) {
                 File.Delete(fileName);
             } else {
                 File.WriteAllBytes(fileName, data);
             }
         } catch (IOException e) {
             Logger.Current.Error("Failed to perform file session teardown for file {0}", fileName);
             Logger.Current.Error(e);
         }
     }
 }
Exemple #2
0
 public void Before(Session s) {
     foreach (string fileName in setups.Keys) {
         try {
             if (shouldRollback[fileName]) {
                 if (File.Exists(fileName)) {
                     rollbacks[fileName] = File.ReadAllBytes(fileName);
                 } else {
                     rollbacks[fileName] = null;
                 }
             }
             File.WriteAllBytes(fileName, setups[fileName]);
         } catch (IOException e) {
             Logger.Current.Error("Failed to perform file session setup for file {0}", fileName);
             Logger.Current.Error(e);
         }
     }
 }
Exemple #3
0
        private static List<PersistedObject<Element>> FindAll(AutomationElement root, TreeScope scope, int count, double waitForResults, Condition condition, Session session) {
            Logger.Current.Trace("Searching for {1} with a timeout of {0} sec", waitForResults, condition);
            List<PersistedObject<Element>> results = null;
            double lastDuration = Double.NaN;
            do {
                if (lastDuration < PollInterval) {
                    double sleepDuration = Math.Min(waitForResults, PollInterval - lastDuration);
                    int millis = (int)(sleepDuration * 1000);
                    if (millis > 0)
                        System.Threading.Thread.Sleep(millis);
                    waitForResults -= sleepDuration;
                }

                long startTicks = DateTime.Now.Ticks;
                results = Wrap(FindAll(root, scope, count, condition, session.Process.Id), session);
                long endTicks = DateTime.Now.Ticks;
                lastDuration = (endTicks - startTicks) / 10000000.0;
                waitForResults -= lastDuration;
                Logger.Current.Trace("{0} sec left", waitForResults);
            } while (waitForResults > 0 && results.Count == 0);
            Logger.Current.Trace("Returning {0} results", results.Count);
            return results;
        }
Exemple #4
0
        private static List<PersistedObject<Element>> Wrap(List<AutomationElement> searchResults, Session session) {
            List<PersistedObject<Element>> result = new List<PersistedObject<Element>>();
            STAHelper.Invoke(
            	delegate() {
	     	       foreach (AutomationElement element in searchResults)
    	    	        result.Add(PersistedObject.Get(Element.Create(element, session.Process.Id), session));
            	}
            );
            return result;
        }
Exemple #5
0
 public void Delete(Session session) {
     if (sessions.Remove(session.Guid))
         session.Dispose();
     else
         throw new ArgumentException("Specified session " + session.Guid + " doesn't exist");
 }
Exemple #6
0
        public Session Create(Dictionary<string, string> capabilities, Dictionary<string, object> sessionSetupInfo) {
            if (!capabilities.ContainsKey("applicationName") || capabilities["applicationName"]==null)
                throw new ArgumentException("Capabilities must specify applicationName");

            foreach (Configuration config in Configurations) {
                bool valid = true;
                foreach(string prop in capabilities.Keys)
                    if (capabilities[prop] != null && (!config.properties.ContainsKey(prop) || config.properties[prop] != capabilities[prop])) {
                        valid = false;
                        break;
                    }

                if (valid) {
                    Session session = new Session(this, config, sessionSetupInfo);
                    sessions[session.Guid] = session;
                    return session;
                }
            }
            throw new ArgumentException("Couldn't find any configuration matching the given capabilities " + JSON.ToString(capabilities));
        }
Exemple #7
0
 public static JSONResponse CreateResponse(Session session, ResponseStatus status, object value) {
     JSONResponse response = new JSONResponse();
     response.Body = new Dictionary<string, object>();
     response.Body["sessionId"] = session == null ? null : session.ToString();
     response.Body["status"] = (int)status;
     response.Body["value"] = value;
     return response;
 }
Exemple #8
0
        public SessionRequest(JSONRequest basic) : base(basic) {
			try {
	            this.Session = Sessions.GetSession(basic);
			} catch (ArgumentException ex) {
				throw new TwinException(ResponseStatus.NoSuchSession, ex.Message, ex);
			}
        }