/// <summary> /// 获取多个对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="objIds"></param> /// <returns></returns> public override IDictionary <string, T> GetObjects <T>(IList <string> objIds) { lock (lockObject) { var objIdList = new List <string>(objIds); objIdList = objIdList.ConvertAll <string>(objId => GetInputKey(objId)); objIdList = (from item in objIdList select item).Distinct().ToList(); IDictionary <string, T> cacheData = new Dictionary <string, T>(); var data = dataCache.MultiGet(objIdList); if (data != null) { foreach (KeyValuePair <string, byte[]> kv in data) { if (kv.Value != null) { cacheData.Add(GetOutputKey(kv.Key), Serialization.BinaryDeSerialize <T>(kv.Value)); } else { cacheData.Add(GetOutputKey(kv.Key), default(T)); } } } return(cacheData); } }
/// <summary> /// Get a number of items from cache /// </summary> /// <typeparam name="T">The type to which to cast the cached items</typeparam> /// <param name="keys">Keys of the cache items</param> /// <returns>A dictionary of cached items of type T, where the dictionary keys correspond to those given</returns> public override Dictionary <string, T> MultiGet <T>(List <string> keys) { var uniqueKeys = keys; // Handles duplicate keys being used if (uniqueKeys != null) { uniqueKeys = uniqueKeys.Distinct().ToList().ConvertAll(key => this.Prefix(key)); } // Retrieve cached items as byte arrays IDictionary <string, byte[]> multiGetResult; try { multiGetResult = IndexusDistributionCache.SharedCache.MultiGet(uniqueKeys); } catch (Exception e) { throw new Exception("Error retrieving items from shared cache. This may indicate that the server is not available", e); } // Build a dictionary of cached items of type T var multiGetTypedResult = new Dictionary <string, T>(); foreach (var item in multiGetResult) { // Do not attempt conversion on null objects if (item.Value == null) { continue; } // Deserialize cached item to type T and add to dictionary var value = Serialization.BinaryDeSerialize <T>(item.Value); multiGetTypedResult.Add(this.UnPrefix(item.Key), value); } return(multiGetTypedResult); }
/// <summary> /// Open file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuFileOpen_Click(object sender, RoutedEventArgs e) { // Open dialog OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); openFileDialog.Filter = "Data file (.dat)|*.bin|All Files *.*|*.*"; if (openFileDialog.ShowDialog() == true) { fileName = openFileDialog.FileName; try { // Restore (deserialize) Serialization serialization = new Serialization(); serialization.BinaryDeSerialize(fileName, out taskMgr, out projectMgr); this.Title = string.Concat("Task Manager - ", System.IO.Path.GetFileName(fileName)); UpdateGUI(); MessageBox.Show("Data read from file", "Success"); } catch (Exception ex) { MessageBox.Show(string.Format("Error:\n{0}", ex.ToString()), "Error"); } } }