internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) : base(problemDescriptor.FullName + ": " + description, cause) { name = problemDescriptor.FullName; proto = problemDescriptor.Proto; this.description = description; }
internal static string GetFullUmbrellaClassName(IDescriptor descriptor) { CSharpFileOptions options = descriptor.File.CSharpOptions; string result = options.Namespace; if (result != "") result += '.'; result += options.UmbrellaClassname; return "global::" + result; }
internal DescriptorValidationException(IDescriptor problemDescriptor, string description) : base(problemDescriptor.FullName + ": " + description) { // Note that problemDescriptor may be partially uninitialized, so we // don't want to expose it directly to the user. So, we only provide // the name and the original proto. name = problemDescriptor.FullName; this.description = description; }
protected internal override void TryConfigure( IDescriptorContext context, IDescriptor descriptor, ICustomAttributeProvider element) { if (element is MemberInfo m) { Type schemaType = GetSchemaType(context, m); if (descriptor is IObjectFieldDescriptor ofd) { _off.MakeGenericMethod(schemaType).Invoke(null, new[] { ofd }); } else if (descriptor is IInterfaceFieldDescriptor ifd) { _iff.MakeGenericMethod(schemaType).Invoke(null, new[] { ifd }); } } }
/// <summary> /// Gets the TTSEngine class Type correspoding to the guid /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type this[Guid guid] { get { foreach (var type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Guid.Equals(guid, descriptor.Id)) { Log.Debug("Found TTS engine of type " + type); return(type); } } Log.Debug("Could not find TTS engine for id " + guid.ToString()); return(null); } }
/// <summary> /// Looks up the cache for the specified GUID and returns the Type /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type Lookup(Guid guid) { if (Equals(guid, NullWordPredictor.Descriptor.Id)) { return(typeof(NullWordPredictor)); } foreach (Type type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Equals(guid, descriptor.Id)) { Log.Debug("Found word predictor of type " + type); return(type); } } Log.Debug("Could not find word predictor for id " + guid.ToString()); return(null); }
/// <summary> /// Determine the distances between this and other descriptor passed in using the list of criteria passed in /// </summary> /// <param name="momentDescriptor">The descriptor to compare against</param> /// <returns>an hashtable containing the ICriterion type as key and distance to descriptor as value.</returns> public override Hashtable DistancesToDescriptor(IDescriptor momentDescriptor) { if (momentDescriptor == null) { throw new ArgumentNullException("cartersianMomentDescriptor", "Descriptor passed in cannot be null"); } if (momentDescriptor.GetType() != this.GetType()) { throw new InvalidCastException("Can only compare similar descriptor, descriptor passed in must be of type '" + this.GetType().ToString() + "' (type '" + momentDescriptor.GetType().ToString() + "' was passed in) "); } Hashtable retVal = new Hashtable(Criteria.Length); foreach (ICriterion criterion in Criteria) { criterion.Pass(this, momentDescriptor); retVal.Add(criterion.GetType(), criterion.DistanceBetweenDescriptors); } return(retVal); }
/// <summary> /// Check if two descriptor are matching, using this criterion /// </summary> /// <param name="descriptorToFind">The original descriptor</param> /// <param name="descriptorTest">The descriptor to test</param> /// <returns>true if within tolerance for this criterion, false otherwise</returns> public override bool Pass(IDescriptor descriptorToFind, IDescriptor descriptorTest) { double dist = 0.0; DescriptorSquareMatrix textureToFind = (DescriptorSquareMatrix)GetDependendObjects(descriptorToFind, "texture"); DescriptorSquareMatrix textureTest = (DescriptorSquareMatrix)GetDependendObjects(descriptorTest, "texture"); // for (int x = 0; x < DescriptorSquareMatrix.Length; x++) { for (int y = 0; y < DescriptorSquareMatrix.Length; y++) { dist += (double)Math.Abs(textureToFind[x, y] - textureTest[x, y]); } } DistanceBetweenDescriptors = dist; return(dist > (double)Value ? false : true); }
/// <summary> /// Looks up the cache for the specified GUID and returns the Type /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type Lookup(Guid guid) { if (Equals(guid, NullTTSEngine.Descriptor.Id)) { return(typeof(NullTTSEngine)); } foreach (Type type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Equals(guid, descriptor.Id)) { Log.Debug("Found TTS Engine of type " + type); return(type); } } Log.Debug("Could not find TTS Engine for id " + guid); return(null); }
public static void AddMeasurementUnitConversionArgument(this IDescriptor descriptor) { if (descriptor is IObjectFieldDescriptor objectField) { objectField.Argument(ArgumentName, argumentDescriptor => argumentDescriptor.Type <EnumType <MeasurementSystem> >().DefaultValue(MeasurementSystem.Metric)) .Use(next => async middlewareContext => { await next(middlewareContext).ConfigureAwait(false); if (middlewareContext.Result is double length) { middlewareContext.Result = ConvertToUnit(length, middlewareContext.Argument <MeasurementSystem>(ArgumentName)); } }); } else if (descriptor is IInterfaceFieldDescriptor interfaceField) { interfaceField.Argument(ArgumentName, argumentDescriptor => argumentDescriptor.Type <EnumType <MeasurementSystem> >().DefaultValue(MeasurementSystem.Metric)); } }
protected internal override void TryConfigure( IDescriptorContext context, IDescriptor descriptor, ICustomAttributeProvider element) { if (descriptor is IArgumentDescriptor arg) { arg.DefaultValue(Value); } if (descriptor is IDirectiveArgumentDescriptor darg) { darg.DefaultValue(Value); } if (descriptor is IInputFieldDescriptor field) { field.DefaultValue(Value); } }
public static void ApplyIdToField( IDescriptor <OutputFieldDefinitionBase> descriptor, NameString typeName = default) { if (descriptor is null) { throw new ArgumentNullException(nameof(descriptor)); } descriptor.Extend().OnBeforeCreate(RewriteDefinition); if (descriptor is IDescriptor <ObjectFieldDefinition> objectFieldDescriptor) { ResultConverterDefinition placeholder = new((_, r) => r, key : WellKnownMiddleware.GlobalId, isRepeatable : false); objectFieldDescriptor.Extend().Definition.ResultConverters.Add(placeholder); objectFieldDescriptor.Extend() .OnBeforeCompletion( (c, d) => AddSerializerToObjectField(c, d, placeholder, typeName)); } }
public static IGraphic GenerateGraphic(String graphicId) { IDescriptor data = Game.Manager.Resources.GraphicDatas[graphicId]; if (data is BasicGraphicData) { return(new BasicGraphic(graphicId)); } if (data is SimpleAnimGraphic) { return(new SimpleAnimGraphic(graphicId)); } if (data is RectangleGraphicData) { return(new RectangleGraphic(graphicId)); } throw new NotImplementedException( String.Format("Graphic ID \"{0}\" was not supported by GenerateGraphic(string)!", graphicId)); }
public CommandCollection Execute(IDescriptor descriptor, CommandCollection commands) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); Message message = new Message(descriptor, commands); message.Serialize(writer); Packet packet = new Packet(ms); ClientConnection.Send(packet); packet.Wait(); BinaryReader reader = new BinaryReader(packet.Response); message = Message.Deserialize(reader, (id) => { return(descriptor); }); return(message.Commands); }
protected internal override void TryConfigure( IDescriptorContext context, IDescriptor d, ICustomAttributeProvider element) { if (d is IComparableFilterFieldDescriptor fieldComparableDescriptor) { fieldComparableDescriptor .BindFiltersExplicitly().AllowEquals().Name(ComparableField); } if (d is IBooleanFilterFieldDescriptor fieldBooleanDescriptor) { fieldBooleanDescriptor .BindFiltersExplicitly().AllowEquals().Name(BooleanField); } if (d is IStringFilterFieldDescriptor fieldStringDescriptor) { fieldStringDescriptor .BindFiltersExplicitly().AllowEquals().Name(StringField); } }
/// <summary> /// Updates the local descriptor with the changes from the remote /// and retrieves up to date descriptor from the local server. /// </summary> private void UpdateDescriptor() { ICommand command = null; CommandCollection collection = new CommandCollection(1); // Set the local descriptor command = new XTableDescriptorSetCommand(this.Descriptor); collection.Add(command); StorageEngine.Execute(this.Descriptor, collection); // Get the local descriptor command = new XTableDescriptorGetCommand(this.Descriptor); collection.Clear(); collection.Add(command); collection = StorageEngine.Execute(this.Descriptor, collection); XTableDescriptorGetCommand resultCommand = (XTableDescriptorGetCommand)collection[0]; this.Descriptor = resultCommand.Descriptor; }
public static IEnumerable <IParameterDescriptor> GetAllParameters(this IDescriptor descriptor) { switch (descriptor) { case IParameterDescriptor parameter: yield return(parameter); break; case ParameterGroup group: { foreach (var child in @group.Items) { foreach (var p in GetAllParameters(child)) { yield return(p); } } break; } } }
/// <summary> /// Initialize the Word Predictor manager by looking for /// Word predictor dlls. /// The extension dirs parameter contains the root directory under /// which to search for Word Predictor DLL files. The directories /// are specified in a comma delimited fashion. /// E.g. Base, Hawking /// These are relative to the application execution directory or /// to the directory where the ACAT framework has been installed. /// It recusrively walks the directories and looks for Word Predictor /// extension DLL files /// </summary> /// <param name="extensionDirs"></param> /// <returns></returns> public bool Init(IEnumerable <String> extensionDirs) { bool retVal = true; if (_wordPredictors == null) { _wordPredictors = new WordPredictors(); // add the null word predictor to our list of // recognizied word predictors IDescriptor descriptor = _nullWordPredictor.Descriptor; if (descriptor != null) { _wordPredictors.Add(descriptor.Id, typeof(NullWordPredictor)); } // walk through the directory to discover retVal = _wordPredictors.Load(extensionDirs); } return(retVal); }
public override bool IsVisible(IReadonlyContext context, IDescriptor descriptor) { /* Groups */ if (ReferenceEquals(descriptor, SignalGroup)) { return(SpellerControlParadigm.EyeTracking != ControlParadigm.Get(context)); } if (ReferenceEquals(descriptor, SsvepGroup)) { return(SpellerControlParadigm.SsvepWithEyeTracking == ControlParadigm.Get(context)); } if (ReferenceEquals(descriptor, P300Group)) { return(SpellerControlParadigm.P300WithEyeTracking == ControlParadigm.Get(context)); } /* Parameters */ if (ReferenceEquals(Channels, descriptor)) { return(ControlParadigm.Get(context) != SpellerControlParadigm.EyeTracking); } if (ReferenceEquals(ActivationMode, descriptor)) { return(ControlParadigm.Get(context) != SpellerControlParadigm.EyeTracking); } if (ReferenceEquals(CursorMovementTolerance, descriptor)) { return(ControlParadigm.Get(context) != SpellerControlParadigm.EyeTracking && DynamicInterval.Get(context)); } if (ReferenceEquals(SelectionDelay, descriptor)) { return(DynamicInterval.Get(context)); } if (ReferenceEquals(InputBarVisibility, descriptor) || ReferenceEquals(ButtonHintColor, descriptor)) { return(CopySpelling.Get(context).Enabled); } return(true); }
private async void OnDeviceConnected(object sender, DeviceEventArgs e) { _read = null; _write = null; UserDialogs.Instance.ShowLoading("Getting informations"); var service = await _device.GetServiceAsync(Guid.Parse(serviceUUID)); if (service != null) { _read = await service.GetCharacteristicAsync(Guid.Parse(readUUID)); _write = await service.GetCharacteristicAsync(Guid.Parse(writeUUID)); IList <IDescriptor> descriptors = (IList <IDescriptor>) await _read.GetDescriptorsAsync(); _notifyDescriptor = descriptors[0]; //_writeBuffer = new byte[PayloadLength + _headerLenght]; if (_read != null && _write != null) { serialDriver = new SerialDriver(_device, _write, _read, _notifyDescriptor); UserDialogs.Instance.HideLoading(); DeviceConnected = "CONNECTED"; IsDisconnectEnabled = true; OnPropertyChanged(nameof(DeviceConnected)); OnPropertyChanged(nameof(IsDisconnectEnabled)); } else { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.ShowError("Unable to get characteristic"); } } }
public void DescriptorMouseDown(FrameworkElement sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && this.InEditMode) { IDescriptor descriptor = sender.DataContext as IDescriptor; if (descriptor != null) { if (1 < e.ClickCount) { LogicalCircuitDescriptor logicalCircuitDescriptor = descriptor as LogicalCircuitDescriptor; if (logicalCircuitDescriptor != null && !logicalCircuitDescriptor.IsCurrent) { this.OpenLogicalCircuit(logicalCircuitDescriptor.Circuit); } } else { this.dragStart = e.GetPosition(sender); this.dragSource = sender; } } } }
protected override T Map(IDataRecord record) { try { IDescriptor obj = GetEntity; obj.Id = (DBNull.Value == record[IdFieldName]) ? 0 : (int)record[IdFieldName]; obj.Description = (DBNull.Value == record[DescriptionFieldName]) ? string.Empty : (string)record[DescriptionFieldName]; return((T)obj); } catch { throw; // NOTE: // consider handling exeption here instead of re-throwing // if graceful recovery can be accomplished } }
protected override void TryConfigure( IDescriptorContext context, IDescriptor descriptor, ICustomAttributeProvider element) { if (descriptor is IObjectTypeDescriptor objectTypeDescriptor && element is Type objectType) { if (string.IsNullOrEmpty(FieldSet)) { throw Key_FieldSet_CannotBeEmpty(objectType); } objectTypeDescriptor.Key(FieldSet !); } if (descriptor is IObjectFieldDescriptor objectFieldDescriptor && element is MemberInfo) { objectFieldDescriptor .Extend() .OnBeforeCreate(d => d.ContextData[WellKnownContextData.KeyMarker] = true); } }
protected internal override void TryConfigure( IDescriptorContext context, IDescriptor descriptor, ICustomAttributeProvider element) { switch (descriptor) { case IInputFieldDescriptor d when element is PropertyInfo: d.ID(TypeName); break; case IArgumentDescriptor d when element is ParameterInfo: d.ID(TypeName); break; case IObjectFieldDescriptor d when element is MemberInfo: d.ID(TypeName); break; case IInterfaceFieldDescriptor d when element is MemberInfo: d.ID(); break; } }
/// <summary> /// Returns the ID of the TTS Engine that supports the /// specified culture info. If no culture-specific /// TTS Engine is found, Guid.Empty is returned /// </summary> /// <param name="ci">culture info</param> /// <returns>ID of the TTS Engine</returns> public Guid GetDefaultByCulture(CultureInfo ci) { Tuple <String, Type> foundTuple = null; // first look for culture-specific TTS Engines foreach (var tuple in _ttsEnginesTypeCache.Values) { if (ci == null) { if (String.IsNullOrEmpty(tuple.Item1)) { foundTuple = tuple; break; } } else if (!String.IsNullOrEmpty(tuple.Item1) && (String.Compare(tuple.Item1, ci.Name, true) == 0) || String.Compare(tuple.Item1, ci.TwoLetterISOLanguageName, true) == 0) { foundTuple = tuple; break; } } if (foundTuple != null) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(foundTuple.Item2); if (descriptor != null) { Log.Debug("Found TTS Engine for culture " + (ci != null ? ci.Name : "Neutral") + "[" + descriptor.Name + "]"); return(descriptor.Id); } } return(Guid.Empty); }
private void SerializeDescriptor(BinaryWriter writer, IDescriptor description) { CountCompression.Serialize(writer, (ulong)description.ID); writer.Write(description.Name); CountCompression.Serialize(writer, (ulong)description.StructureType); description.KeyDataType.Serialize(writer); description.RecordDataType.Serialize(writer); CountCompression.Serialize(writer, (ulong)description.CreateTime.Ticks); CountCompression.Serialize(writer, (ulong)description.ModifiedTime.Ticks); CountCompression.Serialize(writer, (ulong)description.AccessTime.Ticks); if (description.Tag == null) { CountCompression.Serialize(writer, 0); } else { CountCompression.Serialize(writer, (ulong)description.Tag.Length + 1); writer.Write(description.Tag); } }
/// <summary> /// Look up and cross-link all field types etc. /// </summary> internal void CrossLink() { if (Proto.HasExtendee) { IDescriptor extendee = File.DescriptorPool.LookupSymbol(Proto.Extendee, this); if (!(extendee is MessageDescriptor)) { throw new DescriptorValidationException(this, "\"" + Proto.Extendee + "\" is not a message type."); } containingType = (MessageDescriptor)extendee; if (!containingType.IsExtensionNumber(FieldNumber)) { throw new DescriptorValidationException(this, "\"" + containingType.FullName + "\" does not declare " + FieldNumber + " as an extension number."); } } if (Proto.HasTypeName) { IDescriptor typeDescriptor = File.DescriptorPool.LookupSymbol(Proto.TypeName, this); if (!Proto.HasType) { // Choose field type based on symbol. if (typeDescriptor is MessageDescriptor) { fieldType = FieldType.Message; mappedType = MappedType.Message; } else if (typeDescriptor is EnumDescriptor) { fieldType = FieldType.Enum; mappedType = MappedType.Enum; } else { throw new DescriptorValidationException(this, "\"" + Proto.TypeName + "\" is not a type."); } } if (MappedType == MappedType.Message) { if (!(typeDescriptor is MessageDescriptor)) { throw new DescriptorValidationException(this, "\"" + Proto.TypeName + "\" is not a message type."); } messageType = (MessageDescriptor)typeDescriptor; if (Proto.HasDefaultValue) { throw new DescriptorValidationException(this, "Messages can't have default values."); } } else if (MappedType == Descriptors.MappedType.Enum) { if (!(typeDescriptor is EnumDescriptor)) { throw new DescriptorValidationException(this, "\"" + Proto.TypeName + "\" is not an enum type."); } enumType = (EnumDescriptor)typeDescriptor; } else { throw new DescriptorValidationException(this, "Field with primitive type has type_name."); } } else { if (MappedType == MappedType.Message || MappedType == MappedType.Enum) { throw new DescriptorValidationException(this, "Field with message or enum type missing type_name."); } } // We don't attempt to parse the default value until here because for // enums we need the enum type's descriptor. if (Proto.HasDefaultValue) { if (IsRepeated) { throw new DescriptorValidationException(this, "Repeated fields cannot have default values."); } try { switch (FieldType) { case FieldType.Int32: case FieldType.SInt32: case FieldType.SFixed32: defaultValue = TextFormat.ParseInt32(Proto.DefaultValue); break; case FieldType.UInt32: case FieldType.Fixed32: defaultValue = TextFormat.ParseUInt32(Proto.DefaultValue); break; case FieldType.Int64: case FieldType.SInt64: case FieldType.SFixed64: defaultValue = TextFormat.ParseInt64(Proto.DefaultValue); break; case FieldType.UInt64: case FieldType.Fixed64: defaultValue = TextFormat.ParseUInt64(Proto.DefaultValue); break; case FieldType.Float: defaultValue = TextFormat.ParseFloat(Proto.DefaultValue); break; case FieldType.Double: defaultValue = TextFormat.ParseDouble(Proto.DefaultValue); break; case FieldType.Bool: if (Proto.DefaultValue == "true") { defaultValue = true; } else if (Proto.DefaultValue == "false") { defaultValue = false; } else { throw new FormatException("Boolean values must be \"true\" or \"false\""); } break; case FieldType.String: defaultValue = Proto.DefaultValue; break; case FieldType.Bytes: try { defaultValue = TextFormat.UnescapeBytes(Proto.DefaultValue); } catch (FormatException e) { throw new DescriptorValidationException(this, "Couldn't parse default value: " + e.Message); } break; case FieldType.Enum: defaultValue = enumType.FindValueByName(Proto.DefaultValue); if (defaultValue == null) { throw new DescriptorValidationException(this, "Unknown enum default value: \"" + Proto.DefaultValue + "\""); } break; case FieldType.Message: case FieldType.Group: throw new DescriptorValidationException(this, "Message type had default value."); } } catch (FormatException e) { DescriptorValidationException validationException = new DescriptorValidationException(this, "Could not parse default value: \"" + Proto.DefaultValue + "\"", e); throw validationException; } } else { // Determine the default default for this field. if (IsRepeated) { defaultValue = Lists <object> .Empty; } else { switch (MappedType) { case MappedType.Enum: // We guarantee elsewhere that an enum type always has at least // one possible value. defaultValue = enumType.Values[0]; break; case MappedType.Message: defaultValue = null; break; default: defaultValue = GetDefaultValueForMappedType(MappedType); break; } } } if (!IsExtension) { File.DescriptorPool.AddFieldByNumber(this); } if (containingType != null && containingType.Options.MessageSetWireFormat) { if (IsExtension) { if (!IsOptional || FieldType != FieldType.Message) { throw new DescriptorValidationException(this, "Extensions of MessageSets must be optional messages."); } } else { throw new DescriptorValidationException(this, "MessageSets cannot have fields, only extensions."); } } }
internal DescriptorIntPair(IDescriptor descriptor, int number) { this.number = number; this.descriptor = descriptor; }
/// <summary> /// Looks up a descriptor by name, relative to some other descriptor. /// The name may be fully-qualified (with a leading '.'), partially-qualified, /// or unqualified. C++-like name lookup semantics are used to search for the /// matching descriptor. /// </summary> /// <remarks> /// This isn't heavily optimized, but it's only used during cross linking anyway. /// If it starts being used more widely, we should look at performance more carefully. /// </remarks> public IDescriptor LookupSymbol(string name, IDescriptor relativeTo) { IDescriptor result; if (name.StartsWith(".")) { // Fully-qualified name. result = FindSymbol <IDescriptor>(name.Substring(1)); } else { // If "name" is a compound identifier, we want to search for the // first component of it, then search within it for the rest. int firstPartLength = name.IndexOf('.'); string firstPart = firstPartLength == -1 ? name : name.Substring(0, firstPartLength); // We will search each parent scope of "relativeTo" looking for the // symbol. StringBuilder scopeToTry = new StringBuilder(relativeTo.FullName); while (true) { // Chop off the last component of the scope. int dotpos = scopeToTry.ToString().LastIndexOf("."); if (dotpos == -1) { result = FindSymbol <IDescriptor>(name); break; } else { scopeToTry.Length = dotpos + 1; // Append firstPart and try to find. scopeToTry.Append(firstPart); result = FindSymbol <IDescriptor>(scopeToTry.ToString()); if (result != null) { if (firstPartLength != -1) { // We only found the first part of the symbol. Now look for // the whole thing. If this fails, we *don't* want to keep // searching parent scopes. scopeToTry.Length = dotpos + 1; scopeToTry.Append(name); result = FindSymbol <IDescriptor>(scopeToTry.ToString()); } break; } // Not found. Remove the name so we can try again. scopeToTry.Length = dotpos; } } } if (result == null) { throw new DescriptorValidationException(relativeTo, "\"" + name + "\" is not defined."); } else { return(result); } }
public XTableDescriptorSetCommand(IDescriptor descriptor) { Descriptor = descriptor; }
public Message(IDescriptor description, CommandCollection commands) { Description = description; Commands = commands; }
public StorageEngineFindByNameCommand(IDescriptor descriptor) : this(null, descriptor) { }
public static void BeginDescriptorUpdate(IDescriptor descriptor) { VerifyNotNull(descriptor); Monitor.Enter(descriptor); }
public void RemoveDescriptor(IDescriptor descriptor) { _descriptors.Remove(descriptor); }
public StorageEngineFindByIDCommand(IDescriptor descriptor, long id) { Descriptor = descriptor; ID = id; }
/// <summary> /// It resolve dynamic resources /// </summary> /// <param name="resourceValue">Value of resource</param> /// <param name="descriptors">Array of descriptors</param> /// <returns>ServiceException</returns> public static String Resolve(String resourceValue, IDescriptor[] descriptors) { if(resourceValue == null) { return resourceValue; } if(resourceValue.Contains(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFER_REFERENCE)) { //Find {} int openingCurlyBracketIndex = resourceValue.IndexOf(Constants.RESOURCE_SPACE) + 1; int singleClosingCurlyBracketIndex = resourceValue.IndexOf(Constants.RESOURCE_CLOSE_CURLY_BRACKET); int doubleClosingCurlyBracketIndex = resourceValue.IndexOf(Constants.RESOURCE_CLOSE_CURLY_BRACKET + Constants.RESOURCE_CLOSE_CURLY_BRACKET); String resourceKey; if(doubleClosingCurlyBracketIndex != -1) { resourceKey = resourceValue.Substring(openingCurlyBracketIndex, doubleClosingCurlyBracketIndex + 1); int slashIndex = resourceKey.LastIndexOf(Constants.RESOURCE_SLASH); //Find {- String resourceClass = resourceKey.Substring(0, resourceKey.Substring(0, slashIndex).LastIndexOf(Constants.RESOURCE_DOT)); String resourceAPI = resourceKey.Substring(resourceKey.Substring(0, slashIndex).LastIndexOf(Constants.RESOURCE_DOT) + 1, resourceKey.Substring(0, slashIndex).Length); ICollection<Type> resourceAPIParameterTypes = new LinkedList<Type>(); ICollection<String> resourceAPIParameters = new LinkedList<String>(); //Find -}} String apiParameters = resourceKey.Substring(slashIndex + 1, resourceKey.LastIndexOf(Constants.RESOURCE_CLOSE_CURLY_BRACKET) + 1); //Resolve all API parameters String[] apiParameterTokenizer = Regex.Split(apiParameters, Constants.RESOURCE_COMMA); for (int i = 0; i < apiParameterTokenizer.Length;i++) { String apiParameter = apiParameterTokenizer[i]; resourceAPIParameterTypes.Add(typeof(String)); resourceAPIParameters.Add(Resolve(apiParameter, descriptors)); } int count = 0; Type[] apiParameterTypes = new Type[resourceAPIParameters.Count]; foreach(Type resourceAPIParameterType in resourceAPIParameterTypes) { apiParameterTypes[count++] = resourceAPIParameterType; } Object classObject = ClassUtils.CreateClassInstance(resourceClass); String resolvedValue = null; try { resolvedValue = (String) ClassUtils.InvokeMethod(classObject, resourceAPI, apiParameterTypes, resourceAPIParameters.ToArray()); } catch(SiminovException se) { Log.Error(typeof(ResourceUtils).Name, "Resolve", "SiminovException caught while invoking method, RESOURCE-API: " + resourceAPI + ", " + se.Message); throw new ServiceException(typeof(ResourceUtils).Name, "Resolve", se.GetMessage()); } return Resolve(resolvedValue, descriptors); } else { resourceKey = resourceValue.Substring(openingCurlyBracketIndex, singleClosingCurlyBracketIndex); int dotIndex = resourceKey.LastIndexOf(Constants.RESOURCE_DOT); String resourceClass = resourceKey.Substring(0, dotIndex); String resourceAPI = resourceKey.Substring(resourceKey.LastIndexOf(Constants.RESOURCE_DOT) + 1, resourceKey.Length); Object classObject = ClassUtils.CreateClassInstance(resourceClass); String value = null; try { value = (String) ClassUtils.GetValue(classObject, resourceAPI); } catch(SiminovException se) { Log.Error(typeof(ResourceUtils).Name, "resolve", "SiminovException caught while getting values, RESOURCE-API: " + resourceAPI + ", " + se.GetMessage()); throw new ServiceException(typeof(ResourceUtils).Name, "resolve", se.GetMessage()); } String resolvedValue = resourceValue.Replace(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFER_REFERENCE + Constants.RESOURCE_SPACE + resourceKey + Constants.RESOURCE_CLOSE_CURLY_BRACKET, value); return Resolve(resolvedValue, descriptors); } } else if(resourceValue.Contains(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_SELF_REFERENCE)) { String key = resourceValue.Substring(resourceValue.IndexOf(Constants.RESOURCE_SPACE) + 1, resourceValue.IndexOf(Constants.RESOURCE_CLOSE_CURLY_BRACKET)); String value = null; foreach(IDescriptor descriptor in descriptors) { if(descriptor.ContainProperty(key)) { value = descriptor.GetProperty(key); break; } } return Resolve(value, descriptors); } else if(resourceValue.Contains(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFERENCE)) { String key = resourceValue.Substring(resourceValue.IndexOf(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFERENCE) + (Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFERENCE).Length + 1, resourceValue.IndexOf(Constants.RESOURCE_CLOSE_CURLY_BRACKET) - (resourceValue.IndexOf(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFERENCE) + (Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFERENCE).Length + 1)); String value = null; foreach(IDescriptor descriptor in descriptors) { if(descriptor.ContainProperty(key)) { value = descriptor.GetProperty(key); break; } } String resolvedValue = resourceValue.Replace(Constants.RESOURCE_OPEN_CURLY_BRACKET + Constants.RESOURCE_REFERENCE + " " + key + Constants.RESOURCE_CLOSE_CURLY_BRACKET, value); return Resolve(resolvedValue, descriptors); } return resourceValue; }
private static int DetermineBucketNo(IDescriptor descriptor) { return(Math.Abs(descriptor.GetHashCode() % 100)); }
public StorageEngineDescriptionCommand(IDescriptor description) { Descriptor = description; }
public void AddDescriptor(IDescriptor descriptor) { _descriptors.Add(descriptor); }
public StorageEngineFindByNameCommand(string name, IDescriptor descriptor) { Name = name; Descriptor = descriptor; }
private void SerializeDescriptor(BinaryWriter writer, IDescriptor description) { CountCompression.Serialize(writer, (ulong)description.ID); writer.Write(description.Name); CountCompression.Serialize(writer, (ulong)description.StructureType); description.KeyDataType.Serialize(writer); description.RecordDataType.Serialize(writer); CountCompression.Serialize(writer, (ulong)description.CreateTime.Ticks); CountCompression.Serialize(writer, (ulong)description.ModifiedTime.Ticks); CountCompression.Serialize(writer, (ulong)description.AccessTime.Ticks); if (description.Tag == null) CountCompression.Serialize(writer, 0); else { CountCompression.Serialize(writer, (ulong)description.Tag.Length + 1); writer.Write(description.Tag); } }
/// <summary> /// Look up and cross-link all field types etc. /// </summary> internal void CrossLink() { if (Proto.TypeName != "") { IDescriptor typeDescriptor = File.DescriptorPool.LookupSymbol(Proto.TypeName, this); if (Proto.Type != 0) { // Choose field type based on symbol. if (typeDescriptor is MessageDescriptor) { fieldType = FieldType.Message; } else if (typeDescriptor is EnumDescriptor) { fieldType = FieldType.Enum; } else { throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a type."); } } if (fieldType == FieldType.Message) { if (!(typeDescriptor is MessageDescriptor)) { throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a message type."); } messageType = (MessageDescriptor)typeDescriptor; if (Proto.DefaultValue != "") { throw new DescriptorValidationException(this, "Messages can't have default values."); } } else if (fieldType == FieldType.Enum) { if (!(typeDescriptor is EnumDescriptor)) { throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not an enum type."); } enumType = (EnumDescriptor)typeDescriptor; } else { throw new DescriptorValidationException(this, "Field with primitive type has type_name."); } } else { if (fieldType == FieldType.Message || fieldType == FieldType.Enum) { throw new DescriptorValidationException(this, "Field with message or enum type missing type_name."); } } // Note: no attempt to perform any default value parsing File.DescriptorPool.AddFieldByNumber(this); if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat) { throw new DescriptorValidationException(this, "MessageSet format is not supported."); } accessor = CreateAccessor(); }
public void RemoveDescriptor(IDescriptor descriptor) { throw new NotImplementedException(); }