public void Go() { outputView.ShowMenu(); inputView.PressAnyKey(); TimeCounter.Start(); inputView.StartKeyboardListener(); }
public void Analyze() { Console.WriteLine("CallGraphAnalyzer"); TimeCounter OverallAnalysisTime = new TimeCounter(); OverallAnalysisTime.Start(); Set <string> beingAnalyzed = new Set <string>(); foreach (string assembly in options.Assemblies) { beingAnalyzed.Add(Path.GetFileNameWithoutExtension(assembly)); } callgraph = new CallGraph <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly>(this.mdDecoder, beingAnalyzed); foreach (string assembly in options.Assemblies) { AnalyzeAssembly(assembly); } callgraph.EmitDotFile(options.OutputFile); OverallAnalysisTime.Stop(); Console.WriteLine("Total time {0}.", OverallAnalysisTime.ToString()); }
private void _load2_Click(object sender, EventArgs e) { label5.Text = "Working"; Application.DoEvents(); _treeView2.Nodes.Clear(); TimeCounter.Start(); _treeView2.BeginUpdate(); List <TreeNode> list = new List <TreeNode>(); for (int i = 0; i < 10; i++) { list.Add(new TreeNode(i.ToString())); for (int n = 0; n < 500; n++) { list[i].Nodes.Add(n.ToString()); for (int k = 0; k < 5; k++) { list[i].Nodes[n].Nodes.Add(k.ToString()); } } } _treeView2.Nodes.AddRange(list.ToArray()); _treeView2.EndUpdate(); label5.Text = TimeCounter.Finish().ToString(); }
private void _load_Click(object sender, EventArgs e) { label3.Text = "Working"; Application.DoEvents(); _treeView.Model = null; _model = null; GC.Collect(3); TimeCounter.Start(); _model = new TreeModel(); for (int i = 0; i < 10; i++) { _model.Root.Nodes.Add(new Node(i.ToString())); for (int n = 0; n < 500; n++) { _model.Root.Nodes[i].Nodes.Add(new Node(n.ToString())); for (int k = 0; k < 5; k++) { _model.Root.Nodes[i].Nodes[n].Nodes.Add(new Node(k.ToString())); } } } _treeView.Model = _model; label3.Text = TimeCounter.Finish().ToString(); }
private void button1_Click(object sender, EventArgs e) { TimeCounter.Start(); _tree.FullUpdate(); //_model.Root.Nodes[0].Text = "Child"; button1.Text = TimeCounter.Finish().ToString(); }
/// <summary> /// 执行构建 /// </summary> private void ExecuteBuild() { var timecounter = new TimeCounter(); timecounter.Start("AssetBundleBuild"); mAssetBuilder.PreAssetBuild(); mAssetBuilder.PostAssetBuild(); timecounter.End(); }
private void btGet_Click(object sender, EventArgs e) { try { TimeCounter.Start(); int Var_H = pbOrigin.Image.Height; //获取图象的高度 int Var_W = pbOrigin.Image.Width; //获取图象的宽度 Bitmap Var_bmp = new Bitmap(Var_W, Var_H); //根据图象的大小实例化Bitmap类 Bitmap Var_SaveBmp = (Bitmap)pbOrigin.Image; //根据图象实例化Bitmap类 //遍历图象的象素 for (int i = 0; i < Var_W; i++) { for (int j = 0; j < Var_H; j++) { Color tem_color = Var_SaveBmp.GetPixel(i, j); //获取当前象素的颜色值 int tem_r, tem_g, tem_b, tem_Value = 0; //定义变量 int tem_R, tem_G, tem_B; //定义变量 tem_r = tem_color.R; //获取R色值 tem_g = tem_color.G; //获取G色值 tem_b = tem_color.B; //获取B色值 tem_Value = ((tem_r + tem_g + tem_b) / 3); //用平均值法产生黑白图像 tem_R = int.Parse(tbR.Text); tem_G = int.Parse(tbG.Text); tem_B = int.Parse(tbB.Text); int tem_Rr = tem_R - tem_r; int tem_Gg = tem_G - tem_g; int tem_Bb = tem_B - tem_b; int tem_Value2 = ((tem_Rr + tem_Gg + tem_Bb) / 3); int ErMin = int.Parse(tbMin.Text); if (tem_Rr < ErMin && tem_Gg < ErMin && tem_Bb < ErMin) { Var_bmp.SetPixel(i, j, Color.FromArgb(255, 255, 255)); } else { Var_bmp.SetPixel(i, j, Color.FromArgb(tem_r, tem_g, tem_b)); } Process.Maximum = Var_W; Process.Value = i; if (Process.Value >= Var_W) { Process.Value = 0; } } } pbNew.Image = Var_bmp; TimeCounter.Stop(); Process.Value = 0; lblTime.Text = string.Format("{0}秒", TimeCounter.Seconds.ToString()); } catch (Exception) { MessageBox.Show("请选择图片!"); //throw; } }
public void Period() { if (timer.Enabled) { return; } timer.Start(); initScale = Target.localScale; }
// Use this for initialization void Start() { particles = new List <NeoParticle>(); remainShots = new List <NeoShot>(); haveShot = shotOrigin && shotInfo.durationSec > 0; Easing = new EasingFunctions(); particlePool = new ObjectPool(particleCapacity); shotPool = new ObjectPool(10000); particleTimer = new TimeCounter(interval); particleTimer.Start(); }
public void Test_New_3() { int interval = 0; using (var c = new TimeCounter (5, 0)) { c.Elapsed += () => interval += 1; c.Start (); while (c.IsRunning) { System.Threading.Thread.Sleep (1); } System.Threading.Thread.Sleep (1); Assert.AreEqual (5, c.Count); Assert.AreEqual (0, interval); } }
public void ClearTest() { Node node = new Node(""); int num = 125000; for (int i = 0; i < num; i++) { node.Nodes.Add(new Node()); } Assert.AreEqual(num, node.Nodes.Count); TimeCounter.Start(); node.Nodes.Clear(); Console.WriteLine("Clear: {0}", TimeCounter.Finish()); Assert.AreEqual(0, node.Nodes.Count); }
public NeoParticle(Transform target, ParticleInfo info) { this.target = target; this.info = info; float angle = RandDegree(info.defaultAngle, info.defaultAngleAmplitude); target.localEulerAngles = Vector3.forward * angle; if (info.canRefractFirst) { Refract(); } moveCounter = new Counter(1, true); shots = new List <NeoShot>(); lifeTimer = new TimeCounter(info.durationSec); lifeTimer.Start(); }
private void btError_Click(object sender, EventArgs e) { try { TimeCounter.Start(); int Var_H = pbNew.Image.Height; int Var_W = pbNew.Image.Width; Image Image_temp = Error_Size(Var_W, Var_H); pbNew.Image = Image_temp; Process.Value = 0; TimeCounter.Stop(); lblTime.Text = string.Format("{0}秒", TimeCounter.Seconds.ToString()); } catch (Exception) { MessageBox.Show("请先处理图片!"); //throw; } }
public void NodesTest() { TreeNodeAdv target = new TreeNodeAdv(null); Aga.Controls.UnitTests.Aga_Controls_Tree_TreeNodeAdvAccessor accessor = new Aga.Controls.UnitTests.Aga_Controls_Tree_TreeNodeAdvAccessor(target); Collection <TreeNodeAdv> nodes = accessor.Nodes; TimeCounter.Start(); for (int i = 0; i < 125000; i++) { nodes.Add(new TreeNodeAdv(null)); } Console.WriteLine("Add: {0}", TimeCounter.Finish()); TimeCounter.Start(); accessor.Nodes.Clear(); Console.WriteLine("Clear: {0}", TimeCounter.Finish()); Assert.AreEqual(0, accessor.Nodes.Count); }
private void _expand_Click(object sender, EventArgs e) { if (_treeView.Root.Children.Count > 0) { label4.Text = "Working"; Application.DoEvents(); TimeCounter.Start(); if (_treeView.Root.Children[0].IsExpanded) { _treeView.CollapseAll(); } else { _treeView.ExpandAll(); } label4.Text = TimeCounter.Finish().ToString(); } }
// Update is called once per frame void Update() { if (particleTimer.OnLimit()) { particleTimer.Start(); GenerateParticles(1); } var nextParticles = new List <NeoParticle>(); for (int i = 0; i < particles.Count; i++) { if (particles[i].Move(this)) { nextParticles.Add(particles[i]); } else { particlePool.Push(particles[i].target.gameObject); } } particles = nextParticles; var nextShots = new List <NeoShot>(); for (int i = 0; i < remainShots.Count; i++) { if (remainShots[i].Ray(Vector2.zero)) { nextShots.Add(remainShots[i]); } else { PoolShot(remainShots[i]); } } remainShots = nextShots; shotCount = shotPool.Count + remainShots.Count; }
private void btAnalysis_Click(object sender, EventArgs e) { try { TimeCounter.Start(); //Image pic = Image.FromFile(resultFile);//strFilePath是该图片的绝对路径 Image pic = pbOrigin.Image; int intWidth = pic.Width; //长度像素值 int intHeight = pic.Height; //高度像素值 Image Image_temp = BlackandWhiteEffect(pbOrigin); Bitmap bmPic = new Bitmap(Image_temp); Point ptLoction = new Point(Image_temp.Size); if (ptLoction.X > pbNew.Size.Width || ptLoction.Y > pbNew.Size.Height) { //图像框的停靠方式 //pcbPic.Dock = DockStyle.Fill; //图像充满图像框,并且图像維持比例 pbNew.SizeMode = PictureBoxSizeMode.Zoom; } else { //图像在图像框置中 pbNew.SizeMode = PictureBoxSizeMode.CenterImage; } //LoadAsync:非同步载入图像 pbNew.Image = Image_temp; TimeCounter.Stop(); lblTime.Text = string.Format("{0}秒", TimeCounter.Seconds.ToString()); Process.Value = 0; } catch (Exception) { MessageBox.Show("请选择图片!"); //throw; } }
private void _expand2_Click(object sender, EventArgs e) { if (_treeView2.Nodes.Count > 0) { label6.Text = "Working"; Application.DoEvents(); TimeCounter.Start(); //treeView1.BeginUpdate(); if (_treeView2.Nodes[0].IsExpanded) { _treeView2.CollapseAll(); } else { _treeView2.ExpandAll(); } //treeView1.EndUpdate(); label6.Text = TimeCounter.Finish().ToString(); } }
public void TestMethod() { Bitmap b = new Bitmap(500, 50); Graphics gr = Graphics.FromImage(b); int num = 5000; string text = "Some Text String"; Rectangle rect = new Rectangle(0, 0, 500, 50); TimeCounter.Start(); for (int i = 0; i < num; i++) { TextRenderer.MeasureText(text, Control.DefaultFont); TextRenderer.DrawText(gr, text, Control.DefaultFont, rect, Color.Black); } Console.WriteLine("TextRenderer {0}", TimeCounter.Finish()); TimeCounter.Start(); for (int i = 0; i < num; i++) { gr.MeasureString(text, Control.DefaultFont); gr.DrawString(text, Control.DefaultFont, Brushes.Black, rect); } Console.WriteLine("Graphics {0}", TimeCounter.Finish()); }
private void _load_Click(object sender, EventArgs e) { label3.Text = "Working"; Application.DoEvents(); _treeView.Model = null; _model = null; GC.Collect(3); TimeCounter.Start(); _model = new TreeModel(); for (int i = 0; i < 10; i++) { Node node = new Node(i.ToString()); node.Image = Properties.Resources.P; _model.Root.Nodes.Add(node); for (int n = 0; n < 500; n++) { Node node1 = new Node(n.ToString()); node1.Image = Properties.Resources.c1; node.Nodes.Add(node1); for (int k = 0; k < 5; k++) { Node node2 = new Node(k.ToString()); node2.Image = Properties.Resources.c2; node1.Nodes.Add(node2); } } } _treeView.Model = _model; label3.Text = TimeCounter.Finish().ToString(); }
static void SortTest1(string[] args) { CreateRandomFile(@"..\..\dic.txt"); string[] aArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default); string[] bArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default); List <string> aList = new List <string>(aArray); List <string> sList = new List <string>(aArray); List <string> sList2 = new List <string>(aArray); SortTests.Sorting.sfList sList3 = new sfList(aArray); KeyedList <string, int> kList = new KeyedList <string, int>(aArray.Length); KeyedList <string, int> kListDesc = new KeyedList <string, int>(aArray.Length); int val = 1; foreach (string s in sList) { kList.Add(s, val); //val contains original line position of string kListDesc.Add(s, val); ++val; } sList.Clear(); TimeCounter StopWatch = new TimeCounter(); StopWatch.SetOneProcessorAffinity(); Console.WriteLine("base Cycles = {0} IsHighRes = {1}", TimeCounter.Frequency, TimeCounter.IsHighResolution); StopWatch.Start(); //List<string> cList = StringSort.Sort(aList); List <string> cList = new List <string>(aList); StopWatch.Stop(); Console.WriteLine("MS to sort copy: {0}", StopWatch.ElapsedMilSec); int n = 0; foreach (string s in cList) { Console.WriteLine(s); if (++n > 1) { break; } } aList.Clear(); StopWatch.StartNew(); Array.Sort <string>(bArray, CompareString); StopWatch.Stop(); Console.WriteLine("MS to Array.Sort<string> bArray: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < bArray.Length; ++i) { Console.WriteLine(bArray[i]); if (i == 1) { break; } } //reset bArray to unsorted aArray.CopyTo(bArray, 0); StopWatch.StartNew(); StringSort.Sort(aArray); StopWatch.Stop(); Console.WriteLine("MS to sort aArray: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < aArray.Length; ++i) { Console.WriteLine(aArray[i]); if (i == 1) { break; } } StopWatch.StartNew(); Sedgewick.Sort(ref bArray); StopWatch.Stop(); Console.WriteLine("MS to Sedgewick Sort bArray: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < bArray.Length; ++i) { Console.WriteLine(bArray[i]); if (i == 1) { break; } } StopWatch.StartNew(); sList2.Sort(CompareString); //sort using List<string> method //sList2.Sort(CompareString); StopWatch.Stop(); Console.WriteLine("MS to List.Sort() sList2: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < sList2.Count; ++i) { Console.WriteLine(sList2[i]); if (i == 1) { break; } } sList2.Clear(); StopWatch.StartNew(); sList3.Sort(); //sort using StringSort replacement StopWatch.Stop(); Console.WriteLine("MS to sfList.Sort() sList3: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < sList3.Count; ++i) { Console.WriteLine(sList3[i]); if (i == 1) { break; } } StopWatch.StartNew(); kList.Sort(); StopWatch.Stop(); Console.WriteLine("MS to KeyedList.Sort() kList: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < kList.Count; ++i) { Console.WriteLine(kList[i]); if (i == 1) { break; } } //test the sort bool sorted = IsSortedTest(kList, kList.SortAscd); Console.WriteLine("Test: kList is sorted = {0}", sorted); kListDesc.SortAscd = false; //try sorting in descending order StopWatch.StartNew(); kListDesc.Sort(); StopWatch.Stop(); Console.WriteLine("MS to KeyedList.Sort() kListDesc: {0}", StopWatch.ElapsedMilSec); for (int i = 0; i < kListDesc.Count; ++i) { Console.WriteLine(kListDesc[i]); if (i == 1) { break; } } //test the sort sorted = IsSortedTest(kListDesc, kListDesc.SortAscd); Console.WriteLine("Test: kListDesc is sorted descending = {0}", sorted); string[] wArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default); //this is slower than stringSort //WQSort wqs = new WQSort(); //StopWatch.StartNew(); //wqs.Sort(wArray); //StopWatch.Stop(); //Console.WriteLine("MS to WQSort.Sort() wArray: {0}", StopWatch.ElapsedMilSec); //for (int i = 0; i < wArray.Length; ++i) //{ // Console.WriteLine(wArray[i]); // if (i == 1) break; //} List <int> lstInt = new List <int>(wArray.Length); Random rand = new Random((int)StopWatch.ElapsedMilSec); for (int i = 0; i < wArray.Length; ++i) { lstInt.Add(rand.Next()); } StopWatch.StartNew(); lstInt.Sort(); StopWatch.Stop(); Console.WriteLine("MS to List<int>.Sort() with {0} elements: {1:f1}", wArray.Length, StopWatch.ElapsedMilSec); Console.WriteLine("First, Second, Last integer in sorted List"); Console.WriteLine(lstInt[0]); Console.WriteLine(lstInt[1]); Console.WriteLine(lstInt[wArray.Length - 1]); StopWatch.RestoreProcessorAffinity(); //set this thread back to default Proccessor Affinity }
private void BeginPerformanceCount() { _paintCount++; TimeCounter.Start(); }
public static void Main(string[] args) { try { // organizations and users List<Organization> organizations = CreateOrganization(); List<User> users = CreateUsers(); // creating cases CreateCases(100, organizations, users); CreateCases(1000, organizations, users); CreateCases(10000, organizations, users); CreateCases(500000, organizations, users); CreateCases(1000, organizations, users); // search cases CaseDataProvider provider = new CaseDataProvider(); List<Case> cases; Random r = new Random(); TimeCounter counter = new TimeCounter("C. Search by year and number"); int found = 0; for (int i = 0; i < Configuration.SearchesNumber; i++) { counter.Start(); cases = provider.GetByYearAndNumber(2010, r.Next(1, 100000)); counter.Stop(); found += cases.Count; } counter.PrintTime(); counter.PrintLine(string.Format("Found {0} cases, avg. {1} per search.\n", found, found / Configuration.SearchesNumber)); found = 0; counter = new TimeCounter("D. Search by case ID"); for (int i = 0; i < Configuration.SearchesNumber; i++) { counter.Start(); Case theCase = provider.GetById(r.Next(1, 100000)); counter.Stop(); if (theCase != null) { found++; } } counter.PrintTime(); counter.PrintLine(string.Format("Found {0} cases, avg. {1} per search.\n", found, found / Configuration.SearchesNumber)); found = 0; counter = new TimeCounter("E. Search by case title"); for (int i = 0; i < Configuration.SearchesNumber; i++) { counter.Start(); cases = provider.GetByTitle(PhraseGenerator.GetRandomPhrase(1) + "%", 20); counter.Stop(); found += cases.Count; } counter.PrintTime(); counter.PrintLine(string.Format("Found {0} cases, avg. {1} per search.\n", found, found / Configuration.SearchesNumber)); found = 0; counter = new TimeCounter("F. Search by custom field value"); for (int i = 0; i < Configuration.SearchesNumber; i++) { counter.Start(); cases = provider.GetByCustomFieldValue(PhraseGenerator.GetRandomPhrase(1) + "%", 20); counter.Stop(); found += cases.Count; } counter.PrintTime(); counter.PrintLine(string.Format("Found {0} cases, avg. {1} per search.\n", found, found / Configuration.SearchesNumber)); /* if (cases.Count > 0) { Console.WriteLine(cases[0]); } */ } catch (Exception e) { Console.WriteLine("Error occured: {0}", e); } Console.WriteLine("Done, press a key..."); Console.ReadKey(); }
private static List<User> CreateUsers() { List<User> users = new List<User>(); if (Configuration.GenerateOrganization) { Console.WriteLine("Creating users..."); TimeCounter counter = new TimeCounter("Creating 1000 users"); for (int i = 0; i < 1000; i++) { counter.Start(); User user = User.GetOne(); user.Save(); counter.Stop(); users.Add(user); } counter.PrintTime(); } else { users = new UserDataProvider().GetAll(); } return users; }
private static void CreateCases(int number, List<Organization> organizations, List<User> users) { Random r = new Random(); TimeCounter counter = new TimeCounter(string.Format("Create {0} cases", number)); for (int i = 0; i < number; i++) { counter.Start(); Case theCase = Case.GetOne(organizations[r.Next(0, organizations.Count - 1)], users[r.Next(0, users.Count - 1)]); theCase.Save(); counter.Stop(); Thread.Sleep(r.Next(10, 50)); } counter.PrintTime(); }
/// <summary> /// 准备工作 /// </summary> private List <AssetInfo> GetBuildMap(ref Dictionary <string, AssetBundleBuildInfo> abbuildinfomap) { int progressBarCount = 0; Dictionary <string, AssetInfo> allAsset = new Dictionary <string, AssetInfo>(); // 获取所有的收集路径 List <string> collectDirectorys = AssetBundleCollectSettingData.GetAllCollectDirectory(); if (collectDirectorys.Count == 0) { throw new Exception("[BuildPatch] 配置的资源收集路径为空"); } // 获取所有资源 string[] guids = AssetDatabase.FindAssets(string.Empty, collectDirectorys.ToArray()); foreach (string guid in guids) { string mainAssetPath = AssetDatabase.GUIDToAssetPath(guid); if (AssetBundleCollectSettingData.IsIgnoreAsset(mainAssetPath)) { continue; } if (ValidateAsset(mainAssetPath) == false) { continue; } List <AssetInfo> depends = GetDependencies(mainAssetPath); for (int i = 0; i < depends.Count; i++) { AssetInfo assetInfo = depends[i]; if (allAsset.ContainsKey(assetInfo.AssetPath)) { allAsset[assetInfo.AssetPath].DependCount++; } else { allAsset.Add(assetInfo.AssetPath, assetInfo); } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"依赖文件分析:{progressBarCount}/{guids.Length}", (float)progressBarCount / guids.Length); } EditorUtility.ClearProgressBar(); progressBarCount = 0; // 移除零依赖的资源 List <string> removeList = new List <string>(); foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { if (pair.Value.IsCollectAsset) { continue; } if (pair.Value.DependCount == 0) { removeList.Add(pair.Value.AssetPath); } } for (int i = 0; i < removeList.Count; i++) { allAsset.Remove(removeList[i]); Debug.Log($"移除零依赖资源:{removeList[i]}"); } // 设置资源标签 foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { SetAssetBundleLabelAndVariant(pair.Value); // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"设置资源标签:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count); } // 整理Asset所有有效的Asset依赖 // 设置资源标签 TimeCounter timercounter = new TimeCounter(); timercounter.Start("AB依赖分析"); progressBarCount = 0; foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { AssetBundleBuildInfo abbuildinfo = null; if (!abbuildinfomap.TryGetValue(pair.Value.AssetBundleLabel, out abbuildinfo)) { // 统一小写,确保和AssetBuildInfo那方一致 var assetbundlelabletolower = pair.Value.AssetBundleLabel.ToLower(); abbuildinfo = new AssetBundleBuildInfo(assetbundlelabletolower); abbuildinfomap.Add(pair.Value.AssetBundleLabel, abbuildinfo); } var directdepends = AssetDatabase.GetDependencies(pair.Key, false); foreach (var directdepend in directdepends) { AssetInfo assetinfo = null; // allAsset里包含的才是有效的Asset if (allAsset.TryGetValue(directdepend, out assetinfo)) { // 统一小写,确保和AssetBuildInfo那方一致 var assetablablelower = assetinfo.AssetBundleLabel.ToLower(); if (!pair.Value.AssetBundleLabel.Equals(assetinfo.AssetBundleLabel) && !abbuildinfo.DepABPathList.Contains(assetablablelower)) { abbuildinfo.DepABPathList.Add(assetablablelower); } } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"整理AB依赖关系:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count); } timercounter.End(); EditorUtility.ClearProgressBar(); // 返回结果 return(allAsset.Values.ToList()); }
public void BeginProcess() { counter.Start(); }
private static List<Organization> CreateOrganization() { List<Organization> organizations = new List<Organization>(); TimeCounter counter = new TimeCounter("Create 100 organization units"); if (Configuration.GenerateOrganization) { Console.WriteLine("Creating organizations..."); for (int i = 0; i < 100; i++) { counter.Start(); Organization org = Organization.GetOne(); org.Save(); counter.Stop(); organizations.Add(org); } counter.PrintTime(); } else { organizations = new OrganizationDataProvider().GetAll(); } return organizations; }
public static void Main() { TimeCounter timeCounter = new TimeCounter(); TimeSpan elapsed = TimeSpan.Zero; int i = 0; // Try to get clock at system start try { var time = NtpClient.GetNetworkTime(); Utility.SetLocalTime(time); } catch (Exception ex) { // Don't depend on time Debug.Print("Error setting clock: " + ex.Message); } // On board led OutputPort onBoardLed = new OutputPort(Pins.ONBOARD_LED, false); // Humidity and Temperature Sensor = new Dht22Sensor(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, PullUpResistor.Internal); //IRRX: Infrared Decoder NecProtocolDecoder decoder = new NecProtocolDecoder(Pins.GPIO_PIN_D7); NecProtocolDecoder.OnIRCommandReceived += NecDecoder_OnIRCommandReceived; //IRTX: Infrared Encoder IRCodec1 = new InfraredCodecNEC(new InfraredTransmitter(Pins.GPIO_PIN_D8)); IRCodec2 = new InfraredCodecNEC(new InfraredTransmitter(Pins.GPIO_PIN_D9)); Thread.Sleep(1000); // Web Server ServerConfiguration = new Configuration(80); ServerCredential = new Credential("Administrator", "admin", "admin"); Server = new HttpServer(ServerConfiguration, ServerCredential, @"\SD\"); Server.OnServerError += new OnServerErrorDelegate(Server_OnServerError); Server.OnRequestReceived += new OnRequestReceivedDelegate(Server_OnRequestReceived); Server.Start(); // File Server FileServer server = new FileServer(@"\SD\", 1554); while (true) { timeCounter.Start(); { elapsed += timeCounter.Elapsed; if (elapsed.Seconds >= 1) { if (Sensor.Read()) { temperature = Sensor.Temperature; humidity = Sensor.Humidity; status = "DHT Sensor: RH = " + humidity.ToString("F1") + "% Temp = " + temperature.ToString("F1") + "°C "; } elapsed = TimeSpan.Zero; onBoardLed.Write((i++ & 0x01) == 0); // blink on board led #region nulltask //if ((i & 0x01) == 0) //{ // if ((i & 0x02) == 0) // { // IRCodec1.Send(0x00, 0x00); // } // else // { // IRCodec1.Send(0xFF, 0xFF); // } //} //else //{ // if ((i & 0x02) == 0) // { // IRCodec2.Send(0x00, 0x00); // } // else // { // IRCodec2.Send(0xFF, 0xFF); // } //} //if ((i & 0x01) == 0) //{ // if ((i & 0x02) == 0) // { // IRCodec1.Send(0x10, 0x0D); // } // else // { // IRCodec1.Send(0x10, 0x1F); // } //} //else //{ // if ((i & 0x02) == 0) // { // IRCodec2.Send(0x10, 0x03); // } // else // { // IRCodec2.Send(0x10, 0x02); // } //} //if ((i & 0x01) == 0) //{ // IRCodec1.Send(0x10, 0x0D); // IRCodec2.Send(0x10, 0x03); //} //else //{ // IRCodec1.Send(0x10, 0x1F); // IRCodec2.Send(0x10, 0x02); //} //string log = "DHT Sensor: RH = " + humidity.ToString("F1") + // "% Temp = " + temperature.ToString("F1") + "°C "; //Debug.Print(log); #endregion } } timeCounter.Stop(); } }