public bool Save(string fileName) { FileStream fs = new FileStream(fileName, FileMode.Create); try { using (fs) { BinaryWriter bw = new BinaryWriter(fs); using (bw) { if (!Serialize(bw)) { throw new Exception("failed to serialize Config Data"); } } fs.Close(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _appLog.LogError("failed to save config file", ex, "ConfigFile", "Save"); return(false); } return(true); }
public void CloseAndDeleteCurrentActivities() { if (this._activitiesStack.Count == 0) { AppLog.LogError("Activities stack has no activities", true); return; } Activity activity1 = this._activitiesStack.Peek(); Activity parent = activity1.Parent ?? activity1; ((IEnumerable <Activity>)parent.Subactivities).ForEach <Activity>((Activity activity) => { ((IEnumerable <Shot>)activity.Shots).ForEach <Shot>((Shot shot) => { shot.IsDeleted = true; shot.IsDirty = true; //DatabaseManager.Update<Shot>(shot); }); activity.IsDeleted = true; activity.IsDirty = true; //DatabaseManager.Update<Activity>(activity); }); parent.IsDeleted = true; parent.IsDirty = true; //DatabaseManager.Update<Activity>(parent); this._activitiesStack.Clear(); }
/// <summary> /// 检查是否存在同名文件,若存在则中止程序 /// </summary> /// <param name="allFilePaths">指定的全部文件</param> /// <param name="extension">扩展名</param> public static void CheckSameName(Dictionary <string, List <string> > allFilePaths, string extension) { string SameNameFileTemp = null; foreach (KeyValuePair <string, List <string> > kvp in allFilePaths) { if (kvp.Value.Count > 1) { SameNameFileTemp = SameNameFileTemp + "\n存在同名" + extension + "文件:" + kvp.Key + ",位置如下:"; foreach (string st in kvp.Value) { SameNameFileTemp = SameNameFileTemp + "\n" + st; } } } //判断是否存在同名文件,若存在则打印出来,退出程序 if (SameNameFileTemp == null) { // AppLog.Log(string.Format("Excel同名检查完毕,没有发现同名文件\n"), ConsoleColor.Green); } else { AppLog.LogError(SameNameFileTemp); AppLog.LogError("\n存在上面所列同名文件,包含子文件夹都不充许存在同名文件\n"); AppLog.SaveErrorInfoToFile("错误日志"); AppLog.LogErrorAndExit("\n按任意键继续"); } }
//public static bool TryCopy(string srcPath, string destPath) //{ // if (!System.IO.File.Exists(srcPath)) // return false; // try // { // string destThn = ImageItem.GetThumbnailPathAndFileName(destPath); // string srcThn = ImageItem.GetThumbnailPathAndFileName(srcPath); // string destTxt = ImageItem.GetTextFilePathAndFileName(destPath); // string srcTxt = ImageItem.GetTextFilePathAndFileName(srcPath); // System.IO.File.Copy(srcPath, destPath); // if (System.IO.File.Exists(srcThn)) // System.IO.File.Copy(srcThn, destThn); // if (System.IO.File.Exists(srcTxt)) // System.IO.File.Copy(srcTxt, destTxt); // return true; // } // catch (Exception ex) // { // _appLog.LogError(String.Format("Failed to copy file {0}", srcPath), ex, "SlideShowSetupForm", "TryCopy"); // return false; // } //} //public static bool TryMove(string srcPath, string destPath) //{ // if (!System.IO.File.Exists(srcPath)) // return false; // try // { // string destThn = ImageItem.GetThumbnailPathAndFileName(destPath); // string srcThn = ImageItem.GetThumbnailPathAndFileName(srcPath); // string destTxt = ImageItem.GetTextFilePathAndFileName(destPath); // string srcTxt = ImageItem.GetTextFilePathAndFileName(srcPath); // System.IO.File.Move(srcPath, destPath); // if (System.IO.File.Exists(srcThn)) // System.IO.File.Move(srcThn, destThn); // if (System.IO.File.Exists(srcTxt)) // System.IO.File.Move(srcTxt, destTxt); // return true; // } // catch (Exception ex) // { // _appLog.LogError(String.Format("Failed to move file {0}", srcPath), ex, "SlideShowSetupForm", "TryMove"); // return false; // } //} public static bool TryDelete(string srcPath) { if (!System.IO.File.Exists(srcPath)) { return(false); } try { string srcThn = ImageItem.GetThumbnailPathAndFileName(srcPath); string srcTxt = ImageItem.GetTextFilePathAndFileName(srcPath); System.IO.File.Delete(srcPath); if (System.IO.File.Exists(srcThn)) { System.IO.File.Delete(srcThn); } if (System.IO.File.Exists(srcTxt)) { System.IO.File.Delete(srcTxt); } return(true); } catch (Exception ex) { AppLog appLog = new AppLog(); appLog.LogError(String.Format("Failed to delete file {0}", srcPath), ex, "SlideShowSetupForm", "TryDelete"); return(false); } }
private static bool TryCopy(string srcPath, string destPath, string verb, CopyDel copyDel) { if (!System.IO.File.Exists(srcPath)) { return(false); } try { string destThn = ImageItem.GetThumbnailPathAndFileName(destPath); string srcThn = ImageItem.GetThumbnailPathAndFileName(srcPath); string destTxt = ImageItem.GetTextFilePathAndFileName(destPath); string srcTxt = ImageItem.GetTextFilePathAndFileName(srcPath); copyDel(srcPath, destPath); if (System.IO.File.Exists(srcThn)) { copyDel(srcThn, destThn); } if (System.IO.File.Exists(srcTxt)) { copyDel(srcTxt, destTxt); } return(true); } catch (Exception ex) { AppLog appLog = new AppLog(); appLog.LogError(String.Format("Failed to {0} file {1}", verb, srcPath), ex, "SlideShowCommon.Utilities", "Try" + verb); return(false); } }
private static void OnLogMessageReceivedThreaded(string condition, string stackTrace, LogType type) { if (type != LogType.Exception) { return; } AppLog.LogError(string.Format("UNCAUGHT EXCEPTION: {0}{1}STACK_TRACE: {2}", condition, Environment.NewLine, stackTrace), true); }
public bool Load(bool readKeywords, ProgressChangedEventHandler updateProgress) { FileStream fs = new FileStream(PathAndFileName, FileMode.Open, FileAccess.Read); try { using (fs) { BinaryReader br = new BinaryReader(fs); using (br) { string header = br.ReadString(); _name = br.ReadString(); _imageItemCollection = new ImageItemList(); while (br.BaseStream.Position < br.BaseStream.Length) { ImageItem ii = new ImageItem(); //_appLog.LogWarning("loading new image", null, "ScriptFile", "Load()"); ii.Deserialize(br, readKeywords); _imageItemCollection.AddImageItem(ii); if (updateProgress != null) { updateProgress((int)((float)br.BaseStream.Position / (float)br.BaseStream.Length * 100)); } } br.Close(); } fs.Close(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _appLog.LogError("failed to load script file", ex, "ScriptFile", "Load"); return(false); } return(true); }
private static void Request(string serviceUrl, Dictionary <string, string> postFields, Action <string> callback) { IObservable <WWW> wWW; Dictionary <string, string> strs; WWWForm wWWForm = null; if (postFields != null) { wWWForm = new WWWForm(); foreach (KeyValuePair <string, string> postField in postFields) { if (postField.Key == null) { throw new NullReferenceException(string.Format("Post field key is null. URL: {0}\nFields:\n{1}", serviceUrl, WebService.GetFieldsString(postFields))); } if (postField.Value == null) { throw new NullReferenceException(string.Format("Post field value for key '{0}' is null. URL: {1}\nFields:\n{2}", postField.Key, serviceUrl, WebService.GetFieldsString(postFields))); } wWWForm.AddField(postField.Key, postField.Value); } } string str = Uri.EscapeUriString(serviceUrl); if (wWWForm == null) { strs = new Dictionary <string, string>() { { "ACCEPT-ENCODING", "gzip" } }; wWW = ObservableWWW.GetWWW(str, strs, null); } else { strs = new Dictionary <string, string>() { { "ACCEPT-ENCODING", "gzip" } }; wWW = ObservableWWW.PostWWW(str, wWWForm, strs, null); } wWW.Retry <WWW>(5).CatchIgnore <WWW, WWWErrorException>((WWWErrorException ex) => { AppLog.LogError(string.Format("WWW error: {0}", ex.RawErrorMessage), true); callback(null); }).Select <WWW, string>((WWW www) => { string empty = string.Empty; www.responseHeaders.TryGetValue("CONTENT-ENCODING", out empty); if (empty != "gzip") { return(www.text); } return(WebService.Ungzip(www.bytes)); }).Subscribe <string>(callback, (Exception e) => { AppLog.LogException(e, true); callback(null); }); }
public bool AddMRUFile(string fileName) { try { // get an updated list of what's currently in there GetMRUList(); string[] nameArray = { MRU_LIST_1, MRU_LIST_2, MRU_LIST_3, MRU_LIST_4 }; string[] newArray; // if its already in the list, reorder things if (_mruList.Contains(fileName) && _mruList.Count > 1) { newArray = new string[_mruList.Count + 1]; newArray[0] = fileName; int i; for (i = 0; i < _mruList.Count - 1; i++) { if ((string)_mruList[i] == fileName) { break; } newArray[i + 1] = (string)_mruList[i]; } // after breaking, copy the rest of the array for (int j = i + 1; j < _mruList.Count; j++) { newArray[j] = (string)_mruList[j]; } } else { // otherwise index everything down a notch newArray = new string[_mruList.Count + 1]; newArray[0] = fileName; _mruList.CopyTo(newArray, 1); } // now set the registry keys for the first 4 for (int index = 0; (index < newArray.GetLength(0) && index < nameArray.GetLength(0)); index++) { if (newArray[index] != null) { _regKey.SetValue(nameArray[index], newArray[index]); } } return(true); } catch (Exception ex) { _appLog.LogError("failed to add mru file", ex, "RegistrySettings", "AddMRUFile"); return(false); } }
private static void HandleResetPasswordResponse(WebServiceResponse response, Action onFinish, Action <LoginManager.AuthErrorCode, string> onError) { if (!response.Success) { AppLog.LogError(string.Concat("ResetWassword was failed. Reason: ", response.Message), true); if (onError != null) { onError((AuthErrorCode)5, response.Message); } } else if (onFinish != null) { onFinish(); } }
public void RemovePrevBall(CBall ball) { if (ball == null) { return; } if (!this.previousBalls.Contains(ball)) { AppLog.LogError(string.Concat("Previous balls dont contain ball ", ball.gameObject.name), true); } else { this.previousBalls.Remove(ball); } }
private static void BuildUserOffline(int customerId) { LoginManager._user = DataEntry.GetInstance <User>(customerId); if (LoginManager._user == null) { string str = string.Format("User {0} was not found in DB", customerId); AppLog.LogError(str, true); LoginManager.FireLogInFailedEvent(LoginManager.AuthErrorCode.UserNotInDBError, str); } else { LoginManager._isOnlineLogin = false; LoginManager._isUserLoggedIn = true; LoginManager.FireLogInSuccessEvent(); } }
private static void ResponseGetUserInfo(WebServiceResponse response) { if (!response.Success) { AppLog.LogError(string.Concat("ERROR: ", response.Message), true); LoginManager.FireLogInFailedEvent(LoginManager.AuthErrorCode.GetUserInfoError, response.Message); LoginManager.SetLoggingInStatus(false); return; } string empty = string.Empty; if (response.Data.HasField("customerid")) { response.Data.GetField(ref empty, "customerid", null); } string userDexterity = ""; //string userDexterity = DatabaseManager.GetUserDexterity(int.Parse(empty)); LoginManager._user = DataEntry.DeserializeFromData <User>(response.Data); if (LoginManager._user == null) { string str = "Error during parsing User from server."; AppLog.LogError(str, true); LoginManager.FireLogInFailedEvent(LoginManager.AuthErrorCode.GetUserInfoError, str); LoginManager.SetLoggingInStatus(false); } else { if (LoginManager._user.Status == 0) { LoginManager._user.SetUserStatus(User.UserStatus.Guest); } if (!string.IsNullOrEmpty(userDexterity)) { LoginManager._user.Dexterity = userDexterity; } if (string.IsNullOrEmpty(LoginManager._user.Dexterity)) { LoginManager._user.Dexterity = "R"; } //DatabaseManager.InsertOrUpdate<User>(LoginManager._user); LoginManager.GetUserESNs(LoginManager._user.Id); } }
public static void CheckTable() { if (ExcelFolder.IsNeedCheck == true) { string errorString; foreach (KeyValuePair <string, TableInfo> kvp in AppValues.TableInfo) { //合并过的表不再检查 if (AppValues.MergeTableList != null) { if (AppValues.MergeTableList.ContainsKey(kvp.Key)) { continue; } } TableInfo tableInfo = kvp.Value; AppLog.Log(string.Format("\n检查表格\"{0}\":", tableInfo.ExcelNameTips), ConsoleColor.Green); errorString = null; TableCheckHelper.CheckTable(tableInfo, out errorString); if (errorString != null) { AppLog.LogError(string.Format("检查完成,存在以下错误:\n{0}", errorString)); } else { AppLog.Log("检查完成,正确"); } if (AppLog.LogErrorContent.Length > 0) { AppLog.SaveErrorInfoToFile("错误日志.txt"); AppLog.LogErrorAndExit("\n按任意键继续"); } } } }
public void FinishMainActivity() { if (!LoginManager.IsUserLoggedIn) { return; } if (this._activitiesStack.Count == 0) { AppLog.LogError("Activities stack has no activities", true); return; } if (this._activitiesStack.Count != 1) { throw new InvalidOperationException(string.Format("Activities stack contains 0 or more than 1 activities: [ {0} ]", (this._activitiesStack.Count != 0 ? ( from a in this._activitiesStack select a.Id.ToString()).Aggregate <string>((string s1, string s2) => string.Concat(s1, ", ", s2)) : string.Empty))); } Activity now = this._activitiesStack.Pop(); now.EndTime = DateTime.Now; now.IsDirty = true; //DatabaseManager.Update<Activity>(now); }
private static void HandleAuthResponse(WebServiceResponse response) { if (!response.Success) { LoginManager.FireLogInFailedEvent(LoginManager.AuthErrorCode.AuthError, response.Message); LoginManager.SetLoggingInStatus(false); } else { LoginManager.Token = response.Data["session-guid"].str; if (!string.IsNullOrEmpty(LoginManager.Token)) { AppLog.Log("Auth was success.", true); LoginManager.BuildUserOnline(); } else { string str = "ERROR: Unknown error - Account was not created"; AppLog.LogError(str, true); LoginManager.FireLogInFailedEvent(LoginManager.AuthErrorCode.AuthError, str); LoginManager.SetLoggingInStatus(false); } } }
private static void ResponseGetCustomerEsns(WebServiceResponse response) { if (!response.Success) { AppLog.LogError(string.Concat("ERROR: ", response.Message), true); LoginManager.FireLogInFailedEvent(LoginManager.AuthErrorCode.GetCustomerEsnsError, response.Message); LoginManager.SetLoggingInStatus(false); return; } JSONObject item = response.Data["data"]["DATA"]; List <string> list = ( from e in item.list select e[1].str.Trim(new char[] { '\"' })).ToList <string>(); ApplicationDataManager.instance.SetPreviousUsedESNList(list); foreach (string str in list) { SecurityWrapperService.Instance.AddEsnToCache(str); } LoginManager._isOnlineLogin = true; LoginManager._isUserLoggedIn = true; LoginManager.FireLogInSuccessEvent(); LoginManager.SetLoggingInStatus(false); }