public RemoteMenu(Remote remote) { Verify.Argument.IsValidGitObject(remote, "remote"); _remote = remote; Items.Add(GuiItemFactory.GetShowRemoteItem<ToolStripMenuItem>(remote)); Items.Add(GuiItemFactory.GetEditRemotePropertiesItem<ToolStripMenuItem>(remote)); Items.Add(new ToolStripSeparator()); Items.Add(GuiItemFactory.GetFetchFromItem<ToolStripMenuItem>(remote, "{0}")); Items.Add(GuiItemFactory.GetPullFromItem<ToolStripMenuItem>(remote, "{0}")); Items.Add(GuiItemFactory.GetPruneRemoteItem<ToolStripMenuItem>(remote, "{0}")); Items.Add(new ToolStripSeparator()); Items.Add(GuiItemFactory.GetRemoveRemoteItem<ToolStripMenuItem>(remote, "{0}")); Items.Add(GuiItemFactory.GetRenameRemoteItem<ToolStripMenuItem>(remote, "{0}")); Items.Add(new ToolStripSeparator()); var item = new ToolStripMenuItem(Resources.StrCopyToClipboard); item.DropDownItems.Add(GuiItemFactory.GetCopyToClipboardItem<ToolStripMenuItem>(Resources.StrName, remote.Name)); item.DropDownItems.Add(GuiItemFactory.GetCopyToClipboardItem<ToolStripMenuItem>(Resources.StrFetchUrl, remote.FetchUrl)); item.DropDownItems.Add(GuiItemFactory.GetCopyToClipboardItem<ToolStripMenuItem>(Resources.StrPushUrl, remote.PushUrl)); Items.Add(item); }
public static Dictionary<string, KeyValuePair<HashSet<string>, HashSet<Guid>>> GetExtensions(Remote remote) { Dictionary<string, KeyValuePair<HashSet<string>, HashSet<Guid>>> res = remote == null ? new Dictionary<string, KeyValuePair<HashSet<string>, HashSet<Guid>>>(StringComparer.OrdinalIgnoreCase) : remote.GetExtensions(); foreach (IWICBitmapCodecInfo ci in AllComponentsRuleGroup.GetComponentInfos(WICComponentType.WICDecoder)) { Guid cf; ci.GetContainerFormat(out cf); foreach (string ext in Extensions.GetString(ci.GetFileExtensions).Split(',')) { KeyValuePair<HashSet<string>, HashSet<Guid>> data; if (!res.TryGetValue(ext, out data)) { data = new KeyValuePair<HashSet<string>, HashSet<Guid>>(new HashSet<string>(StringComparer.OrdinalIgnoreCase), new HashSet<Guid>()); res.Add(ext, data); } foreach (string mime in Extensions.GetString(ci.GetMimeTypes).Split(',')) { data.Key.Add(mime); } data.Value.Add(cf); } } return res; }
public RenameRemoteDialog(Remote remote) { Verify.Argument.IsNotNull(remote, "remote"); Verify.Argument.IsFalse(remote.IsDeleted, "remote", Resources.ExcObjectIsDeleted.UseAsFormat("Remote")); _remote = remote; InitializeComponent(); Localize(); SetupReferenceNameInputBox(_txtNewName, ReferenceType.Remote); _txtOldName.Text = remote.Name; _txtNewName.Text = remote.Name; _txtNewName.SelectAll(); var inputs = new IUserInputSource[] { _newNameInput = new TextBoxInputSource(_txtNewName), }; _errorNotifier = new UserInputErrorNotifier(NotificationService, inputs); GitterApplication.FontManager.InputFont.Apply(_txtNewName, _txtOldName); _controller = new RenameRemoteController(remote); }
public static IEnumerable<KeyValuePair<Guid, string>> GetComponentInfoPairs(WICComponentType type, Remote remote) { HashSet<Guid> guids = new HashSet<Guid>(); foreach (IWICComponentInfo ci in GetComponentInfos(type)) { Guid clsid; ci.GetCLSID(out clsid); guids.Add(clsid); string s = Extensions.GetString(ci.GetFriendlyName); if (string.IsNullOrEmpty(s)) { s = string.Format(CultureInfo.CurrentUICulture, "CLSID: {0}", clsid); } yield return new KeyValuePair<Guid, string>(clsid, s); } if (remote != null) { foreach (var p in remote.GetComponentInfoPairs(type)) { if (!guids.Contains(p.Key)) { yield return p; } } } }
static void Remote_HelloCallback(object sender, EventArgsHello e) { Console.WriteLine("{0} 对 {1} 说 {2}", e.From, e.To, e.Something); object obj = tcpChannel.ChannelData; //获取客户端地址 if (remoteClass == null) remoteClass = (Remote)Activator.GetObject(typeof(Remote), e.ChannelUris + "/HelloClient"); //获取远程对象代理 remoteClass.Hello("服务端", "客户端", "您好!", ChannelUris);//调用远程对象Hello方法 }
public ShellIntegrationRuleGroup(Remote remote) : base(Resources.ShellIntegrationRule_Text) { foreach (var p in GetExtensions(remote)) { Nodes.Add(new ExtensionRuleGroup(p.Key, p.Value.Key, p.Value.Value)); } }
public AllComponentsRuleGroup(string text, WICComponentType type, Action<ComponentRuleGroup> childCreator, Remote remote) : base(text) { foreach (var p in GetComponentInfoPairs(type, remote)) { Nodes.Add(new ComponentRuleGroup(p.Key, p.Value, childCreator)); } }
public void SetWiiRemoteListener(Remote wremote) { wiiremote = wremote; wiiremote.AccelerationUpdate += HandleWiiremoteAccelerationUpdate; wiiremote.ButtonPressed += HandleWiiremoteButtonPressed; wiiremote.ButtonReleased += HandleWiiremoteButtonReleased; wiiremote.RemoteConnected += HandleWiiremoteRemoteConnected; wiiremote.RemoteDisconnected += HandleWiiremoteRemoteDisconnected; }
internal RemoteReferencesCollection(Remote remote) { Verify.Argument.IsNotNull(remote, "remote"); _remote = remote; _repository = remote.Repository; _remoteBranches = new Dictionary<string, RemoteRepositoryBranch>(); _remoteTags = new Dictionary<string, RemoteRepositoryTag>(); _syncRoot = new object(); }
public static void FetchOrPull(Repository repository, Remote remote, bool pull) { var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag; if(pull) { affectedReferences |= ReferenceType.LocalBranch; } ReferenceChange[] changes; var state1 = RefsState.Capture(repository, affectedReferences); using(repository.Monitor.BlockNotifications( RepositoryNotifications.BranchChanged, RepositoryNotifications.TagChanged)) { try { if(pull) { var p = new PullParameters(); if(remote != null) { p.Repository = remote.Name; } repository.Accessor.Pull.Invoke(p); } else { var p = new FetchParameters(); if(remote != null) { p.Repository = remote.Name; } repository.Accessor.Fetch.Invoke(p); } } finally { repository.Refs.Refresh(affectedReferences); var state2 = RefsState.Capture(repository, affectedReferences); changes = RefsDiff.Calculate(state1, state2); if(changes != null && changes.Length != 0) { repository.OnUpdated(); } } } if(pull) { repository.Remotes.OnPullCompleted(remote, changes); } else { repository.Remotes.OnFetchCompleted(remote, changes); } }
public override void Init() { remote = new REMOTESERVICELib.Remote(); remote.InitialQuick(); uint c; remote.GetDeviceNum(out c); if (c > 0) { REMOTESERVICELib.tagHWINFO hwInfo; remote.EnumDeviceInfo(0, out hwInfo); remote.SetRemoteIsEnable(0, hwInfo.lEnumRemoteID, true); //Name = hwInfo.szDeviceName; remote.OnRemoteData += new _IRemoteEvents_OnRemoteDataEventHandler(remote_OnRemoteData); } }
public override void Deinit() { if (remote != null) { try { remote.UninitialQuick(); } catch { } remote = null; } }
static void Main(string[] args) { Remote remote = new Remote(); Light livingroomlight = new Light("livingroom"); LightOnCommand livingroomlighton = new LightOnCommand(livingroomlight); LightOffCommand livingroomlightoff = new LightOffCommand(livingroomlight); remote.SetCommand(0, livingroomlighton, livingroomlightoff); remote.OnButtonWasPushed(0); //livingroom light is on SimpleRemoteControl remote2 = new SimpleRemoteControl(); remote2.SetCommand(livingroomlighton); remote2.ButtonWasPressed(); //livingroom light is on string z = Console.ReadLine(); }
/// <summary> /// Refresh the list of remotes for the given repo while keeping the /// existing passwords and push commands /// </summary> public void Refresh(ClassRepo repo) { // Build the new list while picking up password fields from the existing list Dictionary<string, Remote> newlist = new Dictionary<string, Remote>(); string[] response = new[] {string.Empty}; ExecResult result = repo.Run("remote -v"); if (result.Success()) { response = result.stdout.Split((Environment.NewLine).ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string s in response) { Remote r = new Remote(); // Split the resulting remote repo name/url into separate strings string[] url = s.Split("\t ".ToCharArray()); string name = url[0]; // Find if the name exists in the main list and save off the password from it if (newlist.ContainsKey(name)) r = newlist[name]; if (remotes.ContainsKey(name)) { r.Password = remotes[name].Password; r.PushCmd = remotes[name].PushCmd; } // Set all other fields that we refresh every time r.Name = name; if (url[2] == "(fetch)") r.UrlFetch = url[1]; if (url[2] == "(push)") r.UrlPush = url[1]; // Add it to the new list newlist[name] = r; } } // Set the newly built list to be the master list remotes = newlist; // Fixup the new current string name if (!remotes.ContainsKey(Current)) Current = remotes.Count > 0 ? remotes.ElementAt(0).Key : ""; }
/// <summary>Create <see cref="RemoveRemoteBranchDialog"/>.</summary> /// <param name="branch"><see cref="RemoteBranch"/> to remove.</param> public RemoveRemoteBranchDialog(RemoteBranch branch) { Verify.Argument.IsNotNull(branch, "branch"); Verify.Argument.IsFalse(branch.IsDeleted, "branch", Resources.ExcObjectIsDeleted.UseAsFormat("RemoteBranch")); InitializeComponent(); _branch = branch; _remote = branch.Remote; Text = Resources.StrRemoveBranch; _lblRemoveBranch.Text = Resources.StrsRemoveBranchFrom.UseAsFormat(branch.Name).AddColon(); _cmdRemoveLocalOnly.Text = Resources.StrsRemoveLocalOnly; _cmdRemoveLocalOnly.Description = Resources.StrsRemoveLocalOnlyDescription; _cmdRemoveFromRemote.Text = Resources.StrsRemoveFromRemote; _cmdRemoveFromRemote.Description = Resources.StrsRemoveFromRemoteDescription.UseAsFormat(_remote.Name); }
/// <summary> /// Initializes a new instance of the AppDomainAssemblyLoader class. The assembly environment will create /// a new application domain with the location of the currently executing assembly as the application base. It /// will also add that root directory to the assembly resolver's path in order to properly load a remotable /// AssemblyLoader object into context. From here, add whatever assembly probe paths you wish in order to /// resolve remote proxies, or extend this class if you desire more specific behavior. /// </summary> /// <param name="setupInfo"> /// The setup information. /// </param> private AppDomainContext(AppDomainSetup setupInfo) { this.UniqueId = Guid.NewGuid(); this.AssemblyImporter = new PathBasedAssemblyResolver(); // Add some root directories to resolve some required assemblies this.AssemblyImporter.AddProbePath(setupInfo.ApplicationBase); this.AssemblyImporter.AddProbePath(setupInfo.PrivateBinPath); // Create the new domain and wrap it for disposal. this.wrappedDomain = new DisposableAppDomain( AppDomain.CreateDomain( this.UniqueId.ToString(), null, setupInfo)); AppDomain.CurrentDomain.AssemblyResolve += this.AssemblyImporter.Resolve; // Create remotes this.loaderProxy = Remote<AssemblyTargetLoader>.CreateProxy(this.wrappedDomain); this.resolverProxy = Remote<PathBasedAssemblyResolver>.CreateProxy(this.wrappedDomain); // Assign the resolver in the other domain (just to be safe) RemoteAction.Invoke( this.wrappedDomain.Domain, this.resolverProxy.RemoteObject, (resolver) => { AppDomain.CurrentDomain.AssemblyResolve += resolver.Resolve; }); // Assign proper paths to the remote resolver this.resolverProxy.RemoteObject.AddProbePath(setupInfo.ApplicationBase); this.resolverProxy.RemoteObject.AddProbePath(setupInfo.PrivateBinPath); this.IsDisposed = false; }
public List<RemoteCode> GetRemoteCodes(Remote remote) { List<RemoteCode> remoteCodeList = new List<RemoteCode>(); /* Build process info to call LIRC */ ProcessStartInfo procInfo = new ProcessStartInfo(); procInfo.FileName = "irsend"; procInfo.UseShellExecute = false; procInfo.RedirectStandardOutput = true; /* Ask LIRC for a list of remotes */ procInfo.Arguments = "list " + remote.Name + " \"\""; Process proc = Process.Start(procInfo); string strOut = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); /* Extract the remote names from the LIRC return*/ using (StringReader reader = new StringReader(strOut)) { string line = string.Empty; RemoteCode code; do { line = reader.ReadLine(); if (line != null && line.StartsWith("irsend: ")) { code = new RemoteCode(); code.Name = line.Split(' ')[2]; code.Command = line.Split(' ')[1]; code.RemoteName = remote.Name; } } while (line != null); } return remoteCodeList; }
public static void Main() { var remote = new Remote(); remote.Activate(); }
public RemoteViewModel(Remote remote) { _remote = remote; }
private void OnRemoteRemoved(Remote remote) { if(_remoteLabel.Tag == remote) { UpdateRemoteLabel(); } }
private void OnRemoteAdded(Remote remote) { if(_remoteLabel.Tag == null) { UpdateRemoteLabel(); } }
/// <summary> /// Sends the system message. /// </summary> /// <param name="message">The message.</param> private void SendSystemMessage(ISystemMessage message) { Remote.Send(message, null, this); Remote.Provider.AfterSendSystemMessage(message); }
public static Task PushAsync(Repository repository, Remote remote, ICollection<Branch> branches, bool forceOverwrite, bool thinPack, bool sendTags, IProgress<OperationProgress> progress, CancellationToken cancellationToken) { var parameters = GetPushParameters(remote.Name, branches, forceOverwrite, thinPack, sendTags); return PushAsync(repository, parameters, progress, cancellationToken); }
public static void Fetch(AuthenticationInfo authentication, Remote remote, Repository repo) { Log.Info(string.Format("Fetching from remote '{0}' using the following refspecs: {1}.", remote.Name, string.Join(", ", remote.FetchRefSpecs.Select(r => r.Specification)))); Commands.Fetch(repo, remote.Name, new string[0], authentication.ToFetchOptions(), null); }
private void Layer_ClientConnected(Remote.Layer.PRoConLayerClient client) { client.Login += new Remote.Layer.PRoConLayerClient.LayerClientHandler(client_LayerClientLogin); client.Logout += new Remote.Layer.PRoConLayerClient.LayerClientHandler(client_LayerClientLogout); }
public static void UpdateRemote(Remote remote, RemoteData remoteData) { Verify.Argument.IsNotNull(remote, "remote"); Verify.Argument.IsNotNull(remoteData, "remoteData"); remote.SetPushUrl(remoteData.PushUrl); remote.SetFetchUrl(remoteData.FetchUrl); }
private static void RunUpdate() { Console.WriteLine("Beginning Update..."); // Get the latest update from the server WebClient client = new WebClient(); string website = client.DownloadString("http://osw.didrole.com/src"); Console.WriteLine(website); var data = ExtractData(website); UpdateData latest_update = new UpdateData(); latest_update.date = new DateTime(0); foreach (var d in data) { if (d.date > latest_update.date) { latest_update = d; } } var file_data = ExtractFileData(client.DownloadString(latest_update.url), latest_update.manifest); string header_file = string.Format("{0} <{1}> {2}\n", latest_update.manifest, latest_update.url, latest_update.date.ToShortDateString()); Console.WriteLine(header_file); // now push to git // get our username + password from the secrets.json file dynamic secrets = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <dynamic>(File.ReadAllText("secrets.json")); string username = secrets["username"]; string password = Encoding.UTF8.GetString(Convert.FromBase64String(secrets["password"])); // check the manifest that is already there try { string old_manifest = File.ReadAllText("AutoOSW/manifest.txt"); // this is already up to date we dont need to do anything if (old_manifest == latest_update.manifest + "\n") { Console.WriteLine("Up to date... No action taken."); return; } } catch (Exception) { Console.WriteLine("No existing repo detected..."); // repo wasnt initialised properly before... this is fine } Console.WriteLine("Prepare for clone..."); // clone the repo to make sure we have it const string repo_url = "https://github.com/josh33901/AutoOSW.git"; Console.WriteLine("Removing old repo..."); try { Directory.Move("AutoOSW/", "AutoOSWOld/"); var d = new DirectoryInfo("AutoOSWOld/"); foreach (var file in d.GetFiles("*", SearchOption.AllDirectories)) { file.Attributes &= ~FileAttributes.ReadOnly; } Directory.Delete("AutoOSWOld/", true); } catch (Exception e) { Console.WriteLine("{0}", e.Message); } Console.WriteLine("Done."); Console.WriteLine("Cloning original repo..."); string git_path = Repository.Clone(repo_url, "AutoOSW/"); Console.WriteLine("Done."); Console.WriteLine("Downloading files from source..."); // download all the files into this directory foreach (var f in file_data) { Console.WriteLine("({0} <{1}>)", f.name, f.url); client.DownloadFile(f.url, "AutoOSW/" + f.name); } Console.WriteLine("Done."); Console.WriteLine("Writing manifest file..."); File.WriteAllText("AutoOSW/manifest.txt", latest_update.manifest + "\n"); // now that we have all the files git add them using (var repo = new Repository("AutoOSW/")) { Console.WriteLine("Staging repo..."); Commands.Stage(repo, "*"); Console.WriteLine("Done."); // Create the committer's signature and commit Console.WriteLine("Commiting to repo..."); Signature author = new Signature("josh33901", "*****@*****.**", DateTime.Now); Signature committer = author; string commit_message = "Update for manifest " + latest_update.manifest + " @ " + latest_update.date.ToShortDateString(); // Commit to the repository try { Commit commit = repo.Commit(commit_message, author, committer); } catch (EmptyCommitException) { Console.WriteLine("No changes detected... Not committing."); return; } Console.WriteLine("Done."); Console.WriteLine("Pushing to origin/master"); Remote remote = repo.Network.Remotes["origin"]; var options = new PushOptions { CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = username, Password = password } }; repo.Network.Push(remote, @"refs/heads/master", options); Console.WriteLine("Done."); Console.WriteLine("Action Finished."); } }
public void TurnFirstDeviceOff() { Remote remote = new Remote(); remote.TurnDeviceOff(1); }
public static Task FetchOrPullAsync( Repository repository, Remote remote, bool pull, IProgress<OperationProgress> progress, CancellationToken cancellationToken) { var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag; if(pull) { affectedReferences |= ReferenceType.LocalBranch; } var suppressedNotifications = repository.Monitor.BlockNotifications( RepositoryNotifications.BranchChanged, RepositoryNotifications.TagChanged); var state1 = RefsState.Capture(repository, affectedReferences); Task task; if(pull) { var p = new PullParameters(); if(remote != null) { p.Repository = remote.Name; } task = repository.Accessor.Pull.InvokeAsync(p, progress, cancellationToken); } else { var p = new FetchParameters(); if(remote != null) { p.Repository = remote.Name; } task = repository.Accessor.Fetch.InvokeAsync(p, progress, cancellationToken); } return task.ContinueWith( t => { progress.Report(new OperationProgress(Resources.StrRefreshingReferences.AddEllipsis())); repository.Refs.Refresh(affectedReferences); var state2 = RefsState.Capture(repository, affectedReferences); var changes = RefsDiff.Calculate(state1, state2); suppressedNotifications.Dispose(); if(changes != null && changes.Length != 0) { repository.OnUpdated(); } TaskUtility.PropagateFaultedStates(t); if(pull) { repository.Remotes.OnPullCompleted(remote, changes); } else { repository.Remotes.OnFetchCompleted(remote, changes); } }); }
public RemoteCheckerClient(Remote remote, RequestBuilder builder, ResponseParser parser) { this.remote = remote; this.builder = builder; this.parser = parser; }
public UploadWorldUI(Remote remote) : base(remote) { }
public Infrared(Remote remote) { _remote = remote; }
private async void asyncWriteToDoItem(Remote.ToDoItem item) { var binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.Name = bindName; binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; var endP = new EndpointAddress(uri); List<IToDoItem> exList = new List<IToDoItem>(0); using (var client = new Remote.ToDoManagerClient(binding, endP)) { await client.CreateToDoItemAsync(item); } }
public Task <int> SendToServerAsync(byte[] data) { return(Remote.SendAsync(data)); }
Remote.kResponse OnClientEvent(Remote.kAction k_Action) { Remote.kResponse k_Response = new Remote.kResponse(); // If multiple Clients try to connect at once if (mb_WaitButton) { k_Response.s_Result = "Sorry! Server is currently busy.\r\nTry again later"; return k_Response; } data1.Text = string.Format("{0}", k_Action.frictionL); data2.Text = string.Format("{0}", k_Action.frictionR); data3.Text = string.Format("{0}", k_Action.tempL); data4.Text = string.Format("{0}", k_Action.tempR); data5.Text = string.Format("{0}", k_Action.interiorTemp); data6.Text = string.Format("{0}", k_Action.brake); while (int.Parse(data6.Text) > 0) { data1.Text = string.Format("{0}", (int.Parse(data1.Text) + int.Parse(data6.Text))); data2.Text = string.Format("{0}", (int.Parse(data2.Text) + int.Parse(data6.Text))); if (int.Parse(data1.Text) > 100) data1.Text = "100"; if (int.Parse(data2.Text) > 100) data2.Text = "100"; System.Threading.Thread.Sleep(500); if (int.Parse(data1.Text) == 100 && int.Parse(data2.Text) == 100) data6.Text = "0"; } return k_Response; }
public Task <int> SendToServerAsync(ushort header, params object[] chunks) { return(Remote.SendAsync(HMessage.Construct(header, chunks))); }
private async Task ReadIncomingAsync() { byte[] packet = await Remote.ReceiveAsync().ConfigureAwait(false); HandleIncoming(packet, ++TotalIncoming); }
internal static void DoUpdate(bool create) { Remote.UpdateMainDatabase(create); Statistics.AddCommand("update"); }
private void client_LayerClientLogin(Remote.Layer.PRoConLayerClient sender) { this.InvokeOnAllEnabled("OnAccountLogin", sender.Username, sender.IPPort, sender.Privileges); }
public Page() { InitializeComponent(); // set width / height this.Width = Double.Parse(System.Windows.Browser.HtmlPage.Document.Body.GetProperty("clientWidth").ToString()); this.Height = Double.Parse(System.Windows.Browser.HtmlPage.Document.Body.GetProperty("clientHeight").ToString()); // we get a reference to the main canvas and add the Canvas maincanvas = (Canvas)this.FindName("Main"); // myCanvas.Background = new SolidColorBrush(Colors.White); // and then we instantiate a new Touch Listener on our main Canvas // so that contained objects can receive events from // multitouch and/or mouse input _wiimotelistener = new Remote(); //maincanvas); _wiimotelistener.AccelerationUpdate += new Remote.AccelerationUpdateHandler(_wiimotelistener_AccelerationUpdate); //new TouchListener.AccelerationUpdateHandler(multiTouchInput_AccelerationUpdate); // _migclient = new MIGClient(); _migclient.ServiceReady += new MIGClient.ServiceReadyHandler(_migclient_ServiceReady); _migclient.AddListener("WII0", _wiimotelistener); _migclient.Connect(); // _cursor = (Canvas)maincanvas.FindName("cursor"); _cursortr = new TransformHelper(_cursor); // _cursor.TransformHelper; _cursortr.Delay = 2.0; _cursortr.Translate = new Point((this.Width / 2) - 100, (this.Height) - 50); Point _balldirection = new Point(3, 6); Ellipse _ball = (Ellipse)maincanvas.FindName("ball"); TransformHelper _balltr = new TransformHelper(_ball); _balltr.Delay = 0.0; TextBlock _scoreText = (TextBlock)maincanvas.FindName("score"); _scoreText.Width = this.Width; int _score = 0; DispatcherTimer _timer = new DispatcherTimer(); _timer.Tick += (sender2, e2) => { _balltr.Translate = new Point(_balltr.Translate.X + _balldirection.X, _balltr.Translate.Y + _balldirection.Y); if (_balltr.Translate.X <= 0) { _balldirection.X = -_balldirection.X; } else if (_balltr.Translate.X + 50 >= this.Width) { _balldirection.X = -_balldirection.X; } if (_balltr.Translate.Y <= 0) { _balldirection.Y = -_balldirection.Y; } else if (_balltr.Translate.Y + 50 >= this.Height) { //_balldirection.Y = -_balldirection.Y; _balltr.Translate = new Point(_balltr.Translate.X, 1); _score = 0; _balldirection = new Point(5, 5); } IEnumerable<UIElement> hits = VisualTreeHelper.FindElementsInHostCoordinates(new Point(_balltr.Translate.X + 25, _balltr.Translate.Y + 50), this); foreach (UIElement uiel in hits) { if (uiel.Equals(_cursor)) { _balltr.Translate = new Point(_balltr.Translate.X + _balldirection.X, _balltr.Translate.Y - _balldirection.Y); _balldirection = new Point(_balldirection.X * 1.025, _balldirection.Y * 1.025); _balldirection.Y = -_balldirection.Y; _score += 10; } } _scoreText.Text = _score + ""; }; _timer.Interval = new TimeSpan(0, 0, 0, 0, 5); _timer.Start(); }