private static void SaveFileToIsoStore(string fileName, byte[] data) { string strBaseDir = string.Empty; const string DelimStr = "/"; char[] delimiter = DelimStr.ToCharArray(); string[] dirsPath = fileName.Split(delimiter); // Get the IsoStore using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { // Recreate the directory structure for (var i = 0; i < dirsPath.Length - 1; i++) { strBaseDir = Path.Combine(strBaseDir, dirsPath[i]); isoStore.CreateDirectory(strBaseDir); } // Create the file if not exists // or override if exist using (var bw = new BinaryWriter(new IsolatedStorageFileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Write, isoStore))) { bw.Write(data); } } }
private static bool GetAttributeByUDAFormula( PresentedPropertiesXml presentedPropertiesInstance, ModelObject modelObj, string udaEquation, out double resultValue) { var removeChar = new[] { '+', '-', '*', '/', '(', ')' }; const string DelimStr = " "; var delimiter = DelimStr.ToCharArray(); string insertAddstr; var findIndex = 0; double doubleValue; var culInfo = CultureInfo.CurrentCulture; var usCulInfo = new CultureInfo("en-us"); resultValue = 0.0; var findString = udaEquation; for (var i = 0; i < removeChar.Length; i++) { findString = findString.Replace(removeChar[i].ToString(CultureInfo.InvariantCulture), " "); } var splitKey = findString.Split(delimiter); var tempKey = new string[splitKey.Length]; for (var i = 0; i < splitKey.Length; i++) { if (splitKey[i].Length <= 0) { continue; } var isDouble = double.TryParse(splitKey[i], NumberStyles.Any, culInfo, out doubleValue); if (isDouble == false) { isDouble = double.TryParse(splitKey[i], NumberStyles.Any, usCulInfo, out doubleValue); } if (isDouble == false) { tempKey[i] = splitKey[i]; insertAddstr = "_UDA_" + i.ToString(CultureInfo.InvariantCulture); findIndex = udaEquation.IndexOf(splitKey[i], findIndex, StringComparison.Ordinal); findIndex = findIndex + splitKey[i].Length; udaEquation = udaEquation.Insert(findIndex, insertAddstr); } } for (var i = 0; i < tempKey.Length; i++) { if (null == tempKey[i] || tempKey[i].Length == 0) { continue; } PresentedProperties property = null; if (!presentedPropertiesInstance.GetPropertyByNameOrModelPropertyName(tempKey[i], ref property)) { continue; } // Maybe should use just visible property name? var propertvalueY = GetPropertvalueYBasedOnType( presentedPropertiesInstance, modelObj, property, true, false); try { doubleValue = Convert.ToDouble(propertvalueY); insertAddstr = tempKey[i] + "_UDA_" + i.ToString(CultureInfo.InvariantCulture); udaEquation = udaEquation.Replace(insertAddstr, doubleValue.ToString(CultureInfo.InvariantCulture)); } catch (Exception ee) { Debug.WriteLine(ee); return(false); } } var mathEval = new MathEvaluate(); if (mathEval.Parse(udaEquation) && mathEval.Error == false) { mathEval.Infix2Postfix(); mathEval.EvaluatePostfix(); } if (mathEval.Error) { if (mathEval.ErrorDescription != MathEvaluate.DivideByZero) { return(false); } } else { resultValue = mathEval.Result; } return(true); }