사용자의 위치를 추적하는 WP7 앱이 있습니다. GeoCoordinate 와쳐의 위치 변경 이벤트에서 격리 된 저장소에 위치를 쓰고 싶습니다. "Operation Not Permitted on IsolatedStorageFileStream"메시지가 계속 나타납니다. 누구든지이 일을하도록 도울 수 있습니까?F # windows 전화 및 스토리지 격리 된 XML
let xname n = XName.op_Implicit(n)
let xdoc (el: seq<XElement>) = new XDocument(Array.map box (Array.ofSeq el))
let xelem s el = new XElement(xname s, box el)
let xstr s = box s
member this.createLocationsFile latitude longitude =
try
let doc : XDocument =
xdoc
[xelem "root"
[xelem "location"
[(xelem "latitude" (xstr latitude))
(xelem "longitude" (xstr longitude))
]
]
]
use store = IsolatedStorageFile.GetUserStoreForApplication()
if not (store.FileExists("locations.xml")) then
let file = new IsolatedStorageFileStream("locations.xml", IO.FileMode.Create, store)
doc.Save(file)
else
let file = new IsolatedStorageFileStream("locations.xml", IO.FileMode.Open, store)
let docAmended : XDocument = XDocument.Load(file)
let elementToAdd =
docAmended.Element(xname "root").Add(
[xelem "location"
[(xelem "latitude" (xstr latitude))
(xelem "longitude" (xstr longitude))
]
])
docAmended.Save(file)
with
| :? IsolatedStorageException as ex -> MessageBox.Show("Error saving file: " + ex.Message) |> ignore
| _ -> MessageBox.Show("Unable to open file") |> ignore
그리고 PositionChangedEventHandler은 다음과 같습니다 :
파일에 좌표를 저장하는 멤버는
let MyPositionChanged(e : GeoPositionChangedEventArgs<GeoCoordinate>, map : Map, ellipse : Ellipse) =
let ppLoc = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude)
map.SetView(ppLoc, 10.0)
//do layer.AddChild(ellipse, ppLoc)
ellipse.Visibility <- System.Windows.Visibility.Visible
let iso = new IsolatedStorageHelper()
let lat = ppLoc.Latitude.ToString()
let lon = ppLoc.Longitude.ToString()
do iso.createLocationsFile lat lon
파일을 격리 된 저장소에 보관하는 중 오류가 발생합니다. createLocationsFile 이벤트의 if 및 else 케이스에서 파일 핸들을 처리 할 수 있는지 확인하십시오. 불행히도, 나는 F # 어, 미안 해요,하지만 그게 내가 C#을 코드에서 검사 할거야. – Eugene
당신은'IsolatedStorageFileStream' 인스턴스를 처리하지 않았습니다. 'let file = ...'을'use file = ...'로 바꾸어보세요. – pad