public WriteOperations(string key, ProviderCacheItem cacheItem, WriteOperationType opType, bool updateInCache) { this._key = key; this._cacheItem = cacheItem; this._opType = opType; this._updateInCache = updateInCache; }
/// <summary> /// Send specified command to Roboteq device. /// Refer to Roboteq datasheet for a full list of available commands and their arguments. /// </summary> /// <param name="opType">Operation type. Possible: RuntimeCommand, Runtime Query, SetConfig, GetConfig</param> /// <param name="commandName">Command name.</param> /// <param name="arg1">Command argument</param> /// <returns>Response form motor controller in form of string array, or null if there was no reply.</returns> private string[] WriteOperation(WriteOperationType opType, string commandName, int arg1) { List <int> args = new List <int>(); args.Add(arg1); return(WriteOperation(opType, commandName, args)); }
protected override void InternalProcessRecord() { LocalizedString message = new LocalizedString("Error updating consumer mailbox. See inner exception for details."); try { this.PrepareDataObject(); WriteOperationType writeOperationType = this.Repair.ToBool() ? WriteOperationType.RepairUpdate : WriteOperationType.Update; ConsumerMailboxHelper.CreateOrUpdateConsumerMailbox(writeOperationType, base.Fields, (IRecipientSession)base.DataSession, delegate(string s) { base.WriteVerbose(new LocalizedString(s)); }, delegate(string s) { this.WriteWarning(new LocalizedString(s)); }); } catch (ADNoSuchObjectException innerException) { throw new ManagementObjectNotFoundException(message, innerException); } catch (ADObjectAlreadyExistsException innerException2) { throw new ManagementObjectAlreadyExistsException(message, innerException2); } catch (ArgumentException innerException3) { throw new TaskArgumentException(message, innerException3); } catch (InvalidOperationException innerException4) { throw new TaskInvalidOperationException(message, innerException4); } }
public WriteOperation(string key, ProviderCacheItem cacheItem, WriteOperationType opType, int retryCount) { this._key = key; this._cacheItem = cacheItem; this._opType = opType; this._retryCount = retryCount; }
public static void CreateOrUpdateConsumerMailbox(WriteOperationType writeOperationType, PropertyBag propertyValuesBag, IRecipientSession session, Action <string> logAction, Action <string> warningLogAction = null) { MbxReadMode mbxReadMode = ((IAggregateSession)session).MbxReadMode; BackendWriteMode backendWriteMode = ((IAggregateSession)session).BackendWriteMode; try { if (logAction == null) { throw new ArgumentNullException("logAction"); } if (warningLogAction == null) { throw new ArgumentNullException("warningLogAction"); } if (!propertyValuesBag.IsModified(ADUserSchema.NetID)) { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, "Property 'ADUserSchema.NetID' must be set", new object[0])); } ulong puid = ((NetID)propertyValuesBag[ADUserSchema.NetID]).ToUInt64(); string text = ((NetID)propertyValuesBag[ADUserSchema.NetID]).ToString(); bool flag = propertyValuesBag.IsModified("MakeExoPrimary") && (bool)propertyValuesBag["MakeExoPrimary"]; bool flag2 = propertyValuesBag.IsModified("MakeExoSecondary") && (bool)propertyValuesBag["MakeExoSecondary"]; bool flag3 = propertyValuesBag.IsModified("SkipMigration") && (bool)propertyValuesBag["SkipMigration"]; ADUser aduser = ConsumerMailboxHelper.ReadUser(session, puid, true); if (aduser == null && (writeOperationType == WriteOperationType.Update || writeOperationType == WriteOperationType.RepairUpdate)) { throw new ADNoSuchObjectException(new LocalizedString(string.Format(CultureInfo.CurrentUICulture, "Cannot update object. Mserv entry for PUID: '{0}' not found", new object[] { text }))); } if (aduser != null && writeOperationType == WriteOperationType.Create && !flag2 && (!flag || !flag3)) { throw new ADObjectAlreadyExistsException(new LocalizedString(string.Format(CultureInfo.CurrentUICulture, "Cannot create object. Mserv entry for PUID: '{0}' already exists", new object[] { text }))); } if (aduser != null && aduser.Database != null && propertyValuesBag.IsModified(ADMailboxRecipientSchema.Database) && !aduser.Database.Equals((ADObjectId)propertyValuesBag[ADMailboxRecipientSchema.Database])) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot update database of an existing consumer mailbox in EXO. PUID: '{0}' Existing database: {1}", new object[] { text, aduser.Database })); } if (flag && flag2) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot set MakeExoPrimary and MakeExoSecondary at the same time. PUID: '{0}'", new object[] { text })); } if (aduser == null) { aduser = new ADUser(); } if (flag) { if (writeOperationType == WriteOperationType.Create && aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.None) { logAction("Current state: No mserv footprint - i.e. no mailbox in EXO and Hotmail."); logAction("Action requested: MakeExoPrimary: Create a brand new primary consumer mailbox in EXO. "); } else if (writeOperationType == WriteOperationType.RepairCreate && (aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.None || aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.Exo)) { logAction("Current state: Either no mserv footprint exists or a primary mailbox exists in EXO."); logAction("Action requested: MakeExoPrimary: Retry creation of primary consumer mailbox in EXO. "); } else if ((writeOperationType == WriteOperationType.Update || writeOperationType == WriteOperationType.RepairUpdate) && aduser.Database != null && aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.Hotmail) { logAction("Current state: Primary mailbox exists in Hotmail and Secondary mailbox exists in EXO."); logAction("Action requested: MakeExoPrimary: Switch from hotmail to EXO. "); } else { if ((writeOperationType != WriteOperationType.Create && writeOperationType != WriteOperationType.RepairCreate) || aduser.PrimaryMailboxSource() != PrimaryMailboxSourceType.Hotmail || aduser.Database != null || !flag3) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot proceed with MakeExoPrimary operation. Invalid state detected. PUID: '{0}' Current primary mailbox source: {1} Write operation type: {2}", new object[] { text, aduser.PrimaryMailboxSource(), writeOperationType })); } logAction("Current state: Primary mailbox exists in Hotmail and no secondary mailbox exists in EXO."); logAction("Action requested: MakeExoPrimary: Switch directly from hotmail to EXO w/o migrating email contents and SkipMigration flag is supplied. "); } } if (flag2) { if (writeOperationType == WriteOperationType.Create && aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.Hotmail) { logAction("Current state: An existing primary mailbox in Hotmail."); logAction("Action requested: MakeExoSecondary: Create a brand new secondary consumer mailbox in EXO. "); } else { if (writeOperationType != WriteOperationType.RepairCreate || aduser.PrimaryMailboxSource() != PrimaryMailboxSourceType.Hotmail) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Invalid state detected. Cannot proceed with MakeExoSecondary operation. A hotmail account must exist for PUID: '{0}'. Current primary mailbox source: {1} Write operation type: {2}", new object[] { text, aduser.PrimaryMailboxSource(), writeOperationType })); } logAction("Current state: An existing primary mailbox in Hotmail with or without a secondary mailbox in EXO."); logAction("Action requested: MakeExoSecondary: Retry creating a brand new secondary consumer mailbox in EXO. "); } propertyValuesBag[ADUserSchema.IsMigratedConsumerMailbox] = true; } if ((flag || flag2) && aduser.Database == null && !propertyValuesBag.IsModified(ADMailboxRecipientSchema.Database)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "You must specify Database for creating a new mailbox. PUID: '{0}'", new object[] { text })); } if (!flag && !flag2 && aduser.Database == null) { throw new ADNoSuchObjectException(new LocalizedString(string.Format(CultureInfo.CurrentUICulture, "Cannot perform this operation. No consumer mailbox (primary/secondary) exists for this user in EXO. PUID: '{0}'", new object[] { text }))); } ADRawEntry adrawEntry = new ADRawEntry(); ADObjectId adobjectId = aduser.Database ?? (propertyValuesBag[ADMailboxRecipientSchema.Database] as ADObjectId); if (adobjectId != null && ConsumerMailboxHelper.PopulateStoreOnlyProperties(adrawEntry, puid, propertyValuesBag, true)) { logAction(string.Format("Saving store properties for user - puid: {0}", text)); AggregationHelper.PerformMbxModification(adobjectId.ObjectGuid, ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid), adrawEntry.propertyBag as ADPropertyBag, false); } if (ConsumerMailboxHelper.PopulateMservPuidRecordProperties(aduser, puid, flag, flag2, propertyValuesBag)) { logAction(string.Format("Saving PUID records in Mserv for user - puid: {0}", text)); ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.WriteToMServ; session.Save(aduser); aduser = ConsumerMailboxHelper.ReadUser(session, puid, true); } if (writeOperationType == WriteOperationType.RepairCreate || writeOperationType == WriteOperationType.RepairUpdate) { ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.WriteToMServ; ConsumerMailboxHelper.SaveChangesInRepairMode(session, puid, ConsumerMailboxHelper.MServAliasAndOtherRecordProperties, propertyValuesBag, logAction, warningLogAction); } else if (ConsumerMailboxHelper.PopulateAliasAndOtherRecordProperties(aduser, puid, propertyValuesBag)) { logAction(string.Format("Saving Aliases and other records in Mserv for user - puid: {0}", text)); ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.WriteToMServ; session.Save(aduser); } } finally { ((IAggregateSession)session).MbxReadMode = mbxReadMode; ((IAggregateSession)session).BackendWriteMode = backendWriteMode; } }
/// <summary> /// Send specified command to Roboteq device. /// Refer to Roboteq datasheet for a full list of available commands and their arguments. /// </summary> /// <param name="opType">Operation type. Possible: RuntimeCommand, Runtime Query, SetConfig, GetConfig</param> /// <param name="commandName">Command name. </param> /// <returns>Response form motor controller in form of string array, or null if there was no reply.</returns> private string[] WriteOperation(WriteOperationType opType, string commandName) { List<int> args = new List<int>(); return WriteOperation(opType, commandName, args); }
/// <summary> /// Send specified command to Roboteq device. /// Refer to Roboteq datasheet for a full list of available commands and their arguments. /// </summary> /// <param name="opType">Operation type. Possible: RuntimeCommand, Runtime Query, SetConfig, GetConfig</param> /// <param name="commandName">Command name.</param> /// <param name="arg1">First command argument</param> /// <param name="arg2">Second command argument</param> /// <returns>Response form motor controller in form of string array, or null if there was no reply.</returns> private string[] WriteOperation(WriteOperationType opType, string commandName, int arg1, int arg2) { List<int> args = new List<int>(); args.Add(arg1); args.Add(arg2); return WriteOperation(opType, commandName, args); }
/// <summary> /// Send specified command to Roboteq device. /// Refer to Roboteq datasheet for a full list of available commands and their arguments. /// </summary> /// <param name="opType">Operation type. Possible: RuntimeCommand, Runtime Query, SetConfig, GetConfig</param> /// <param name="commandName">Command name.</param> /// <param name="arguments">List of arguments. Commands accept from 0 to 2 args</param> /// <returns>Response form motor controller in form of string array, or null if there was no reply.</returns> private string[] WriteOperation(WriteOperationType opType, string commandName, List<int> arguments) { if (!serialPort.IsOpen) { Connect(); } string prefix = ""; switch (opType) { case WriteOperationType.RuntimeCommand: prefix = "!"; break; case WriteOperationType.RuntimeQuery: prefix = "?"; break; case WriteOperationType.GetConfig: prefix = "~"; break; case WriteOperationType.SetConfig: prefix = "^"; break; } string command = prefix + commandName; foreach (int argument in arguments) { string temp = Convert.ToString(argument); command += (" " + temp); } CleanSerialPortBuffer(); serialPort.WriteLine(command); if ((opType == WriteOperationType.RuntimeQuery) || (opType == WriteOperationType.GetConfig)) { string response = ""; while (response.Length == 0) { System.Threading.Thread.Sleep(10); response = serialPort.ReadLine(); if (response.Contains("+")) { response = ""; } else if (response.Contains("-")) { response = ""; } } int pos = response.IndexOf("="); string reply = response.Substring(pos + 1); return reply.Split(':'); } return null; }
public WriteOperation(Token[] toks, InstructionForm ParentForm) { // As a note, all operations should be 4 characters, // if they are unable to be 4 characters, then they // should be sets of 4 characters seperated in // some way. (this allows for the write operations to // be aligned in the cpud file) Token tok = toks[0]; switch (toks.Length) { case 1: if (tok.Type == TokenType.Number) { this.Type = WriteOperationType.Byte; this.ByteValue = (byte)tok.NumberValue.Value; } else if (tok.Value.StartsWith("arg")) { this.ArgIdx = (byte)(Utils.SingleDigitParse(tok.Value[3]) - 1); if (!ParentForm[ArgIdx].ArgType.HasSize) { this.Type = WriteOperationType.Arg; } else { switch(ParentForm[ArgIdx].ArgType.Size) { case 1: this.Type = WriteOperationType.Imm8; break; case 2: this.Type = WriteOperationType.Imm16; break; case 4: this.Type = WriteOperationType.Imm32; break; default: throw new Exception("Unknown arg type!"); } } } else // Prefix { this.Type = WriteOperationType.Prefix; this.SelectedPrefix = PrefixRegistry.GetPrefixName(tok.Value); if (this.SelectedPrefix == null) throw new Exception("Unknown write operation '" + tok.Value + "'!"); } break; case 3: this.Type = WriteOperationType.BytePlusArg; this.ArgIdx = (byte)(Utils.SingleDigitParse(toks[2].Value[3]) - 1); this.ByteValue = (byte)tok.NumberValue.Value; break; case 4: if (tok.Value == "evil") { if (toks[1].Type != TokenType.LSqBracket) throw new Exception("Expected an opening square bracket before the exception's message!"); if (toks[3].Type != TokenType.RSqBracket) throw new Exception("Expected the closing square bracket after the exception's message!"); this.Type = WriteOperationType.Throw; this.MessageThrown = toks[2].Value; } else if (tok.Value.StartsWith("arg")) { if (toks[1].Type != TokenType.LSqBracket) throw new Exception("Expected an opening square bracket before the argument write operation!"); if (toks[3].Type != TokenType.RSqBracket) throw new Exception("Expected the closing square bracket after the argument write operation!"); this.ArgIdx = (byte)(Utils.SingleDigitParse(tok.Value[3]) - 1); this.Type = WriteOperationType.Arg; this.WriteArguments.Add(new WriteOperationArgument(toks[2])); } else { throw new Exception("Unknown write operation type!"); } break; default: if (tok.Value.StartsWith("arg")) { if (toks[1].Type != TokenType.LSqBracket) throw new Exception("Expected an opening square bracket before the argument write operation!"); this.Type = WriteOperationType.Arg; this.ArgIdx = (byte)(Utils.SingleDigitParse(tok.Value[3]) - 1); for (int i = 2; i < toks.Length - 1; i += 2) { this.WriteArguments.Add(new WriteOperationArgument(toks[i])); if (i + 1 < toks.Length - 1 && toks[i + 1].Type != TokenType.Comma) throw new Exception("Expected a comma!"); } if (toks[toks.Length - 1].Type != TokenType.RSqBracket) throw new Exception("Expected the closing square bracket after the argument write operation!"); } else { throw new Exception("Unknown number of tokens passed in!"); } break; } }
public InternalWriteOperation(string key, ProviderCacheItem cacheItem, WriteOperationType opType, int retryCount) : base(key, cacheItem, opType, retryCount) { }
/// <summary> /// Send specified command to Roboteq device. /// Refer to Roboteq datasheet for a full list of available commands and their arguments. /// </summary> /// <param name="opType">Operation type. Possible: RuntimeCommand, Runtime Query, SetConfig, GetConfig</param> /// <param name="commandName">Command name.</param> /// <param name="arguments">List of arguments. Commands accept from 0 to 2 args</param> /// <returns>Response form motor controller in form of string array, or null if there was no reply.</returns> private string[] WriteOperation(WriteOperationType opType, string commandName, List <int> arguments) { if (!serialPort.IsOpen) { Connect(); } string prefix = ""; switch (opType) { case WriteOperationType.RuntimeCommand: prefix = "!"; break; case WriteOperationType.RuntimeQuery: prefix = "?"; break; case WriteOperationType.GetConfig: prefix = "~"; break; case WriteOperationType.SetConfig: prefix = "^"; break; } string command = prefix + commandName; foreach (int argument in arguments) { string temp = Convert.ToString(argument); command += (" " + temp); } CleanSerialPortBuffer(); serialPort.WriteLine(command); if ((opType == WriteOperationType.RuntimeQuery) || (opType == WriteOperationType.GetConfig)) { string response = ""; while (response.Length == 0) { System.Threading.Thread.Sleep(10); response = serialPort.ReadLine(); if (response.Contains("+")) { response = ""; } else if (response.Contains("-")) { response = ""; } } int pos = response.IndexOf("="); string reply = response.Substring(pos + 1); return(reply.Split(':')); } return(null); }