public void ExecuteTest1() { var complex = new Complex(3.1, 2.5); var exp = new Re(new ComplexNumber(complex)); Assert.Equal(complex.Real, exp.Execute()); }
public void ToStringTest() { var complex = new Complex(3.1, 2.5); var exp = new Re(new ComplexNumber(complex)); Assert.Equal("re(3.1+2.5i)", exp.ToString()); }
public void IlReNonMuovediDueCasa() { //Given Re re = new Re(Colore.Bianco); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.C, traversaPartenza: Traversa.Quarta, colonnaArrivo: Colonna.C, traversaArrivo: Traversa.Sesta); //Then Assert.False(esito); }
public void IlReMuoveIndieitroASinistradiUnaCasa() { //Given Re re = new Re(Colore.Bianco); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.C, traversaPartenza: Traversa.Quarta, colonnaArrivo: Colonna.B, traversaArrivo: Traversa.Terza); //Then Assert.True(esito); }
public void IlRePuoMuovereInDiagonaleDiUnaCasa() { //Given Re re = new Re(Colore.Nero); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.E, traversaPartenza: Traversa.Ottava, colonnaArrivo: Colonna.F, traversaArrivo: Traversa.Settima); //Then Assert.True(esito); }
public override string ToString() { string result = "0"; if (Re != 0) { result = Re.ToString(); } if (Im != 0) { result = string.Format("{0} {1}i", result, Im > 0 ? "+ " + Im : "- " + Im * -1); } return(result); }
public void MovimentoOrizzontale() { //Given Re re = new Re(Colore.Bianco); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.D, traversaPartenza: Traversa.Quarta, colonnaArrivo: Colonna.E, traversaArrivo: Traversa.Quarta); //Then Assert.True(esito); }
public void MovimentoNonValido() { //Given Re re = new Re(Colore.Bianco); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.D, traversaPartenza: Traversa.Quarta, colonnaArrivo: Colonna.H, traversaArrivo: Traversa.Prima); //Then Assert.False(esito); }
static void Main(string[] args) { StreamWriter writer; Scacchiera s = Scacchiera.Istanza; Pedone p = new Pedone(Colore.Bianco) { Posizione = s.GetCella('B', 2) }; Torre t = new Torre(Colore.Bianco) { Posizione = s.GetCella('C', 1) }; Alfiere a = new Alfiere(Colore.Bianco) { Posizione = s.GetCella('E', 2) }; Re re = new Re(Colore.Bianco) { Posizione = s.GetCella('E', 1) }; Regina r = new Regina(Colore.Bianco) { Posizione = s.GetCella('G', 3) }; Cavallo c = new Cavallo(Colore.Bianco) { Posizione = s.GetCella('F', 2) }; s.Print(); Console.WriteLine(); Console.WriteLine("".PadRight(40, '-')); Console.WriteLine(); try { p.Muovi(s.GetCella('B', 3)); t.Muovi(s.GetCella('C', 4)); a.Muovi(s.GetCella('B', 5)); re.Muovi(s.GetCella('F', 1)); r.Muovi(s.GetCella('G', 5)); c.Muovi(s.GetCella('E', 5)); s.Stampa(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
public void IlReNonPuòRestareFermo(Colore c) { //Given var re = new Re(c); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.A, traversaPartenza: Traversa.Prima, colonnaArrivo: Colonna.A, traversaArrivo: Traversa.Prima); //Then Assert.False(esito); }
/// <summary> /// Restart server if freeze/slowness detected /// </summary> private void RestartServer(ServerTimer timer) { if (this.IsStopping) { return; } this.IsStopping = true; if (timer == null || timer.Server == null) { return; } Log.WriteInfo("Stopping frozen server {0}...", timer.Server.Name); var id = timer.With(x => x.Server).With(x => x.Process).Return(x => x.Id, 0); if (id == 0) { Log.WriteInfo("Unable to restart server {0}. Unknown process id.", timer.Server.Name); return; } Util.Try(() => { var process = Process.GetProcessById(id); if (process == null) { Log.WriteInfo("Unable to restart server {0}. Process not found.", timer.Server.Name); return; } if (string.IsNullOrWhiteSpace(this.Server.Process.CommandLine)) { Log.WriteInfo("Unable to restart a server {0}. Empty command line!", timer.Server.Name); return; } process.Kill(); }, false); Util.Try(() => { Thread.Sleep(1000); Log.WriteInfo("Starting server {0}...", timer.Server.Name); var exeFile = Re.GetSubString(this.Server.Process.CommandLine, @"^(.*exe).*$"); var arguments = Re.GetSubString(this.Server.Process.CommandLine, @"^.*?\s(.*)$"); var directory = this.Server.Process.Path; this.StartProcess(exeFile, arguments, directory); }); }
public void IlRePuoMuovereInDiagonaleDiUno(Colore colore) { //Given Re re = new Re(colore); Scacchiera scacchiera = new Scacchiera(); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.A, traversaPartenza: Traversa.Prima, colonnaArrivo: Colonna.B, traversaArrivo: Traversa.Seconda, scacchiera: scacchiera); //Then Assert.True(esito); }
public void IlRePuoMuovereSoloDiUno(Colore colore) { //Given Re re = new Re(colore); Scacchiera scacchiera = new Scacchiera(); //When bool esito = re.PuòMuovere( colonnaPartenza: Colonna.F, traversaPartenza: Traversa.Ottava, colonnaArrivo: Colonna.C, traversaArrivo: Traversa.Quarta, scacchiera: scacchiera); //Then Assert.False(esito); }
public void GetStreamId() { checkTimer = new Timer((obj) => { var youtubeChannel = obj as YoutubeChannel; if (String.IsNullOrWhiteSpace(ChannelName)) { return; } var channelUrl = webClient.GetRedirectUrl(String.Format(@"https://www.youtube.com/user/{0}/live", ChannelName.Replace("#", ""))); if (channelUrl == null || !channelUrl.Contains("v=")) { channelUrl = webClient.GetRedirectUrl(String.Format(@"https://www.youtube.com/channel/{0}/live", ChannelName.Replace("#", ""))); } youtubeChannel.checkTimer.Change(15000, 15000); if (String.IsNullOrWhiteSpace(channelUrl)) { return; } humanReadableChannelName = this.With(x => webClient.Download(channelUrl)) .With(x => Re.GetSubString(x, @"name=""title""\s*content=""(.*?)""")); youtubeChannel.checkTimer.Change(60000, 60000); var id = Re.GetSubString(channelUrl, @"v=([^&]+)"); if (!String.IsNullOrWhiteSpace(id) && videoId != id) { youtubeChannel.videoId = id; youtubeChannel.checkTimer.Change(Timeout.Infinite, Timeout.Infinite); if (chatPoller != null) { chatPoller.Stop(); } if (statsPoller != null) { statsPoller.Stop(); } youtubeChannel.SetupPollers(); } }, this, 0, 15000); }
private Uri GetServerUri() { var re = @"this\.server=.*?""(.*?)"""; var serverUrl = this.With(x => GoodgameGet("http://goodgame.ru/js/minified/chat.js")) .With(x => Re.GetSubString(x, re)); Uri uri; if (Uri.TryCreate(serverUrl, UriKind.Absolute, out uri)) { return(uri); } else { return(null); } }
public bool Login() { lock (loginLock) { _opcode = 0; List <KeyValuePair <string, string> > cookies = new List <KeyValuePair <string, string> >(); isLoggedIn = false; if (String.IsNullOrEmpty(_login) || String.IsNullOrEmpty(_password)) { return(false); } var result = loginWC.DownloadString(loginUrl); if (String.IsNullOrEmpty(result)) { return(false); } var auth_token = Re.GetSubString(result, reAuthToken, 1); if (String.IsNullOrEmpty(result)) { return(false); } loginWC.ContentType = ContentType.UrlEncoded; result = loginWC.UploadString(loginUrl, String.Format(loginParams, HttpUtility.UrlEncode(_login), HttpUtility.UrlEncode(_password), HttpUtility.UrlEncode(auth_token))); var assetsHost = Re.GetSubString(result, reAssetsHost, 1); if (String.IsNullOrEmpty(assetsHost)) { return(false); } _user = Re.GetSubString(result, reUserName, 1); if (String.IsNullOrEmpty(_user)) { return(false); } isLoggedIn = true; return(true); } }
private void ReadRawMessage(string rawMessage) { Log.WriteInfo("Connectcast raw message received {0}", rawMessage); var command = Re.GetSubString(rawMessage, @"([^\[]*)"); var data = this.With(x => Re.GetSubString(rawMessage, @".*?(\[.*)$")) .With(x => JsonUtil.ParseArray(x)); if (String.IsNullOrWhiteSpace(command)) { return; } if (packetHandlers.ContainsKey(command)) { packetHandlers[command](this, data); } }
//-- в строку public override string ToString() { if (Im != 0) { if (Im > 0) { return(Re + "+i" + Im); } else { return(Re.ToString() + "-i" + Math.Abs(Im)); } } else { return(Re.ToString()); } }
private string GoodgameGet(string url) { var content = webClient.Download(url); if (content != null && content.Length < 1000 && content.Contains("location.href=")) { var cookieName = Re.GetSubString(content, @"\.cookie=\""(.*?)="); var cookieValue = Re.GetSubString(content, @"\.cookie=\"".*?=(.*?)"""); var newHref = Re.GetSubString(content, @"location\.href=""(.*?)"""); if (!String.IsNullOrWhiteSpace(cookieName) && !String.IsNullOrWhiteSpace(cookieValue) && !String.IsNullOrWhiteSpace(newHref)) { webClient.Encoding = System.Text.Encoding.UTF8; webClient.SetCookie(cookieName, cookieValue, "goodgame.ru"); content = webClient.Download(newHref); } } return(content); }
public bool LoginWithUsername() { var indexPage = LoginWebClient.Download("http://sc2tv.ru"); if (String.IsNullOrWhiteSpace(indexPage)) { return(false); } var username = Config.GetParameterValue("Username") as string; var password = Config.GetParameterValue("Password") as string; Config.SetParameterValue("Cookies", null); if (String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password)) { IsAnonymous = true; return(true); } var formBuildId = Re.GetSubString(indexPage, @"form_build_id.*?value=""(.*?)"""); var formId = Re.GetSubString(indexPage, @"form_id.*?value=""(.*?)"""); if (String.IsNullOrWhiteSpace(formBuildId) || String.IsNullOrWhiteSpace(formId) || String.IsNullOrWhiteSpace(username) || String.IsNullOrWhiteSpace(password)) { return(false); } LoginWebClient.ContentType = ContentType.UrlEncodedUTF8; LoginWebClient.Upload("http://sc2tv.ru/node", String.Format("name={0}&pass={1}&form_build_id={2}&form_id={3}", Url.Encode(username), Url.Encode(password), formBuildId, formId)); if (String.IsNullOrEmpty(LoginWebClient.CookieValue("drupal_uid", "http://sc2tv.ru"))) { return(false); } Config.SetParameterValue("Cookies", JsonUtil.ToJson(LoginWebClient.CookiesTable)); Config.SetParameterValue("AuthTokenCredentials", username + password); return(LoginWithCookies()); }
private FileStream GetFile(string path) { var fullPath = path; if (!Re.IsMatch(path, @"^.:\\.*$")) { fullPath = (webContentFolder + path.Replace("/", @"\")).Replace(@"\\", @"\"); } try { return(File.OpenRead(fullPath)); } catch { Log.WriteError("Web server is unable to read a file: {0}", fullPath); return(null); } }
public bool SetTopic() { if (string.IsNullOrWhiteSpace(ownChannelId) || !Status.IsLoggedIn) { return(false); } var searchGame = Games.FirstOrDefault(game => game.Name.Equals(Info.CurrentGame.Name, StringComparison.InvariantCultureIgnoreCase)); if (searchGame == null) { QueryGameList(Info.CurrentGame.Name, null); searchGame = Games.FirstOrDefault(game => game.Name.Equals(Info.CurrentGame.Name, StringComparison.InvariantCultureIgnoreCase)); } if (searchGame != null) { Info.CurrentGame.Id = searchGame.Id; } var parameters = String.Format("objType=7&objId={0}&title={1}&gameId={2}", ownChannelId, HttpUtility.UrlEncode(Info.Topic), Info.CurrentGame.Id); webClient.ContentType = ContentType.UrlEncoded; webClient.Headers["X-Requested-With"] = "XMLHttpRequest"; webClient.Upload("http://goodgame.ru/ajax/channel/update_title/", parameters); //Check if succeed var content = GoodgameGet(String.Format(@"http://goodgame.ru/channel/{0}", ownChannel)); if (!String.IsNullOrWhiteSpace(content)) { if (Info.Topic.Equals(Re.GetSubString(content, @"<title>([^<]*)</title>")) && Info.CurrentGame.Name.Equals(this.With(x => Re.GetSubString(content, @"StreamTitleEdit[^,]*,[^,]*,[^,]*,[^,]*,[^']*'([^']*)'")) .With(x => x.Trim()))) { return(true); } } return(false); }
public void ilRePuòMangiarePezzoAvversarioInOrizzontaleVerticaleDiagonale( Colonna colonnaPartenza, Traversa traversaPartenza, Colonna colonnaArrivo, Traversa traversaArrivo, Colore colore, Colore colorePezzoBloccante, Colonna colonnaPezzoBloccante, Traversa traversaPezzoBloccante) { //Given Re re = new Re(colore); Scacchiera scacchiera = new Scacchiera(); scacchiera[colonnaPezzoBloccante, traversaPezzoBloccante].PezzoPresente = new Pedone(colorePezzoBloccante); //When bool esito = re.PuòMuovere(colonnaPartenza, traversaPartenza, colonnaArrivo, traversaArrivo, scacchiera); //Then Assert.True(esito); }
public void IlReNonSiPuòMuovereSeUnPezzoDelloStessoColoreBloccaLoSpostamento( Colonna colonnaPartenza, Traversa traversaPartenza, Colonna colonnaArrivo, Traversa traversaArrivo, Colore colore, Colore colorePezzoBloccante, Colonna colonnaPezzoBloccante, Traversa traversaPezzoBloccante) { //Given Re re = new Re(colore); Scacchiera scacchiera = new Scacchiera(); scacchiera[colonnaPezzoBloccante, traversaPezzoBloccante].PezzoPresente = new Pedone(colorePezzoBloccante); //When bool esito = re.PuòMuovere(colonnaPartenza, traversaPartenza, colonnaArrivo, traversaArrivo, scacchiera); //Then Assert.False(esito); }
public static void Register(HttpConfiguration config) { // Web API configuration and services config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors); }
public override string ToString() { if (Im != 0) { if (Re > 0) { return(Im + "*i+" + Re); } else if (Re < 0) { return(Im + "*i" + Re); } else { return(Im + "*i"); } } else { return(Re.ToString()); } }
public void replaceAll(NSObject sender) { Unused.Value = sender; OnUpdateLists(); string dir = Directory.description(); Re re = new Re { UseRegex = UseRegex, CaseSensitive = CaseSensitive, MatchWords = MatchWords, WithinText = WithinText, Pattern = FindText, }; var replaceAll = new ReplaceAll(dir, re.Make(), ReplaceText, Include, AllExcludes()); replaceAll.Title = string.Format("Replacing '{0}' with '{1}'.", FindText, ReplaceText); replaceAll.Run(); Unused.Value = new FindProgressController(replaceAll); // FindProgressController will handle retain counts and references }
public void findAll(NSObject sender) { Unused.Value = sender; OnUpdateLists(); string dir = Directory.description(); Re re = new Re { UseRegex = UseRegex, CaseSensitive = CaseSensitive, MatchWords = MatchWords, WithinText = WithinText, Pattern = FindText, }; var findAll = new FindAll(dir, re.Make(), Include, AllExcludes()); findAll.Title = string.Format("Find '{0}'", FindText); findAll.Run(); Unused.Value = new FindResultsController(findAll); // FindResultsController will handle retain counts and references }
/// <summary> /// Creates an expression object from <see cref="FunctionToken"/>. /// </summary> /// <param name="token">The function token.</param> /// <returns>An expression.</returns> protected virtual IExpression CreateFunction(FunctionToken token) { IExpression exp; switch (token.Function) { case Functions.Add: exp = new Add(); break; case Functions.Sub: exp = new Sub(); break; case Functions.Mul: exp = new Mul(); break; case Functions.Div: exp = new Div(); break; case Functions.Pow: exp = new Pow(); break; case Functions.Absolute: exp = new Abs(); break; case Functions.Sine: exp = new Sin(); break; case Functions.Cosine: exp = new Cos(); break; case Functions.Tangent: exp = new Tan(); break; case Functions.Cotangent: exp = new Cot(); break; case Functions.Secant: exp = new Sec(); break; case Functions.Cosecant: exp = new Csc(); break; case Functions.Arcsine: exp = new Arcsin(); break; case Functions.Arccosine: exp = new Arccos(); break; case Functions.Arctangent: exp = new Arctan(); break; case Functions.Arccotangent: exp = new Arccot(); break; case Functions.Arcsecant: exp = new Arcsec(); break; case Functions.Arccosecant: exp = new Arccsc(); break; case Functions.Sqrt: exp = new Sqrt(); break; case Functions.Root: exp = new Root(); break; case Functions.Ln: exp = new Ln(); break; case Functions.Lg: exp = new Lg(); break; case Functions.Lb: exp = new Lb(); break; case Functions.Log: exp = new Log(); break; case Functions.Sineh: exp = new Sinh(); break; case Functions.Cosineh: exp = new Cosh(); break; case Functions.Tangenth: exp = new Tanh(); break; case Functions.Cotangenth: exp = new Coth(); break; case Functions.Secanth: exp = new Sech(); break; case Functions.Cosecanth: exp = new Csch(); break; case Functions.Arsineh: exp = new Arsinh(); break; case Functions.Arcosineh: exp = new Arcosh(); break; case Functions.Artangenth: exp = new Artanh(); break; case Functions.Arcotangenth: exp = new Arcoth(); break; case Functions.Arsecanth: exp = new Arsech(); break; case Functions.Arcosecanth: exp = new Arcsch(); break; case Functions.Exp: exp = new Exp(); break; case Functions.GCD: exp = new GCD(); break; case Functions.LCM: exp = new LCM(); break; case Functions.Factorial: exp = new Fact(); break; case Functions.Sum: exp = new Sum(); break; case Functions.Product: exp = new Product(); break; case Functions.Round: exp = new Round(); break; case Functions.Floor: exp = new Floor(); break; case Functions.Ceil: exp = new Ceil(); break; case Functions.Derivative: exp = new Derivative(); break; case Functions.Simplify: exp = new Simplify(); break; case Functions.Del: exp = new Del(); break; case Functions.Define: exp = new Define(); break; case Functions.Vector: exp = new Vector(); break; case Functions.Matrix: exp = new Matrix(); break; case Functions.Transpose: exp = new Transpose(); break; case Functions.Determinant: exp = new Determinant(); break; case Functions.Inverse: exp = new Inverse(); break; case Functions.If: exp = new If(); break; case Functions.For: exp = new For(); break; case Functions.While: exp = new While(); break; case Functions.Undefine: exp = new Undefine(); break; case Functions.Im: exp = new Im(); break; case Functions.Re: exp = new Re(); break; case Functions.Phase: exp = new Phase(); break; case Functions.Conjugate: exp = new Conjugate(); break; case Functions.Reciprocal: exp = new Reciprocal(); break; case Functions.Min: exp = new Min(); break; case Functions.Max: exp = new Max(); break; case Functions.Avg: exp = new Avg(); break; case Functions.Count: exp = new Count(); break; case Functions.Var: exp = new Var(); break; case Functions.Varp: exp = new Varp(); break; case Functions.Stdev: exp = new Stdev(); break; case Functions.Stdevp: exp = new Stdevp(); break; default: exp = null; break; } var diff = exp as DifferentParametersExpression; if (diff != null) diff.ParametersCount = token.CountOfParams; return exp; }
public void ReTest() { var tokens = new List<IToken> { new FunctionToken(Functions.Re, 1), new SymbolToken(Symbols.OpenBracket), new ComplexNumberToken(new Complex(3, -2)), new SymbolToken(Symbols.CloseBracket) }; var exp = parser.Parse(tokens); var expected = new Re(new ComplexNumber(new Complex(3, -2))); Assert.Equal(expected, exp); }
public void FindNext() { try { IText text = DoFindTextWindow(); int index = text.Selection.location + text.Selection.length; if (m_find.UseRegex && text.Selection.length == 0) if (FindText == "^" || FindText == "$") ++index; int length = text.Text.Length - index; DoMakeRe(); // If we are searching for new text then we'll remember where we // started so we can indicate to the user when the entire document // has been searched. if (m_re != m_oldFindRe) // note that we have to use Re because Regex is too lame to override Equals { m_oldFindIndex = text.Selection.location; m_oldWrapped = false; m_oldFindRe = m_re; } Match match = m_regex.Match(text.Text, index, length); // find wrap if (!match.Success) { var defaults = NSUserDefaults.standardUserDefaults(); var defaultsKey = NSString.Create("find wrap"); bool wrap = defaults.objectForKey(defaultsKey).IsNil() || defaults.boolForKey(defaultsKey).To<bool>(); if (wrap) { match = m_regex.Match(text.Text, 0, index); m_oldWrapped = true; } } if (match.Success) { var window = text.Boss.Get<IWindow>(); window.Window.makeKeyAndOrderFront(null); text.Selection = new NSRange(match.Index, match.Length); text.ShowSelection(); if (m_oldWrapped && match.Index >= m_oldFindIndex) { var editor = text.Boss.Get<ITextEditor>(); editor.ShowInfo("Reached Start"); m_oldWrapped = false; } } else Functions.NSBeep(); } catch (Exception e) { Log.WriteLine(TraceLevel.Error, "App", "Couldn't find next"); Log.WriteLine(TraceLevel.Error, "App", e.ToString()); NSString message = NSString.Create(e.Message); Unused.Value = Functions.NSRunCriticalAlertPanel(null, message); } }
private void DoMakeRe() { m_re = new Re { UseRegex = m_find.UseRegex, CaseSensitive = m_find.CaseSensitive, MatchWords = m_find.MatchWords, WithinText = m_find.WithinText, Pattern = FindText, }; m_regex = m_re.Make(); }