public void Connect() { ThreadPool.QueueUserWorkItem(delegate { try { lock (_sync) { if (!IsConnected) { State = ConnectionState.Connecting; AspectHandleDisconnect(delegate { Storage = new RemoteStorage(true, ServerAddress); }); VerifyConnection(); } } } catch (Exception ex) { XTrace.XTrace.Exception(ex); } }); }
public virtual bool Delete(string fileName) { if (!Directory.Exists(this.RootDirectory)) { Directory.CreateDirectory(this.RootDirectory); } RemoteStorage remoteStorage = CommunityExpress.Instance.RemoteStorage; if (remoteStorage.FileExists(fileName)) { remoteStorage.DeleteFile(fileName); } if (remoteStorage.FileExists(fileName + "_LastDelete")) { remoteStorage.DeleteFile(fileName + "_LastDelete"); } remoteStorage.WriteFile(fileName + "_LastDelete", BitConverter.GetBytes(DateTime.Now.ToFileTime())); string path = Path.Combine(this.RootDirectory, fileName); if (!System.IO.File.Exists(path)) { return(true); } System.IO.File.Delete(path); return(!System.IO.File.Exists(path)); }
private void StudentPage_Loaded(object sender, RoutedEventArgs e) { //DataGrid1.ItemsSource = RemoteStorage.StudentOutView; //RemoteStorage.FetchStudent(); SelectorViewModel.SelectorMode = SelectorMode.StructDest; ButtonQuery.Click += (o, e) => RemoteStorage.FetchStudentsAsync(); ButtonAdd.Click += (o, e) => PageNavigator.NavigateToPopup <StudentAddPage>(); }
public CloudSaveManager(ICredentialProvider <UnitySocialCredential> credentialProvider) { if (credentialProvider == null) { throw new ArgumentNullException("credentialProvider"); } _credentialProvider = credentialProvider; _local = new LocalStorage(); _remote = new RemoteStorage(credentialProvider); }
private void StructPage_Loaded(object sender, RoutedEventArgs e) { SelectorViewModel.SelectorMode = SelectorMode.StructOnly; ButtonQuery.Click += (o, e) => RemoteStorage.FetchClassSummaryAsync(); ButtonAdd.Click += (o, e) => { if (SelectorViewModel.Profession == FrameWork.Dto.Profession.All) { PageNavigator.NavigateToPopup <StructAddPage>(); } else { PageNavigator.NavigateToPopup <StructAddPage>(SelectorViewModel.Profession); } }; }
private void DestPage_Loaded(object sender, RoutedEventArgs e) { SelectorViewModel.SelectorMode = SelectorMode.DestOnly; ButtonQuery.Click += (o, e) => RemoteStorage.FetchDestSummaryAsync(); ButtonAdd.Click += (o, e) => { if (SelectorViewModel.Province == FrameWork.Dto.Province.All) { PageNavigator.NavigateToPopup <DestAddPage>(); } else { PageNavigator.NavigateToPopup <DestAddPage>(SelectorViewModel.Province); } }; //RemoteStorage.FetchDestSummary(); }
public ExecutionResult RunPage(string serverAddress, string pageIdentifier, string resultDataIdentifier) { try { new StructuredTextFileXTraceListener("FaatAgent", XTrace.RelativePath.TempFolder); using (var storage = new RemoteStorage(false, serverAddress)) { var mp = new ModelProvider.ModelProvider(storage); return(RunPage(mp, pageIdentifier, resultDataIdentifier)); } } catch (Exception ex) { return(new ExecutionResult { Exception = ex }); } }
private async void ToolbarItem_Clicked_Rename(object sender, EventArgs e) { var options = new ObservableCollection <EntryWithOptionViewModel.EntryWithOptionViewModelEntry>(); if (!string.IsNullOrEmpty(Model.WordbookTitleUser) && Model.WordbookTitleUser != Model.WordbookTitleHtml) { var item = new EntryWithOptionViewModel.EntryWithOptionViewModelEntry(Model.WordbookTitleUser, Model.WordbookTitleUser); options.Add(item); } if (!string.IsNullOrEmpty(Model.WordbookTitleHtml)) { var item = new EntryWithOptionViewModel.EntryWithOptionViewModelEntry(Model.WordbookTitleHtml, Model.WordbookTitleHtml); options.Add(item); } foreach (var item in RemoteStorage.GetNameSuggestions(Model.Uri)) { if (item != Model.WordbookTitleUser) { options.Add(new EntryWithOptionViewModel.EntryWithOptionViewModelEntry(item, item)); } } if (Model == null) { return; } var vm = (new EntryWithOptionViewModel(AppResources.WordbookRenameMessage, options, Model.WordbookTitle)); var page = new EntryWithOptionPage(vm); var waitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset); page.Disappearing += (s, e2) => waitHandle.Set(); await Navigation.PushAsync(page); await Task.Run(() => waitHandle.WaitOne()); var tmp = vm.GetValue <string>(); if (tmp.Item2) { Model.WordbookTitleUser = tmp.Item1; await WordbooksImpressStorage.SaveLocalData(); } }
/// <summary> /// It is guaranteed that CloudStorage can be accessed (server started) /// before a client calls module ClientInitialize() method. /// </summary> internal protected unsafe void ClientInitialize(RunningMode remoteRunningMode, MemoryCloud mc = null) { //Debug.Assert(TrinityConfig.CurrentRunningMode == RunningMode.Client); //Debug.Assert(remoteRunningMode == RunningMode.Server || remoteRunningMode == RunningMode.Proxy); if (mc == null) { mc = Global.CloudStorage; } m_memoryCloud = mc; string moduleName = GetModuleName(); RemoteStorage rs = remoteRunningMode == RunningMode.Server ? mc.StorageTable.FirstOrDefault(_ => _ is RemoteStorage) as RemoteStorage : mc.ProxyList.FirstOrDefault(); if (null == rs) { string msg = "ClientInitialize: " + moduleName + ": No remote communication instance found."; Log.WriteLine(LogLevel.Error, msg); throw new InvalidOperationException(msg); } ushort synReqOffset; ushort synReqRspOffset; ushort asynReqOffset; if (!rs.GetCommunicationModuleOffset(moduleName, out synReqOffset, out synReqRspOffset, out asynReqOffset)) { string msg = "CommunicationModule " + moduleName + " not found on the remote side."; Log.WriteLine(LogLevel.Error, msg); throw new InvalidOperationException(msg); } else { this.SynReqIdOffset = synReqOffset; this.SynReqRspIdOffset = synReqRspOffset; this.AsynReqIdOffset = asynReqOffset; } SetupMessagePassingInterfaces(remoteRunningMode); }
private void TermPage_Loaded(object sender, RoutedEventArgs e) { ButtonQuery.Click += (o, e) => RemoteStorage.FetchTermsAsync(); }
private void OpenCoursePage_Loaded(object sender, RoutedEventArgs e) { SelectorViewModel.SelectorMode = SelectorMode.StructTeacherCourse; ButtonQuery.Click += (o, e) => RemoteStorage.FetchCourseSummaryAsync(); }
private void ReportsPage_Loaded(object sender, RoutedEventArgs e) { SelectorViewModel.SelectorMode = SelectorMode.StructTeacherCourse; ButtonQuery.Click += (o, e) => RemoteStorage.FetchReportsAsync(); ButtonAdd.Click += (o, e) => PageNavigator.NavigateToPopup <ReportAddPage>(); }
private void ReportSummaryPage_Loaded(object sender, RoutedEventArgs e) { SelectorViewModel.SelectorMode = SelectorMode.StructOnly; ButtonQuery.Click += (o, e) => RemoteStorage.FetchReportSummariesAsync(); }
private void TeacherPage_Loaded(object sender, RoutedEventArgs e) { ButtonQuery.Click += (o, e) => RemoteStorage.FetchTeachersAsync(); ButtonAdd.Click += (o, e) => PageNavigator.NavigateToPopup <TeacherAddPage>(); }
private void bgThread_GetDrives(object sender, DoWorkEventArgs e) { e.Result = RemoteStorage.GetStorageDevices(); }
public PCSaveDevice(string gameName) { this.RootDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), gameName); if (PCSaveDevice.CloudSavesSynced) { return; } RemoteStorage remoteStorage = CommunityExpress.Instance.RemoteStorage; for (int index = 0; index < 3; ++index) { string str = "SaveSlot" + (object)index; PCSaveDevice.CloudEntry cloudEntry = new PCSaveDevice.CloudEntry() { Exists = remoteStorage.FileExists(str) }; try { if (cloudEntry.Exists) { CommunityExpressNS.File file = remoteStorage.GetFile(str); cloudEntry.Data = file.ReadBytes(); using (MemoryStream memoryStream = new MemoryStream(cloudEntry.Data)) { using (BinaryReader binaryReader = new BinaryReader((Stream)memoryStream)) cloudEntry.LastModifiedTimestamp = new long?(binaryReader.ReadInt64()); } } } catch (Exception ex) { PCSaveDevice.Log(string.Concat(new object[4] { (object)"Error getting cloud save #", (object)index, (object)" : ", (object)ex })); cloudEntry.Corrupted = true; } try { if (remoteStorage.FileExists(str + "_LastDelete")) { using (MemoryStream memoryStream = new MemoryStream(remoteStorage.GetFile(str + "_LastDelete").ReadBytes())) { using (BinaryReader binaryReader = new BinaryReader((Stream)memoryStream)) cloudEntry.LastDeletedTimestamp = new long?(binaryReader.ReadInt64()); } } } catch (Exception ex) { PCSaveDevice.Log(string.Concat(new object[4] { (object)"Error getting last delete time for cloud save #", (object)index, (object)" : ", (object)ex })); } string path = Path.Combine(this.RootDirectory, str); if (!System.IO.File.Exists(path)) { if (cloudEntry.Exists && !cloudEntry.Corrupted && (!cloudEntry.LastDeletedTimestamp.HasValue || cloudEntry.LastDeletedTimestamp.Value < cloudEntry.LastModifiedTimestamp.Value)) { PCSaveDevice.Log("Copying back cloud save #" + (object)index + " to local because it did not exist locally"); try { using (FileStream fileStream = new FileStream(path, FileMode.Create)) { using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream)) binaryWriter.Write(cloudEntry.Data); } } catch (Exception ex) { PCSaveDevice.Log(string.Concat(new object[4] { (object)"Error copying cloud entry data to local for cloud save #", (object)index, (object)" : ", (object)ex })); } } } else { long num = long.MinValue; try { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream)) num = binaryReader.ReadInt64(); } } catch (Exception ex) { PCSaveDevice.Log("Error while loading local file for timestamp compare : " + (object)ex); } if (cloudEntry.LastDeletedTimestamp.HasValue && cloudEntry.LastDeletedTimestamp.Value > num) { PCSaveDevice.Log("Deleting local save #" + (object)index + " because of pending cloud deletion"); System.IO.File.Delete(path); num = long.MinValue; } if (cloudEntry.Exists && !cloudEntry.Corrupted && (!cloudEntry.LastDeletedTimestamp.HasValue || cloudEntry.LastDeletedTimestamp.Value < cloudEntry.LastModifiedTimestamp.Value) && cloudEntry.LastModifiedTimestamp.Value > num) { PCSaveDevice.Log("Copying back cloud save #" + (object)index + " to local because the local copy is older"); try { using (FileStream fileStream = new FileStream(path, FileMode.Create)) { using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream)) binaryWriter.Write(cloudEntry.Data); } } catch (Exception ex) { PCSaveDevice.Log(string.Concat(new object[4] { (object)"Error copying cloud entry data to local for cloud save #", (object)index, (object)" : ", (object)ex })); } } } PCSaveDevice.CloudSavesSynced = true; } }