private DNWithBinary CreateWKGuid(ADContainer container, ADObjectId dn, Guid wkGuid) { DNWithBinary dnwithBinary = new DNWithBinary(dn.DistinguishedName, wkGuid.ToByteArray()); container.OtherWellKnownObjects.Add(dnwithBinary); this.configurationSession.Save(container); TaskLogger.Trace(Strings.InfoCreatedWKGuid(wkGuid.ToString(), dn.DistinguishedName, container.DistinguishedName)); return(dnwithBinary); }
private ADGroup FindADGroup(IConfigurationSession session, ADContainer container, string groupName) { ADGroup[] array = session.Find <ADGroup>(container.Id, QueryScope.OneLevel, new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, groupName), null, 1); if (array == null || array.Length == 0) { return(null); } return(array[0]); }
// read A/D from device internal static void getVoltage(ADContainer adc, bool[] channel, int trial) { byte[] state; double[] curVoltage = new double [channel.Length]; if (!chanSelected) { Debug.WriteLine("No channel selected yet. Cannot get voltage reading."); return; } while (trial-- > 0) { state = adc.readDevice(); if (adc.canADMultiChannelRead()) { // do all channels together adc.doADConvert(channel, state); curVoltage = adc.getADVoltage(state); } else { // do one channel at a time; for (int i = 0; i < maxNumChan; i++) { if (channel [i]) { adc.doADConvert(i, state); curVoltage [i] = adc.getADVoltage(i, state); } } } Debug.Write(" Voltage Reading:"); for (int i = 0; i < maxNumChan; i++) { if (channel [i]) // show value up to 2 decimal places { Debug.Write(" Ch" + i + " = " + ((int)(curVoltage [i] * 10000)) / 10000.0 + ADUnit); } } Debug.WriteLine(""); } }
public void InitializeServiceInstanceADStructure() { if (this.configSession.Read <SyncServiceInstance>(this.serviceInstanceObjectId) == null) { SyncServiceInstance syncServiceInstance = new SyncServiceInstance(); syncServiceInstance.SetId(this.serviceInstanceObjectId); this.configSession.Save(syncServiceInstance); } if (this.configSession.Read <ADContainer>(this.divergenceContainerObjectId) == null) { ADContainer adcontainer = new ADContainer(); adcontainer.SetId(this.divergenceContainerObjectId); this.configSession.Save(adcontainer); } }
public static ADContainer GetAdminSDHolder(ADObjectId domainId, IConfigurationSession session) { ExchangeOrganizationalUnit exchangeOrganizationalUnit = session.ResolveWellKnownGuid <ExchangeOrganizationalUnit>(WellKnownGuid.SystemWkGuid, domainId); if (exchangeOrganizationalUnit == null) { throw new SystemContainerNotFoundException(DNConvertor.FqdnFromDomainDistinguishedName(domainId.DistinguishedName), WellKnownGuid.SystemWkGuid); } ADContainer adcontainer = session.Read <ADContainer>(exchangeOrganizationalUnit.Id.GetChildId("AdminSDHolder")); if (adcontainer == null) { throw new AdminSDHolderNotFoundException(exchangeOrganizationalUnit.DistinguishedName); } return(adcontainer); }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); ADContainer container = this.FindRootUsersContainer(this.domainConfigurationSession, this.rootDomain.Id); string text = string.Format("{0}$$$", this.rootDomain.Name); ADGroup adgroup = this.FindADGroup(this.domainConfigurationSession, container, text); if (adgroup != null) { base.WriteVerbose(Strings.InfoGroupAlreadyPresent(text)); } else { LocalizedString exchangeMigrationSidHistoryAuditingDSGDescription = Strings.ExchangeMigrationSidHistoryAuditingDSGDescription; this.CreateDomainLocalSecurityGroup(container, text, exchangeMigrationSidHistoryAuditingDSGDescription); } TaskLogger.LogExit(); }
/// <summary> /// Method main /// /// </summary> /// <param name="args"> /// </param> public static void Main1(string[] args) { OneWireContainer owc = null; ADContainer adc = null; Stream stream = loadResourceFile("ADcontainerDemo.input.txt"); dis = new StreamReader(stream); // find and initialize the first OneWireContainer with // ADContainer interface owc = initContainer(); if (!(owc is ADContainer)) { cleanup(); Debug.WriteLine("*************************************************************************"); Debug.WriteLine("No ADContainer found. Exit program."); Debug.WriteLine(""); return; } else { adc = (ADContainer)owc; } maxNumChan = adc.NumberADChannels; // array to determine whether a specific channel has been selected bool[] channel = new bool [maxNumChan]; for (int i = 0; i < maxNumChan; i++) // default, no channel selected { channel [i] = false; } byte[] state = null; // data from device double[] ranges = null; // A/D ranges double alarmLow = 0; // alarm low value double alarmHigh = 0; // alarm high value bool alarming; // temporary storage for user input int inputInt = 0; double inputDouble = 0.0; double inputLow = 0.0; double inputHigh = 0.0; string inputString = null; bool moreInput = true; int curMenuChoice = 0; initMenu(); while (true) { curMenuChoice = getMenuChoice(hashMainMenu, mainMenuItemCount); try { switch (curMenuChoice) { case 0: // Select Channel Debug.WriteLine("*************************************************************************"); Debug.WriteLine("All previously selectd channels have been cleared."); state = adc.readDevice(); for (int i = 0; i < maxNumChan; i++) { // clear all channel selection channel [i] = false; if (adc.hasADAlarms()) { // disable alarms adc.setADAlarmEnable(i, ADContainer_Fields.ALARM_LOW, false, state); adc.setADAlarmEnable(i, ADContainer_Fields.ALARM_HIGH, false, state); } } adc.writeDevice(state); chanSelected = false; state = adc.readDevice(); int count = 1; moreInput = true; while (moreInput && (count <= maxNumChan)) { Debug.Write("Please enter channel # " + count + " ( Enter -1 if no more): "); inputInt = (int)Number; if (inputInt == -1) { moreInput = false; } else { if (isChannelValid(inputInt)) { channel [inputInt] = true; count++; chanSelected = true; if (adc.hasADAlarms()) { // enable alarms adc.setADAlarmEnable(inputInt, ADContainer_Fields.ALARM_LOW, true, state); adc.setADAlarmEnable(inputInt, ADContainer_Fields.ALARM_HIGH, true, state); } } } } // while (moreInput && (count <= maxNumChan)) adc.writeDevice(state); Debug.Write(" Channels to monitor = "); if (count == 1) { Debug.WriteLine("NONE"); } else { for (int i = 0; i < maxNumChan; i++) { if (channel [i]) { Debug.Write(i + " "); } } Debug.WriteLine(""); } break; case 1: // Get A/D Once getVoltage(adc, channel, 1); break; case 2: // Get A/D Multiple Time Debug.Write("Please enter number of times: "); inputInt = (int)Number; getVoltage(adc, channel, inputInt); break; case 3: // Get A/D ranges if (!chanSelected) { Debug.WriteLine("No channel selected yet. Cannot get A/D ranges."); } else { state = adc.readDevice(); for (int i = 0; i < maxNumChan; i++) { if (channel [i]) { ranges = adc.getADRanges(i); Debug.Write("Ch " + i + " - Available: " + ranges [0] + ADUnit); for (int j = 1; j < ranges.Length; j++) { Debug.Write(", " + ranges [j] + ADUnit); } Debug.WriteLine(". Current: " + adc.getADRange(i, state) + ADUnit); } } } break; case 4: // Set A/D ranges Debug.WriteLine("*************************************************************************"); state = adc.readDevice(); moreInput = true; while (moreInput) { Debug.Write("Please enter channel number: "); inputInt = (int)Number; if (isChannelValid(inputInt)) { Debug.Write("Please enter range value: "); inputDouble = Number; adc.setADRange(inputInt, inputDouble, state); adc.writeDevice(state); state = adc.readDevice(); Debug.WriteLine(" Ch" + inputInt + " A/D Ranges set to: " + adc.getADRange(inputInt, state)); Debug.Write("Set more A/D ranges (Y/N)? "); inputString = dis.ReadLine(); if (!inputString.Trim().ToUpper().Equals("Y")) { moreInput = false; } } } // while(moreInput) break; case 5: // Get High and Low Alarms if (!adc.hasADAlarms()) { Debug.WriteLine("A/D alarms not supported"); } else if (!chanSelected) { Debug.WriteLine("No channel selected yet. Cannot get high and low alarms."); } else { state = adc.readDevice(); for (int i = 0; i < maxNumChan; i++) { if (channel [i]) { alarmLow = adc.getADAlarm(i, ADContainer_Fields.ALARM_LOW, state); alarmHigh = adc.getADAlarm(i, ADContainer_Fields.ALARM_HIGH, state); // show results up to 2 decimal places Debug.WriteLine("Ch " + i + " Alarm: High = " + ((int)(alarmHigh * 100)) / 100.0 + ADUnit + ", Low = " + ((int)(alarmLow * 100)) / 100.0 + ADUnit); } } // for } break; case 6: // Set High and Low Alarms if (!adc.hasADAlarms()) { Debug.WriteLine("A/D alarms not supported"); } else { Debug.WriteLine("*************************************************************************"); state = adc.readDevice(); moreInput = true; while (moreInput) { Debug.Write("Please enter channel number: "); inputInt = (int)Number; if (isChannelValid(inputInt)) { bool inputValid = false; while (!inputValid) { Debug.Write("Please enter alarm high value: "); inputHigh = Number; if (inputHigh > adc.getADRange(inputInt, state)) { Debug.WriteLine("Current A/D range is: " + adc.getADRange(inputInt, state) + ADUnit + ". Invalid alarm high value."); } else { inputValid = true; } } Debug.Write("Please enter alarm low value: "); inputLow = Number; adc.setADAlarm(inputInt, ADContainer_Fields.ALARM_LOW, inputLow, state); adc.setADAlarm(inputInt, ADContainer_Fields.ALARM_HIGH, inputHigh, state); adc.writeDevice(state); state = adc.readDevice(); // show results up to 2 decimal places Debug.WriteLine(" Set Ch" + inputInt + " Alarm: High = " + ((int)(adc.getADAlarm(inputInt, ADContainer_Fields.ALARM_HIGH, state) * 100)) / 100.0 + ADUnit + ", Low = " + ((int)(adc.getADAlarm(inputInt, ADContainer_Fields.ALARM_LOW, state) * 100)) / 100.0 + ADUnit); Debug.Write("Set more A/D alarms (Y/N)? "); inputString = dis.ReadLine(); if (!inputString.Trim().ToUpper().Equals("Y")) { moreInput = false; } } } // while(moreInput) } break; case 7: // hasADAlarmed if (!adc.hasADAlarms()) { Debug.WriteLine("A/D alarms not supported"); } else { alarming = owc.Alarming; if (alarming) { Debug.Write(" Alarms: "); state = adc.readDevice(); for (int i = 0; i < maxNumChan; i++) { if (channel [i]) { if (adc.hasADAlarmed(i, ADContainer_Fields.ALARM_HIGH, state)) { Debug.Write("Ch" + i + " alarmed high; "); } if (adc.hasADAlarmed(i, ADContainer_Fields.ALARM_LOW, state)) { Debug.Write("Ch" + i + " alarmed low; "); } } } Debug.WriteLine(""); } else { Debug.WriteLine(" Not Alarming"); } } break; case 8: cleanup(); return; } } catch (Exception e) { printException(e); } } // while }
// find the first OneWireContainer with ADContainer interface // if found, initialize the container internal static OneWireContainer initContainer() { byte[] state = null; OneWireContainer owc = null; ADContainer adc = null; try { adapter = OneWireAccessProvider.DefaultAdapter; // get exclusive use of adapter adapter.beginExclusive(true); adapter.setSearchAllDevices(); adapter.targetAllFamilies(); adapter.Speed = DSPortAdapter.SPEED_REGULAR; // enumerate through all the One Wire device found for (System.Collections.IEnumerator owc_enum = adapter.AllDeviceContainers; owc_enum.MoveNext();) { // get the next owc owc = (OneWireContainer)owc_enum.Current; // check for One Wire device that implements ADCotainer interface if (owc is ADContainer) { adc = (ADContainer)owc; // access One Wire device state = adc.readDevice(); double[] range = null; double[] resolution = null; // set resolution for (int channel = 0; channel < adc.NumberADChannels; channel++) { range = adc.getADRanges(channel); resolution = adc.getADResolutions(channel, range [0]); // set to largest range adc.setADRange(channel, range [0], state); // set to highest resolution adc.setADResolution(channel, resolution [resolution.Length - 1], state); if (adc.hasADAlarms()) { // disable all alarms adc.setADAlarmEnable(channel, ADContainer_Fields.ALARM_LOW, false, state); adc.setADAlarmEnable(channel, ADContainer_Fields.ALARM_HIGH, false, state); } } adc.writeDevice(state); // print device information Debug.WriteLine(""); Debug.WriteLine("*************************************************************************"); Debug.WriteLine("* 1-Wire Device Name: " + owc.Name); Debug.WriteLine("* 1-Wire Device Other Names: " + owc.AlternateNames); Debug.WriteLine("* 1-Wire Device Address: " + owc.AddressAsString); Debug.WriteLine("* 1-Wire Device Max speed: " + ((owc.MaxSpeed == DSPortAdapter.SPEED_OVERDRIVE) ? "Overdrive" : "Normal")); Debug.WriteLine("* 1-Wire Device Number of Channels: " + adc.NumberADChannels); Debug.WriteLine("* 1-Wire Device Can Read MultiChannels: " + adc.canADMultiChannelRead()); Debug.WriteLine("* 1-Wire Device Description: " + owc.Description); Debug.WriteLine("*************************************************************************"); Debug.WriteLine(" Hit ENTER to continue..."); dis.ReadLine(); break; } } // enum all owc } catch (Exception e) { printException(e); } return(owc); }
private ADGroup CreateDomainLocalSecurityGroup(ADContainer container, string groupName, LocalizedString groupDescription) { GroupTypeFlags groupType = GroupTypeFlags.DomainLocal | GroupTypeFlags.SecurityEnabled; return(this.CreateGroup(this.rootDomainRecipientSession, container.Id, groupName, groupDescription, groupType)); }
protected sealed override void InternalProcessRecord() { TaskLogger.LogEnter(new object[] { this.DataObject }); if (this.DataObject.MajorVersion != LocalServer.GetServer().MajorVersion) { base.WriteError(new CannotModifyCrossVersionObjectException(this.DataObject.Id.DistinguishedName), ErrorCategory.InvalidOperation, null); return; } ClientAccessServer clientAccessServer = new ClientAccessServer(this.DataObject); if (base.Fields.IsModified("ClientAccessArray")) { ClientAccessArray clientAccessArrayFromIdParameter = this.GetClientAccessArrayFromIdParameter(); if (clientAccessArrayFromIdParameter == null) { clientAccessServer.ClientAccessArray = null; } else { if (clientAccessArrayFromIdParameter.IsPriorTo15ExchangeObjectVersion) { base.WriteError(new InvalidOperationException(Strings.ErrorCannotSetToOldClientAccessArray(clientAccessArrayFromIdParameter.ExchangeVersion.ToString(), ClientAccessArray.MinimumSupportedExchangeObjectVersion.ToString())), ErrorCategory.InvalidOperation, this.Identity); return; } clientAccessServer.ClientAccessArray = (ADObjectId)clientAccessArrayFromIdParameter.Identity; } } bool flag = false; ADServiceConnectionPoint adserviceConnectionPoint = null; ADObjectId childId = clientAccessServer.Id.GetChildId("Protocols").GetChildId("Autodiscover").GetChildId(clientAccessServer.Name); if (base.Fields.IsModified("AutoDiscoverServiceInternalUri") && this.AutoDiscoverServiceInternalUri == null && base.Fields.IsModified("AutoDiscoverSiteScope") && this.AutoDiscoverSiteScope == null) { adserviceConnectionPoint = new ADServiceConnectionPoint(); adserviceConnectionPoint.SetId(childId); base.DataSession.Delete(adserviceConnectionPoint); ADObjectId parent = adserviceConnectionPoint.Id.Parent; ADContainer adcontainer = new ADContainer(); adcontainer.SetId(parent); base.DataSession.Delete(adcontainer); flag = true; } else { adserviceConnectionPoint = ((IConfigurationSession)base.DataSession).Read <ADServiceConnectionPoint>(childId); if (adserviceConnectionPoint == null) { adserviceConnectionPoint = new ADServiceConnectionPoint(); adserviceConnectionPoint.SetId(childId); if (!base.Fields.IsModified("AutoDiscoverServiceInternalUri")) { string text = ComputerInformation.DnsFullyQualifiedDomainName; if (string.IsNullOrEmpty(text)) { text = ComputerInformation.DnsPhysicalHostName; } adserviceConnectionPoint.ServiceBindingInformation.Add("https://" + text + "/Autodiscover/Autodiscover.xml"); } if (!base.Fields.IsModified("AutoDiscoverSiteScope")) { adserviceConnectionPoint.Keywords.Add("77378F46-2C66-4aa9-A6A6-3E7A48B19596"); string siteName = NativeHelpers.GetSiteName(false); if (!string.IsNullOrEmpty(siteName)) { adserviceConnectionPoint.Keywords.Add("Site=" + siteName); } } adserviceConnectionPoint.ServiceDnsName = ComputerInformation.DnsPhysicalHostName; adserviceConnectionPoint.ServiceClassName = "ms-Exchange-AutoDiscover-Service"; flag = true; } if (base.Fields.IsModified("AutoDiscoverServiceInternalUri")) { adserviceConnectionPoint.ServiceBindingInformation.Clear(); if (this.AutoDiscoverServiceInternalUri != null) { adserviceConnectionPoint.ServiceBindingInformation.Add(this.AutoDiscoverServiceInternalUri.ToString()); } flag = true; } if (base.Fields.IsModified("AutoDiscoverSiteScope")) { adserviceConnectionPoint.Keywords.Clear(); adserviceConnectionPoint.Keywords.Add("77378F46-2C66-4aa9-A6A6-3E7A48B19596"); if (this.AutoDiscoverSiteScope != null) { foreach (string str in this.AutoDiscoverSiteScope) { adserviceConnectionPoint.Keywords.Add("Site=" + str); } } flag = true; } if (flag) { ADObjectId parent2 = adserviceConnectionPoint.Id.Parent; if (((IConfigurationSession)base.DataSession).Read <ADContainer>(parent2) == null) { ADContainer adcontainer2 = new ADContainer(); adcontainer2.SetId(parent2); base.DataSession.Save(adcontainer2); } base.DataSession.Save(adserviceConnectionPoint); } } bool flag2 = false; if (this.CleanUpInvalidAlternateServiceAccountCredentials.ToBool() && this.alternateServiceAccountCredentialsToRemove.Count > 0) { foreach (AlternateServiceAccountCredential credential in this.alternateServiceAccountCredentialsToRemove) { this.alternateServiceAccountConfiguration.RemoveCredential(credential); } flag2 = true; } if (this.RemoveAlternateServiceAccountCredentials.ToBool()) { flag2 = this.alternateServiceAccountConfiguration.RemoveAllCredentials(); flag2 = true; } if (this.AlternateServiceAccountCredential != null) { for (int i = this.AlternateServiceAccountCredential.Length - 1; i >= 0; i--) { this.alternateServiceAccountConfiguration.AddCredential(this.AlternateServiceAccountCredential[i]); flag2 = true; } } if (this.DataObject.ObjectState != ObjectState.Unchanged) { base.InternalProcessRecord(); } else if (!flag && !flag2) { this.WriteWarning(Strings.WarningForceMessage); } TaskLogger.LogExit(); }
private ADGroup CreateGroup(ADOrganizationalUnit usgContainer, string groupName, int groupId, Guid wkGuid, string groupDescription, GroupTypeFlags groupType, bool createAsRoleGroup) { ADRecipient adrecipient = base.ResolveExchangeGroupGuid <ADRecipient>(wkGuid); DNWithBinary dnwithBinary = null; if (adrecipient != null) { base.LogReadObject(adrecipient); if (adrecipient.RecipientType != RecipientType.Group) { base.WriteError(new InvalidWKObjectTargetException(wkGuid.ToString(), "CN=Microsoft Exchange,CN=Services," + this.configurationSession.ConfigurationNamingContext.DistinguishedName, adrecipient.Id.DistinguishedName, groupType.ToString()), ErrorCategory.NotSpecified, null); } ADGroup adgroup = adrecipient as ADGroup; base.LogReadObject(adgroup); if ((adgroup.GroupType & groupType) != groupType) { base.WriteError(new InvalidWKObjectTargetException(wkGuid.ToString(), "CN=Microsoft Exchange,CN=Services," + this.configurationSession.ConfigurationNamingContext.DistinguishedName, adgroup.Id.DistinguishedName, groupType.ToString()), ErrorCategory.NotSpecified, null); } if (createAsRoleGroup && adgroup.RecipientTypeDetails != RecipientTypeDetails.RoleGroup) { base.WriteError(new InvalidWKObjectTargetException(wkGuid.ToString(), "CN=Microsoft Exchange,CN=Services," + this.configurationSession.ConfigurationNamingContext.DistinguishedName, adgroup.Id.DistinguishedName, RecipientTypeDetails.RoleGroup.ToString()), ErrorCategory.NotSpecified, null); } base.WriteVerbose(Strings.InfoGroupAlreadyPresent(adgroup.Id.DistinguishedName)); dnwithBinary = DirectoryCommon.FindWellKnownObjectEntry(this.exchangeConfigContainer.OtherWellKnownObjects, wkGuid); if (dnwithBinary == null) { dnwithBinary = this.CreateWKGuid(this.exchangeConfigContainer, adgroup.Id, wkGuid); } if (createAsRoleGroup) { InitializeExchangeUniversalGroups.UpgradeRoleGroupLocalization(adgroup, groupId, groupDescription, this.rootDomainRecipientSession); } return(adgroup); } ADContainer adcontainer = this.exchangeConfigContainer; dnwithBinary = DirectoryCommon.FindWellKnownObjectEntry(adcontainer.OtherWellKnownObjects, wkGuid); if (dnwithBinary == null) { adcontainer = this.configContainer; dnwithBinary = DirectoryCommon.FindWellKnownObjectEntry(adcontainer.OtherWellKnownObjects, wkGuid); } if (dnwithBinary != null) { base.WriteError(new InvalidWKObjectException(dnwithBinary.ToString(), adcontainer.DistinguishedName), ErrorCategory.NotSpecified, null); } ADGroup adgroup2 = null; try { if (createAsRoleGroup) { adgroup2 = InitializeExchangeUniversalGroups.CreateUniqueRoleGroup(this.rootDomainRecipientSession, this.rootDomain.Id, usgContainer.Id, groupName, groupId, groupDescription, OrganizationId.ForestWideOrgId); } else { adgroup2 = InitializeExchangeUniversalGroups.CreateUniqueChildSG(this.rootDomainRecipientSession, this.rootDomain.Id, usgContainer.Id, groupName, groupDescription, groupType, OrganizationId.ForestWideOrgId); } dnwithBinary = this.CreateWKGuid(this.exchangeConfigContainer, adgroup2.Id, wkGuid); } finally { if (adgroup2 == null && dnwithBinary != null) { this.exchangeConfigContainer.OtherWellKnownObjects.Remove(dnwithBinary); this.domainConfigurationSession.Save(this.exchangeConfigContainer); base.LogWriteObject(this.exchangeConfigContainer); } else if (adgroup2 != null && dnwithBinary == null) { this.rootDomainRecipientSession.Delete(adgroup2); base.LogWriteObject(adgroup2); adgroup2 = null; } } return(adgroup2); }