Here are the examples of the csharp api string.Equals(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
725 Examples
19
View Source File : CommandPacket.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public CommandPacket Command(string cmd, string subcmd = null)
{
if (!string.IsNullOrWhiteSpace(_command) && _command.Equals(_input.FirstOrDefault())) _input.RemoveAt(0);
if (!string.IsNullOrWhiteSpace(_subcommand) && _subcommand.Equals(_input.FirstOrDefault())) _input.RemoveAt(0);
_command = cmd;
_subcommand = subcmd;
if (!string.IsNullOrWhiteSpace(_command))
{
if (!string.IsNullOrWhiteSpace(_subcommand)) _input.Insert(0, _subcommand);
_input.Insert(0, _command);
}
return this;
}
19
View Source File : SerialBusManager.cs
License : GNU General Public License v3.0
Project Creator : a4004
License : GNU General Public License v3.0
Project Creator : a4004
private static string GetDeviceName(string comPort)
{
try
{
string result = new ManagementObjectSearcher("Select * from Win32_SerialPort")
.Get().OfType<ManagementObject>()
.Where(o => comPort.Equals(o["DeviceID"]))
.First().Properties.OfType<PropertyData>()
.Where(t => t.Name.Equals("Description"))
.First().Value as string;
return result;
}
catch
{
return $"Unknown device ({comPort})";
}
}
19
View Source File : LogTrace.cs
License : GNU Affero General Public License v3.0
Project Creator : active-logic
License : GNU Affero General Public License v3.0
Project Creator : active-logic
public bool Matches(object scope, string reason)
=> (this.scope.ToString()).Equals(scope)
&& this.reason == TraceFormat.ReasonField(reason);
19
View Source File : OffsetConverter.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.FirstOrDefault(v => v == DependencyProperty.UnsetValue) != null)
{
return double.NaN;
}
double placementTargetWidth = (double)values[0];
double toolTipWidth = (double)values[1];
if ("Center".Equals(parameter))
{
return (placementTargetWidth / 2.0) - (toolTipWidth / 2.0);
}
else if ("Right".Equals(parameter))
{
return placementTargetWidth - toolTipWidth;
}
return 0;
}
19
View Source File : CSRedisClientPipe.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public CSRedisClientPipe Set(string key, string value, int expireSeconds = -1, CSRedisExistence? exists = null) =>
PipeCommand(key, (c, k) => {
if (expireSeconds > 0 || exists != null) c.Client.Set(k, value, expireSeconds > 0 ? new int?(expireSeconds) : null, exists == CSRedisExistence.Nx ? new RedisExistence?(RedisExistence.Nx) : (exists == CSRedisExistence.Xx ? new RedisExistence?(RedisExistence.Xx) : null));
else c.Client.Set(k, value);
}, v => "OK".Equals(v));
19
View Source File : CSRedisClientPipe.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public CSRedisClientPipe SetBytes(string key, byte[] value, int expireSeconds = -1, CSRedisExistence? exists = null) =>
PipeCommand(key, (c, k) => {
if (expireSeconds > 0 || exists != null) c.Client.Set(k, value, expireSeconds > 0 ? new int?(expireSeconds) : null, exists == CSRedisExistence.Nx ? new RedisExistence?(RedisExistence.Nx) : (exists == CSRedisExistence.Xx ? new RedisExistence?(RedisExistence.Xx) : null));
else c.Client.Set(k, value);
}, v => "OK".Equals(v));
19
View Source File : PageService.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
public FrameworkElement? GetPage(string? pageName)
{
if (pageName == null)
{
return null;
}
if (pageName.Equals(OperatorPageName))
{
return _operatorPage.Value;
}
if (pageName.Equals(SettingsPageName))
{
return _settingsPage.Value;
}
throw new ArgumentOutOfRangeException(nameof(pageName));
}
19
View Source File : PageService.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
private void SetScrollerPosition(string? pageName)
{
if (pageName == null)
{
return;
}
if (pageName.Equals(OperatorPageName))
{
ScrollViewer?.ScrollToVerticalOffset(_operatorPageScrollerPosition);
}
else if (pageName.Equals(SettingsPageName))
{
ScrollViewer?.ScrollToVerticalOffset(_settingsPageScrollerPosition);
}
}
19
View Source File : CommandLineOptions.cs
License : MIT License
Project Creator : Apr4h
License : MIT License
Project Creator : Apr4h
public bool CheckIfNoArgs()
{
if (Processes.Equals(false) && File.Equals(false) && InjectedThreads.Equals(false)
&& Help.Equals(false) && Directory.Equals(false))
{
return true;
}
else
{
return false;
}
}
19
View Source File : Sources.cs
License : MIT License
Project Creator : azist
License : MIT License
Project Creator : azist
public override bool Equals(object obj)
{
return FileName.Equals(obj);
}
19
View Source File : Sources.cs
License : MIT License
Project Creator : azist
License : MIT License
Project Creator : azist
public override bool Equals(object obj)
{
return Content.Equals(obj);
}
19
View Source File : VisibilityToInverseVisibilityConverter.cs
License : MIT License
Project Creator : benruehl
License : MIT License
Project Creator : benruehl
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Visibility valueAsVisibility = (Visibility)value;
if (valueAsVisibility == Visibility.Visible)
return "hidden".Equals(parameter) ? Visibility.Hidden : Visibility.Collapsed;
return Visibility.Visible;
}
19
View Source File : System_StringWrap.cs
License : MIT License
Project Creator : bjfumac
License : MIT License
Project Creator : bjfumac
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int Equals(IntPtr L)
{
try
{
int count = LuaDLL.lua_gettop(L);
if (count == 2 && TypeChecker.CheckTypes<string>(L, 2))
{
System.String obj = (System.String)ToLua.CheckObject(L, 1, typeof(System.String));
string arg0 = ToLua.ToString(L, 2);
bool o = obj != null ? obj.Equals(arg0) : arg0 == null;
LuaDLL.lua_pushboolean(L, o);
return 1;
}
else if (count == 2 && TypeChecker.CheckTypes<object>(L, 2))
{
System.String obj = (System.String)ToLua.CheckObject(L, 1, typeof(System.String));
object arg0 = ToLua.ToVarObject(L, 2);
bool o = obj != null ? obj.Equals(arg0) : arg0 == null;
LuaDLL.lua_pushboolean(L, o);
return 1;
}
else if (count == 3)
{
System.String obj = (System.String)ToLua.CheckObject(L, 1, typeof(System.String));
string arg0 = ToLua.CheckString(L, 2);
System.StringComparison arg1 = (System.StringComparison)ToLua.CheckObject(L, 3, typeof(System.StringComparison));
bool o = obj.Equals(arg0, arg1);
LuaDLL.lua_pushboolean(L, o);
return 1;
}
else
{
return LuaDLL.luaL_throw(L, "invalid arguments to method: System.String.Equals");
}
}
catch (Exception e)
{
return LuaDLL.toluaL_exception(L, e);
}
}
19
View Source File : FOTreeBuilder.cs
License : Apache License 2.0
Project Creator : cajuncoding
License : Apache License 2.0
Project Creator : cajuncoding
internal void Parse(XmlReader reader)
{
int buflen = 500;
char[] buffer = new char[buflen];
try
{
object nsuri = reader.NameTable.Add("http://www.w3.org/2000/xmlns/");
FonetDriver.ActiveDriver.FireFonetInfo("Building formatting object tree");
streamRenderer.StartRenderer();
var sw = System.Diagnostics.Stopwatch.StartNew();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Attributes atts = new Attributes();
while (reader.MoveToNextAttribute())
{
if (!reader.NamespaceURI.Equals(nsuri))
{
SaxAttribute newAtt = new SaxAttribute();
newAtt.Name = reader.Name;
newAtt.NamespaceURI = reader.NamespaceURI;
newAtt.Value = reader.Value;
atts.attArray.Add(newAtt);
}
}
reader.MoveToElement();
StartElement(reader.NamespaceURI, reader.LocalName, atts.TrimArray());
if (reader.IsEmptyElement)
{
EndElement();
}
break;
case XmlNodeType.EndElement:
EndElement();
break;
case XmlNodeType.Text:
char[] chars = reader.ReadString().ToCharArray();
if (currentFObj != null)
{
currentFObj.AddCharacters(chars, 0, chars.Length);
}
if (reader.NodeType == XmlNodeType.Element)
{
goto case XmlNodeType.Element;
}
if (reader.NodeType == XmlNodeType.EndElement)
{
goto case XmlNodeType.EndElement;
}
break;
default:
break;
}
}
FonetDriver.ActiveDriver.FireFonetInfo(String.Format("Parsing completed in [{0}] seconds.", sw.Elapsed.TotalSeconds));
FonetDriver.ActiveDriver.FireFonetInfo("Parsing of doreplacedent complete, stopping renderer.");
streamRenderer.StopRenderer();
}
catch (Exception exception)
{
FonetDriver.ActiveDriver.FireFonetError(exception.ToString());
}
finally
{
if (reader.ReadState != ReadState.Closed)
{
reader.Close();
}
}
}
19
View Source File : FOTreeBuilder.cs
License : Apache License 2.0
Project Creator : cajuncoding
License : Apache License 2.0
Project Creator : cajuncoding
internal void Parse(XmlReader reader)
{
int buflen = 500;
char[] buffer = new char[buflen];
try
{
object nsuri = reader.NameTable.Add("http://www.w3.org/2000/xmlns/");
FonetDriver.ActiveDriver.FireFonetInfo("Building formatting object tree");
streamRenderer.StartRenderer();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Attributes atts = new Attributes();
while (reader.MoveToNextAttribute())
{
if (!reader.NamespaceURI.Equals(nsuri))
{
SaxAttribute newAtt = new SaxAttribute();
newAtt.Name = reader.Name;
newAtt.NamespaceURI = reader.NamespaceURI;
newAtt.Value = reader.Value;
atts.attArray.Add(newAtt);
}
}
reader.MoveToElement();
StartElement(reader.NamespaceURI, reader.LocalName, atts.TrimArray());
if (reader.IsEmptyElement)
{
EndElement();
}
break;
case XmlNodeType.EndElement:
EndElement();
break;
case XmlNodeType.Text:
char[] chars = reader.ReadString().ToCharArray();
if (currentFObj != null)
{
currentFObj.AddCharacters(chars, 0, chars.Length);
}
if (reader.NodeType == XmlNodeType.Element)
{
goto case XmlNodeType.Element;
}
if (reader.NodeType == XmlNodeType.EndElement)
{
goto case XmlNodeType.EndElement;
}
break;
default:
break;
}
}
FonetDriver.ActiveDriver.FireFonetInfo("Parsing of doreplacedent complete, stopping renderer");
streamRenderer.StopRenderer();
}
catch (Exception exception)
{
FonetDriver.ActiveDriver.FireFonetError(exception.ToString());
}
finally
{
if (reader.ReadState != ReadState.Closed)
{
reader.Close();
}
}
}
19
View Source File : SubscriptionTestBase.cs
License : MIT License
Project Creator : ChilliCream
License : MIT License
Project Creator : ChilliCream
protected async Task<IReadOnlyDictionary<string, object>> WaitForMessage(
WebSocket webSocket,
string type,
TimeSpan timeout)
{
var timer = Stopwatch.StartNew();
try
{
while (timer.Elapsed <= timeout)
{
await Task.Delay(50);
IReadOnlyDictionary<string, object> message =
await webSocket.ReceiveServerMessageAsync();
if (message != null && type.Equals(message["type"]))
{
return message;
}
if (message != null &&
!MessageTypes.Connection.KeepAlive.Equals(message["type"]))
{
throw new InvalidOperationException(
$"Unexpected message type: {message["type"]}");
}
}
}
finally
{
timer.Stop();
}
return null;
}
19
View Source File : Tools.cs
License : MIT License
Project Creator : Codectory
License : MIT License
Project Creator : Codectory
public static void SetAutoStart(string applicationName, string filePath, bool autostart)
{
RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
object existing = rk.GetValue(applicationName);
if (filePath.Equals(existing) && autostart)
return;
if (rk.GetValue(applicationName) == null && !autostart)
return;
if (autostart)
rk.SetValue(applicationName, filePath);
else
rk.DeleteValue(applicationName, false);
}
19
View Source File : TextValueItem.cs
License : MIT License
Project Creator : dahall
License : MIT License
Project Creator : dahall
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj)) return true;
switch (obj)
{
case null:
return false;
case TextValueItem<T> lci:
return Equals(lci);
case string s:
return Text.Equals(obj);
}
return obj.GetType() == Value.GetType() && Value.Equals(obj);
}
19
View Source File : PdfName.cs
License : MIT License
Project Creator : damienbod
License : MIT License
Project Creator : damienbod
public override bool Equals(object obj)
{
return _value.Equals(obj);
}
19
View Source File : QueryExpressionParser.cs
License : MIT License
Project Creator : Danielku15
License : MIT License
Project Creator : Danielku15
private Expression LogicalOr()
{
var left = LogicalAnd();
while (CurrentTokenKind == QueryExpressionTokenKind.Keyword && "or".Equals(TokenData))
{
NextToken();
var right = LogicalAnd();
left = Expression.Or(left, right);
}
return left;
}
19
View Source File : QueryExpressionParser.cs
License : MIT License
Project Creator : Danielku15
License : MIT License
Project Creator : Danielku15
private Expression LogicalAnd()
{
var left = Comparison();
while (CurrentTokenKind == QueryExpressionTokenKind.Keyword && "and".Equals(TokenData))
{
NextToken();
var right = Comparison();
left = Expression.And(left, right);
}
return left;
}
19
View Source File : PgpPublicKey.cs
License : MIT License
Project Creator : dcomms
License : MIT License
Project Creator : dcomms
public IEnumerable GetSignaturesForId(
string id)
{
if (id == null)
throw new ArgumentNullException("id");
for (int i = 0; i != ids.Count; i++)
{
if (id.Equals(ids[i]))
{
return new EnumerableProxy((IList)idSigs[i]);
}
}
return null;
}
19
View Source File : PbeUtilities.cs
License : MIT License
Project Creator : dcomms
License : MIT License
Project Creator : dcomms
public static bool IsPkcs12(
string algorithm)
{
string mechanism = (string)algorithms[Platform.ToUpperInvariant(algorithm)];
return mechanism != null && Pkcs12.Equals(algorithmType[mechanism]);
}
19
View Source File : PbeUtilities.cs
License : MIT License
Project Creator : dcomms
License : MIT License
Project Creator : dcomms
public static bool IsPkcs5Scheme1(
string algorithm)
{
string mechanism = (string)algorithms[Platform.ToUpperInvariant(algorithm)];
return mechanism != null && Pkcs5S1.Equals(algorithmType[mechanism]);
}
19
View Source File : PbeUtilities.cs
License : MIT License
Project Creator : dcomms
License : MIT License
Project Creator : dcomms
public static bool IsPkcs5Scheme2(
string algorithm)
{
string mechanism = (string)algorithms[Platform.ToUpperInvariant(algorithm)];
return mechanism != null && Pkcs5S2.Equals(algorithmType[mechanism]);
}
19
View Source File : PbeUtilities.cs
License : MIT License
Project Creator : dcomms
License : MIT License
Project Creator : dcomms
public static bool IsOpenSsl(
string algorithm)
{
string mechanism = (string)algorithms[Platform.ToUpperInvariant(algorithm)];
return mechanism != null && OpenSsl.Equals(algorithmType[mechanism]);
}
19
View Source File : StringDropdownList.cs
License : GNU General Public License v3.0
Project Creator : DeepHydro
License : GNU General Public License v3.0
Project Creator : DeepHydro
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
_editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
// use a list box
ListBox lb = new ListBox();
lb.SelectionMode = SelectionMode.One;
lb.SelectedValueChanged += OnListBoxSelectedValueChanged;
var tool = context.Instance;
foreach (var atr in context.PropertyDescriptor.Attributes)
{
if (atr.GetType() == typeof(DropdownListSource))
{
var ds = atr as DropdownListSource;
var list = tool.GetType().GetProperty(ds.SourceName).GetValue(tool) as string[];
if (list != null)
{
foreach (var str in list)
{
int index = lb.Items.Add(str);
if (str.Equals(value))
{
lb.SelectedIndex = index;
}
}
break;
}
}
}
// show this model stuff
_editorService.DropDownControl(lb);
if (lb.SelectedItem == null) // no selection, return the preplaceded-in value as is
return value;
return lb.SelectedItem;
}
19
View Source File : Policy.cs
License : Apache License 2.0
Project Creator : Devolutions
License : Apache License 2.0
Project Creator : Devolutions
public bool RemoveFilteredPolicy(string sec, string pType, int fieldIndex, params string[] fieldValues)
{
List<List<string>> tmp = new List<List<string>>();
List<List<string>> policy = this.GetPolicy(sec, pType);
bool res = false;
foreach (List<string> rule in policy)
{
bool matched = true;
foreach (var fieldValue in fieldValues.Select((s, i) => new {i, s}))
{
if (!fieldValue.Equals(string.Empty) && !rule[fieldIndex + fieldValue.i].Equals(fieldValue))
{
matched = false;
break;
}
}
if (matched)
{
res = true;
}
else
{
tmp.Add(rule);
}
}
this.Getreplacedertion(sec, pType).Policy = tmp;
return res;
}
19
View Source File : ColorString.cs
License : MIT License
Project Creator : dotnet-shell
License : MIT License
Project Creator : dotnet-shell
public override bool Equals(object obj)
{
return Text.Equals(obj);
}
19
View Source File : PgpPublicKey.cs
License : GNU General Public License v3.0
Project Creator : DSorlov
License : GNU General Public License v3.0
Project Creator : DSorlov
public IEnumerable GetSignaturesForId(
string id)
{
if (id == null)
throw new ArgumentNullException("id");
for (int i = 0; i != ids.Count; i++)
{
if (id.Equals(ids[i]))
{
return new EnumerableProxy((IList)idSigs[i]);
}
}
return null;
}
19
View Source File : PbeUtilities.cs
License : GNU General Public License v3.0
Project Creator : DSorlov
License : GNU General Public License v3.0
Project Creator : DSorlov
public static bool IsPkcs12(
string algorithm)
{
string mechanism = (string) algorithms[algorithm.ToUpper(CultureInfo.InvariantCulture)];
return mechanism != null && Pkcs12.Equals(algorithmType[mechanism]);
}
19
View Source File : PbeUtilities.cs
License : GNU General Public License v3.0
Project Creator : DSorlov
License : GNU General Public License v3.0
Project Creator : DSorlov
public static bool IsPkcs5Scheme1(
string algorithm)
{
string mechanism = (string)algorithms[algorithm.ToUpper(CultureInfo.InvariantCulture)];
return mechanism != null && Pkcs5S1.Equals(algorithmType[mechanism]);
}
19
View Source File : PbeUtilities.cs
License : GNU General Public License v3.0
Project Creator : DSorlov
License : GNU General Public License v3.0
Project Creator : DSorlov
public static bool IsPkcs5Scheme2(
string algorithm)
{
string mechanism = (string)algorithms[algorithm.ToUpper(CultureInfo.InvariantCulture)];
return mechanism != null && Pkcs5S2.Equals(algorithmType[mechanism]);
}
19
View Source File : PbeUtilities.cs
License : GNU General Public License v3.0
Project Creator : DSorlov
License : GNU General Public License v3.0
Project Creator : DSorlov
public static bool IsOpenSsl(
string algorithm)
{
string mechanism = (string)algorithms[algorithm.ToUpper(CultureInfo.InvariantCulture)];
return mechanism != null && OpenSsl.Equals(algorithmType[mechanism]);
}
19
View Source File : CloudObject.cs
License : MIT License
Project Creator : dtylman
License : MIT License
Project Creator : dtylman
public override bool Equals(object obj)
{
return source.Equals(obj);
}
19
View Source File : Comparint.cs
License : MIT License
Project Creator : ecjtuseclab
License : MIT License
Project Creator : ecjtuseclab
bool IEqualityComparer<T>.Equals(T x, T y)
{
if (x == null && y == null)
{
return false;
}
if (comparintFiledName.Length == 0)
{
return x.Equals(y);
}
bool result = true;
var typeX = x.GetType();//获取类型
var typeY = y.GetType();
foreach (var filedName in comparintFiledName)
{
var xPropertyInfo = (from p in typeX.GetProperties() where p.Name.Equals(filedName) select p).FirstOrDefault();
var yPropertyInfo = (from p in typeY.GetProperties() where p.Name.Equals(filedName) select p).FirstOrDefault();
result = result
&& xPropertyInfo != null && yPropertyInfo != null
&& xPropertyInfo.GetValue(x, null).ToString().Equals(yPropertyInfo.GetValue(y, null));
}
return result;
}
19
View Source File : CyberarmsCurrentLocks.cs
License : MIT License
Project Creator : EFTEC
License : MIT License
Project Creator : EFTEC
public void Add(int id, Image icon, string statusName, string clientIp, string displayName, DateTime lockDate, DateTime unlockDate, int status) {
DataGridViewRow row = FindRow(id);
if (row != null) {
if (row.Cells[2].Value.ToString().Equals(status)) {
return;
}
} else {
dataGridViewLocks.Rows.Insert(0, new DataGridViewRow());
row = dataGridViewLocks.Rows[0];
}
(row.Cells[1] as DataGridViewImageCell).Value = icon;
row.Cells[2].Value = statusName;
row.Cells[3].Value = clientIp;
row.Cells[4].Value = displayName;
row.Cells[5].Value = lockDate;
row.Cells[6].Value = unlockDate;
row.Cells[7].Value = id.ToString();
row.Cells[8].Value = status;
}
19
View Source File : GrammaticalRelation.cs
License : Mozilla Public License 2.0
Project Creator : ehsan2022002
License : Mozilla Public License 2.0
Project Creator : ehsan2022002
public override bool Equals(Object o)
{
if (this == o) return true;
if (o is String)
{
// TODO: Remove this. It's broken but was meant to cover legacy code. It would be correct to just return false.
//new Throwable("Warning: comparing GrammaticalRelation to String").printStackTrace();
return this.ToString().Equals(o);
}
if (!(o is GrammaticalRelation)) return false;
var gr = (GrammaticalRelation)o;
// == okay for language as enum!
return this.language == gr.language &&
this.shortName.Equals(gr.shortName) &&
(this.specific == gr.specific ||
(this.specific != null && this.specific.Equals(gr.specific)));
}
19
View Source File : EntityPropertyEditor.cs
License : GNU General Public License v3.0
Project Creator : faib920
License : GNU General Public License v3.0
Project Creator : faib920
public void Start(IWindowsFormsEditorService edSvc, object value)
{
SelectedItems.Clear();
this.edSvc = edSvc;
Value = value;
if (value == null)
{
return;
}
foreach (ListViewItem item in base.Items)
{
if (item.Text.Equals(value))
{
item.Focused = true;
item.Selected = true;
item.EnsureVisible();
break;
}
}
}
19
View Source File : EditorFrame.xaml.cs
License : BSD 2-Clause "Simplified" License
Project Creator : fcarver
License : BSD 2-Clause "Simplified" License
Project Creator : fcarver
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
MainWindow wnd = (MainWindow)Application.Current.MainWindow;
if (e.AddedItems.Count > 0)
{
var ti = e.AddedItems[0] as TabItem;
if (ti != null && "Tree".Equals(ti.Header) && e.RemovedItems.Count > 0) // "==" dont work
{
wnd.contextribTree.Visibility = Visibility.Visible;
wnd.Ribbon.SelectedTabItem = wnd.ribbonTabTreeView;
return;
}
}
//else
wnd.contextribTree.Visibility = Visibility.Collapsed;
if (wnd.Ribbon.SelectedTabItem == wnd.ribbonTabTreeView)
{
wnd.Ribbon.SelectedTabItem = null;
}
e.Handled = true;
}
19
View Source File : ST.cs
License : MIT License
Project Creator : funwaywang
License : MIT License
Project Creator : funwaywang
public static bool? GetBool(object value)
{
if (value == null || string.Empty.Equals(value))
return null;
if (value is bool)
{
return (bool)value;
}
else if (value is string)
{
switch (((string)value).ToLower())
{
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
return false;
default:
return null;
}
}
else if (value is int)
{
return (int)value != 0;
}
else
{
return null;
}
}
19
View Source File : AuthChecker.cs
License : GNU Affero General Public License v3.0
Project Creator : fuwei54321
License : GNU Affero General Public License v3.0
Project Creator : fuwei54321
public static void checkConfig(ClientConfig config, IAuthSource source)
{
string redirectUri = config.redirectUri;
if (!GlobalAuthUtil.isHttpProtocol(redirectUri) && !GlobalAuthUtil.isHttpsProtocol(redirectUri))
{
throw new Exception(AuthResponseStatus.ILLEGAL_REDIRECT_URI.GetDesc());
}
// facebook的回调地址必须为https的链接
if ("FACEBOOK".Equals(source.getName().ToUpper()) && !GlobalAuthUtil.isHttpsProtocol(redirectUri))
{
// Facebook's redirect uri must use the HTTPS protocol
throw new Exception(AuthResponseStatus.ILLEGAL_REDIRECT_URI.GetDesc());
}
// 支付宝在创建回调地址时,不允许使用localhost或者127.0.0.1
if ("ALIPAY".Equals(source.getName().ToUpper()) && GlobalAuthUtil.isLocalHost(redirectUri))
{
// The redirect uri of alipay is forbidden to use localhost or 127.0.0.1
throw new Exception(AuthResponseStatus.ILLEGAL_REDIRECT_URI.GetDesc());
}
}
19
View Source File : AuthChecker.cs
License : GNU Affero General Public License v3.0
Project Creator : fuwei54321
License : GNU Affero General Public License v3.0
Project Creator : fuwei54321
public static void checkCode(IAuthSource source, AuthCallback callback)
{
string code = callback.code;
if (source.getName().ToUpper().Equals(DefaultAuthSourceEnum.ALIPAY_MP.ToString()))
{
code = callback.auth_code;
}
else if ("HUAWEI".Equals(source.getName().ToUpper()))
{
code = callback.authorization_code;
}
if (string.IsNullOrWhiteSpace(code))
{
throw new Exception(AuthResponseStatus.ILLEGAL_CODE.GetDesc());
}
}
19
View Source File : PBDriver.cs
License : Apache License 2.0
Project Creator : Ginger-Automation
License : Apache License 2.0
Project Creator : Ginger-Automation
public override void RunAction(Act act)
{
//TODO: add func to Act + Enum for switch
string actClreplaced = act.GetType().ToString();
mUIAutomationHelper.mLoadTimeOut = mActionTimeout;
mUIAutomationHelper.taskFinished = false;
//TODO: avoid hard coded string...
actClreplaced = actClreplaced.Replace("GingerCore.Actions.", "");
if (!actClreplaced.Equals(typeof(ActUIASwitchWindow)) && !actClreplaced.Equals(typeof(ActSwitchWindow)) && (actClreplaced == "Common.ActUIElement" && (((ActUIElement)act).ElementAction != ActUIElement.eElementAction.Switch)))
{
CheckRetrySwitchWindowIsNeeded();
}
if(act.Timeout!=null)
{
mUIAutomationHelper.mLoadTimeOut = act.Timeout;
}
try
{
Reporter.ToLog(eLogLevel.DEBUG, "Start Executing action of type '" + actClreplaced + "' Description is" + act.Description);
switch (actClreplaced)
{
case "ActPBControl":
ActPBControl actPBC = (ActPBControl)act;
HandlePBControlAction(actPBC);
break;
case "ActGenElement":
ActGenElement AGE = (ActGenElement)act;
HandlePBGenericWidgetControlAction(AGE);
break;
case "ActBrowserElement":
ActBrowserElement actBE=(ActBrowserElement)act;
HandlePBBrowserElementAction(actBE);
break;
//TODO: ActSwitchWindow is the correct approach for switch window. And we should guide the users accordingly.
//Down the line we need to clean up ActUIASwitchWindow. This is old way, but we keep it to support old actions
case "ActUIASwitchWindow":
mUIAutomationHelper.SwitchWindow((ActUIASwitchWindow)act);
break;
case "ActSwitchWindow":
mUIAutomationHelper.SmartSwitchWindow((ActSwitchWindow)act);
break;
case "ActMenuItem":
ActMenuItem actMenuItem = (ActMenuItem)act;
HandleMenuControlAction(actMenuItem);
break;
case "ActWindow":
ActWindow actWindow = (ActWindow)act;
HandleWindowControlAction(actWindow);
break;
//case "ActUIAButton":
// ActUIAButton b = (ActUIAButton)act;
// UIA.ClickButton(b);
// break;
//case "ActUIATextBox":
// ActUIATextBox ATB = (ActUIATextBox)act;
// if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.SetValue)
// {
// UIA.SetTextBoxValue(ATB);
// return;
// }
// if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetValue) UIA.GetTextBoxValue(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetValue) UIA.GetTextBoxValue(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsDisabled) UIA.IsTextBoxDisabled(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetFont) UIA.GetTextBoxFont(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsPrepopulated) UIA.IsTextBoxPrepopulated(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsRequired) UIA.IsTextBoxRequired(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsDisplayed) UIA.IsTextBoxDisplayed(ATB);
// //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetInputLength) UIA.GetTextBoxInputLength(ATB);
// break;
//case "ActUIALabel":
// if (((ActUIALabel)act).LabelAction == ActUIALabel.eLabelAction.GetForeColor) UIA.LabelGetColor((ActUIALabel)act);
// break;
//TODO: What Jave is doing here? is it needed?
case "Java.ActTableElement":
ActTableElement actTable = (ActTableElement)act;
mUIAutomationHelper.HandleGridControlAction(actTable);
break;
case "ActTableElement":
ActTableElement actTable1 = (ActTableElement)act;
mUIAutomationHelper.HandleGridControlAction(actTable1);
break;
case "ActSmartSync":
mUIAutomationHelper.SmartSyncHandler((ActSmartSync)act);
break;
//case "ActUIAClickOnPoint":
// ActUIAClickOnPoint ACP = (ActUIAClickOnPoint)act;
// if (ACP.ActUIAClickOnPointAction == ActUIAClickOnPoint.eUIAClickOnPointAction.ClickXY) UIA.ClickOnPoint(ACP);
// break;
case "ActScreenShot":
try
{
//TODO: Implement Multi window capture
if (act.WindowsToCapture == Act.eWindowsToCapture.AllAvailableWindows)
{
List<AppWindow> list = mUIAutomationHelper.GetListOfDriverAppWindows();
List<Bitmap> bList;
foreach (AppWindow aw in list)
{
Bitmap bmp = mUIAutomationHelper.GetAppWindowAsBitmap(aw);
act.AddScreenShot(bmp);
bList = mUIAutomationHelper.GetAppDialogAsBitmap(aw);
foreach (Bitmap tempbmp in bList)
{
act.AddScreenShot(tempbmp);
}
bList.Clear();
}
}
else
{
Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap();
act.AddScreenShot(bmp);
}
return;
}
catch (Exception ex)
{
act.Error = "Error: Action failed to be performed, Details: " + ex.Message;
}
break;
//case "ActUIAImage":
// if (((ActUIAImage)act).ImageAction == ActUIAImage.eImageAction.IsVisible) UIA.ImageIsVisible((ActUIAImage)act);
// break;
//case "ActPBControl":
// ActPBControl APBC = (ActPBControl)act;
// RunControlAction(APBC);
// break;
//case "ActMenuItem":
// ActMenuItem ami = (ActMenuItem)act;
// MenuItem(ami);
// break;
case "Common.ActUIElement":
//ActUIElement actUIPBC = (ActUIElement)act;
HandleUIElementAction(act);
break;
default:
throw new Exception("Action unknown/not implemented for the Driver: " + this.GetType().ToString());
}
}
catch (System.Runtime.InteropServices.COMException e)
{
Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType()+ " Description:"+act.Description+" Error details:", e);
CheckAndRetryRunAction(act,e);
return;
}
catch (ElementNotAvailableException e)
{
Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e);
CheckAndRetryRunAction(act,e);
return;
}
catch (ArgumentException e)
{
Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e);
CheckAndRetryRunAction(act, e);
return;
}
catch(Exception e)
{
Reporter.ToLog(eLogLevel.WARN, "Exception at Run action",e);
act.Error = e.Message;
}
}
19
View Source File : WindowsDriver.cs
License : Apache License 2.0
Project Creator : Ginger-Automation
License : Apache License 2.0
Project Creator : Ginger-Automation
public override void RunAction(Act act)
{
//TODO: add func to Act + Enum for switch
string actClreplaced = act.GetType().Name;
mUIAutomationHelper.mLoadTimeOut = mActionTimeout;
mUIAutomationHelper.taskFinished = false;
if (!actClreplaced.Equals(typeof(ActSwitchWindow)) || (actClreplaced.Equals(typeof(ActWindow)) && ((ActWindow)act).WindowActionType != ActWindow.eWindowActionType.Switch))
{
var checkWindow = true;
if(actClreplaced.Equals(typeof(ActUIElement)) && ((ActUIElement)act).ElementAction.Equals(ActUIElement.eElementAction.Switch))
{
checkWindow = false;
}
if (checkWindow)
{
CheckRetrySwitchWindowIsNeeded();
}
}
if (act.Timeout != null)
{
mUIAutomationHelper.mLoadTimeOut = act.Timeout;
}
try
{
switch (actClreplaced)
{
case "ActUIElement":
HandleUIElementAction(act);
break;
case "ActWindowsControl":
HandleWindowsControlAction((ActWindowsControl)act);
break;
case "ActWindow":
ActWindow actWindow = (ActWindow)act;
HandleWindowAction(actWindow);
break;
//TODO: ActSwitchWindow is the correct approach for switch window. And we should guide the users accordingly.
case "ActSwitchWindow":
mUIAutomationHelper.SmartSwitchWindow((ActSwitchWindow)act);
break;
case "ActGenElement":
ActGenElement AGE = (ActGenElement)act;
HandleWindowsGenericWidgetControlAction(AGE);
break;
case "ActMenuItem":
ActMenuItem actMenuItem = (ActMenuItem)act;
HandleMenuControlAction(actMenuItem);
break;
case "ActSmartSync":
mUIAutomationHelper.SmartSyncHandler((ActSmartSync)act);
break;
case "ActScreenShot":
try
{
//TODO: When capturing all windows, we do showwindow. for few applications show window is causing application to minimize
//Disabling the capturing all windows for Windows driver until we fix show window issue
Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap();
act.AddScreenShot(bmp);
//if not running well. need to add return same as PBDrive
}
catch (Exception ex)
{
act.Error = "Error: Action failed to be performed, Details: " + ex.Message;
}
break;
case "ActBrowserElement":
ActBrowserElement actWBE = (ActBrowserElement)act;
HandleWindowsBrowserElementAction(actWBE);
break;
case "ActTableElement":
ActTableElement actTable = (ActTableElement)act;
HandleWindowsWidgetTableControlAction(actTable);
break;
default:
throw new Exception("Action unknown/not implemented for the Driver: " + this.GetType().ToString());
}
}
catch (System.Runtime.InteropServices.COMException e)
{
Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e);
CheckAndRetryRunAction(act, e);
return;
}
catch (ElementNotAvailableException e)
{
Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e);
CheckAndRetryRunAction(act, e);
return;
}
catch (ArgumentException e)
{
Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e);
CheckAndRetryRunAction(act, e);
return;
}
catch (Exception e)
{
Reporter.ToLog(eLogLevel.WARN, "Exception at Run action", e);
act.Error = e.Message;
}
}
19
View Source File : TemplateBuilder.cs
License : GNU General Public License v3.0
Project Creator : grandnode
License : GNU General Public License v3.0
Project Creator : grandnode
public async Task<IHtmlContent> Build()
{
if (_metadata.ConvertEmptyStringToNull && string.Empty.Equals(_model))
{
_model = null;
}
// Normally this shouldn't happen, unless someone writes their own custom Object templates which
// don't check to make sure that the object hasn't already been displayed
if (_viewData.TemplateInfo.Visited(_modelExplorer))
{
return HtmlString.Empty;
}
// Create VDD of type object so any model type is allowed.
var viewData = new ViewDataDictionary<object>(_viewData);
// Create a new ModelExplorer in order to preserve the model metadata of the original _viewData even
// though _model may have been reset to null. Otherwise we might lose track of the model type /property.
viewData.ModelExplorer = _modelExplorer.GetExplorerForModel(_model);
var formatString = _readOnly ?
viewData.ModelMetadata.DisplayFormatString :
viewData.ModelMetadata.EditFormatString;
var formattedModelValue = _model;
if (_model == null)
{
if (_readOnly)
{
formattedModelValue = _metadata.NullDisplayText;
}
}
else if (!string.IsNullOrEmpty(formatString))
{
formattedModelValue = string.Format(CultureInfo.CurrentCulture, formatString, _model);
}
else if (viewData.ModelMetadata.IsEnum && _model is Enum modelEnum)
{
// Cover the case where the model is an enum and we want the string value of it
var value = modelEnum.ToString("d");
var enumGrouped = viewData.ModelMetadata.EnumGroupedDisplayNamesAndValues;
Debug.replacedert(enumGrouped != null);
foreach (var kvp in enumGrouped)
{
if (kvp.Value == value)
{
// Creates a ModelExplorer with the same Metadata except that the Model is a string instead of an Enum
formattedModelValue = kvp.Key.Name;
break;
}
}
}
viewData.TemplateInfo.FormattedModelValue = formattedModelValue;
viewData.TemplateInfo.HtmlFieldPrefix = _viewData.TemplateInfo.GetFullHtmlFieldName(_htmlFieldName);
if (_additionalViewData != null)
{
foreach (var kvp in HtmlHelper.ObjectToDictionary(_additionalViewData))
{
viewData[kvp.Key] = kvp.Value;
}
}
var visitedObjectsKey = _model ?? _modelExplorer.ModelType;
viewData.TemplateInfo.AddVisited(visitedObjectsKey);
var templateRenderer = new TemplateRenderer(
_viewEngine,
_bufferScope,
_viewContext,
viewData,
_templateName,
_readOnly);
return await templateRenderer.Render();
}
19
View Source File : WinStartup.cs
License : MIT License
Project Creator : hasankhan
License : MIT License
Project Creator : hasankhan
public static bool IsAdded(string key, string path)
{
using (var runKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
{
bool added = path.Equals(runKey.GetValue(key));
return added;
}
}
19
View Source File : PrintXPS.cs
License : MIT License
Project Creator : huali20040714
License : MIT License
Project Creator : huali20040714
public void Dispose()
{
GC.SuppressFinalize(this);
bool _printerDeleted = false;
if (_printerCreated && !string.IsNullOrEmpty(_printerName))
{
try
{
DeletePrinter();
_printerDeleted = true;
_printerName = null;
_printerCreated = false;
}
catch { }
}
if (_portCreated && !string.IsNullOrEmpty(_port))
{
if (!_printerDeleted && PrinterExists(_printerName))
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer WHERE Name='" + _printerName + "'");
foreach (ManagementObject printer in searcher.Get())
{
if (_port.Equals(printer["PortName"]))
{
printer["PortName"] = _defaultPort;
printer.Put();
}
}
try
{
DeletePort(_port);
_port = null;
_portCreated = false;
}
catch { }
}
}
}
19
View Source File : NumericUpDownCell.cs
License : MIT License
Project Creator : iccb1013
License : MIT License
Project Creator : iccb1013
protected override bool SetValue(int rowIndex, object value)
{
bool changed = (base.GetValue(rowIndex) != null && value != null) && base.GetValue(rowIndex).ToString().Equals(value) == false;
PropertyGridValidateResult validateResult = this.Owner.ValidateValue(this.OwnerRow.PropertyName, value, changed);
if (validateResult.Success == false)
{
this.ErrorText = validateResult.Message;
return false;
}
return base.SetValue(rowIndex, value);
}
19
View Source File : TextBoxCell.cs
License : MIT License
Project Creator : iccb1013
License : MIT License
Project Creator : iccb1013
protected override bool SetValue(int rowIndex, object value)
{
if (this.DataGridView != null && ((PropertyGridDataGridView)this.DataGridView).SelectedObjectSeting == false)
{
PropertyTextBoxEditorAttribute editorAttribute = (PropertyTextBoxEditorAttribute)this.PropertyEditorAttribute;
if (value == null || value.ToString() == String.Empty)
{
if (editorAttribute.AllowEmpty == false)
{
this.ErrorText = Language.Current.PropertyGrid_ErrorText_NullValueInefficacy;
return false;
}
return base.SetValue(rowIndex, value);
}
try
{
Convert.ChangeType(value, editorAttribute.TypeCode);
}
catch (Exception ex)
{
this.ErrorText = ex.Message;
return false;
}
if (String.IsNullOrEmpty(editorAttribute.Regex) == false)
{
if (value != null)
{
Regex r = new Regex(editorAttribute.Regex, RegexOptions.Singleline);
Match m = r.Match(value.ToString());
if (m.Success == false)
{
this.ErrorText = editorAttribute.RegexMsg;
return false;
}
}
}
bool changed = (base.GetValue(rowIndex) != null && value != null) && base.GetValue(rowIndex).ToString().Equals(value) == false;
PropertyGridValidateResult validateResult = this.Owner.ValidateValue(this.OwnerRow.PropertyName, value, changed);
if (validateResult.Success == false)
{
this.ErrorText = validateResult.Message;
return false;
}
}
return base.SetValue(rowIndex, value);
}
See More Examples