How to use ToString method of System.Tuple class

Best FlaUI code snippet using System.Tuple.ToString

WorkstationManager.cs

Source:WorkstationManager.cs Github

copy

Full Screen

...119 }120 }121 catch (Exception e)122 {123 Logger.Instance.WriteEntry("WorkstationManager_SignIn: " + e.ToString(), LogType.Exception);124 }125126 #endregion127128 bool signedIn = false;129 Database.MonitoredSystem monitoredSystem = null;130 OrganizationalUnit ou;131132 try133 {134 var result = (from p in dataContext.MonitoredSystem135 where p.MacAddress == monitoredSystemMAC136 select p);137138 monitoredSystem = result.FirstOrDefault();139140 if (monitoredSystem == null)141 {142 //logging exception143 var messageNew = new StringBuilder();144 messageNew.Append("WorkstationManager_SignIn: ");145 messageNew.Append("Workstation " + monitoredSystemMAC + " ");146 messageNew.Append("(" + (Platform)operatingSystem + ") ");147 messageNew.Append("is new. The workstation will be moved to OU Default!");148 MISD.Core.Logger.Instance.WriteEntry(messageNew.ToString(), LogType.Info);149150 #region Create organisation units if necessary and get the organisation unit for the monitored system151 //Create organisation units if necessary and get the organisation unit for the monitored system152 var myOUs = ADManager.Instance.GetOU(monitoredSystemFQDN);153154 try155 {156 foreach (var unit in myOUs)157 {158 if (!OUManager.Instance.Exists(unit))159 {160 if (unit == myOUs.First())161 {162 //create organisation unit with parent root163 OUManager.Instance.CreateOU(unit.Split('.').Last(), null, DateTime.Now);164 }165 else166 {167 //create organisation unit whit his parent168 var parent = (from p in dataContext.OrganizationalUnit169 where p.FQDN == myOUs[myOUs.IndexOf(unit) - 1]170 select p).FirstOrDefault();171 if (parent == null)172 {173 Logger.Instance.WriteEntry("WorkstationManager_SignIn: Could not create inner OU for FQDN " + myOUs.Last(), LogType.Warning);174 }175 else176 {177 OUManager.Instance.CreateOU(unit.Split('.').Last(), parent.FQDN, DateTime.Now);178 }179 }180 }181 }182 }183 catch (Exception e)184 {185 //logging exception186 var messageEx2 = new StringBuilder();187 messageEx2.Append("WorkstationWebService_SignIn: ");188 messageEx2.Append("Workstation " + monitoredSystem.Name + " ");189 messageEx2.Append("(" + monitoredSystem.OperatingSystem.ToString() + ") ");190 messageEx2.Append("can´t sign in. Can't check for the OUs or create new OUs. " + e.ToString());191 MISD.Core.Logger.Instance.WriteEntry(messageEx2.ToString(), LogType.Exception);192 }193194 if (myOUs.Count != 0 && !(myOUs.Count == 1 && myOUs.First().Equals(Properties.Settings.Default.DefaultOU)))195 {196 //set last organisation unit in list as unit for the monitored system197 ou = (from p in dataContext.OrganizationalUnit198 where p.FQDN == myOUs.Last()199 select p).FirstOrDefault();200201 if (ou == null)202 {203 Logger.Instance.WriteEntry("WorkstationManager_SignIn: Could not find inner OU for FQDN " + myOUs.Last(), LogType.Warning);204 ou = (from p in dataContext.OrganizationalUnit205 where p.FQDN == Properties.Settings.Default.DefaultOU206 select p).FirstOrDefault();207 }208 }209 else210 {211 //if the monitored system has no ou set to default organisation unit212 //check default and create if necessary213 if (!OUManager.Instance.Exists(Properties.Settings.Default.DefaultOU))214 {215 Logger.Instance.WriteEntry("WorkstationWebService_SignIn: Create default OU.", LogType.Info);216 OUManager.Instance.CreateOU(Properties.Settings.Default.DefaultOU, null, DateTime.Now);217 }218219 ou = (from p in dataContext.OrganizationalUnit220 where p.FQDN == Properties.Settings.Default.DefaultOU221 select p).FirstOrDefault();222 }223224 #endregion225226 monitoredSystem = new Database.MonitoredSystem();227 monitoredSystem.OrganizationalUnit = ou;228 monitoredSystem.Name = monitoredSystemFQDN;229 monitoredSystem.FQDN = monitoredSystemFQDN;230 monitoredSystem.IsAvailable = true;231 monitoredSystem.IsIgnored = false;232 monitoredSystem.OperatingSystem = operatingSystem;233 monitoredSystem.MacAddress = monitoredSystemMAC;234235 dataContext.MonitoredSystem.InsertOnSubmit(monitoredSystem);236 dataContext.SubmitChanges();237238 //create indicator entries for the new workstations in the db.239 PluginManager.Instance.UpdateDatabase();240 }241 else242 {243 if (monitoredSystem.IsIgnored)244 {245 MISD.Core.Logger.Instance.WriteEntry("WorkstationManager_SignIn: The monitored system " + monitoredSystem.Name + " is ignored and cannot sign in.", LogType.Debug);246 return false;247 }248 if (monitoredSystem.IsAvailable)249 {250 //logging exception251 var messageEx1 = new StringBuilder();252 messageEx1.Append("WorkstationManager_SignIn: ");253 messageEx1.Append("Workstation " + monitoredSystem.Name + " ");254 messageEx1.Append("(" + monitoredSystem.OperatingSystem.ToString() + ") ");255 messageEx1.Append("can´t sign in. The workstation was already signed in!");256 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);257 }258259 //set monitored system as online260 monitoredSystem.IsAvailable = true;261262 bool platformChanged = false;263264 //set the current platform265 #region logging plattfrom change266 if (monitoredSystem.OperatingSystem != operatingSystem)267 {268 Logger.Instance.WriteEntry("WorkstationManager_SignIn: Operating system of workstation " + monitoredSystem.Name + " has changed to " + operatingSystem, LogType.Debug);269 platformChanged = true;270 }271 #endregion272 monitoredSystem.OperatingSystem = operatingSystem;273274 dataContext.SubmitChanges();275276 if (platformChanged)277 {278 //create indicator entries for the new workstations in the db.279 PluginManager.Instance.UpdateDatabase();280 }281282 //logging info283 var messageOK = new StringBuilder();284 messageOK.Append("WorkstationManager_SignIn: ");285 messageOK.Append("Workstation " + monitoredSystem.Name + " ");286 messageOK.Append("(" + monitoredSystem.OperatingSystem.ToString() + ") ");287 messageOK.Append("has signed in.");288 MISD.Core.Logger.Instance.WriteEntry(messageOK.ToString(), LogType.Info);289 }290 signedIn = true;291 }292 catch (Exception e)293 {294 signedIn = false;295296 //logging exception297 string workstationLogName;298 string osLogName;299 if (monitoredSystem != null)300 {301 workstationLogName = monitoredSystem.Name;302 osLogName = monitoredSystem.OperatingSystem.ToString();303 }304 else305 {306 workstationLogName = "[unkown]";307 osLogName = "system unkown";308 }309310 var messageEx2 = new StringBuilder();311 messageEx2.Append("WorkstationManager_SignIn: ");312 messageEx2.Append("Workstation " + workstationLogName + " ");313 messageEx2.Append("(" + osLogName + ") ");314 messageEx2.Append("sign in has failed. " + e.ToString());315 MISD.Core.Logger.Instance.WriteEntry(messageEx2.ToString(), LogType.Exception);316 }317318 return signedIn;319 }320 }321322 public bool SignOut(string monitoredSystemMAC)323 {324 using (var dataContext = DataContextFactory.CreateDataContext())325 {326 #region check arguments327328 if (monitoredSystemMAC == "")329 {330 return false;331 }332333 #endregion334335 bool signedOut = false;336 MonitoredSystem monitoredSystem = null;337338 try339 {340 monitoredSystem = (from ms in dataContext.MonitoredSystem341 where ms.MacAddress == monitoredSystemMAC342 select ms).FirstOrDefault();343344 if (monitoredSystem != null)345 {346 if (monitoredSystem.IsIgnored)347 {348 MISD.Core.Logger.Instance.WriteEntry("WorkstationManager_SignOut: The monitored system " + monitoredSystem.Name + " is ignored and cannot sign out.", LogType.Debug);349 return false;350 }351 if (monitoredSystem.IsAvailable == false)352 {353 #region logging exception354 //logging exception355 var messageEx1 = new StringBuilder();356 messageEx1.Append("WorkstationWebService_SignOut: ");357 messageEx1.Append("Workstation" + monitoredSystem.Name + " ");358 messageEx1.Append("(" + monitoredSystem.OperatingSystem.ToString() + ") ");359 messageEx1.Append("can´t sign out. The workstation is already signed out!");360 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);361 #endregion362 }363 else364 {365 monitoredSystem.IsAvailable = false;366 dataContext.SubmitChanges();367 #region logging info368 //logging info369 var messageOK = new StringBuilder();370 messageOK.Append("WorkstationManager_SignOut: ");371 messageOK.Append("Workstation" + monitoredSystem.Name + " ");372 messageOK.Append("(" + monitoredSystem.OperatingSystem.ToString() + ") ");373 messageOK.Append("has signed out.");374 MISD.Core.Logger.Instance.WriteEntry(messageOK.ToString(), LogType.Info);375 #endregion376 }377 }378 signedOut = true;379 }380 catch (Exception e)381 {382 signedOut = false;383384 #region logging exception385 //logging exception386 string workstationLogName;387 string osLogName;388 if (monitoredSystem != null)389 {390 workstationLogName = monitoredSystem.Name;391 osLogName = monitoredSystem.OperatingSystem.ToString();392 }393 else394 {395 workstationLogName = "[unkown]";396 osLogName = "system unkown";397 }398399 var messageEx2 = new StringBuilder();400 messageEx2.Append("WorkstationManager_SignOut: ");401 messageEx2.Append("Workstation" + workstationLogName + " ");402 messageEx2.Append("(" + osLogName + ") ");403 messageEx2.Append("sign out has failed. " + e.ToString());404 MISD.Core.Logger.Instance.WriteEntry(messageEx2.ToString(), LogType.Exception);405406 #endregion407 }408409 return signedOut;410 }411 }412413 public Func<MISDDataContext, int, Tuple<bool, bool>> GetMonitoredSystemState = CompiledQuery.Compile<MISDDataContext, int, Tuple<bool, bool>>((dataContext, monitoredSystemID) => dataContext.MonitoredSystem.Where(p => p.ID == monitoredSystemID).Select(p => new Tuple<bool, bool>(p.IsInMaintenanceMode, p.IsIgnored)).SingleOrDefault());414 public Func<MISDDataContext, int, string, string, Indicator> GetIndicatorByMonitoredSystemIDPluginNameAndIndicatorName = CompiledQuery.Compile<MISDDataContext, int, string, string, Indicator>((dataContext, monitoredSystemID, pluginName, indicatorName) => dataContext.Indicator.Where(p => p.Name == indicatorName && p.MonitoredSystemID == monitoredSystemID && p.PluginMetadata.Name == pluginName && (p.PluginMetadata.Platform == p.MonitoredSystem.OperatingSystem || p.PluginMetadata.Platform == (byte)Platform.Server)).FirstOrDefault());415416 public Func<MISDDataContext, double, ValueFloat> GetFloatByValue = CompiledQuery.Compile<MISDDataContext, double, ValueFloat>((dataContext, value) => dataContext.ValueFloat.Where(p => p.Value == value).SingleOrDefault());417 public Func<MISDDataContext, string, ValueString> GetStringByValue = CompiledQuery.Compile<MISDDataContext, string, ValueString>((dataContext, value) => dataContext.ValueString.Where(p => p.Value == value).SingleOrDefault());418 public Func<MISDDataContext, byte, ValueByte> GetByteByValue = CompiledQuery.Compile<MISDDataContext, byte, ValueByte>((dataContext, value) => dataContext.ValueByte.Where(p => p.Value == value).SingleOrDefault());419 public Func<MISDDataContext, int, ValueInt> GetIntByValue = CompiledQuery.Compile<MISDDataContext, int, ValueInt>((dataContext, value) => dataContext.ValueInt.Where(p => p.Value == value).SingleOrDefault());420 public Func<MISDDataContext, int, MISD.Server.Database.PluginMetadata> GetPluginByIndicatorID = CompiledQuery.Compile<MISDDataContext, int, MISD.Server.Database.PluginMetadata>((dataContext, indicatorID) => dataContext.Indicator.Where(p => p.ID == indicatorID).Select(p => p.PluginMetadata).FirstOrDefault());421422 public bool UploadIndicatorValues(int monitoredSystemID, string pluginName, List<Tuple<string, Object, MISD.Core.DataType, DateTime>> indicatorValues)423 {424425 bool success = false;426 try427 {428 using (var dataContext = DataContextFactory.CreateDataContext())429 {430 // Item 1: MaintenanceMode, Item2: IsIgnored431 var monitoredSystemState = GetMonitoredSystemState(dataContext, monitoredSystemID);432 if (monitoredSystemState.Item1 == true || monitoredSystemState.Item2 == true)433 {434 //logging exception435 var messageEx1 = new StringBuilder();436 messageEx1.Append("WorkstationManager_UploadIndicatorValues: ");437 messageEx1.Append("Transfer from " + monitoredSystemID + " and " + pluginName + " ignored. ");438 messageEx1.Append("The system is ignored or in maintance status. ");439 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Debug);440 }441 else442 {443 foreach (var listTuple in indicatorValues)444 {445 if (listTuple.Item2 != null)446 {447 var indicator = GetIndicatorByMonitoredSystemIDPluginNameAndIndicatorName(dataContext, monitoredSystemID, pluginName, listTuple.Item1);448 if (indicator == null)449 {450 //logging exception451 var message = new StringBuilder();452 message.Append("WorkstationManager_UploadIndicatorValues: ");453 message.Append("Transfer from " + monitoredSystemID + " and " + pluginName + " failed. Could not find the indicator.");454 MISD.Core.Logger.Instance.WriteEntry(message.ToString(), LogType.Debug);455 continue;456 }457458 int valueID = 0;459460 if (listTuple.Item3 == Core.DataType.Byte)461 {462 #region create byte463464 lock (byteRoot)465 {466 string index = cacheManByte.Get(Convert.ToByte(listTuple.Item2));467 if (index == null)468 {469 using (var byteDataContext = DataContextFactory.CreateDataContext())470 {471 var element = GetByteByValue(byteDataContext, Convert.ToByte(listTuple.Item2));472 if (element == null)473 {474 ValueByte byteValue = new ValueByte();475 byteValue.Value = Convert.ToByte(listTuple.Item2);476 byteDataContext.ValueByte.InsertOnSubmit(byteValue);477 byteDataContext.SubmitChanges();478 valueID = byteValue.ID;479 cacheManByte.Add(Convert.ToByte(listTuple.Item2), valueID.ToString());480 }481 else482 {483 valueID = element.ID;484 cacheManByte.Add(Convert.ToByte(listTuple.Item2), valueID.ToString());485 }486 }487 }488 else489 {490 valueID = Convert.ToInt32(index);491 }492 }493 #endregion494 }495 else if (listTuple.Item3 == Core.DataType.Float)496 {497 #region create float498499 lock (floatRoot)500 {501 string index = cacheManFloat.Get((float) Convert.ToDouble(listTuple.Item2));502 if (index == null)503 {504 using (var floatDataContext = DataContextFactory.CreateDataContext())505 {506 var element = GetFloatByValue(floatDataContext, Convert.ToDouble(listTuple.Item2));507508 if (element == null)509 {510 ValueFloat floatValue = new ValueFloat();511 floatValue.Value = Convert.ToDouble(listTuple.Item2);512 floatDataContext.ValueFloat.InsertOnSubmit(floatValue);513 floatDataContext.SubmitChanges();514 valueID = floatValue.ID;515 cacheManFloat.Add((float)Convert.ToDouble(listTuple.Item2), valueID.ToString());516 }517 else518 {519 valueID = element.ID;520 cacheManFloat.Add((float)Convert.ToDouble(listTuple.Item2), valueID.ToString());521 }522 }523 }524 else525 {526 valueID = Convert.ToInt32(index);527 }528 }529 #endregion530 }531 else if (listTuple.Item3 == Core.DataType.Int)532 {533 #region create int534535 lock (intRoot)536 {537 string index = cacheManInt.Get(Convert.ToInt32(listTuple.Item2));538 if (index == null)539 {540 using (var intDataContext = DataContextFactory.CreateDataContext())541 {542543 var element = GetIntByValue(intDataContext, Convert.ToInt32(listTuple.Item2));544545 if (element == null)546 {547548 ValueInt intValue = new ValueInt();549 intValue.Value = Convert.ToInt32(listTuple.Item2);550 intDataContext.ValueInt.InsertOnSubmit(intValue);551 intDataContext.SubmitChanges();552 valueID = intValue.ID;553 cacheManInt.Add(Convert.ToInt32(listTuple.Item2), valueID.ToString());554 }555 else556 {557 valueID = element.ID;558 cacheManInt.Add(Convert.ToInt32(listTuple.Item2), valueID.ToString());559 }560 }561 }562 else563 {564 valueID = Convert.ToInt32(index);565 }566 }567 #endregion568 }569 else if (listTuple.Item3 == Core.DataType.String)570 {571 #region create string572573 lock (stringRoot)574 {575 string index = cacheManString.Get(listTuple.Item2.ToString());576 if (index == null)577 {578 using (var stringDataContext = DataContextFactory.CreateDataContext())579 {580 var element = GetStringByValue(stringDataContext, listTuple.Item2 as string);581582 if (element == null)583 {584 ValueString stringValue = new ValueString();585 stringValue.Value = listTuple.Item2.ToString();586 stringDataContext.ValueString.InsertOnSubmit(stringValue);587 stringDataContext.SubmitChanges();588 valueID = stringValue.ID;589 cacheManString.Add(listTuple.Item2.ToString(), valueID.ToString());590 }591 else592 {593 valueID = element.ID;594 cacheManString.Add(listTuple.Item2.ToString(), valueID.ToString());595 }596 }597 }598 else599 {600 valueID = Convert.ToInt32(index);601 }602 }603 #endregion604 }605606 IndicatorValue value = new IndicatorValue();607 value.IndicatorID = indicator.ID;608 value.Timestamp = listTuple.Item4.Ticks;609 value.Mapping = (byte)MetricManager.Instance.GetMetricValue(indicator.MonitoredSystemID, pluginName, listTuple.Item1, listTuple.Item2.ToString());610 value.ValueID = valueID;611612 dataContext.IndicatorValue.InsertOnSubmit(value);613614 dataContext.SubmitChanges();615616 // Caching für GetLatestData617 //var ms = Database.PrecompiledQueries.GetMonitoredSystemByID(dataContext, monitoredSystemID);618 //ValueManager.Instance.CacheIndicator(619 // new Tuple<string, string, string, string, MappingState, DateTime>620 // (621 // ms.MacAddress, pluginName, indicator.Name, listTuple.Item2.ToString(),(MappingState) value.Mapping, new DateTime( value.Timestamp)622 // )623 //);624625626 //set monitored system mapping627 #region monitored system mapping628 var monitoredSystem = PrecompiledQueries.GetMonitoredSystemByID(dataContext, monitoredSystemID);629 if (monitoredSystem.Status != (byte)MappingState.Maintenance)630 {631 if (value.Mapping == (byte)MappingState.Critical)632 {633 //set mapping state634 monitoredSystem.Status = (byte)MappingState.Critical;635636 //set end time637 monitoredSystem.CriticalEnd = indicator.MappingDuration + DateTime.Now.Ticks;638639 dataContext.SubmitChanges();640 }641 else if (value.Mapping == (byte)MappingState.Warning && monitoredSystem.Status != (byte)MappingState.Critical)642 {643 //set mapping state644 monitoredSystem.Status = (byte)MappingState.Warning;645646 //set end time647 monitoredSystem.WarningEnd = indicator.MappingDuration + DateTime.Now.Ticks;648649 dataContext.SubmitChanges();650 } 651 }652 #endregion653 #region indicator mapping654 if (value.Mapping == (byte)MappingState.Critical)655 {656 //set mapping state657 indicator.Status = (byte)MappingState.Critical;658659 //set end time660 indicator.CriticalEnd = indicator.MappingDuration + DateTime.Now.Ticks;661662 dataContext.SubmitChanges();663 }664 else if (value.Mapping == (byte)MappingState.Warning && indicator.Status != (byte)MappingState.Critical)665 {666 //set mapping state667 indicator.Status = (byte)MappingState.Warning;668669 //set end time670 indicator.WarningEnd = indicator.MappingDuration + DateTime.Now.Ticks;671672 dataContext.SubmitChanges();673 }674 #endregion675676 //send warning mails to the observing users677 #region waring mails678 if (value.Mapping == (byte)MappingState.Critical)679 {680 var mailThread = new Thread(new ThreadStart(() =>681 {682 Mailer.Instance.SendAllWarnings(683 monitoredSystemID,684 new DateTime(value.Timestamp),685 pluginName,686 listTuple.Item1,687 (listTuple.Item2 == null) ? "" : listTuple.Item2.ToString());688 }));689 mailThread.Start();690 }691 #endregion692693 success = true;694 }695 else696 {697 success = false;698 #region logging699 //logging exception700 var messageEx3 = new StringBuilder();701 messageEx3.Append("WorkstationManager_UploadIndicatorValues: ");702 messageEx3.Append("Transfer from " + monitoredSystemID + " and " + pluginName + " failed. Value (Object) was null.");703 MISD.Core.Logger.Instance.WriteEntry(messageEx3.ToString(), LogType.Debug);704 #endregion705 }706 }707 }708 }709 }710 catch (Exception e)711 {712 //logging exception713 var messageEx2 = new StringBuilder();714 messageEx2.Append("WorkstationManager_UploadIndicatorValues: ");715 messageEx2.Append("Transfer from " + monitoredSystemID + " and " + pluginName + " failed. " + e.ToString());716 MISD.Core.Logger.Instance.WriteEntry(messageEx2.ToString(), LogType.Exception);717 }718 return success;719 }720721 public List<IndicatorSettings> GetIndicatorSetting(string monitoredSystemMAC)722 {723 using (var dataContext = DataContextFactory.CreateReadOnlyDataContext())724 {725 try726 {727 var os = (from q in dataContext.MonitoredSystem728 where q.MacAddress == monitoredSystemMAC729 select q.OperatingSystem).FirstOrDefault();730731 //gets PluginMetadata and converts into DataHolder.PluginMetadata732 var settings = (from q in dataContext.Indicator733 where q.MonitoredSystem.MacAddress == monitoredSystemMAC734 where (q.PluginMetadata.Platform == os || q.PluginMetadata.Platform == 4)735 select new Core.IndicatorSettings()736 {737 PluginName = q.PluginMetadata.Name,738 IndicatorName = q.Name,739 MonitoredSystemMAC = monitoredSystemMAC,740 FilterStatement = q.FilterStatement,741 UpdateInterval = (q.UpdateInterval == null) ? new TimeSpan(1, 0, 0) : new TimeSpan((long)q.UpdateInterval),742 StorageDuration = (q.StorageDuration == null) ? new TimeSpan(31, 0, 0, 0) : new TimeSpan((long)q.StorageDuration),743 MappingDuration = (q.MappingDuration == null) ? new TimeSpan(24, 0, 0) : new TimeSpan((long)q.MappingDuration),744 DataType = (DataType)q.ValueType,745 MetricCritical = q.StatementCritical,746 MetricWarning = q.StatementWarning,747 IndicatorMapping = q.Status == null ? MappingState.OK : (MappingState)q.Status748 }).ToList();749750 return (List<Core.IndicatorSettings>)settings;751 }752 catch (Exception e)753 {754 //logging exception755 var messageEx = new StringBuilder();756 messageEx.Append("WorkstationManager_GetIndicatorSetting: ");757 messageEx.Append("Can't create list of indicator settings for " + monitoredSystemMAC + ". " + e.ToString());758 MISD.Core.Logger.Instance.WriteEntry(messageEx.ToString(), LogType.Exception);759760 return null;761 }762 }763 }764765 public bool SetIndicatorSetting(List<IndicatorSettings> settings)766 {767 using (var dataContext = DataContextFactory.CreateDataContext())768 {769 bool returns = true;770771 foreach (IndicatorSettings s in settings)772 {773 try774 {775 var setting = (from q in dataContext.Indicator776 where q.MonitoredSystem.MacAddress == s.MonitoredSystemMAC777 where q.PluginMetadata.Name == s.PluginName778 where q.Name == s.IndicatorName779 select q).FirstOrDefault();780781 if (setting != null)782 {783 setting.PluginMetadata.Name = s.PluginName;784 setting.Name = s.IndicatorName;785 setting.MonitoredSystem.MacAddress = s.MonitoredSystemMAC;786 setting.FilterStatement = s.FilterStatement;787 setting.UpdateInterval = s.UpdateInterval.Ticks;788 setting.StorageDuration = s.StorageDuration.Ticks;789 setting.MappingDuration = s.MappingDuration.Ticks;790 setting.ValueType = (byte)s.DataType;791 setting.StatementCritical = s.MetricCritical;792 setting.StatementWarning = s.MetricWarning;793 dataContext.SubmitChanges();794 }795 else796 {797 Logger.Instance.WriteEntry("WorkstationManager_SetIndicatorSetting: Could not find the indicator to be updated (name: " + s.IndicatorName + ")", LogType.Warning);798 }799 }800 catch (Exception e)801 {802 //logging exception803 var messageEx1 = new StringBuilder();804 messageEx1.Append("WorkstationManager_SetIndicatorSetting: ");805 messageEx1.Append("Setting of" + s + " failed. " + e.ToString());806 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);807 returns = false;808 }809 }810 return returns;811 }812 }813814 public List<string> AddWorkstationsToIgnoreList(List<Tuple<string, DateTime>> monitoredSystemMACAddresses)815 {816 using (var dataContext = DataContextFactory.CreateDataContext())817 {818 List<string> returns = new List<string>();819820 foreach (Tuple<string, DateTime> tuple in monitoredSystemMACAddresses)821 {822 try823 {824 var workstation = (from p in dataContext.MonitoredSystem825 where p.MacAddress == tuple.Item1826 select p).FirstOrDefault();827828 if (workstation != null && (workstation.LastUpdate == null || workstation.LastUpdate <= tuple.Item2.Ticks))829 {830 workstation.LastUpdate = tuple.Item2.Ticks;831832 workstation.IsIgnored = true;833834 835 dataContext.SubmitChanges();836 returns.Add(tuple.Item1);837838 // 839 }840 else841 {842 var messageEx1 = new StringBuilder();843 messageEx1.Append("WorkstationManager_AddWorkstationsToIgnoreList: ");844 messageEx1.Append("Adding of" + tuple.Item1 + "to IgnoreList failed. MS not found or update time too late.");845 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);846 }847848849 }850 catch (Exception e)851 {852 //logging exception853 var messageEx1 = new StringBuilder();854 messageEx1.Append("WorkstationManager_AddWorkstationsToIgnoreList: ");855 messageEx1.Append("Adding of" + tuple.Item1 + "to IgnoreList failed. " + e.ToString());856 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);857858 }859 }860 return returns;861 }862 }863864 public List<string> RemoveWorkstationsFromIgnoreList(List<Tuple<string, DateTime>> monitoredSystemMACAddresses)865 {866 using (var dataContext = DataContextFactory.CreateDataContext())867 {868 List<string> returns = new List<string>();869870 foreach (Tuple<string, DateTime> tuple in monitoredSystemMACAddresses)871 {872 try873 {874 var workstation = (from p in dataContext.MonitoredSystem875 where p.MacAddress == tuple.Item1876 select p).FirstOrDefault();877878 if (workstation != null && (workstation.LastUpdate == null || workstation.LastUpdate <= tuple.Item2.Ticks))879 {880 workstation.LastUpdate = tuple.Item2.Ticks;881882 workstation.IsIgnored = false;883884 dataContext.SubmitChanges();885 returns.Add(tuple.Item1);886887 //set new parent ou888 if (workstation.OrganizationalUnit.Name == "IgnoredOuForInternalUsageOfIgnoredSystems")889 {890 var ignoredou = (from p in dataContext.OrganizationalUnit891 where p.Name == "FromIgnored"892 select p).ToList();893 int id;894 if (ignoredou.Count == 0)895 {896 id = OUManager.Instance.AddOU("FromIgnored", null, System.DateTime.Now);897 }898 else 899 { 900 id = ignoredou.FirstOrDefault().ID; 901 }902903 //MoveMonitoredSystem to FromIgnored904 var msList = new List<Tuple<string, int, DateTime>>();905 msList.Add(new Tuple<string, int, DateTime>(workstation.MacAddress, id, DateTime.Now));906 WorkstationManager.Instance.MoveMonitoredSystem(msList);907 }908 }909 else910 {911 //logging exception912 var messageEx1 = new StringBuilder();913 messageEx1.Append("WorkstationManager_AddWorkstationsToIgnoreList: ");914 messageEx1.Append("Removing of" + tuple.Item1 + "from IgnoreList failed. MS not found or update time too late.");915 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);916 }917918 }919 catch (Exception e)920 {921 //logging exception922 var messageEx1 = new StringBuilder();923 messageEx1.Append("WorkstationManager_AddWorkstationsToIgnoreList: ");924 messageEx1.Append("Removing of" + tuple.Item1 + "from IgnoreList failed. " + e.ToString());925 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);926 }927 }928 return returns;929 }930 }931932 public List<Tuple<string, string>> GetIgnoredMonitoredSystems()933 {934 using (var dataContext = DataContextFactory.CreateReadOnlyDataContext())935 {936 try937 {938 List<Tuple<string, string>> returnList = new List<Tuple<string, string>>();939940 // TODO Jonas bitte drüber schauen :-)941 var ignoredMonitoredSystems = (from p in dataContext.MonitoredSystem942 where p.IsIgnored == true943 select p).ToList();944945 foreach (MonitoredSystem monitoredSystem in ignoredMonitoredSystems)946 {947 returnList.Add(new Tuple<string, string>(monitoredSystem.MacAddress, monitoredSystem.Name));948 }949950 return returnList;951 }952 catch (Exception e)953 {954 //logging exception955 var messageEx = new StringBuilder();956 messageEx.Append("WorkstationManager_GetIgnoredWorkstationNames: ");957 messageEx.Append("Can't create list of ignored workstations. " + e.ToString());958 MISD.Core.Logger.Instance.WriteEntry(messageEx.ToString(), LogType.Exception);959960 return null;961 }962 }963 }964965 public List<string> ActivateMaintenanceMode(List<Tuple<string, DateTime>> monitoredSystemMACAddresses)966 {967 using (var dataContext = DataContextFactory.CreateDataContext())968 {969 List<string> returns = new List<string>();970971 foreach (Tuple<string, DateTime> tuple in monitoredSystemMACAddresses)972 {973 try974 {975 /* COMMENT by Yannic: Now I need the whole monitored system. 976 var id = PrecompiledQueries.GetMonitoredSystemIDByMAC(dataContext, tuple.Item1);*/977978 var monitoredSystem = (from p in dataContext.MonitoredSystem979 where p.MacAddress == tuple.Item1980 select p).FirstOrDefault();981982 if (monitoredSystem != null && (monitoredSystem.LastUpdate == null || monitoredSystem.LastUpdate < tuple.Item2.Ticks))983 {984 monitoredSystem.LastUpdate = tuple.Item2.Ticks;985986 var maintenance = new Database.Maintenance()987 {988 MonitoredSystemID = monitoredSystem.ID,989 Beginning = System.DateTime.Now,990 End = null991 };992 993 dataContext.Maintenance.InsertOnSubmit(maintenance);994 dataContext.SubmitChanges();995 996 returns.Add(tuple.Item1);997 }998 else999 {1000 //logging1001 var messageEx1 = new StringBuilder();1002 messageEx1.Append("WorkstationManager_ActivateMaintenanceMode: ");1003 messageEx1.Append("Adding of" + tuple.Item1 + "to Maintenance failed. MS not found or update time too late.");1004 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);1005 }1006 }1007 catch (Exception e)1008 {1009 //logging exception1010 var messageEx1 = new StringBuilder();1011 messageEx1.Append("WorkstationManager_ActivateMaintenanceMode: ");1012 messageEx1.Append("Adding of" + tuple.Item1 + "to Maintenance failed. " + e.ToString());1013 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);1014 }1015 }1016 return returns;1017 }1018 }10191020 public List<string> DeactivateMaintenanceMode(List<Tuple<string, DateTime>> monitoredSystemMACAddresses)1021 {1022 using (var dataContext = DataContextFactory.CreateDataContext())1023 {1024 var returns = new List<string>();1025 foreach (Tuple<string, DateTime> tuple in monitoredSystemMACAddresses)1026 {10271028 var workstation = (from p in dataContext.Maintenance1029 let id = p.MonitoredSystem.MacAddress == tuple.Item11030 let start = p.Beginning != null1031 let stop = p.End == null1032 where id & start & stop1033 select p).FirstOrDefault();10341035 var monitoredSystem = (from p in dataContext.MonitoredSystem1036 where p.MacAddress == tuple.Item11037 select p).FirstOrDefault();10381039 if (workstation != null && monitoredSystem != null && (monitoredSystem.LastUpdate == null || monitoredSystem.LastUpdate < tuple.Item2.Ticks))1040 {1041 monitoredSystem.LastUpdate = tuple.Item2.Ticks;1042 workstation.End = System.DateTime.Now;1043 try1044 {1045 dataContext.SubmitChanges();1046 returns.Add(tuple.Item1);1047 }1048 catch (Exception e)1049 {1050 //logging exception1051 var messageEx1 = new StringBuilder();1052 messageEx1.Append("WorkstationManager_DeactivateMaintenanceMode: ");1053 messageEx1.Append("Removing of" + tuple.Item1 + "from Maintenance failed. " + e.ToString());1054 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);1055 }1056 }1057 else1058 {1059 //logging exception1060 var messageEx1 = new StringBuilder();1061 messageEx1.Append("WorkstationManager_DeactivateMaintenanceMode: ");1062 messageEx1.Append("Removing of" + tuple.Item1 + "from Maintenance failed. MS not found or update time too late.");1063 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);1064 }1065 1066 }1067 return returns;1068 }1069 }10701071 public bool MoveMonitoredSystem(List<Tuple<string, int, DateTime>> monitoredSystems)1072 {1073 using (var dataContext = DataContextFactory.CreateDataContext())1074 {1075 bool returnValue = true;1076 foreach (var tuple in monitoredSystems)1077 {1078 var workstation = (from p in dataContext.MonitoredSystem1079 where p.MacAddress == tuple.Item11080 select p).FirstOrDefault();10811082 if (workstation != null && (workstation.LastUpdate == null || workstation.LastUpdate < tuple.Item3.Ticks))1083 {1084 try1085 {1086 workstation.LastUpdate = tuple.Item3.Ticks;1087 workstation.OrganizationalUnitID = tuple.Item2;1088 dataContext.SubmitChanges();1089 }1090 catch (Exception e)1091 {1092 returnValue = false;10931094 //logging exception1095 var messageEx1 = new StringBuilder();1096 messageEx1.Append("WorkstationManager_MoveMonitoredSystem: ");1097 messageEx1.Append("Moving of monitored System with MAC=" + tuple.Item1 + " failed. " + e.ToString());1098 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);1099 }1100 }1101 else1102 {1103 //logging exception1104 var messageEx1 = new StringBuilder();1105 messageEx1.Append("WorkstationManager_MoveMonitoredSystem: ");1106 messageEx1.Append("Moving of monitored System with MAC=" + tuple.Item1 + " failed. MS not found or update time too late.");1107 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);1108 }1109 }1110 return returnValue;1111 }1112 }11131114 public bool ChangeWorkstationName(string mac, string newName, DateTime updateTime)1115 {1116 if (newName == String.Empty)1117 {1118 return false;1119 }1120 try1121 {1122 using (var dataContext = DataContextFactory.CreateDataContext())1123 {1124 var ms = PrecompiledQueries.GetMonitoredSystemByMAC(dataContext, mac);11251126 if (ms != null && (ms.LastUpdate == null || ms.LastUpdate < updateTime.Ticks))1127 {1128 ms.Name = newName;1129 ms.LastUpdate = updateTime.Ticks;1130 dataContext.SubmitChanges();1131 return true; 1132 }1133 else1134 {1135 //logging exception1136 var messageEx1 = new StringBuilder();1137 messageEx1.Append("WorkstationManager_ChangeWorkstationName: ");1138 messageEx1.Append("Name of ms" + mac + "to" + newName + " failed. " + "UpdateTime to late or MS not found.");1139 MISD.Core.Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Warning);1140 return false;1141 }1142 }1143 }1144 catch (Exception e)1145 {1146 Logger.Instance.WriteEntry("WorkstationManager_ChangeWorkstationName: Can't change name" + e.StackTrace, LogType.Exception);1147 return false;1148 }1149 }11501151 #endregion1152 }1153} ...

Full Screen

Full Screen

Tuple.cs

Source:Tuple.cs Github

copy

Full Screen

...15 /// Helper so we can call some tuple methods recursively without knowing the underlying types.16 /// </summary>17 internal interface ITupleInternal : ITuple18 {19 string ToString(StringBuilder sb);20 int GetHashCode(IEqualityComparer comparer);21 }22 public static class Tuple23 {24 public static Tuple<T1> Create<T1>(T1 item1)25 {26 return new Tuple<T1>(item1);27 }28 public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)29 {30 return new Tuple<T1, T2>(item1, item2);31 }32 public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3)33 {34 return new Tuple<T1, T2, T3>(item1, item2, item3);35 }36 public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4)37 {38 return new Tuple<T1, T2, T3, T4>(item1, item2, item3, item4);39 }40 public static Tuple<T1, T2, T3, T4, T5> Create<T1, T2, T3, T4, T5>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)41 {42 return new Tuple<T1, T2, T3, T4, T5>(item1, item2, item3, item4, item5);43 }44 public static Tuple<T1, T2, T3, T4, T5, T6> Create<T1, T2, T3, T4, T5, T6>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)45 {46 return new Tuple<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, item6);47 }48 public static Tuple<T1, T2, T3, T4, T5, T6, T7> Create<T1, T2, T3, T4, T5, T6, T7>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)49 {50 return new Tuple<T1, T2, T3, T4, T5, T6, T7>(item1, item2, item3, item4, item5, item6, item7);51 }52 public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8)53 {54 return new Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<T8>(item8));55 }56 // Note: F# compiler depends on the exact tuple hashing algorithm. Do not ever change it.57 // From System.Web.Util.HashCodeCombiner58 internal static int CombineHashCodes(int h1, int h2)59 {60 return ((h1 << 5) + h1) ^ h2;61 }62 internal static int CombineHashCodes(int h1, int h2, int h3)63 {64 return CombineHashCodes(CombineHashCodes(h1, h2), h3);65 }66 internal static int CombineHashCodes(int h1, int h2, int h3, int h4)67 {68 return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));69 }70 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5)71 {72 return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);73 }74 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6)75 {76 return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6));77 }78 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7)79 {80 return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7));81 }82 internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8)83 {84 return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8));85 }86 }87 [Serializable]88 public class Tuple<T1> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple89 {90 private readonly T1 m_Item1; // Do not rename (binary serialization)91 public T1 Item1 => m_Item1;92 public Tuple(T1 item1)93 {94 m_Item1 = item1;95 }96 public override bool Equals([NotNullWhen(true)] object? obj)97 {98 return Equals(obj, EqualityComparer<object>.Default);99 }100 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)101 {102 return Equals(other, comparer);103 }104 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)105 {106 if (other == null) return false;107 if (other is not Tuple<T1> objTuple)108 {109 return false;110 }111 return comparer.Equals(m_Item1, objTuple.m_Item1);112 }113 int IComparable.CompareTo(object? obj)114 {115 return CompareTo(obj, Comparer<object>.Default);116 }117 int IStructuralComparable.CompareTo(object? other, IComparer comparer)118 {119 return CompareTo(other, comparer);120 }121 private int CompareTo(object? other, IComparer comparer)122 {123 if (other == null) return 1;124 if (other is not Tuple<T1> objTuple)125 {126 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));127 }128 return comparer.Compare(m_Item1, objTuple.m_Item1);129 }130 public override int GetHashCode()131 {132 return GetHashCode(EqualityComparer<object>.Default);133 }134 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)135 {136 return GetHashCode(comparer);137 }138 int ITupleInternal.GetHashCode(IEqualityComparer comparer)139 {140 return GetHashCode(comparer);141 }142 private int GetHashCode(IEqualityComparer comparer)143 {144 return comparer.GetHashCode(m_Item1!);145 }146 public override string ToString()147 {148 StringBuilder sb = new StringBuilder();149 sb.Append('(');150 return ToString(sb);151 }152 string ITupleInternal.ToString(StringBuilder sb)153 {154 return ToString(sb);155 }156 private string ToString(StringBuilder sb)157 {158 sb.Append(m_Item1);159 sb.Append(')');160 return sb.ToString();161 }162 /// <summary>163 /// The number of positions in this data structure.164 /// </summary>165 int ITuple.Length => 1;166 /// <summary>167 /// Get the element at position <param name="index"/>.168 /// </summary>169 object? ITuple.this[int index]170 {171 get172 {173 if (index != 0)174 {175 throw new IndexOutOfRangeException();176 }177 return Item1;178 }179 }180 }181 [Serializable]182 public class Tuple<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple183 {184 private readonly T1 m_Item1; // Do not rename (binary serialization)185 private readonly T2 m_Item2; // Do not rename (binary serialization)186 public T1 Item1 => m_Item1;187 public T2 Item2 => m_Item2;188 public Tuple(T1 item1, T2 item2)189 {190 m_Item1 = item1;191 m_Item2 = item2;192 }193 public override bool Equals([NotNullWhen(true)] object? obj)194 {195 return Equals(obj, EqualityComparer<object>.Default);196 }197 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)198 {199 return Equals(other, comparer);200 }201 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)202 {203 if (other == null) return false;204 if (other is not Tuple<T1, T2> objTuple)205 {206 return false;207 }208 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2);209 }210 int IComparable.CompareTo(object? obj)211 {212 return CompareTo(obj, Comparer<object>.Default);213 }214 int IStructuralComparable.CompareTo(object? other, IComparer comparer)215 {216 return CompareTo(other, comparer);217 }218 private int CompareTo(object? other, IComparer comparer)219 {220 if (other == null) return 1;221 if (other is not Tuple<T1, T2> objTuple)222 {223 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));224 }225 int c = comparer.Compare(m_Item1, objTuple.m_Item1);226 if (c != 0) return c;227 return comparer.Compare(m_Item2, objTuple.m_Item2);228 }229 public override int GetHashCode()230 {231 return GetHashCode(EqualityComparer<object>.Default);232 }233 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)234 {235 return GetHashCode(comparer);236 }237 int ITupleInternal.GetHashCode(IEqualityComparer comparer)238 {239 return GetHashCode(comparer);240 }241 private int GetHashCode(IEqualityComparer comparer)242 {243 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!));244 }245 public override string ToString()246 {247 StringBuilder sb = new StringBuilder();248 sb.Append('(');249 return ToString(sb);250 }251 string ITupleInternal.ToString(StringBuilder sb)252 {253 return ToString(sb);254 }255 private string ToString(StringBuilder sb)256 {257 sb.Append(m_Item1);258 sb.Append(", ");259 sb.Append(m_Item2);260 sb.Append(')');261 return sb.ToString();262 }263 /// <summary>264 /// The number of positions in this data structure.265 /// </summary>266 int ITuple.Length => 2;267 /// <summary>268 /// Get the element at position <param name="index"/>.269 /// </summary>270 object? ITuple.this[int index] =>271 index switch272 {273 0 => Item1,274 1 => Item2,275 _ => throw new IndexOutOfRangeException(),276 };277 }278 [Serializable]279 public class Tuple<T1, T2, T3> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple280 {281 private readonly T1 m_Item1; // Do not rename (binary serialization)282 private readonly T2 m_Item2; // Do not rename (binary serialization)283 private readonly T3 m_Item3; // Do not rename (binary serialization)284 public T1 Item1 => m_Item1;285 public T2 Item2 => m_Item2;286 public T3 Item3 => m_Item3;287 public Tuple(T1 item1, T2 item2, T3 item3)288 {289 m_Item1 = item1;290 m_Item2 = item2;291 m_Item3 = item3;292 }293 public override bool Equals([NotNullWhen(true)] object? obj)294 {295 return Equals(obj, EqualityComparer<object>.Default);296 }297 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)298 {299 return Equals(other, comparer);300 }301 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)302 {303 if (other == null) return false;304 if (other is not Tuple<T1, T2, T3> objTuple)305 {306 return false;307 }308 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3);309 }310 int IComparable.CompareTo(object? obj)311 {312 return CompareTo(obj, Comparer<object>.Default);313 }314 int IStructuralComparable.CompareTo(object? other, IComparer comparer)315 {316 return CompareTo(other, comparer);317 }318 private int CompareTo(object? other, IComparer comparer)319 {320 if (other == null) return 1;321 if (other is not Tuple<T1, T2, T3> objTuple)322 {323 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));324 }325 int c = comparer.Compare(m_Item1, objTuple.m_Item1);326 if (c != 0) return c;327 c = comparer.Compare(m_Item2, objTuple.m_Item2);328 if (c != 0) return c;329 return comparer.Compare(m_Item3, objTuple.m_Item3);330 }331 public override int GetHashCode()332 {333 return GetHashCode(EqualityComparer<object>.Default);334 }335 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)336 {337 return GetHashCode(comparer);338 }339 int ITupleInternal.GetHashCode(IEqualityComparer comparer)340 {341 return GetHashCode(comparer);342 }343 private int GetHashCode(IEqualityComparer comparer)344 {345 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!));346 }347 public override string ToString()348 {349 StringBuilder sb = new StringBuilder();350 sb.Append('(');351 return ToString(sb);352 }353 string ITupleInternal.ToString(StringBuilder sb)354 {355 return ToString(sb);356 }357 private string ToString(StringBuilder sb)358 {359 sb.Append(m_Item1);360 sb.Append(", ");361 sb.Append(m_Item2);362 sb.Append(", ");363 sb.Append(m_Item3);364 sb.Append(')');365 return sb.ToString();366 }367 /// <summary>368 /// The number of positions in this data structure.369 /// </summary>370 int ITuple.Length => 3;371 /// <summary>372 /// Get the element at position <param name="index"/>.373 /// </summary>374 object? ITuple.this[int index] =>375 index switch376 {377 0 => Item1,378 1 => Item2,379 2 => Item3,380 _ => throw new IndexOutOfRangeException(),381 };382 }383 [Serializable]384 public class Tuple<T1, T2, T3, T4> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple385 {386 private readonly T1 m_Item1; // Do not rename (binary serialization)387 private readonly T2 m_Item2; // Do not rename (binary serialization)388 private readonly T3 m_Item3; // Do not rename (binary serialization)389 private readonly T4 m_Item4; // Do not rename (binary serialization)390 public T1 Item1 => m_Item1;391 public T2 Item2 => m_Item2;392 public T3 Item3 => m_Item3;393 public T4 Item4 => m_Item4;394 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4)395 {396 m_Item1 = item1;397 m_Item2 = item2;398 m_Item3 = item3;399 m_Item4 = item4;400 }401 public override bool Equals([NotNullWhen(true)] object? obj)402 {403 return Equals(obj, EqualityComparer<object>.Default);404 }405 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)406 {407 return Equals(other, comparer);408 }409 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)410 {411 if (other == null) return false;412 if (other is not Tuple<T1, T2, T3, T4> objTuple)413 {414 return false;415 }416 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4);417 }418 int IComparable.CompareTo(object? obj)419 {420 return CompareTo(obj, Comparer<object>.Default);421 }422 int IStructuralComparable.CompareTo(object? other, IComparer comparer)423 {424 return CompareTo(other, comparer);425 }426 private int CompareTo(object? other, IComparer comparer)427 {428 if (other == null) return 1;429 if (other is not Tuple<T1, T2, T3, T4> objTuple)430 {431 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));432 }433 int c = comparer.Compare(m_Item1, objTuple.m_Item1);434 if (c != 0) return c;435 c = comparer.Compare(m_Item2, objTuple.m_Item2);436 if (c != 0) return c;437 c = comparer.Compare(m_Item3, objTuple.m_Item3);438 if (c != 0) return c;439 return comparer.Compare(m_Item4, objTuple.m_Item4);440 }441 public override int GetHashCode()442 {443 return GetHashCode(EqualityComparer<object>.Default);444 }445 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)446 {447 return GetHashCode(comparer);448 }449 int ITupleInternal.GetHashCode(IEqualityComparer comparer)450 {451 return GetHashCode(comparer);452 }453 private int GetHashCode(IEqualityComparer comparer)454 {455 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!));456 }457 public override string ToString()458 {459 StringBuilder sb = new StringBuilder();460 sb.Append('(');461 return ToString(sb);462 }463 string ITupleInternal.ToString(StringBuilder sb)464 {465 return ToString(sb);466 }467 private string ToString(StringBuilder sb)468 {469 sb.Append(m_Item1);470 sb.Append(", ");471 sb.Append(m_Item2);472 sb.Append(", ");473 sb.Append(m_Item3);474 sb.Append(", ");475 sb.Append(m_Item4);476 sb.Append(')');477 return sb.ToString();478 }479 /// <summary>480 /// The number of positions in this data structure.481 /// </summary>482 int ITuple.Length => 4;483 /// <summary>484 /// Get the element at position <param name="index"/>.485 /// </summary>486 object? ITuple.this[int index] =>487 index switch488 {489 0 => Item1,490 1 => Item2,491 2 => Item3,492 3 => Item4,493 _ => throw new IndexOutOfRangeException(),494 };495 }496 [Serializable]497 public class Tuple<T1, T2, T3, T4, T5> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple498 {499 private readonly T1 m_Item1; // Do not rename (binary serialization)500 private readonly T2 m_Item2; // Do not rename (binary serialization)501 private readonly T3 m_Item3; // Do not rename (binary serialization)502 private readonly T4 m_Item4; // Do not rename (binary serialization)503 private readonly T5 m_Item5; // Do not rename (binary serialization)504 public T1 Item1 => m_Item1;505 public T2 Item2 => m_Item2;506 public T3 Item3 => m_Item3;507 public T4 Item4 => m_Item4;508 public T5 Item5 => m_Item5;509 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5)510 {511 m_Item1 = item1;512 m_Item2 = item2;513 m_Item3 = item3;514 m_Item4 = item4;515 m_Item5 = item5;516 }517 public override bool Equals([NotNullWhen(true)] object? obj)518 {519 return Equals(obj, EqualityComparer<object>.Default);520 }521 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)522 {523 return Equals(other, comparer);524 }525 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)526 {527 if (other == null) return false;528 if (other is not Tuple<T1, T2, T3, T4, T5> objTuple)529 {530 return false;531 }532 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5);533 }534 int IComparable.CompareTo(object? obj)535 {536 return CompareTo(obj, Comparer<object>.Default);537 }538 int IStructuralComparable.CompareTo(object? other, IComparer comparer)539 {540 return CompareTo(other, comparer);541 }542 private int CompareTo(object? other, IComparer comparer)543 {544 if (other == null) return 1;545 if (other is not Tuple<T1, T2, T3, T4, T5> objTuple)546 {547 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));548 }549 int c = comparer.Compare(m_Item1, objTuple.m_Item1);550 if (c != 0) return c;551 c = comparer.Compare(m_Item2, objTuple.m_Item2);552 if (c != 0) return c;553 c = comparer.Compare(m_Item3, objTuple.m_Item3);554 if (c != 0) return c;555 c = comparer.Compare(m_Item4, objTuple.m_Item4);556 if (c != 0) return c;557 return comparer.Compare(m_Item5, objTuple.m_Item5);558 }559 public override int GetHashCode()560 {561 return GetHashCode(EqualityComparer<object>.Default);562 }563 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)564 {565 return GetHashCode(comparer);566 }567 int ITupleInternal.GetHashCode(IEqualityComparer comparer)568 {569 return GetHashCode(comparer);570 }571 private int GetHashCode(IEqualityComparer comparer)572 {573 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!));574 }575 public override string ToString()576 {577 StringBuilder sb = new StringBuilder();578 sb.Append('(');579 return ToString(sb);580 }581 string ITupleInternal.ToString(StringBuilder sb)582 {583 return ToString(sb);584 }585 private string ToString(StringBuilder sb)586 {587 sb.Append(m_Item1);588 sb.Append(", ");589 sb.Append(m_Item2);590 sb.Append(", ");591 sb.Append(m_Item3);592 sb.Append(", ");593 sb.Append(m_Item4);594 sb.Append(", ");595 sb.Append(m_Item5);596 sb.Append(')');597 return sb.ToString();598 }599 /// <summary>600 /// The number of positions in this data structure.601 /// </summary>602 int ITuple.Length => 5;603 /// <summary>604 /// Get the element at position <param name="index"/>.605 /// </summary>606 object? ITuple.this[int index] =>607 index switch608 {609 0 => Item1,610 1 => Item2,611 2 => Item3,612 3 => Item4,613 4 => Item5,614 _ => throw new IndexOutOfRangeException(),615 };616 }617 [Serializable]618 public class Tuple<T1, T2, T3, T4, T5, T6> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple619 {620 private readonly T1 m_Item1; // Do not rename (binary serialization)621 private readonly T2 m_Item2; // Do not rename (binary serialization)622 private readonly T3 m_Item3; // Do not rename (binary serialization)623 private readonly T4 m_Item4; // Do not rename (binary serialization)624 private readonly T5 m_Item5; // Do not rename (binary serialization)625 private readonly T6 m_Item6; // Do not rename (binary serialization)626 public T1 Item1 => m_Item1;627 public T2 Item2 => m_Item2;628 public T3 Item3 => m_Item3;629 public T4 Item4 => m_Item4;630 public T5 Item5 => m_Item5;631 public T6 Item6 => m_Item6;632 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6)633 {634 m_Item1 = item1;635 m_Item2 = item2;636 m_Item3 = item3;637 m_Item4 = item4;638 m_Item5 = item5;639 m_Item6 = item6;640 }641 public override bool Equals([NotNullWhen(true)] object? obj)642 {643 return Equals(obj, EqualityComparer<object>.Default);644 }645 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)646 {647 return Equals(other, comparer);648 }649 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)650 {651 if (other == null) return false;652 if (other is not Tuple<T1, T2, T3, T4, T5, T6> objTuple)653 {654 return false;655 }656 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6);657 }658 int IComparable.CompareTo(object? obj)659 {660 return CompareTo(obj, Comparer<object>.Default);661 }662 int IStructuralComparable.CompareTo(object? other, IComparer comparer)663 {664 return CompareTo(other, comparer);665 }666 private int CompareTo(object? other, IComparer comparer)667 {668 if (other == null) return 1;669 if (other is not Tuple<T1, T2, T3, T4, T5, T6> objTuple)670 {671 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));672 }673 int c = comparer.Compare(m_Item1, objTuple.m_Item1);674 if (c != 0) return c;675 c = comparer.Compare(m_Item2, objTuple.m_Item2);676 if (c != 0) return c;677 c = comparer.Compare(m_Item3, objTuple.m_Item3);678 if (c != 0) return c;679 c = comparer.Compare(m_Item4, objTuple.m_Item4);680 if (c != 0) return c;681 c = comparer.Compare(m_Item5, objTuple.m_Item5);682 if (c != 0) return c;683 return comparer.Compare(m_Item6, objTuple.m_Item6);684 }685 public override int GetHashCode()686 {687 return GetHashCode(EqualityComparer<object>.Default);688 }689 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)690 {691 return GetHashCode(comparer);692 }693 int ITupleInternal.GetHashCode(IEqualityComparer comparer)694 {695 return GetHashCode(comparer);696 }697 private int GetHashCode(IEqualityComparer comparer)698 {699 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!));700 }701 public override string ToString()702 {703 StringBuilder sb = new StringBuilder();704 sb.Append('(');705 return ToString(sb);706 }707 string ITupleInternal.ToString(StringBuilder sb)708 {709 return ToString(sb);710 }711 private string ToString(StringBuilder sb)712 {713 sb.Append(m_Item1);714 sb.Append(", ");715 sb.Append(m_Item2);716 sb.Append(", ");717 sb.Append(m_Item3);718 sb.Append(", ");719 sb.Append(m_Item4);720 sb.Append(", ");721 sb.Append(m_Item5);722 sb.Append(", ");723 sb.Append(m_Item6);724 sb.Append(')');725 return sb.ToString();726 }727 /// <summary>728 /// The number of positions in this data structure.729 /// </summary>730 int ITuple.Length => 6;731 /// <summary>732 /// Get the element at position <param name="index"/>.733 /// </summary>734 object? ITuple.this[int index] =>735 index switch736 {737 0 => Item1,738 1 => Item2,739 2 => Item3,740 3 => Item4,741 4 => Item5,742 5 => Item6,743 _ => throw new IndexOutOfRangeException(),744 };745 }746 [Serializable]747 public class Tuple<T1, T2, T3, T4, T5, T6, T7> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple748 {749 private readonly T1 m_Item1; // Do not rename (binary serialization)750 private readonly T2 m_Item2; // Do not rename (binary serialization)751 private readonly T3 m_Item3; // Do not rename (binary serialization)752 private readonly T4 m_Item4; // Do not rename (binary serialization)753 private readonly T5 m_Item5; // Do not rename (binary serialization)754 private readonly T6 m_Item6; // Do not rename (binary serialization)755 private readonly T7 m_Item7; // Do not rename (binary serialization)756 public T1 Item1 => m_Item1;757 public T2 Item2 => m_Item2;758 public T3 Item3 => m_Item3;759 public T4 Item4 => m_Item4;760 public T5 Item5 => m_Item5;761 public T6 Item6 => m_Item6;762 public T7 Item7 => m_Item7;763 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7)764 {765 m_Item1 = item1;766 m_Item2 = item2;767 m_Item3 = item3;768 m_Item4 = item4;769 m_Item5 = item5;770 m_Item6 = item6;771 m_Item7 = item7;772 }773 public override bool Equals([NotNullWhen(true)] object? obj)774 {775 return Equals(obj, EqualityComparer<object>.Default);776 }777 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)778 {779 return Equals(other, comparer);780 }781 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)782 {783 if (other == null) return false;784 if (other is not Tuple<T1, T2, T3, T4, T5, T6, T7> objTuple)785 {786 return false;787 }788 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6) && comparer.Equals(m_Item7, objTuple.m_Item7);789 }790 int IComparable.CompareTo(object? obj)791 {792 return ((IStructuralComparable)this).CompareTo(obj, Comparer<object>.Default);793 }794 int IStructuralComparable.CompareTo(object? other, IComparer comparer)795 {796 return CompareTo(other, comparer);797 }798 private int CompareTo(object? other, IComparer comparer)799 {800 if (other == null) return 1;801 if (other is not Tuple<T1, T2, T3, T4, T5, T6, T7> objTuple)802 {803 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));804 }805 int c = comparer.Compare(m_Item1, objTuple.m_Item1);806 if (c != 0) return c;807 c = comparer.Compare(m_Item2, objTuple.m_Item2);808 if (c != 0) return c;809 c = comparer.Compare(m_Item3, objTuple.m_Item3);810 if (c != 0) return c;811 c = comparer.Compare(m_Item4, objTuple.m_Item4);812 if (c != 0) return c;813 c = comparer.Compare(m_Item5, objTuple.m_Item5);814 if (c != 0) return c;815 c = comparer.Compare(m_Item6, objTuple.m_Item6);816 if (c != 0) return c;817 return comparer.Compare(m_Item7, objTuple.m_Item7);818 }819 public override int GetHashCode()820 {821 return GetHashCode(EqualityComparer<object>.Default);822 }823 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)824 {825 return GetHashCode(comparer);826 }827 int ITupleInternal.GetHashCode(IEqualityComparer comparer)828 {829 return GetHashCode(comparer);830 }831 private int GetHashCode(IEqualityComparer comparer)832 {833 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!));834 }835 public override string ToString()836 {837 StringBuilder sb = new StringBuilder();838 sb.Append('(');839 return ToString(sb);840 }841 string ITupleInternal.ToString(StringBuilder sb)842 {843 return ToString(sb);844 }845 private string ToString(StringBuilder sb)846 {847 sb.Append(m_Item1);848 sb.Append(", ");849 sb.Append(m_Item2);850 sb.Append(", ");851 sb.Append(m_Item3);852 sb.Append(", ");853 sb.Append(m_Item4);854 sb.Append(", ");855 sb.Append(m_Item5);856 sb.Append(", ");857 sb.Append(m_Item6);858 sb.Append(", ");859 sb.Append(m_Item7);860 sb.Append(')');861 return sb.ToString();862 }863 /// <summary>864 /// The number of positions in this data structure.865 /// </summary>866 int ITuple.Length => 7;867 /// <summary>868 /// Get the element at position <param name="index"/>.869 /// </summary>870 object? ITuple.this[int index] =>871 index switch872 {873 0 => Item1,874 1 => Item2,875 2 => Item3,876 3 => Item4,877 4 => Item5,878 5 => Item6,879 6 => Item7,880 _ => throw new IndexOutOfRangeException(),881 };882 }883 [Serializable]884 public class Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> : IStructuralEquatable, IStructuralComparable, IComparable, ITupleInternal, ITuple where TRest : notnull885 {886 private readonly T1 m_Item1; // Do not rename (binary serialization)887 private readonly T2 m_Item2; // Do not rename (binary serialization)888 private readonly T3 m_Item3; // Do not rename (binary serialization)889 private readonly T4 m_Item4; // Do not rename (binary serialization)890 private readonly T5 m_Item5; // Do not rename (binary serialization)891 private readonly T6 m_Item6; // Do not rename (binary serialization)892 private readonly T7 m_Item7; // Do not rename (binary serialization)893 private readonly TRest m_Rest; // Do not rename (binary serialization)894 public T1 Item1 => m_Item1;895 public T2 Item2 => m_Item2;896 public T3 Item3 => m_Item3;897 public T4 Item4 => m_Item4;898 public T5 Item5 => m_Item5;899 public T6 Item6 => m_Item6;900 public T7 Item7 => m_Item7;901 public TRest Rest => m_Rest;902 public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)903 {904 if (rest is not ITupleInternal)905 {906 throw new ArgumentException(SR.ArgumentException_TupleLastArgumentNotATuple);907 }908 m_Item1 = item1;909 m_Item2 = item2;910 m_Item3 = item3;911 m_Item4 = item4;912 m_Item5 = item5;913 m_Item6 = item6;914 m_Item7 = item7;915 m_Rest = rest;916 }917 public override bool Equals([NotNullWhen(true)] object? obj)918 {919 return Equals(obj, EqualityComparer<object>.Default);920 }921 bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)922 {923 return Equals(other, comparer);924 }925 private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer)926 {927 if (other == null) return false;928 if (other is not Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objTuple)929 {930 return false;931 }932 return comparer.Equals(m_Item1, objTuple.m_Item1) && comparer.Equals(m_Item2, objTuple.m_Item2) && comparer.Equals(m_Item3, objTuple.m_Item3) && comparer.Equals(m_Item4, objTuple.m_Item4) && comparer.Equals(m_Item5, objTuple.m_Item5) && comparer.Equals(m_Item6, objTuple.m_Item6) && comparer.Equals(m_Item7, objTuple.m_Item7) && comparer.Equals(m_Rest, objTuple.m_Rest);933 }934 int IComparable.CompareTo(object? obj)935 {936 return CompareTo(obj, Comparer<object>.Default);937 }938 int IStructuralComparable.CompareTo(object? other, IComparer comparer)939 {940 return CompareTo(other, comparer);941 }942 private int CompareTo(object? other, IComparer comparer)943 {944 if (other == null) return 1;945 if (other is not Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objTuple)946 {947 throw new ArgumentException(string.Format(SR.ArgumentException_TupleIncorrectType, GetType()), nameof(other));948 }949 int c = comparer.Compare(m_Item1, objTuple.m_Item1);950 if (c != 0) return c;951 c = comparer.Compare(m_Item2, objTuple.m_Item2);952 if (c != 0) return c;953 c = comparer.Compare(m_Item3, objTuple.m_Item3);954 if (c != 0) return c;955 c = comparer.Compare(m_Item4, objTuple.m_Item4);956 if (c != 0) return c;957 c = comparer.Compare(m_Item5, objTuple.m_Item5);958 if (c != 0) return c;959 c = comparer.Compare(m_Item6, objTuple.m_Item6);960 if (c != 0) return c;961 c = comparer.Compare(m_Item7, objTuple.m_Item7);962 if (c != 0) return c;963 return comparer.Compare(m_Rest, objTuple.m_Rest);964 }965 public override int GetHashCode()966 {967 return GetHashCode(EqualityComparer<object>.Default);968 }969 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)970 {971 return GetHashCode(comparer);972 }973 private int GetHashCode(IEqualityComparer comparer)974 {975 // We want to have a limited hash in this case. We'll use the last 8 elements of the tuple976 ITupleInternal t = (ITupleInternal)m_Rest;977 if (t.Length >= 8) { return t.GetHashCode(comparer); }978 // In this case, the m_Rest member has fewer than 8 elements so we need to combine our elements with the elements in m_Rest.979 int k = 8 - t.Length;980 switch (k)981 {982 case 1:983 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));984 case 2:985 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));986 case 3:987 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));988 case 4:989 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));990 case 5:991 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));992 case 6:993 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));994 case 7:995 return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer));996 }997 Debug.Fail("Missed all cases for computing Tuple hash code");998 return -1;999 }1000 int ITupleInternal.GetHashCode(IEqualityComparer comparer)1001 {1002 return GetHashCode(comparer);1003 }1004 public override string ToString()1005 {1006 StringBuilder sb = new StringBuilder();1007 sb.Append('(');1008 return ToString(sb);1009 }1010 string ITupleInternal.ToString(StringBuilder sb)1011 {1012 return ToString(sb);1013 }1014 private string ToString(StringBuilder sb)1015 {1016 sb.Append(m_Item1);1017 sb.Append(", ");1018 sb.Append(m_Item2);1019 sb.Append(", ");1020 sb.Append(m_Item3);1021 sb.Append(", ");1022 sb.Append(m_Item4);1023 sb.Append(", ");1024 sb.Append(m_Item5);1025 sb.Append(", ");1026 sb.Append(m_Item6);1027 sb.Append(", ");1028 sb.Append(m_Item7);1029 sb.Append(", ");1030 return ((ITupleInternal)m_Rest).ToString(sb);1031 }1032 /// <summary>1033 /// The number of positions in this data structure.1034 /// </summary>1035 int ITuple.Length => 7 + ((ITupleInternal)Rest).Length;1036 /// <summary>1037 /// Get the element at position <param name="index"/>.1038 /// </summary>1039 object? ITuple.this[int index] =>1040 index switch1041 {1042 0 => Item1,1043 1 => Item2,1044 2 => Item3,...

Full Screen

Full Screen

OBJSeleForm.cs

Source:OBJSeleForm.cs Github

copy

Full Screen

...90 {91 DataRow newRow = dataTable.NewRow();92 TabPage newtabPage = new TabPage();93 newRow["面积"] = area.TupleSelect(i);94 newRow["宽"] = width.TupleSelect(i).D.ToString("0.0");95 newRow["高"] = height.TupleSelect(i).D.ToString("0.0");96 newRow["宽高比"] = ratio.TupleSelect(i).D.ToString("0.0");97 newRow["外圆半径"] = radius.TupleSelect(i).D.ToString("0.0");98 newRow["内圆半径"] = InnerRadius.TupleSelect(i).D.ToString("0.0");99 newRow["圆度"] = circularity.TupleSelect(i).D.ToString("0.00");100 newRow["row"] = rows.TupleSelect(i).D.ToString("0.0");101 newRow["col"] = cols.TupleSelect(i).D.ToString("0.0");102 newRow["length1"] = length1.TupleSelect(i).D.ToString("0.0");103 newRow["length2"] = length2.TupleSelect(i).D.ToString("0.0");104 newRow["phi"] = phi.TupleSelect(i).TupleDeg().D.ToString("0.0");105 newRow["紧密"] = compatness.TupleSelect(i).D.ToString("0.0");106 newRow["轮廓长度"] = contLength.TupleSelect(i).D.ToString("0.0");107 newRow["矩形度"] = rectangularity.TupleSelect(i).D.ToString("0.0");108 newRow["中心平均距离"] = distance.TupleSelect(i).D.ToString("0.0");109 newRow["距离的标准差"] = sigma.TupleSelect(i).D.ToString("0.0");110 newRow["园度因子"] = roundness.TupleSelect(i).D.ToString("0.0");111 newRow["多边形边数"] = sides.TupleSelect(i).D.ToString("0.0");112 113 newRow["row1"] = row1.TupleSelect(i).D.ToString("0.0");114 newRow["col1"] = column1.TupleSelect(i).D.ToString("0.0");115 newRow["row2"] = row2.TupleSelect(i).D.ToString("0.0");116 newRow["col2"] = col2.TupleSelect(i).D.ToString("0.0");117 newRow["inRow1"] = inRow1.TupleSelect(i).D.ToString("0.0");118 newRow["inCol1"] = inCol1.TupleSelect(i).D.ToString("0.0");119 newRow["inRow2"] = inRow2.TupleSelect(i).D.ToString("0.0");120 newRow["inCol2"] = inCol2.TupleSelect(i).D.ToString("0.0");121 newRow["区域空洞"] = numHoles.TupleSelect(i).D.ToString("0.0");122 newRow["连接数量"] = numConnected.TupleSelect(i).D.ToString("0.0");123 //tpgListReadW.TabPages.Add(newtabPage);124 dataTable.Rows.Add(newRow);125 ////DictionaryEntry dictionaryEntry = new DictionaryEntry("","");126 //dataGridView1.Rows[i].Cells[0].Value = area.TupleSelect(i);127 //dataGridView1.Rows[i].Cells[1].Value = row.TupleSelect(i).D . ToString("0.0");128 //dataGridView1.Rows[i].Cells[2].Value = column.TupleSelect(i).D.ToString("0.0");129 //dataGridView1.Rows[i].Cells[3].Value = circularity.TupleSelect(i).D.ToString("0.00");130 //dataGridView1.Rows[i].Cells[4].Value = length1.TupleSelect(i).D.ToString("0.0");131 //dataGridView1.Rows[i].Cells[5].Value = length2.TupleSelect(i).D.ToString("0.0");132 //dataGridView1.Rows[i].Cells[6].Value = phi.TupleSelect(i).TupleDeg().D.ToString("0.0");133 index.Append(i+1);134 //Al.Add(dictionaryEntry);135 }136 dataGridView1.DataSource = dataTable;137 HWind.OneResIamge.AddImageMassage(rows, cols, index);138 }139 }140 catch (Exception ex)141 {142 }143 }144 private void OBJSeleForm_Load(object sender, EventArgs e)145 {146 HWind.Initialize(hWindowControl1);147 HWind.OneResIamge.ColorResu = ColorResult.blue;148 }149 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)150 {151 152 }153 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)154 {155 try156 {157 HWind.HobjClear();158 HOperatorSet.SelectObj(HObjectErr, out HObject hObject, e.RowIndex + 1);159 HWind.OneResIamge.GetKeyHobj().Clear();160 HWind.OneResIamge.AddNameOBJ("sele", hObject, Color.Red.Name.ToLower());161 HWind.AddObj(HObjectErr.RemoveObj(e.RowIndex+1));162 HOperatorSet.SmallestRectangle2(hObject, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2);163 HOperatorSet.AreaCenter(hObject, out HTuple area, out row, out HTuple col);164 HOperatorSet.SmallestRectangle1(hObject, out HTuple row1, out HTuple col1, out HTuple row2, out HTuple col2);165 HWindID.SetPart(hWindowControl1.HalconWindow, row.TupleInt(), column.TupleInt(),length1.TupleInt()+100);166 if (e.ColumnIndex>=19&&e.ColumnIndex<=26)167 {168 HOperatorSet.GenRectangle1(out HObject hObject1, row1, col1, row2, col2);169 HWind.OneResIamge.AddNameOBJ("Rectangle1", hObject1, Color.Yellow.Name.ToLower());170 HOperatorSet.InnerRectangle1(hObject, out row1, out col1, out row2, out col2);171 HOperatorSet.GenRectangle1(out hObject1, row1, col1, row2, col2);172 HWind.OneResIamge.AddNameOBJ("InnerRectangle1", hObject1, Color.Blue.Name.ToLower());173 }174 else if (e.ColumnIndex >= 12 && e.ColumnIndex <= 17)175 {176 HOperatorSet.SmallestCircle(hObject, out row, out col, out HTuple radius);177 HOperatorSet.GenCircle(out HObject hObject1, row, col,radius);178 179 HWind.OneResIamge.AddNameOBJ("Circle", hObject1, Color.Yellow.Name.ToLower());180 HOperatorSet.InnerCircle(hObject, out row, out col, out radius);181 HOperatorSet.GenCircle(out hObject1, row, col, radius);182 HWind.OneResIamge.AddNameOBJ("InnerCircle", hObject1, Color.Blue.Name.ToLower());183 }184 else if (e.ColumnIndex >= 8 && e.ColumnIndex <= 10)185 {186 HOperatorSet.GenRectangle2(out HObject hObject1, row, col, phi,length1,length2);187 HWind.OneResIamge.AddNameOBJ("Rectangle2", hObject1, Color.Yellow.Name.ToLower());188 }189 HWind.OneResIamge.AddImageMassage(rows, cols, index);190 HWind.OneResIamge.ISMassageBack = true;191 HTuple txes = new HTuple();192 for (int i = 0; i < dataGridView1.Columns.Count; i++)193 {194 txes.Append(dataGridView1.Columns[i].HeaderText+ ":"+dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString());195 }196 HWind.AddMeassge(txes);197 // HWindID.OneResIamge.AddImageMassage(inets, inecol, e.RowIndex+1);198 HWind.ShowObj();199 }200 catch (Exception)201 {202 }203 }204 private void dataGridView1_SelectionChanged(object sender, EventArgs e)205 {206 207 }208 private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)...

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6{7 {8 static void Main(string[] args)9 {10 Tuple<string, int, string> t = Tuple.Create("John", 1, "C#");11 Console.WriteLine(t.ToString());12 Console.ReadLine();13 }14 }15}

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 static void Main(string[] args)4 {5 var tuple = Tuple.Create(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9, 10, 11, 12, 13, 14, Tuple.Create(15, 16, 17, 18, 19, 20, 21, Tuple.Create(22, 23, 24, 25, 26, 27, 28, Tuple.Create(29, 30, 31, 32, 33, 34, 35, Tuple.Create(36, 37, 38, 39, 40, 41, 42, Tuple.Create(43, 44, 45, 46, 47, 48, 49, Tuple.Create(50, 51, 52, 53, 54, 55, 56, Tuple.Create(57, 58, 59, 60, 61, 62, 63, Tuple.Create(64, 65, 66, 67, 68, 69, 70, Tuple.Create(71, 72, 73, 74, 75, 76, 77, Tuple.Create(78, 79, 80, 81, 82, 83, 84, Tuple.Create(85, 86, 87, 88, 89, 90, 91, Tuple.Create(92, 93, 94, 95, 96, 97, 98, Tuple.Create(99, 100))))))))))))));6 Console.WriteLine(tuple.ToString());7 }8}

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 public static void Main()4 {5 new Tuple<int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7);6 Console.WriteLine(tuple.ToString());7 }8}

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 {4 static void Main(string[] args)5 {6 Tuple<int, string, int> tuple = new Tuple<int, string, int>(1, "Hello", 2);7 Console.WriteLine(tuple.ToString());8 Console.ReadLine();9 }10 }11}12using System;13{14 {15 static void Main(string[] args)16 {17 Tuple<int, string, int> tuple = new Tuple<int, string, int>(1, "Hello", 2);18 Console.WriteLine(tuple.ToString());19 Console.ReadLine();20 }21 }22}23using System;24{25 {26 static void Main(string[] args)27 {28 Tuple<int, string, int> tuple = new Tuple<int, string, int>(1, "Hello", 2);29 Console.WriteLine(tuple.ToString());30 Console.ReadLine();31 }32 }33}34using System;35{36 {37 static void Main(string[] args)38 {39 Tuple<int, string, int> tuple = new Tuple<int, string, int>(1, "Hello", 2);40 Console.WriteLine(tuple.ToString());41 Console.ReadLine();42 }43 }44}45using System;46{47 {48 static void Main(string[] args)49 {50 Tuple<int, string, int> tuple = new Tuple<int, string, int>(1, "Hello", 2);51 Console.WriteLine(tuple.ToString());52 Console.ReadLine();53 }54 }55}56using System;57{58 {

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 {4 static void Main(string[] args)5 {6 Tuple<string, string, string> tuple = new Tuple<string, string, string>("1", "2", "3");7 Console.WriteLine(tuple.ToString());8 Console.ReadLine();9 }10 }11}12using System;13{14 {15 static void Main(string[] args)16 {17 Tuple<string, string, string> tuple = new Tuple<string, string, string>("1", "2", "3");18 Console.WriteLine(tuple.ToString());19 Console.ReadLine();20 }21 }22}23using System;24{25 {26 static void Main(string[] args)27 {28 Tuple<string, string, string> tuple = new Tuple<string, string, string>("1", "2", "3");29 Console.WriteLine(tuple.ToString());30 Console.ReadLine();31 }32 }33}34using System;35{36 {37 static void Main(string[] args)38 {39 Tuple<string, string, string> tuple = new Tuple<string, string, string>("1", "2", "3");40 Console.WriteLine(tuple.ToString());41 Console.ReadLine();42 }43 }44}45using System;46{47 {48 static void Main(string[] args)49 {50 Tuple<string, string, string> tuple = new Tuple<string, string, string>("1", "2", "3");51 Console.WriteLine(tuple.ToString());52 Console.ReadLine();53 }54 }55}56using System;

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 {4 static void Main(string[] args)5 {6 var myTuple = new Tuple<int, string>(1, "first");7 Console.WriteLine(myTuple.ToString());8 Console.ReadLine();9 }10 }11}

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 public static void Main()4 {5 var tuple = new Tuple<string, int>("Hello", 123);6 Console.WriteLine(tuple.ToString());7 }8}9using System;10{11 public static void Main()12 {13 var tuple = new Tuple<string, int>("Hello", 123);14 Console.WriteLine(tuple.ToString());15 }16}17using System;18{19 public static void Main()20 {21 var tuple = new Tuple<string, int>("Hello", 123);22 Console.WriteLine(tuple.ToString());23 }24}25using System;26{27 public static void Main()28 {29 var tuple = new Tuple<string, int>("Hello", 123);30 Console.WriteLine(tuple.ToString());31 }32}33using System;34{35 public static void Main()36 {37 var tuple = new Tuple<string, int>("Hello", 123);38 Console.WriteLine(tuple.ToString());39 }40}41using System;42{43 public static void Main()44 {45 var tuple = new Tuple<string, int>("Hello", 123);46 Console.WriteLine(tuple.ToString());47 }48}49using System;50{51 public static void Main()52 {53 var tuple = new Tuple<string, int>("Hello", 123);54 Console.WriteLine(tuple.ToString());55 }56}57using System;58{59 public static void Main()60 {61 var tuple = new Tuple<string, int>("Hello", 123);62 Console.WriteLine(tuple.ToString

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 public static void Main()4 {5 Tuple<string, int, int> tuple = Tuple.Create("hello", 2, 3);6 Console.WriteLine(tuple.ToString());7 }8}

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2{3 static void Main()4 {5 var tuple = new Tuple<int, string>(1, "One");6 Console.WriteLine(tuple.ToString());7 Console.ReadLine();

Full Screen

Full Screen

ToString

Using AI Code Generation

copy

Full Screen

1using System;2namespace ConsoleApplication1 {3 class Program {4 static void Main(string[] args) {5 var tuple = new Tuple<int, string>(1, "one");6 Console.WriteLine(tuple.ToString());7 }8 }9}10using System;11namespace ConsoleApplication1 {12 class Program {13 static void Main(string[] args) {14 var tuple = new Tuple<int, string, bool>(1, "one", true);15 Console.WriteLine(tuple.ToString());16 }17 }18}19using System;20namespace ConsoleApplication1 {21 class Program {22 static void Main(string[] args) {23 var tuple = new Tuple<int, string, bool, decimal>(1, "one", true, 1.1m);24 Console.WriteLine(tuple.ToString());25 }26 }27}28using System;29namespace ConsoleApplication1 {30 class Program {31 static void Main(string[] args) {32 var tuple = new Tuple<int, string, bool, decimal, char>(1, "one", true, 1.1m, 'a');33 Console.WriteLine(tuple.ToString());34 }35 }36}37using System;38namespace ConsoleApplication1 {39 class Program {40 static void Main(string[] args) {41 var tuple = new Tuple<int, string, bool, decimal, char, DateTime>(1, "one", true, 1.1m, 'a', DateTime.Now);42 Console.WriteLine(tuple.ToString());43 }44 }45}46using System;47namespace ConsoleApplication1 {48 class Program {49 static void Main(string[] args) {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run FlaUI automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Tuple

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful