private static Dictionary<DateTime, String> LoadEvents(String filePath) { List<String> activities = new List<String>(); List<DateTime> timestamps = new List<DateTime>(); Dictionary<DateTime, String> events = new Dictionary<DateTime, String>(); int k = 0; foreach (String line in File.ReadAllLines(filePath)) { string[] tokens = line.Split(new char[] { ';' }); Console.WriteLine("Line " + k); timestamps.Add(DateTime.Parse(tokens[0])); activities.Add(tokens[1]); events.Add(DateTime.Parse(tokens[0]), tokens[1]); Console.WriteLine("Timestamp per line " + DateTime.Parse(tokens[0]) + " Activity = " + tokens[1]); k++; } var tsArray = timestamps.ToArray(); var actArray = activities.ToArray(); Console.WriteLine("tsArray length " + tsArray.Length + ", actArray length " + actArray.Length); for (int j = 0; j < tsArray.Length; j++) { Console.WriteLine("tsArray[" + j + "] = " + tsArray[j].ToString() + " -- actArray[" + j + "] = " + actArray[j].ToString()); } SimulateReadingFile(events); return events; }
// Constructor(s) public Weapon() : base() { this.Damage = Globals.Randomizer.Next(10, 20); this.ShieldPiercing = (float)Math.Round(Globals.Randomizer.NextDouble(), 2); this.Chance = Globals.Randomizer.Next(20, 30); this.Depth = 0.5f; this.Texture = TextureManager.weapons[Globals.Randomizer.Next(0, TextureManager.weapons.Count)]; ShootMethods = new List<Shoot>(); ShootMethods.Add(FireStandard); ShootMethods.Add(FireAiming); ShootMethods.Add(FireCrit); ShootMethods.Add(FireDelayEnemyShot); ShootMethods.Add(FireDamageOverTime); ShootMethods.Add(FireChanceToMiss); Action = Globals.Randomizer.Next(0, ShootMethods.Count); // Initialize weapon ShootMethods[Action](Position, Direction, 0, null, true); Targets = new List<string>(); // Description LoadDescription(); }
private static Thickness ConvertFromString(string s) { var parts = s.Split(',') .Take(4) .Select(part => part.Trim()); if (parts.Count() == 1) { var uniformLength = double.Parse(parts.First()); return new Thickness(uniformLength); } double left = 0, top = 0, right = 0, bottom = 0; IList<Action<double>> setValue = new List<Action<double>> { val => left = val, val => top = val, val => right = val, val => bottom = val, }; var i = 0; foreach (var part in parts) { var v = double.Parse(part); setValue[i](v); i++; } return new Thickness(left, top, right, bottom); }
static void Main() { List<MethodInvoker> list = new List<MethodInvoker>(); for (int index = 0; index < 5; index++) { int counter = index * 10; list.Add(delegate { Console.WriteLine(counter); counter++; }); } foreach (MethodInvoker t in list) { t(); } list[0](); list[0](); list[0](); list[1](); }
public void Create(object self, List<Func<object, IFilter>> creators) { _filters = new IFilter[creators.Count]; for (var i = 0; i < creators.Count; i++) { _filters[i] = creators[i](self); } }
private static void Main(string[] args) { var contents = new List<Func<int>>(); for (var i = 4; i < 7; i++) { int j = i; contents.Add(() => j); } for (var k = 0; k < contents.Count; k++) Console.WriteLine(contents[k]()); }
static void Main() { var methods = new List<Action>(); foreach (var word in new string[] { "hello", "world" }) { methods.Add(() => Console.Write(word + " ")); } methods[0](); methods[1](); }
static IEnumerable<int> Test_2 () { List<Func<int>> lambdas = new List<Func<int>> (); for (int i = 0; i < 4; ++i) { int h = i; lambdas.Add (() => h); } for (int i = 0; i < 4; ++i) { yield return lambdas[i] (); } }
private static void Main(string[] args) { var contents = new List<Func<int>>(); var s = new StringBuilder(); for (var i = 4; i < 7; i++) { var j = i; contents.Add(() => j); } for (var k = 0; k < contents.Count; k++) s.Append(contents[k]()); Console.WriteLine(s); }
static void Main() { var items = new string[] {"Moe", "Larry", "Curly"}; var actions = new List<Action>{}; int i; for(i=0;i<items.Length;i++) //foreach (string item in items) { actions.Add(()=>{ Console.WriteLine(items[i]);}); } for (i=0;i<items.Length;i++) { actions[i](); } }
static void LawOfClosures() { var DelayedActions = new List<Func<int>>(); var s = ""; for (var i = 4; i < 7; i++) { DelayedActions.Add(() => i); } for (var k = 0; k < DelayedActions.Count; k++) s += DelayedActions[k](); Console.WriteLine(s); }
public static void Main() { var actions = new List<Action>(); var sb = new StringBuilder(); for (int i = 0; i < 5; i++) { int i2 = i; actions.Add(() => sb.AppendLine(i2.ToString())); } for (int i = 0; i < actions.Count; i++) actions[i](); Console.WriteLine(sb.ToString()); }
public static string[] Split(string str, char[] separators, int maxComponents, StringSplitOptions options) { ContractUtils.RequiresNotNull(str, "str"); #if SILVERLIGHT || WP75 if (separators == null) return SplitOnWhiteSpace(str, maxComponents, options); bool keep_empty = (options & StringSplitOptions.RemoveEmptyEntries) != StringSplitOptions.RemoveEmptyEntries; List<string> result = new List<string>(maxComponents == Int32.MaxValue ? 1 : maxComponents + 1); int i = 0; int next; while (maxComponents > 1 && i < str.Length && (next = str.IndexOfAny(separators, i)) != -1) { if (next > i || keep_empty) { result.Add(str.Substring(i, next - i)); maxComponents--; } i = next + 1; } if (i < str.Length || keep_empty) { result.Add(str.Substring(i)); } return result.ToArray(); #else return str.Split(separators, maxComponents, options); #endif }
public bool Execute(List<Vehicle> vehicles) { try { foreach (var vehicle in vehicles) { var vehicleEntity = _db.Vehicle.Find(vehicle.Id); if (vehicleEntity != null) { vehicleEntity.Id = vehicle.Id; vehicleEntity.BookingId = vehicle.BookingId; vehicleEntity.VehicleType = vehicle.VehicleType; vehicleEntity.TrailerType = vehicle.TrailerType; _db.MarkVehicleAsModified(vehicleEntity); _db.SaveChanges(); } } } catch (Exception e) { return false; } return true; }
public virtual IList<ItemToolboxNode> Load (LoaderContext ctx, string filename) { SystemPackage sp = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetPackageFromPath (filename); ReferenceType rt; string rname; if (sp != null) { rt = ReferenceType.Package; rname = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyFullName (filename, null); } else { rt = ReferenceType.Assembly; rname = filename; } List<ItemToolboxNode> list = new List<ItemToolboxNode> (); var types = Runtime.RunInMainThread (delegate { // Stetic is not thread safe, it has to be used from the gui thread return GuiBuilderService.SteticApp.GetComponentTypes (filename); }).Result; foreach (ComponentType ct in types) { if (ct.Category == "window") continue; ComponentToolboxNode cn = new ComponentToolboxNode (ct); cn.ReferenceType = rt; cn.Reference = rname; list.Add (cn); } return list; }
static void Main2(string[] args) { var numReal = new List<double>(80); Random gerador = new Random(); double maior = 0; double menor = 0; double soma = 0; double media = 0; for (int i = 0; i < 80; i++) { numReal.Add(gerador.NextDouble()); if (i == 0) { maior = numReal[i]; menor = numReal[i]; } soma += numReal[i]; } media = soma / 80; for (int i = 0; i < 80; i++) { maior = (numReal[i] > maior) ? numReal[i] : maior; menor = (numReal[i] < menor) ? numReal[i] : menor; } Console.WriteLine("Maior: {0:F2}", maior); Console.WriteLine("Menor: {0:F2}", menor); Console.WriteLine("Soma: {0:F2}", soma); Console.WriteLine("Media: {0:F2}", media); Console.ReadKey(); }
public static List<ProjectItem> GetPendingChanges() { var projectItems = new List<ProjectItem>(); var dte = (DTE)Package.GetGlobalService(typeof(SDTE)); var projectCollections = new List<RegisteredProjectCollection>(RegisteredTfsConnections.GetProjectCollections()); foreach (var registeredProjectCollection in projectCollections) { var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(registeredProjectCollection); var versionControl = projectCollection.GetService<VersionControlServer>(); var workspace = versionControl.GetWorkspace(dte.Solution.FileName); foreach (var pendingChange in workspace.GetPendingChangesEnumerable()) { if (pendingChange.FileName != null && (pendingChange.FileName.EndsWith(".cs") || pendingChange.FileName.EndsWith(".config"))) { var projectItem = dte.Solution.FindProjectItem(pendingChange.FileName); if (projectItem != null) { projectItems.Add(projectItem); } } } } return projectItems; }
/// <summary> /// get nesting of circles within given dimensions /// </summary> /// <param name="circles">input planar surfaces to be cut</param> /// <param name="spacing">spacing between input result</param> /// <param name="width">width of sheet</param> /// <param name="length">length of sheet</param> internal Nesting(List<PolyCurve> polycurves, double spacing, double width, double length) { Width = width; Length = length; Spacing = spacing; ListPolyCurve = TileVertical(MapToXYPlane(polycurves), spacing); }
static void Main(string[] args) { List<ulong> testIntegers = new List<ulong>() { 117, 0, 1, 4, 69, 642, 932, 6903, 69382, 504967, 4028492, 902409102, 1403102045, ulong.MaxValue }; ConsoleTests(testIntegers); UnicodeTests(testIntegers); }
protected void Initialize() { Instance.PropertyChanged += Instance_PropertyChanged; PropertyInfo[] propertyInfos = Instance.GetType().GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { // Inspect each INotifyPropertyChanged if (propertyInfo.PropertyType.GetInterfaces().Contains(typeof(INotifyPropertyChanged))) { INotifyPropertyChanged propertyValue = propertyInfo.GetValue(Instance) as INotifyPropertyChanged; if (propertyValue != null) { propertyValues.Add(propertyInfo.Name, propertyValue); propertyValue.PropertyChanged += PropertyValue_PropertyChanged; } } // Inspect each DependsOn attribute DependsOnAttribute dependsOnAttribute = propertyInfo.GetCustomAttribute<DependsOnAttribute>(); if (dependsOnAttribute != null) { foreach (string property in dependsOnAttribute.Properties) { List<PropertyInfo> dependencies; if (!propertyDependencies.TryGetValue(property, out dependencies)) propertyDependencies.Add(property, dependencies = new List<PropertyInfo>()); if (!dependencies.Contains(propertyInfo)) dependencies.Add(propertyInfo); } } } }
public MainPage() { this.InitializeComponent(); placeList = new List<Place>(); getCurrentPosition(); TravelMap.GotFocus += TravelMap_Tapped; }
public Dir(string key, string name) { this.key = key; this.name = name; sub_dirs = new List<Dir>(); values = new List<Val>(); }
/// <summary> /// 获得数据列表 /// </summary> public List<HisClient.Model.his_pm_import> DataTableToList(DataTable dt) { List<HisClient.Model.his_pm_import> modelList = new List<HisClient.Model.his_pm_import>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { HisClient.Model.his_pm_import model; for (int n = 0; n < rowsCount; n++) { model = new HisClient.Model.his_pm_import(); model.ID= dt.Rows[n]["ID"].ToString(); model.SEND_DEPT_CODE= dt.Rows[n]["SEND_DEPT_CODE"].ToString(); model.RECEIVE_DEPT_CODE= dt.Rows[n]["RECEIVE_DEPT_CODE"].ToString(); model.PAKAGE_OUT_CODE= dt.Rows[n]["PAKAGE_OUT_CODE"].ToString(); model.CREATE_BY= dt.Rows[n]["CREATE_BY"].ToString(); if(dt.Rows[n]["CREATE_DATE"].ToString()!="") { model.CREATE_DATE=DateTime.Parse(dt.Rows[n]["CREATE_DATE"].ToString()); } model.IMPORT_CODE= dt.Rows[n]["IMPORT_CODE"].ToString(); modelList.Add(model); } } return modelList; }
public IEnumerable<int> GetEnqueuedJobIds(string queue, int @from, int perPage) { var result = new List<int>(); using (var messageQueue = new MessageQueue(String.Format(_pathPattern, queue))) { var current = 0; var end = @from + perPage; var enumerator = messageQueue.GetMessageEnumerator2(); var formatter = new BinaryMessageFormatter(); while (enumerator.MoveNext()) { if (current >= @from && current < end) { var message = enumerator.Current; message.Formatter = formatter; result.Add(int.Parse((string)message.Body)); } if (current >= end) break; current++; } } return result; }
void Init(String domainName, String connStringName, Boolean pSecure, bool chekControllers) { //_LdapWrapper = new LdapWrapper(); //LoadControllersFromDatabase( pConnString); _DomainUrlInfo = DomainsUrl_Get_FromSp(connStringName, domainName);// _DomainUrlInfoList.First<DomainUrlInfo>(p => p.DomainName == domainName); if (_DomainUrlInfo == null) { throw new Fwk.Exceptions.TechnicalException("No se encontró la información del dominio especificado"); } if (chekControllers) { _DomainControllers = GetDomainControllersByDomainId(System.Configuration.ConfigurationManager.ConnectionStrings[connStringName].ConnectionString, _DomainUrlInfo.Id); if (_DomainControllers == null || _DomainControllers.Count == 0) throw new Fwk.Exceptions.TechnicalException("No se encuentra configurado ningún controlador de dominio para el sitio especificado."); // Prueba de conectarse a algún controlador de dominio disponible, siempre arranando del primero. debería // TODO: reemplazarse por un sistema de prioridad automática para que no intente conectarse primero a los funcionales conocidos //LdapException wLastExcept = GetDomainController(pSecure, _DomainControllers); if (_DomainController == null) { throw new Fwk.Exceptions.TechnicalException("No se encontró ningún controlador de dominio disponible para el sitio especificado.");//, wLastExcept); } } }
public static string[] GetInfo(string filename) { List<string> fileinfo = new List<string>(); TagLib.File tagFile = TagLib.File.Create(filename); string artiest = tagFile.Tag.FirstPerformer; string titel = tagFile.Tag.Title; if (artiest == null || artiest == "") { // Controleer of de artiest staat aangegeven bij de titel if (titel == null || titel == "") { titel = System.IO.Path.GetFileNameWithoutExtension(filename); } if (titel != null && titel != "") { // Controleer of de titel gesplits kan worden string[] title = titel.Split(new char[] {'-'}); if (title.Length > 1) { artiest = title[0].Trim(); titel = title[1].Trim(); } } } fileinfo.Add(artiest); fileinfo.Add(titel); fileinfo.Add(tagFile.Properties.Duration.TotalSeconds.ToString()); return fileinfo.ToArray(); }
private void InitializeMonitor() { _monitorList = new List<AbstractMonitor>(); _monitorList.AddRange(from tp in typeof(AbstractMonitor).Assembly.GetTypes() where typeof(AbstractMonitor).IsAssignableFrom(tp) && !tp.IsAbstract select Activator.CreateInstance(tp) as AbstractMonitor); }
//新建工具树 public DemoTools() { items = new List<ToolTreeItem>(); ToolTreeItem item = new ToolTreeItem("Demo|Basic", "DemoTest", callDemoWindow); items.Add(item); }
/// <summary> /// Returns a list of visual branches which are around the given commit. /// </summary> /// <param name="commit"></param> /// <param name="repo"></param> /// <returns></returns> public static List<Branch> GetBranchesAroundCommit(Commit commit, ObservableCollection<Branch> branches) { List<Branch> list = new List<Branch>(); // Loop through all branches and determine if they are around the specified commit. foreach (Branch branch in branches) { // Tip has to be found and in case multiple branches share the tree, get rid of the others -- messes up visual position counting. if (branch.Tip == null || list.Any(b => branch.Tip.Branches.Contains(b)) || list.Any(b => b.Tip.Branches.Contains(branch))) continue; // The branch's tip must be newer/same than the commit. if (branch.Tip.Date >= commit.Date) // TODO: && first commit-ever must be older? We might not need to do that... ... ? { list.Add(branch); } else { // If there's a branch with a tip commit older than commit.Date, then it's around this commit if they don't share a single branch. bool foundThisBranch = branch.Tip.Branches.Any(b => commit.Branches.Contains(b)); if (foundThisBranch == false) list.Add(branch); } } return list; }
List<ValueNode> gr_array_list() { List<ValueNode> list = new List<ValueNode>(); while (Lookahead(TokenType.OpenParanthese) || Lookahead(TokenType.OpenSquareBracket) || //Lookahead(TokenType.ExpressionParanthese) || Lookahead(TokenType.Integer) || Lookahead(TokenType.Float) || Lookahead(TokenType.String) || Lookahead(TokenType.True) || Lookahead(TokenType.False)) { list.Add(gr_value()); if (Lookahead(TokenType.Comma)) { Match(TokenType.Comma); } else { break; } } return list; }