// CLOVER:ON /// <summary> /// Gets those <see cref="System.Reflection.ConstructorInfo"/>s /// that are applicable for autowiring the supplied <paramref name="definition"/>. /// </summary> /// <param name="definition"> /// The <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/> /// (definition) that is being autowired by constructor. /// </param> /// <param name="minimumArgumentCount"> /// The absolute minimum number of arguments that any returned constructor /// must have. If this parameter is equal to zero (0), then all constructors /// are valid (regardless of their argument count), including any default /// constructor. /// </param> /// <returns> /// Those <see cref="System.Reflection.ConstructorInfo"/>s /// that are applicable for autowiring the supplied <paramref name="definition"/>. /// </returns> public static ConstructorInfo[] GetConstructors( IObjectDefinition definition, int minimumArgumentCount) { const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly; ConstructorInfo[] constructors = null; if (minimumArgumentCount > 0) { MemberInfo[] ctors = definition.ObjectType.FindMembers( MemberTypes.Constructor, flags, new CriteriaMemberFilter().FilterMemberByCriteria, new MinimumArgumentCountCriteria(minimumArgumentCount)); constructors = (ConstructorInfo[])ArrayList.Adapter(ctors).ToArray(typeof(ConstructorInfo)); } else { constructors = definition.ObjectType.GetConstructors(flags); } SortConstructors(constructors); return(constructors); }
/// <include file='doc\DomainUpDown.uex' path='docs/doc[@for="DomainUpDown.SortDomainItems"]/*' /> /// <devdoc> /// Sorts the domain values /// </devdoc> private void SortDomainItems() { if (inSort) { return; } inSort = true; try { // Sanity check Debug.Assert(sorted == true, "Sorted == false"); if (!sorted) { return; } if (domainItems != null) { // Sort the domain values ArrayList.Adapter(domainItems).Sort(new DomainUpDownItemCompare()); // Update the domain index if (!UserEdit) { int newIndex = MatchIndex(stringValue, true); if (newIndex != -1) { SelectIndex(newIndex); } } } } finally { inSort = false; } }
protected override bool StartTest() { logoStr = ""; sInputPowerArray = ""; sRXDmiPowArray = ""; sDiffArray = ""; if (AnalysisInputParameters(inputParameters) == false) { OutPutandFlushLog(); return(false); } if (tempps != null && tempAtten != null) { // open apc //CloseandOpenAPC(Convert.ToByte(APCMODE.IBAISandIMODON)); // open apc Log.SaveLogToTxt("Step3...Start Test TestRxDmiPowErrorCurve"); int TestCount; double countMol = (Math.Abs(testRxDmiPowErrorCurveStruct.RxInputPowerMax - testRxDmiPowErrorCurveStruct.RxInputPowerMin)) % testRxDmiPowErrorCurveStruct.AttStep; if (countMol == 0) { TestCount = Convert.ToInt32((Math.Abs(testRxDmiPowErrorCurveStruct.RxInputPowerMax - testRxDmiPowErrorCurveStruct.RxInputPowerMin)) / testRxDmiPowErrorCurveStruct.AttStep); } else { TestCount = Convert.ToInt32((Math.Abs(testRxDmiPowErrorCurveStruct.RxInputPowerMax - testRxDmiPowErrorCurveStruct.RxInputPowerMin) - countMol) / testRxDmiPowErrorCurveStruct.AttStep) + 1; } InputPowerArray = new double[TestCount + 1]; RXDmiPowArray = new double[TestCount + 1]; DiffArray = new double[TestCount + 1]; DiffRawArray = new double[TestCount + 1]; for (int i = 0; i < TestCount + 1; i++) { if (i != TestCount) { InputPowerArray[i] = testRxDmiPowErrorCurveStruct.RxInputPowerMax - i * testRxDmiPowErrorCurveStruct.AttStep; } else { if (testRxDmiPowErrorCurveStruct.RxInputPowerMax - i * testRxDmiPowErrorCurveStruct.AttStep < testRxDmiPowErrorCurveStruct.RxInputPowerMin) { InputPowerArray[i] = testRxDmiPowErrorCurveStruct.RxInputPowerMin; } else { InputPowerArray[i] = testRxDmiPowErrorCurveStruct.RxInputPowerMax - i * testRxDmiPowErrorCurveStruct.AttStep; } } } tempAtten.AttnValue(InputPowerArray[0].ToString(), 1); Thread.Sleep(3000); for (int j = 0; j < InputPowerArray.Length; j++) { tempAtten.AttnValue(InputPowerArray[j].ToString(), 1); RXDmiPowArray[j] = dut.ReadDmiRxp(); DiffArray[j] = Math.Abs(InputPowerArray[j] - RXDmiPowArray[j]); DiffRawArray[j] = InputPowerArray[j] - RXDmiPowArray[j]; if (j != InputPowerArray.Length - 1) { sInputPowerArray += InputPowerArray[j] + ","; sRXDmiPowArray += RXDmiPowArray[j] + ","; sDiffArray += DiffArray[j] + ","; } else { sInputPowerArray += InputPowerArray[j]; sRXDmiPowArray += RXDmiPowArray[j]; sDiffArray += DiffArray[j]; } Log.SaveLogToTxt("InputPowerArray[" + j.ToString() + "]:" + InputPowerArray[j].ToString() + "RXDmiPowArray[" + j.ToString() + "]:" + RXDmiPowArray[j].ToString() + "DiffArray[" + j.ToString() + "]" + DiffArray[j].ToString()); } byte maxIndex; Algorithm.SelectMaxValue(ArrayList.Adapter(DiffArray), out maxIndex); MaxErr = DiffRawArray[maxIndex]; ErrMaxPoint = InputPowerArray[maxIndex]; Log.SaveLogToTxt("ErrMaxPoint=" + ErrMaxPoint.ToString() + " MaxErr" + MaxErr.ToString()); //tempAtten.OutPutSwitch(false); //Thread.Sleep(2000); //RxNopticalPoint=dut.ReadDmiRxp(); //tempAtten.OutPutSwitch(true); OutPutandFlushLog(); return(true); } else { Log.SaveLogToTxt("Equipments are not enough!"); OutPutandFlushLog(); return(false); } }
public void TestArrayListWrappers() { //-------------------------------------------------------------------------- // Variable definitions. //-------------------------------------------------------------------------- ArrayList arrList = null; string[] strHeroes = { "Aquaman", "Atom", "Batman", "Black Canary", "Captain America", "Captain Atom", "Catwoman", "Cyborg", "Flash", "Green Arrow", "Green Lantern", "Hawkman", "Huntress", "Ironman", "Nightwing", "Robin", "SpiderMan", "Steel", "Superman", "Thor", "Wildcat", "Wonder Woman", }; // // Construct array list. // arrList = new ArrayList((ICollection)strHeroes); //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of //BinarySearch, Following variable cotains each one of these types of array lists ArrayList[] arrayListTypes = { (ArrayList)arrList.Clone(), (ArrayList)ArrayList.Adapter(arrList).Clone(), (ArrayList)ArrayList.FixedSize(arrList).Clone(), (ArrayList)arrList.GetRange(0, arrList.Count).Clone(), (ArrayList)ArrayList.Synchronized(arrList).Clone() }; foreach (ArrayList arrayListType in arrayListTypes) { arrList = arrayListType; // // [] Reverse entire array list. // arrList.Reverse(0, arrList.Count); // Verify items have been reversed. for (int ii = 0; ii < arrList.Count; ++ii) { Assert.Equal(0, strHeroes[ii].CompareTo((String)arrList[arrList.Count - ii - 1])); } // // [] Attempt invalid Reverse using negative index // // Assert.Throws <ArgumentOutOfRangeException>(() => arrList.Reverse(-100, arrList.Count)); // // [] Attempt Reverse using out of range index // Assert.Throws <ArgumentException>(() => arrList.Reverse(1000, arrList.Count)); // // [] Attempt Reverse using negative count. // Assert.Throws <ArgumentOutOfRangeException>(() => arrList.Reverse(0, -arrList.Count)); // // [] Attempt Reverse using zero count. // arrList.Reverse(0, 0); // Verify no reversal (List should still be reveresed of the original.) for (int ii = 0; ii < arrList.Count; ++ii) { Assert.Equal(0, strHeroes[ii].CompareTo((string)arrList[arrList.Count - ii - 1])); } } }
/// <summary> /// /// </summary> /// <param name="file"></param> /// <param name="folderName"></param> /// <param name="fileName"></param> /// <returns></returns> public string picUpLoad(HttpPostedFileBase file, string folderName, string fileName, int width, int height) { var PicUrl = UntilMethod.appsetingValue("PicUrl"); #region 设置本地临时路径和允许允许上传的文件格式与大小 string fileTypes = "jpg,jpeg,png,bmp"; int maxSize = 4096000;//大小限制4M 和web.config中一致 #endregion #region 临时路径是否存在 var TempfolderPath = HttpRuntime.AppDomainAppPath.ToString() + "uploadTemp"; if (!Directory.Exists(TempfolderPath)) { fileRWhelper.CreateDirectory(TempfolderPath);//创建路径 } #endregion #region 裁剪并保存图片 string fileExt = Path.GetExtension(file.FileName).ToLower(); fileName = fileName + fileExt; string TempfilePath = TempfolderPath + "//" + fileName; if (width == 0 && height == 0) { Image image = Image.FromStream(file.InputStream); image.Save(TempfilePath); } else { GenerateThumbnailWarr(TempfilePath, width, height, file.InputStream); } #endregion #region 是否符合格式与大小 ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(',')); if (file.InputStream == null || file.InputStream.Length > maxSize) { //大小限制 } if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1) { //格式限制 } #endregion #region 先将图片保存至程序所在目录 //string newFileName = Guid.NewGuid().ToString() + fileExt; //string TempfilePath = TempfolderPath + newFileName; //file.SaveAs(TempfilePath); #endregion #region 至图片服务器 string filesdir = "//" + folderName + "//"; String uploadUrl = PicUrl + "/Services/PicServices.aspx?PathDir=" + filesdir; String fileFormName = "file"; String contenttype = "image/jpeg"; string boundary = "----------" + DateTime.Now.Ticks.ToString("x"); HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uploadUrl); webrequest.ContentType = "multipart/form-data; boundary=" + boundary; webrequest.Method = "POST"; StringBuilder sb = new StringBuilder(); sb.Append("--"); sb.Append(boundary); sb.Append("\r\n"); sb.Append("Content-Disposition: form-data; name=\""); sb.Append(fileFormName); sb.Append("\"; filename=\""); sb.Append(Path.GetFileName(fileName)); sb.Append("\""); sb.Append("\r\n"); sb.Append("Content-Type: "); sb.Append(contenttype); sb.Append("\r\n"); sb.Append("\r\n"); string postHeader = sb.ToString(); byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader); byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); FileStream fileStream = new FileStream(TempfilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length; webrequest.ContentLength = length; Stream requestStream = webrequest.GetRequestStream(); requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length); byte[] buffer = new Byte[(int)fileStream.Length]; int bytesRead = 0; while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { requestStream.Write(buffer, 0, bytesRead); } requestStream.Write(boundaryBytes, 0, boundaryBytes.Length); requestStream.Close(); fileStream.Close(); fileStream.Dispose(); Thread.Sleep(1000); string fileUrl = PicUrl + filesdir + fileName; #endregion #region 除临时文件 FileInfo info = new FileInfo(TempfilePath); info.Delete(); #endregion fileUrl = fileUrl.Replace(PicUrl, ""); return(fileUrl); }
public static DefaultArgumentsDefinition CreateFrom(IList args, int start, int end, IokeObject message, object on, IokeObject context) { Runtime runtime = context.runtime; IList <Argument> arguments = new SaneList <Argument>(); IList <string> keywords = new SaneList <string>(); int min = 0; int max = 0; bool hadOptional = false; string rest = null; string krest = null; foreach (object obj in ArrayList.Adapter(args).GetRange(start, end - start)) { Message m = (Message)IokeObject.dataOf(obj); string mname = m.Name; if (!"+:".Equals(mname) && m.IsKeyword()) { string name = mname; IokeObject dValue = context.runtime.nilMessage; if (m.next != null) { dValue = m.next; } arguments.Add(new KeywordArgument(name.Substring(0, name.Length - 1), dValue)); keywords.Add(name); } else if (mname.Equals("+")) { string name = Message.GetName(m.Arguments(null)[0]); if (name.StartsWith(":")) { krest = name.Substring(1); } else { rest = name; max = -1; } hadOptional = true; } else if (mname.Equals("+:")) { string name = m.next != null?Message.GetName(m.next) : Message.GetName(m.Arguments(null)[0]); krest = name; hadOptional = true; } else if (m.next != null) { string name = mname; hadOptional = true; if (max != -1) { max++; } arguments.Add(new OptionalArgument(name, m.next)); } else { if (hadOptional) { int index = IndexOf(args, obj) + start; IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition, message, context, "Error", "Invocation", "ArgumentWithoutDefaultValue"), context).Mimic(message, context); condition.SetCell("message", message); condition.SetCell("context", context); condition.SetCell("receiver", on); condition.SetCell("argumentName", runtime.GetSymbol(m.Name)); condition.SetCell("index", runtime.NewNumber(index)); IList newValue = IokeList.GetList(runtime.WithRestartReturningArguments(() => { runtime.ErrorCondition(condition); }, context, new NewArgumentGivingRestart("provideDefaultValue", "defaultValue"), new Restart.DefaultValuesGivingRestart("substituteNilDefault", runtime.nil, 1))); if (max != -1) { max++; } arguments.Add(new OptionalArgument(m.Name, runtime.CreateMessage(Message.Wrap(IokeObject.As(newValue[0], context))))); } else { min++; max++; arguments.Add(new Argument(IokeObject.As(obj, context).Name)); } } } return(new DefaultArgumentsDefinition(arguments, keywords, rest, krest, min, max, false)); }
private static T FindMedian <T>(IList <T> data, int index, int lenght, IComparer <T> comparer) { ArrayList.Adapter((IList)data).Sort(index, lenght, (IComparer)comparer); return(data[index + (lenght / 2)]); }
public static int BinarySearch(this IList semiSortedList, object value) { ArrayList realValues = ArrayList.Adapter(semiSortedList); return(realValues.BinarySearch(value)); }
public void TestRemoveAtAdapter() { PrivateTestRemoveAt(ArrayList.Adapter(new ArrayList())); }
public void TestBinarySearchAdapter() { PrivateTestBinarySearch(ArrayList.Adapter(new ArrayList())); }
public void TestCopyToAdapter() { PrivateTestCopyTo(ArrayList.Adapter(new ArrayList())); }
public void TestCloneAdapter() { PrivateTestClone(ArrayList.Adapter(new ArrayList())); }
public void TestIndexOfAdapter() { PrivateTestIndexOf(ArrayList.Adapter(new ArrayList())); }
public void TestAddRangeAdapter() { PrivateTestAddRange(ArrayList.Adapter(new ArrayList())); }
public void TestEnumeratorAdapter() { PrivateTestEnumerator(ArrayList.Adapter(new ArrayList())); }
public void TestArrayListWrappers() { //-------------------------------------------------------------------------- // Variable definitions. //-------------------------------------------------------------------------- ArrayList arrList = null; int start = 3; int count = 15; string[] strHeroes = { "Aquaman", "Atom", "Batman", "Black Canary", "Captain America", "Captain Atom", "Catwoman", "Cyborg", "Flash", "Green Arrow", "Green Lantern", "Hawkman", "Huntress", "Ironman", "Nightwing", "Robin", "SpiderMan", "Steel", "Superman", "Thor", "Wildcat", "Wonder Woman", }; string[] strResult = { "Aquaman", "Atom", "Batman", "Superman", "Thor", "Wildcat", "Wonder Woman", }; // // Construct array list. // // Construct ArrayList. arrList = new ArrayList((ICollection)strHeroes); //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of //BinarySearch, Following variable cotains each one of these types of array lists ArrayList[] arrayListTypes = { (ArrayList)arrList.Clone(), (ArrayList)ArrayList.Adapter(arrList).Clone(), (ArrayList)arrList.GetRange(0, arrList.Count).Clone(), (ArrayList)ArrayList.Synchronized(arrList).Clone() }; foreach (ArrayList arrayListType in arrayListTypes) { arrList = arrayListType; // // [] Remove objects from the ArrayList. // for (int ii = 0; ii < count; ++ii) { arrList.RemoveAt(start); } // Verify the items in the array. for (int ii = 0; ii < strResult.Length; ++ii) { Assert.Equal(0, strResult[ii].CompareTo((string)arrList[ii])); } // // [] Attempt invalid remove using negative index // Assert.Throws <ArgumentOutOfRangeException>(() => arrList.RemoveAt(-100)); // // [] Attempt remove using out of range index // Assert.Throws <ArgumentOutOfRangeException>(() => arrList.RemoveAt(1000)); } }
// Sorts an IList<T> in place. public static void Sort <T>(this IList <T> list, IComparer <T> comparer) { ArrayList.Adapter((IList)list).Sort(new ComparerComparer <T>(comparer)); }
/// <summary> /// Generates an Assembly from a list of script filenames /// </summary> /// <param name="filenames">The filenames of the scripts</param> /// <param name="references">Assembly references for the script</param> /// <returns>The generated assembly</returns>C public Assembly CreateAssembly(IList filenames, IList references) { string fileType = null; foreach (var extension in filenames.Cast <string>().Select(Path.GetExtension)) { if (fileType == null) { fileType = extension; } else if (fileType != extension) { throw new ArgumentException("All files in the file list must be of the same type."); } } // ensure that compilerErrors is null compilerErrors = null; // Select the correct CodeDomProvider based on script file extension CodeDomProvider codeProvider; switch (fileType) { case ".cs": codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); break; case ".vb": codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); break; case ".js": codeProvider = new Microsoft.JScript.JScriptCodeProvider(); break; default: throw new InvalidOperationException("Script files must have a .cs, .vb, or .js extension, for C#, Visual Basic.NET, or JScript respectively."); } // Set compiler parameters var compilerParams = new CompilerParameters { CompilerOptions = "/target:library /optimize", GenerateExecutable = false, GenerateInMemory = true, IncludeDebugInformation = false }; compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); compilerParams.ReferencedAssemblies.Add("System.dll"); // Add custom references foreach (string reference in references.Cast <string>().Where(reference => !compilerParams.ReferencedAssemblies.Contains(reference))) { compilerParams.ReferencedAssemblies.Add(reference); } // Do the compilation CompilerResults results = codeProvider.CompileAssemblyFromFile(compilerParams, (string[])ArrayList.Adapter(filenames).ToArray(typeof(string))); // Do we have any compiler errors if (results.Errors.Count > 0) { compilerErrors = results.Errors; throw new Exception( "Compiler error(s) encountered and saved to AssemblyFactory.CompilerErrors"); } Assembly createdAssembly = results.CompiledAssembly; return(createdAssembly); }
protected override bool StartTest() { logger.FlushLogBuffer(); logoStr = ""; if (AnalysisInputParameters(inputParameters) == false) { logger.FlushLogBuffer(); return(false); } if (selectedEquipList["DUT"] != null && selectedEquipList["ATTEN"] != null && selectedEquipList["POWERSUPPLY"] != null) { Powersupply tempps = (Powersupply)selectedEquipList["POWERSUPPLY"]; Attennuator tempAtten = (Attennuator)selectedEquipList["ATTEN"]; // open apc string apcstring = null; dut.APCStatus(out apcstring); if (apcstring == "OFF" || apcstring == "FF") { logoStr += logger.AdapterLogString(0, "Step2...Start Open apc"); dut.APCON(); logoStr += logger.AdapterLogString(0, "Power off"); tempps.Switch(false); Thread.Sleep(200); logoStr += logger.AdapterLogString(0, "Power on"); tempps.Switch(true); Thread.Sleep(500); bool isOpen = dut.APCStatus(out apcstring); if (apcstring == "ON") { logoStr += logger.AdapterLogString(1, "APC ON"); } else { logoStr += logger.AdapterLogString(3, "APC NOT ON"); } } // open apc logoStr += logger.AdapterLogString(0, "Step3...Start Test RxDmi"); double[] tempRxPowerDmiArray = new double[testRxPowerDmiStruct.ArrayListRxInputPower.Count]; double[] tempRxPowerErrArray = new double[testRxPowerDmiStruct.ArrayListRxInputPower.Count]; for (byte i = 0; i < testRxPowerDmiStruct.ArrayListRxInputPower.Count; i++) { tempAtten.AttnValue(testRxPowerDmiStruct.ArrayListRxInputPower[i].ToString()); Thread.Sleep(1000); tempRxPowerDmiArray[i] = dut.ReadDmiRxp(); tempRxPowerErrArray[i] = Math.Abs(Convert.ToDouble(testRxPowerDmiStruct.ArrayListRxInputPower[i].ToString()) - tempRxPowerDmiArray[i]); logoStr += logger.AdapterLogString(1, "testRxPowerDmiStruct.ArrayListRxInputPower[" + i.ToString() + "]:" + testRxPowerDmiStruct.ArrayListRxInputPower[i].ToString() + "tempRxPowerDmiArray[" + i.ToString() + "]:" + tempRxPowerDmiArray[i].ToString() + "tempRxPowerErrArray[" + i.ToString() + "]" + tempRxPowerErrArray[i].ToString()); } byte maxIndex; MaxErr = algorithm.SelectMaxValue(ArrayList.Adapter(tempRxPowerErrArray), out maxIndex); ErrMaxPoint = Convert.ToDouble(testRxPowerDmiStruct.ArrayListRxInputPower[maxIndex].ToString()); logoStr += logger.AdapterLogString(1, "ErrMaxPoint=" + ErrMaxPoint.ToString() + " MaxErr" + MaxErr.ToString()); AnalysisOutputParameters(outputParameters); logger.FlushLogBuffer(); return(true); } else { logoStr += logger.AdapterLogString(4, "Equipments is not enough!"); logger.FlushLogBuffer(); return(false); } }
protected override IList NonGenericIListFactory(int count) => ArrayList.Adapter(Helpers.CreateIntArrayList(count));
public int GetEvaluatedArguments(IokeObject context, IokeObject message, object on, IList argumentsWithoutKeywords, IDictionary <string, object> givenKeywords) { Runtime runtime = context.runtime; IList arguments = message.Arguments; int argCount = 0; foreach (object o in arguments) { if (Message.IsKeyword(o)) { givenKeywords[IokeObject.As(o, context).Name] = Interpreter.GetEvaluatedArgument(((Message)IokeObject.dataOf(o)).next, context); } else if (Message.HasName(o, "*") && IokeObject.As(o, context).Arguments.Count == 1) // Splat { object result = Interpreter.GetEvaluatedArgument(IokeObject.As(o, context).Arguments[0], context); if (IokeObject.dataOf(result) is IokeList) { IList elements = IokeList.GetList(result); foreach (object ox in elements) { argumentsWithoutKeywords.Add(ox); } argCount += elements.Count; } else if (IokeObject.dataOf(result) is Dict) { IDictionary keys = Dict.GetMap(result); foreach (DictionaryEntry me in keys) { givenKeywords[Text.GetText(IokeObject.ConvertToText(me.Key, message, context, true)) + ":"] = me.Value; } } else if (IokeObject.FindCell((IokeObject)result, "asTuple") != runtime.nul) { object tupledValue = Interpreter.Send(runtime.asTuple, context, result); object[] values = Tuple.GetElements(tupledValue); foreach (object val in values) { argumentsWithoutKeywords.Add(val); } argCount += values.Length; } else { IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition, message, context, "Error", "Invocation", "NotSpreadable"), context).Mimic(message, context); condition.SetCell("message", message); condition.SetCell("context", context); condition.SetCell("receiver", on); condition.SetCell("given", result); IList outp = IokeList.GetList(runtime.WithRestartReturningArguments(() => { runtime.ErrorCondition(condition); }, context, new Restart.DefaultValuesGivingRestart("ignoreArgument", runtime.nil, 0), new Restart.DefaultValuesGivingRestart("takeArgumentAsIs", IokeObject.As(result, context), 1) )); foreach (object ox in outp) { argumentsWithoutKeywords.Add(ox); } argCount += outp.Count; } } else { var xx = Interpreter.GetEvaluatedArgument(o, context); argumentsWithoutKeywords.Add(xx); argCount++; } } while (argCount < min || (max != -1 && argCount > max)) { int finalArgCount = argCount; if (argCount < min) { IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition, message, context, "Error", "Invocation", "TooFewArguments"), context).Mimic(message, context); condition.SetCell("message", message); condition.SetCell("context", context); condition.SetCell("receiver", on); condition.SetCell("missing", runtime.NewNumber(min - argCount)); IList newArguments = IokeList.GetList(runtime.WithRestartReturningArguments(() => { runtime.ErrorCondition(condition); }, context, new NewArgumentGivingRestart("provideExtraArguments"), new Restart.DefaultValuesGivingRestart("substituteNilArguments", runtime.nil, min - argCount))); foreach (object ox in newArguments) { argumentsWithoutKeywords.Add(ox); } argCount += newArguments.Count; } else { IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition, message, context, "Error", "Invocation", "TooManyArguments"), context).Mimic(message, context); condition.SetCell("message", message); condition.SetCell("context", context); condition.SetCell("receiver", on); condition.SetCell("extra", runtime.NewList(ArrayList.Adapter(argumentsWithoutKeywords).GetRange(max, finalArgCount - max))); runtime.WithReturningRestart("ignoreExtraArguments", context, () => { runtime.ErrorCondition(condition); }); argCount = max; } } var intersection = new SaneHashSet <string>(givenKeywords.Keys); foreach (string k in keywords) { intersection.Remove(k); } if (krest == null && intersection.Count > 0) { IokeObject condition = IokeObject.As(IokeObject.GetCellChain(runtime.Condition, message, context, "Error", "Invocation", "MismatchedKeywords"), context).Mimic(message, context); condition.SetCell("message", message); condition.SetCell("context", context); condition.SetCell("receiver", on); IList expected = new SaneArrayList(); foreach (string s in keywords) { expected.Add(runtime.NewText(s)); } condition.SetCell("expected", runtime.NewList(expected)); IList extra = new SaneArrayList(); foreach (string s in intersection) { extra.Add(runtime.NewText(s)); } condition.SetCell("extra", runtime.NewList(extra)); runtime.WithReturningRestart("ignoreExtraKeywords", context, () => { runtime.ErrorCondition(condition); }); } return(argCount); }
protected bool CurveVccDMIandWriteCoefs() { byte tempCOUNT; if (GlobalParameters.TotalVccCount <= 0) { tempCOUNT = 1; } else { tempCOUNT = GlobalParameters.TotalVccCount; } try { { for (byte i = 0; i < tempVccArray.Length; i++) { tempVccArray[i] = tempVccArray[i] * 10000; } for (byte i = 0; i < tempCOUNT; i++) { double[] tempAdc = new double[calVccDmiStruct.ArrayListVcc.Count]; for (byte j = 0; j < calVccDmiStruct.ArrayListVcc.Count; j++) { tempAdc[j] = vccAdcArray[i, j]; allVccAdcArray.Add(vccAdcArray[i, j]); } double[] coefArray = Algorithm.MultiLine(tempAdc, tempVccArray, calVccDmiStruct.ArrayListVcc.Count, 1); vccDmiCoefC = (float)coefArray[0]; vccDmiCoefB = (float)coefArray[1]; //vccDmiCoefA = (float)coefArray[2]; vccDmiCoefArray = ArrayList.Adapter(coefArray); vccDmiCoefArray.Reverse(); for (byte k = 0; k < vccDmiCoefArray.Count; k++) { Log.SaveLogToTxt("vccDmiCoefArray[" + k.ToString() + "]=" + vccDmiCoefArray[k].ToString() + " " + Algorithm.ByteArraytoString(2, ",", Algorithm.INT16To2Bytes(vccDmiCoefArray[k]))); } Log.SaveLogToTxt("Step4...WriteCoef"); #region W&R Vcccoefc isWriteCoefCOk = dut.SetVcccoefc(vccDmiCoefC.ToString(), (byte)(i + 1)); if (isWriteCoefCOk) { Log.SaveLogToTxt("WritevccDmiCoefC:" + isWriteCoefCOk.ToString()); } else { Log.SaveLogToTxt("WritevccDmiCoefC:" + isWriteCoefCOk.ToString()); } #endregion #region W&R Vcccoefb isWriteCoefBOk = dut.SetVcccoefb(vccDmiCoefB.ToString(), (byte)(i + 1)); if (isWriteCoefBOk) { Log.SaveLogToTxt("WritevccDmiCoefB:" + isWriteCoefBOk.ToString()); } else { Log.SaveLogToTxt("WritevccDmiCoefB:" + isWriteCoefBOk.ToString()); } #endregion //#region W&R Vcccoefa ////isWriteCoefAOk = dut.SetVcccoefa(vccDmiCoefA.ToString(), i + 1); //if (isWriteCoefAOk) //{ // isWriteCoefAOk = true; // Log.SaveLogToTxt("WritevccDmiCoefA:" + isWriteCoefAOk.ToString()); //} //else //{ // Log.SaveLogToTxt("WritevccDmiCoefA:" + isWriteCoefAOk.ToString()); //} //#endregion if (isWriteCoefBOk & isWriteCoefCOk) { Log.SaveLogToTxt("isCalVccDmiOk:" + true.ToString()); } else { Log.SaveLogToTxt("isCalVccDmiOk:" + false.ToString()); return(false); } } } return(true); } catch (InnoExCeption ex)//from driver { //Log.SaveLogToTxt(ex.ID + ": " + ex.Message + "\r\n" + ex.StackTrace); exceptionList.Add(ex); return(false); } catch (Exception error)//from itself { //one way: deal this exception itself InnoExCeption ex = new InnoExCeption(ExceptionDictionary.Code._0x02100, error.StackTrace); //Log.SaveLogToTxt(ex.ID + ": " + ex.Message + "\r\n" + ex.StackTrace); exceptionList.Add(ex); return(false); //the other way is: should throw exception, rather than the above three code. see below: //throw new InnoExCeption(ExceptionDictionary.Code._0x02100, error.StackTrace); } }
public Assembly CreateAssembly(IList filenames, IList references) { string fileType = null; foreach (string filename in filenames) { string extension = Path.GetExtension(filename); if (fileType == null) { fileType = extension; } else if (fileType != extension) { throw new ArgumentException("All files in the file list must be of the same type."); } } compilerErrors = null; CodeDomProvider codeProvider = null; switch (fileType) { case ".cs": codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); break; case ".vb": codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); break; default: throw new InvalidOperationException("Script files must have a .cs, .vb, or .js extension, for C#, Visual Basic.NET, or JScript respectively."); } CompilerParameters compilerParams = new CompilerParameters(); compilerParams.CompilerOptions = "/target:library /optimize"; compilerParams.GenerateExecutable = false; compilerParams.GenerateInMemory = true; compilerParams.IncludeDebugInformation = false; compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); compilerParams.ReferencedAssemblies.Add("System.dll"); foreach (string reference in references) { if (!compilerParams.ReferencedAssemblies.Contains(reference)) { compilerParams.ReferencedAssemblies.Add(reference); } } CompilerResults results = codeProvider.CompileAssemblyFromFile( compilerParams, (string[])ArrayList.Adapter(filenames).ToArray(typeof(string))); if (results.Errors.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (CompilerError item in results.Errors) { sb.AppendFormat("{0} line:{1} {2}\r\n", item.FileName, item.Line, item.ErrorText); } compilerErrors = results.Errors; throw new Exception( "Compiler error(s)\r\n" + sb.ToString()); } Assembly createdAssembly = results.CompiledAssembly; return(createdAssembly); }
public Boolean runTest() { int iCountErrors = 0; int iCountTestcases = 0; ArrayList lAdapter = null; IEnumerator ienumList = null; IEnumerator ienumWrap = null; Console.WriteLine(strName + ": " + strTest + " runTest started..."); Console.WriteLine("To run the test in verbose mode try /v"); if (strActiveBugs.Length != 0) { Console.WriteLine("ACTIVE BUGS " + strActiveBugs); } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] check for ArgumentNullException when argument null"); } try { lAdapter = ArrayList.Adapter(null); } catch (ArgumentNullException) {} catch (Exception ex) { Console.WriteLine("Err_001a, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] make sure changes Through listAdapter show up in list"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString() + " from before"); } lAdapter = ArrayList.Adapter(tempList); lAdapter.Reverse(0, lAdapter.Count); int j = 9; for (int i = 0; i < lAdapter.Count; i++) { if (!lAdapter[i].Equals(j.ToString() + " from before")) { Console.WriteLine("Err_002b, Element from listadapter '" + lAdapter[i] + "' should equal element from ilist '" + j.ToString() + " from before' but it does not"); ++iCountErrors; } j--; } } catch (Exception ex) { Console.WriteLine("Err_002a, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] make sure changes Through list show up in listAdapter"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString() + " from before"); } lAdapter = ArrayList.Adapter(tempList); tempList.Clear(); if (lAdapter.Count != 0) { Console.WriteLine("Err_003b, listadapter does not have changes made to templist should have count 0 but has count " + lAdapter.Count); } } catch (Exception ex) { Console.WriteLine("Err_003a, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] test to see if enumerators are correctly enumerate through elements"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString()); } ienumList = tempList.GetEnumerator(); lAdapter = ArrayList.Adapter(tempList); ienumWrap = tempList.GetEnumerator(); int j = 0; while (ienumList.MoveNext()) { if (!ienumList.Current.Equals(j.ToString())) { Console.WriteLine("Err_004a, enumerator on list expected to return " + j + " but returned " + ienumList.Current); ++iCountErrors; } j++; } j = 0; while (ienumWrap.MoveNext()) { if (!ienumWrap.Current.Equals(j.ToString())) { Console.WriteLine("Err_004b, enumerator on listadapter expected to return " + j + " but returned " + ienumWrap.Current); ++iCountErrors; } j++; } } catch (Exception ex) { Console.WriteLine("Err_004c, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] test to see if enumerators are correctly enumerate through elements"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString()); } ienumList = tempList.GetEnumerator(); lAdapter = ArrayList.Adapter(tempList); ienumWrap = tempList.GetEnumerator(); int j = 0; while (ienumList.MoveNext()) { if (!ienumList.Current.Equals(j.ToString())) { Console.WriteLine("Err_004a, enumerator on list expected to return " + j + " but returned " + ienumList.Current); ++iCountErrors; } j++; } j = 0; while (ienumWrap.MoveNext()) { if (!ienumWrap.Current.Equals(j.ToString())) { Console.WriteLine("Err_004b, enumerator on listadapter expected to return " + j + " but returned " + ienumWrap.Current); ++iCountErrors; } j++; } } catch (Exception ex) { Console.WriteLine("Err_004c, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] test to see if enumerators are correctly getting invalidated with list modified through list"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString()); } ienumList = tempList.GetEnumerator(); lAdapter = ArrayList.Adapter(tempList); ienumWrap = tempList.GetEnumerator(); ienumList.MoveNext(); ienumWrap.MoveNext(); tempList.Add("Hey this is new element"); try { ienumList.MoveNext(); Console.WriteLine("Err_006b, ienumList.MoveNext should have thrown since list was modified"); ++iCountErrors; } catch (InvalidOperationException) {} try { ienumWrap.MoveNext(); Console.WriteLine("Err_006c, ienumWrap.MoveNext should have thrown since list was modified"); ++iCountErrors; } catch (InvalidOperationException) {} } catch (Exception ex) { Console.WriteLine("Err_006c, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] test to see if enumerators are correctly getting invalidated with list modified through listAdapter"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString()); } ienumList = tempList.GetEnumerator(); lAdapter = ArrayList.Adapter(tempList); ienumWrap = tempList.GetEnumerator(); ienumList.MoveNext(); ienumWrap.MoveNext(); lAdapter.Add("Hey this is new element"); try { ienumList.MoveNext(); Console.WriteLine("Err_007b, ienumList.MoveNext should have thrown since list was modified"); ++iCountErrors; } catch (InvalidOperationException) {} try { ienumWrap.MoveNext(); Console.WriteLine("Err_007c, ienumWrap.MoveNext should have thrown since list was modified"); ++iCountErrors; } catch (InvalidOperationException) {} } catch (Exception ex) { Console.WriteLine("Err_007c, unexpected exception " + ex.ToString()); ++iCountErrors; } ++iCountTestcases; if (verbose) { Console.Error.WriteLine("[] to see if listadaptor modified using InsertRange works"); } try { ArrayList tempList = new ArrayList(); for (int i = 0; i < 10; i++) { tempList.Add(i.ToString()); } lAdapter = ArrayList.Adapter(tempList); ArrayList tempListSecond = new ArrayList(); for (int i = 10; i < 20; i++) { tempListSecond.Add(i.ToString()); } lAdapter.InsertRange(lAdapter.Count, tempListSecond); if (lAdapter.Count != 20) { Console.WriteLine("Err_008a, lAdapter should have had count 20 but had count " + lAdapter.Count); ++iCountErrors; } } catch (Exception ex) { Console.WriteLine("Err_008b, unexpected exception " + ex.ToString()); ++iCountErrors; } Console.Error.Write(strName); Console.Error.Write(": "); if (iCountErrors == 0) { Console.Error.WriteLine(strTest + " iCountTestcases==" + iCountTestcases.ToString() + " paSs"); return(true); } else { Console.WriteLine(strTest + " FAiL"); Console.Error.WriteLine(strTest + " iCountErrors==" + iCountErrors.ToString()); return(false); } }
public void Test02() { //-------------------------------------------------------------------------- // Variable definitions. //-------------------------------------------------------------------------- ArrayList arrList = null; string[] strHeroes = { "Aquaman", "Atom", "Batman", "Black Canary", "Captain America", "Captain Atom", "Catwoman", "Cyborg", "Flash", "Green Arrow", "Green Lantern", "Hawkman", "Huntress", "Ironman", "Nightwing", "Robin", "SpiderMan", "Steel", "Superman", "Thor", "Wildcat", "Wonder Woman", }; // // Construct array list. // arrList = new ArrayList((ICollection)strHeroes); //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of //BinarySearch, Following variable cotains each one of these types of array lists ArrayList[] arrayListTypes = { (ArrayList)arrList.Clone(), (ArrayList)ArrayList.Adapter(arrList).Clone(), (ArrayList)ArrayList.FixedSize(arrList).Clone(), (ArrayList)arrList.GetRange(0, arrList.Count).Clone(), (ArrayList)ArrayList.Synchronized(arrList).Clone() }; foreach (ArrayList arrayListType in arrayListTypes) { arrList = arrayListType; // // [] Reverse entire array list. // // Reverse entire array list. arrList.Reverse(); // Verify items have been reversed. for (int ii = 0; ii < arrList.Count; ++ii) { Assert.Equal(0, strHeroes[ii].CompareTo((String)arrList[arrList.Count - ii - 1])); } //[]Team review feedback - Reversing lists of varying sizes inclusing 0 arrList = new ArrayList(); arrList.Reverse(); arrList = new ArrayList(); for (int i = 0; i < 1; i++) { arrList.Add(i); } arrList.Reverse(); } }
public ActionResult UploadImage() { string savePath = "/swf/"; string saveUrl = "/swf/"; string fileTypes = "swf,flv,jpg,png,gif"; double maxSize = 50 * 1024 * 1024; //Convert.ToDouble(file.ContentLength) > Convert.ToDouble(ConfigInfo<UploadInfo>.Instance().UploadSize) * 1024 * 1024 Hashtable hash = new Hashtable(); HttpPostedFileBase file = Request.Files["imgFile"]; if (file == null) { hash = new Hashtable(); hash["error"] = 0; hash["url"] = "请选择文件"; return(Json(hash)); } string dirPath = Server.MapPath(savePath); if (!Directory.Exists(dirPath)) { hash = new Hashtable(); hash["error"] = 0; hash["url"] = "上传目录不存在"; return(Json(hash)); } string fileName = file.FileName; string fileExt = Path.GetExtension(fileName).ToLower(); ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(',')); if (file.InputStream == null || file.InputStream.Length > maxSize) { hash = new Hashtable(); hash["error"] = 0; hash["url"] = "上传文件大小超过限制"; return(Json(hash)); } if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1) { hash = new Hashtable(); hash["error"] = 0; hash["url"] = "上传文件扩展名是不允许的扩展名"; return(Json(hash)); } string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; string filePath = dirPath + newFileName; file.SaveAs(filePath); string fileUrl = saveUrl + newFileName; //fileUrl = DealMvc.Common.Globals.UpFileZY(fileUrl); hash = new Hashtable(); hash["error"] = 0; hash["url"] = fileUrl; return(Json(hash, "text/html;charset=UTF-8"));; }
// Sorts an IList<T> in place. internal static void Sort <T>(this IList <T> list, Comparison <T> comparison) { ArrayList.Adapter((IList)list).Sort(new ComparisonComparer <T>(comparison)); }
public void TestArrayListWrappers() { //-------------------------------------------------------------------------- // Variable definitions. //-------------------------------------------------------------------------- ArrayList arrList = null; String[] arrCopy = null; arrList = new ArrayList(strHeroes); //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of //BinarySearch, Following variable cotains each one of these types of array lists ArrayList[] arrayListTypes = { (ArrayList)arrList.Clone(), (ArrayList)ArrayList.Adapter(arrList).Clone(), (ArrayList)arrList.GetRange(0, arrList.Count).Clone(), (ArrayList)ArrayList.Synchronized(arrList).Clone() }; foreach (ArrayList arrayListType in arrayListTypes) { arrList = arrayListType; // // [] CopyTo an array normal // arrCopy = new String[strHeroes.Length]; arrList.CopyTo(arrCopy, 0); for (int i = 0; i < arrCopy.Length; i++) { Assert.Equal <string>(strHeroes[i], arrCopy[i]); } //[] Normal Copy Test 2 - copy 0 elements arrList.Clear(); arrList.Add(null); arrList.Add(arrList); arrList.Add(null); arrList.Remove(null); arrList.Remove(null); arrList.Remove(arrList); Assert.Equal(0, arrList.Count); arrCopy = new String[strHeroes.Length]; // put some elements in arrCopy that should not be overriden for (int i = 0; i < strHeroes.Length; i++) { arrCopy[i] = strHeroes[i]; } //copying 0 elements into arrCopy arrList.CopyTo(arrCopy, 1); // check to make sure sentinals stay the same for (int i = 0; i < arrCopy.Length; i++) { Assert.Equal <string>(strHeroes[i], arrCopy[i]); } //[] Normal Copy Test 3 - copy 0 elements from the end arrList.Clear(); Assert.Equal(0, arrList.Count); arrCopy = new String[strHeroes.Length]; // put some elements in arrCopy that should not be overriden for (int i = 0; i < strHeroes.Length; i++) { arrCopy[i] = strHeroes[i]; } //copying 0 elements into arrCopy, into last valid index of arrCopy arrList.CopyTo(arrCopy, arrCopy.Length - 1); // check to make sure sentinals stay the same for (int i = 0; i < arrCopy.Length; i++) { Assert.Equal <string>(strHeroes[i], arrCopy[i]); } //[] Copy so that exception should be thrown arrList.Clear(); arrCopy = new String[2]; //copying 0 elements into arrCopy arrList.CopyTo(arrCopy, arrCopy.Length); // [] Copy so that exception should be thrown 2 arrList.Clear(); Assert.Equal(0, arrList.Count); arrCopy = new String[0]; //copying 0 elements into arrCopy arrList.CopyTo(arrCopy, 0); // [] CopyTo with negative index Assert.Throws <ArgumentOutOfRangeException>(() => arrList.CopyTo(arrCopy, -1)); // [] CopyTo with array with index is not large enough Assert.Throws <ArgumentException>(() => { arrList.Clear(); for (int i = 0; i < 10; i++) { arrList.Add(i); } arrList.CopyTo(new Object[11], 2); }); // [] CopyTo with null array Assert.Throws <ArgumentNullException>(() => arrList.CopyTo(null, 0)); // [] CopyTo with multidimentional array Assert.Throws <ArgumentException>(() => arrList.CopyTo(new Object[10, 10], 1)); } }
private void InitializeEvent() { //绑定风格选择框 cb_themeStyle.Items.AddRange(ArrayList.Adapter(Enum.GetValues(typeof(eStyle))).ToArray()); cb_themeStyle.SelectedIndexChanged += (sender, e) => { var theme = (eStyle)cb_themeStyle.SelectedItem; styleManager1.ManagerStyle = theme; }; //绑定右键菜单 contextMenuBar.SetContextMenuEx(lv_stockInfo, bi_stockList_right); //右键上下文菜单事件 rightContext_btnInsert.Click += (sender, e) => { bar2.Hide(); bar2.Show(); }; rightContext_btnDelete.Click += (sender, e) => { foreach (ListViewItem selectedItem in lv_stockInfo.SelectedItems) { var stockInfo = selectedItem.Tag as StockInfo; if (stockInfo != null) { _stockService.RemoveStockInfo(stockInfo.StockId); } } InitStockData(); }; rightContext_btnOpenSina.Click += (sender, e) => { foreach (ListViewItem selectedItem in lv_stockInfo.SelectedItems) { var stockInfo = selectedItem.Tag as StockInfo; if (stockInfo != null) { Process.Start(string.Format("http://finance.sina.com.cn/realstock/company/{0}/nc.shtml", stockInfo.StockId)); } } }; int inputVersion = 1; //智能补全 tb_stockId.KeyUp += (sender, e) => { int currentVersion = Interlocked.Increment(ref inputVersion); var control = tb_stockId; string input = control.Text.Trim(); Task.Factory.StartNew(() => { var dataList = _stockService.Suggest(input); if (currentVersion == inputVersion) { control.Invoke(new Action(() => { control.DataSource = dataList; })); } }); }; tb_stockId.AutoCompeleControl.Click += (sender, e) => { var item = tb_stockId.AutoCompeleControl.SelectedItems[0]; if (item != null) { var suggestInfo = item.Tag as SuggestInfo; if (suggestInfo != null) { tb_stockId.Text = suggestInfo.StockCode; } } }; //绑定显示列 var attributes = _configInfo.ShowHeaderSetting; lb_property.DataSource = attributes; lb_property.DisplayMember = "Description"; lb_property.CheckStateMember = "IsShow"; lb_property.ValueMember = "IsShow"; lb_property.SelectedIndexChanged += (sender, e) => { if (lb_property.SelectedIndex > 0) { lb_property.SetItemCheckState(lb_property.SelectedIndex, CheckState.Checked); } }; lb_property.ItemCheck += (sender, e) => { var attr = ((ShowDescriptionEntity)((ItemBindingData)e.Item.Tag).DataItem); attr.IsShow = e.Item.CheckState == CheckState.Checked; InitStockData(); }; //插入新股票 Action <object, EventArgs> action = (sender, e) => { var selectedItems = tb_stockId.AutoCompeleControl.SelectedItems; if (selectedItems.Count <= 0 && tb_stockId.AutoCompeleControl.Items.Count > 0) { tb_stockId.AutoCompeleControl.Items[0].Selected = true; } if (selectedItems != null && selectedItems.Count == 1) { var suggestInfo = (SuggestInfo)selectedItems[0].Tag; _stockService.InsertStockInfo(new StockEntity() { StockId = suggestInfo.StockId }); InitStockData(); } }; btn_insertStock.Click += new EventHandler(action); tb_stockId.AutoCompeleControl.DoubleClick += new EventHandler(action); //退出时保存设置 this.Closed += (sender, e) => _stockService.SaveConfigEntity(_configInfo); }
public void TestCopyToWithCount() { //-------------------------------------------------------------------------- // Variable definitions. //-------------------------------------------------------------------------- ArrayList arrList = null; string[] arrCopy = null; string[] strHeroes = { "Aquaman", "Atom", "Batman", "Black Canary", "Captain America", "Captain Atom", "Catwoman", "Cyborg", "Flash", "Green Arrow", "Green Lantern", "Hawkman", "Huntress", "Ironman", "Nightwing", "Robin", "SpiderMan", "Steel", "Superman", "Thor", "Wildcat", "Wonder Woman", }; // // Construct array list. // arrList = new ArrayList(); Assert.NotNull(arrList); // Add items to the lists. for (int ii = 0; ii < strHeroes.Length; ++ii) { arrList.Add(strHeroes[ii]); } // Verify items added to list. Assert.Equal(strHeroes.Length, arrList.Count); //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of //BinarySearch, Following variable cotains each one of these types of array lists ArrayList[] arrayListTypes = { arrList, ArrayList.Adapter(arrList), ArrayList.FixedSize(arrList), arrList.GetRange(0, arrList.Count), ArrayList.ReadOnly(arrList), ArrayList.Synchronized(arrList) }; foreach (ArrayList arrayListType in arrayListTypes) { arrList = arrayListType; // // [] Use CopyTo copy range of items to array. // int start = 3; int count = 15; // Allocate sting array. arrCopy = new String[100]; // Obtain string from ArrayList. arrList.CopyTo(start, arrCopy, start, count); // Verify the items in the array. for (int ii = start; ii < start + count; ++ii) { Assert.Equal(0, ((String)arrList[ii]).CompareTo(arrCopy[ii])); } // // [] Invalid Arguments // // 2nd throw ArgumentOutOfRangeException // rest throw ArgumentException Assert.ThrowsAny <ArgumentException>(() => arrList.CopyTo(0, arrCopy, -100, 1000)); Assert.Throws <ArgumentOutOfRangeException>(() => arrList.CopyTo(-1, arrCopy, 0, 1)); Assert.Throws <ArgumentOutOfRangeException>(() => arrList.CopyTo(0, arrCopy, 0, -1)); // this is valid now arrCopy = new String[100]; arrList.CopyTo(arrList.Count, arrCopy, 0, 0); Assert.Throws <ArgumentException>(() => { arrCopy = new String[100]; arrList.CopyTo(arrList.Count - 1, arrCopy, 0, 24); }); Assert.Throws <ArgumentNullException>(() => arrList.CopyTo(0, null, 3, 15)); Assert.Throws <ArgumentException>(() => { arrCopy = new String[1]; arrList.CopyTo(0, arrCopy, 3, 15); }); Assert.Throws <ArgumentException>(() => arrList.CopyTo(0, new Object[arrList.Count, arrList.Count], 0, arrList.Count)); // same as above, some iteration throws different exceptions: ArgumentOutOfRangeException Assert.ThrowsAny <ArgumentException>(() => arrList.CopyTo(0, new Object[arrList.Count, arrList.Count], 0, -1)); } }