Beispiel #1
0
 public WindowSession(ApplicationSession applicationSession, InitializeOption initializeOption)
 {
     this.applicationSession = applicationSession;
     windowItemsMap = WindowItemsMap.Create(initializeOption, RectX.UnlikelyWindowPosition);
     if (windowItemsMap.LoadedFromFile) initializeOption.NonCached();
     this.initializeOption = initializeOption;
 }
Beispiel #2
0
        public static WindowItemsMap Create(InitializeOption initializeOption, Point currentWindowPosition)
        {
            if (initializeOption.NoIdentification)
            {
                return(new NullWindowItemsMap());
            }

            string fileLocation = FileLocation(initializeOption);

            if (File.Exists(fileLocation))
            {
                Logger.DebugFormat("[PositionBasedSearch] Loading WindowItemsMap for: {0}, from {1}", initializeOption.Identifier, fileLocation);
                WindowItemsMap windowItemsMap = null;
                try
                {
                    using (var fileStream = CreateFileStream(fileLocation))
                    {
                        windowItemsMap = (WindowItemsMap)CreateDataContractSerializer().ReadObject(fileStream);
                    }
                }
                catch (Exception ex)
                {
                    Logger.DebugFormat("[PositionBasedSearch] Loading WindowItemsMap FAILED for: {0}, Error: {1}", initializeOption.Identifier, ex.Message);
                    Logger.DebugFormat("[PositionBasedSearch] Deleting WindowItemsMap for: {0}", initializeOption.Identifier);
                    try { File.Delete(fileLocation); }
                    catch (IOException) { }
                }

                if (windowItemsMap != null)
                {
                    windowItemsMap.currentWindowPosition = currentWindowPosition;
                    windowItemsMap.loadedFromFile        = true;
                    return(windowItemsMap);
                }
            }

            Logger.DebugFormat("[PositionBasedSearch] Creating new WindowItemsMap for: {0}", initializeOption.Identifier);
            return(new WindowItemsMap(fileLocation, currentWindowPosition));
        }