Example #1
0
        private Hl7Error CreateInvalidCodeError(XmlNode node, Type type, string code)
        {
            string message = "The code, \"" + code + "\", in element <" + NodeUtil.GetLocalOrTagName(node) + "> is not a valid value for domain type \""
                             + ClassUtils.GetShortClassName(type) + "\"";

            return(new Hl7Error(Hl7ErrorCode.VALUE_NOT_IN_CODE_SYSTEM, message, (XmlElement)node));
        }
Example #2
0
 /// <summary>
 /// The only purpose of this handler is to fix a Linux listview issue where
 /// the header is sometimes not visible when a tab is switched to
 /// </summary>
 private void ListReposVisibleChanged(object sender, EventArgs e)
 {
     if (!ClassUtils.IsMono())
     {
         return;                       // Linux/Mono fixup only
     }
     if (!Visible)
     {
         return;           // Only on becoming visible
     }
     // Adjust the header columns
     listRepos.BeginUpdate();
     foreach (ColumnHeader l in listRepos.Columns)
     {
         string values  = Properties.Settings.Default.ReposColumnWidths;
         int[]  columns = values.Split(',').Select(Int32.Parse).ToArray();
         // Either set the column width from the user settings, or
         // make columns auto-adjust to fit the width of the largest item
         if (Properties.Settings.Default.ReposColumnWidths != null &&
             columns[l.Index] > 0)
         {
             l.Width = columns[l.Index];
         }
         else
         {
             l.Width = -2;
         }
     }
     listRepos.EndUpdate();
 }
Example #3
0
 private static Type GetReturnType(string sanitizedDomainType)
 {
     // these might be legacy problems with the NFLD API (not released; for testing only)
     if (ClassUtils.GetShortClassName(typeof(HealthcareProviderRoleType)).EqualsIgnoreCase(sanitizedDomainType))
     {
         sanitizedDomainType = ClassUtils.GetShortClassName(typeof(HealthcareProviderRoleType));
     }
     else
     {
         if (ClassUtils.GetShortClassName(typeof(OtherIDsRoleCode)).Equals(sanitizedDomainType))
         {
             sanitizedDomainType = ClassUtils.GetShortClassName(typeof(OtherIdentifierRoleType));
         }
     }
     if (StringUtils.IsNotBlank(sanitizedDomainType))
     {
         try
         {
             string packageName = ClassUtils.GetPackageName(typeof(OtherIdentifierRoleType));
             //.NET need to get namespace for domainvalue
             return((Type)Ca.Infoway.Messagebuilder.Runtime.GetType(packageName + "." + sanitizedDomainType));
         }
         catch (TypeLoadException)
         {
         }
     }
     // this is an expected result
     return(null);
 }
        public virtual ParameterCollection Generate(ParameterInfo[] parameters, FieldInfo[] fields, ILGenerator generator)
        {
            ParameterCollection collection = new ParameterCollection();

            // The number of effective parameters after unmapping
            int parameterCount = 0;

            // Get the provider factory field
            FieldInfo providerFactory = ClassUtils.GetField <DbProviderFactory>(fields, GenerationConstants.ProviderFactoryFieldName);

            foreach (ParameterInfo parameter in parameters)
            {
                LocalBuilder[] localParams = GetGenerator(parameter.ParameterType).Generate(parameter, providerFactory, generator);
                parameterCount += localParams.Length;

                if (localParams.Length > 0)
                {
                    // Set the local for the given parameter
                    collection[parameter] = localParams.First();
                }
            }

            // Set the local to the array
            collection.CollectionLocal = CreateArray(typeof(DbParameter[]), parameterCount, generator);

            return(collection);
        }
Example #5
0
 /// <summary>
 /// Check the connection opened to the remote node.
 /// </summary>
 /// <param name="isLinux"></param>
 private async void EnableCheckConnection()
 {
     while (RemoteNodeStatus)
     {
         try
         {
             if (!ClassUtils.SocketIsConnected(_remoteNodeClient))
             {
                 RemoteNodeStatus = false;
                 break;
             }
             else
             {
                 if (!await SendPacketRemoteNodeAsync(ClassRemoteNodeCommandForWallet.RemoteNodeSendPacketEnumeration.KeepAlive + "|0"))
                 {
                     RemoteNodeStatus = false;
                     break;
                 }
             }
         }
         catch
         {
             RemoteNodeStatus = false;
             break;
         }
         await Task.Delay(1000);
     }
 }
Example #6
0
        private string GetUsageOptionName(Option opt)
        {
            Type type = opt.Type;

            if (type != null && type.IsArray)
            {
                Array arr = (Array)opt.Target.GetValue(this);
                if (arr != null)
                {
                    int    length          = arr.Length;
                    string elementTypeName = ClassUtils.TypeShortName(arr.GetType().GetElementType());

                    StringBuilder result = new StringBuilder();
                    for (int i = 0; i < length; ++i)
                    {
                        result.Append(elementTypeName);
                        if (i < length - 1)
                        {
                            result.Append(',');
                        }
                    }
                    return(result.ToString());
                }
            }

            string typename = ClassUtils.TypeShortName(type);

            return(typename != null ? typename : "opt");
        }
Example #7
0
        private MethodInfo[] resolveExecuteMethods()
        {
            List <MethodInfo> result = new List <MethodInfo>();

            ListMethodsFilter filter = delegate(MethodInfo method)
            {
                if (method.Name != "Execute")
                {
                    return(false);
                }

                if (method.IsAbstract)
                {
                    return(false);
                }

                return(method.ReturnType == typeof(void) || method.ReturnType == typeof(bool));
            };

            Type type = GetCommandType();

            while (type != null)
            {
                ClassUtils.ListInstanceMethods(result, type, filter);
                type = type.BaseType;
            }

            return(result.ToArray());
        }
Example #8
0
        private bool IsStandardDataType(BeanProperty property)
        {
            string packageName = ClassUtils.GetPackageName(property.PropertyType);

            if (packageName.StartsWith("java."))
            {
                return(true);
            }
            else
            {
                if (StringUtils.Equals(packageName, ClassUtils.GetPackageName(typeof(Identifier))))
                {
                    return(true);
                }
                else
                {
                    if (typeof(Code).IsAssignableFrom(property.PropertyType))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
        protected virtual void SetParameterSize(LocalBuilder parameterBuilder, ParameterInfo parameterInfo, ILGenerator generator)
        {
            ParameterAttribute attribute = parameterInfo.GetCustomAttribute <ParameterAttribute>();

            // If we don't have a ParameterAttribute, then the size is the default
            if (attribute == null)
            {
                return;
            }

            // If the size is not set then use the default
            if (attribute.Size == 0)
            {
                return;
            }

            // Load the local variable associated with this parameter
            generator.Emit(OpCodes.Ldloc, parameterBuilder);

            // Load the parameter direction
            generator.Emit(OpCodes.Ldc_I4, attribute.Size);

            // Call the set method on the Value property
            generator.Emit(OpCodes.Callvirt, ClassUtils.GetPropertySetMethod <DbParameter>(nameof(DbParameter.Size)));
        }
Example #10
0
        private void SetProportionalSize()
        {
            int iTextPortion;

            if (FLabelPosition == LabelPosition.LabelAbove ||
                FLabelPosition == LabelPosition.LabelBelow)
            {
                FPanel.Wrap    = true;
                FTextBox.Width = new Unit(base.Width.Value);
                FLabel.Width   = new Unit(base.Width.Value);
            }
            else
            {
                FPanel.Wrap  = false;
                iTextPortion = PercentValue(FTextBoxPortion);
                if (iTextPortion == -1)
                {
                    iTextPortion = 50;
                }
                SetControlSize(FTextBox, iTextPortion);
                if (!ClassUtils.IsEmpty(this.Caption))
                {
                    SetControlSize(FLabel, 100 - iTextPortion);
                }
            }
            SetLabelProps();
        }
        private void HandleConvertibleType(PropertyInfo propertyInfo, object entity, object value, Type targetType)
        {
            MethodInfo convertMethod  = ClassUtils.GetConvertMethod(targetType);
            object     convertedValue = convertMethod.Invoke(null, new[] { value });

            propertyInfo.SetValue(entity, convertedValue);
        }
Example #12
0
        public BaseActor AddActor(string actorType, params object[] param)
        {
            BaseActor actor = ClassUtils.CreateInstance <BaseActor>(actorType, param);

            _AddActor(actor);
            return(actor);
        }
Example #13
0
        public T AddActor <T>(params object[] param) where T : BaseActor
        {
            T actor = ClassUtils.CreateInstance <T>(param);

            _AddActor(actor);
            return(actor);
        }
Example #14
0
        public void GetUpcastChainTest()
        {
            String code =
                @"class A {}
class B extends A {}
class C extends B {}
"                                                                       ;

            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            ExecutionMirror mirror = fsr.Execute(code, core);
            int             idA    = core.ClassTable.IndexOf("A");
            int             idB    = core.ClassTable.IndexOf("B");
            int             idC    = core.ClassTable.IndexOf("C");
            ClassNode       cnA    = core.ClassTable.ClassNodes[idA];
            ClassNode       cnB    = core.ClassTable.ClassNodes[idB];
            ClassNode       cnC    = core.ClassTable.ClassNodes[idC];
            List <int>      idsA   = ClassUtils.GetClassUpcastChain(cnA, core);
            List <int>      idsB   = ClassUtils.GetClassUpcastChain(cnB, core);
            List <int>      idsC   = ClassUtils.GetClassUpcastChain(cnC, core);

            Assert.IsTrue(idsA.Count == 2);
            Assert.IsTrue(idsA.Contains(idA));

            Assert.IsTrue(idsB.Count == 3);
            Assert.IsTrue(idsB.Contains(idA));
            Assert.IsTrue(idsB.Contains(idB));
            Assert.IsTrue(idsC.Count == 4);
            Assert.IsTrue(idsC.Contains(idA));
            Assert.IsTrue(idsC.Contains(idB));
            Assert.IsTrue(idsC.Contains(idC));
        }
Example #15
0
        /// <summary>
        /// Make a new genesis key for dynamic encryption.
        /// </summary>
        /// <returns></returns>
        public static string MakeRandomWalletPassword()
        {
            string walletPassword = string.Empty;

            while (!CheckSpecialCharacters(walletPassword) || !CheckLetter(walletPassword) || !CheckNumber(walletPassword))
            {
                for (int i = 0; i < ClassUtils.GetRandomBetween(10, 128); i++)
                {
                    var randomUpper = ClassUtils.GetRandomBetween(0, 100);
                    if (randomUpper <= 30)
                    {
                        walletPassword += ListOfCharacters[ClassUtils.GetRandomBetween(0, ListOfCharacters.Count - 1)];
                    }
                    else if (randomUpper > 30 && randomUpper <= 50)
                    {
                        walletPassword += ListOfCharacters[ClassUtils.GetRandomBetween(0, ListOfCharacters.Count - 1)].ToUpper();
                    }
                    else if (randomUpper > 50 && randomUpper <= 70)
                    {
                        walletPassword += ListOfSpecialCharacters[ClassUtils.GetRandomBetween(0, ListOfSpecialCharacters.Count - 1)];
                    }
                    else if (randomUpper > 70)
                    {
                        walletPassword += ListOfNumbers[ClassUtils.GetRandomBetween(0, ListOfNumbers.Count - 1)];
                    }
                }
            }
            return(walletPassword);
        }
Example #16
0
        /// <summary>
        /// Создание экземпляра класса <see cref="EulerMonomap2D"/>.
        /// </summary>
        public EulerMonomap2D(string characteristics, char splitter = ',')
        {
            var chars = characteristics.Split(splitter).Select(int.Parse).ToArray();

            if (chars.Length != 15)
            {
                ClassUtils.SetIndexValues(this, PropertyPrefix, chars.Cast <object>().ToArray());
            }
            else
            {
                S0  = chars[0];
                S1  = chars[1];
                S2  = chars[2];
                S3  = chars[3];
                S4  = chars[4];
                S5  = chars[5];
                S6  = chars[6];
                S7  = chars[7];
                S8  = chars[8];
                S9  = chars[9];
                S10 = chars[10];
                S11 = chars[11];
                S12 = chars[12];
                S13 = chars[13];
                S14 = chars[14];
            }
        }
        /// <summary>
        /// Asynchronously runs the given procedure and maps its result to an <see cref="System.Collections.Generic.IEnumerable{T}"/> of type <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The type to map to</typeparam>
        /// <param name="procedureName">The name of the procedure to call</param>
        /// <param name="parameters">The parameters to pass into the procedure</param>
        /// <returns>The mapped object</returns>
        public async Task <IEnumerable <T> > ExecuteEnumerableMappedProcedureAsync <T>(string procedureName, params DbParameter[] parameters) where T : class, new()
        {
            DataSet dataSet = await ExecuteScalarProcedureAsync(procedureName, parameters);

            MethodInfo mapMethod = ClassUtils.GetMethod <ProcedureMapper>(nameof(MapProcedureEnumerable));

            return((IEnumerable <T>)mapMethod.InvokeGenericMethod(new[] { typeof(T) }, this, new[] { dataSet }));
        }
Example #18
0
        internal int ComputeCastDistance(List <StackValue> args, ClassTable classTable, Core core)
        {
            //Compute the cost to migrate a class calls argument types to the coresponding base types
            //This cannot be used to determine whether a function can be called as it will ignore anything that doesn't
            //it should only be used to determine which class is closer

            if (args.Count != FormalParams.Length)
            {
                return(int.MaxValue);
            }

            int distance = 0;

            if (0 == args.Count)
            {
                return(distance);
            }
            else
            {
                // Check if all the types match the current function at 'n'
                for (int i = 0; i < args.Count; ++i)
                {
                    int rcvdType = (int)args[i].metaData.type;

                    // If its a default argumnet, then it wasnt provided by the caller
                    // The rcvdType is the type of the argument signature
                    if (args[i].optype == AddressType.DefaultArg)
                    {
                        rcvdType = FormalParams[i].UID;
                    }

                    int expectedType = FormalParams[i].UID;

                    int currentCost = 0;

                    if (FormalParams[i].IsIndexable != ArrayUtils.IsArray(args[i])) //Replication code will take care of this
                    {
                        continue;
                    }
                    else if (FormalParams[i].IsIndexable && (FormalParams[i].IsIndexable == ArrayUtils.IsArray(args[i])))
                    {
                        continue;
                    }
                    else if (expectedType == rcvdType && (FormalParams[i].IsIndexable == ArrayUtils.IsArray(args[i])))
                    {
                        continue;
                    }
                    else if (rcvdType != ProtoCore.DSASM.Constants.kInvalidIndex &&
                             expectedType != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        currentCost += ClassUtils.GetUpcastCountTo(classTable.ClassNodes[rcvdType],
                                                                   classTable.ClassNodes[expectedType], core);
                    }
                    distance += currentCost;
                }
                return(distance);
            }
        }
Example #19
0
 public void CanInvokeGenericMethod()
 {
     Assert.DoesNotThrow(() =>
     {
         MethodInfo method = ClassUtils.GetMethod <GenericUtilsTest>(nameof(GenericMethod));
         TypeUtils.InvokeGenericMethod(method, new[] { typeof(string) }, this, new[] { "Parameter" });
     },
                         "The call must be successful");
 }
Example #20
0
 private void CreateWarningIfPropertyIsNotMapped(RelationshipSorter sorter, MessagePartHolder currentMessagePart, Relationship
                                                 relationship)
 {
     if (sorter.GetBeanType() != null)
     {
         this.log.Debug("Relationship " + Describer.Describe(currentMessagePart, relationship) + " does not appear to be mapped to any property of "
                        + ClassUtils.GetShortClassName(sorter.GetBeanType()));
     }
 }
Example #21
0
        /// <summary>
        ///     Return the status of connection.
        /// </summary>
        /// <returns></returns>
        public bool GetStatusConnectToSeed(bool isLinux = false)
        {
            if (!ClassUtils.SocketIsConnected(_connector))
            {
                _isConnected = false;
            }

            return(_isConnected);
        }
Example #22
0
        private MethodInfo GetMapMethod(Type mapType)
        {
            if (mapType.IsGenericTypeDefinition(typeof(IEnumerable <>)))
            {
                return(ClassUtils.GetMethod <IProcedureMapper>(MappedEnumerableProcedure).MakeGenericMethod(mapType.GetGenericArguments().First()));
            }

            return(ClassUtils.GetMethod <IProcedureMapper>(MappedProcedure).MakeGenericMethod(mapType));
        }
Example #23
0
        public static int GetTypeDifferenceWeight(List <Type> paramTypes, List <Type> argTypes)
        {
            var result = 0;

            for (var i = 0; i < paramTypes.Count; i++)
            {
                var paramType = paramTypes[i];
                var argType   = i < argTypes.Count ? argTypes[i] : null;
                if (argType == null)
                {
                    if (paramType.IsPrimitive)
                    {
                        return(int.MaxValue);
                    }
                }
                else
                {
                    var paramTypeClazz = paramType;
                    if (!ClassUtils.IsAssignable(paramTypeClazz, argType))
                    {
                        return(int.MaxValue);
                    }

                    if (paramTypeClazz.IsPrimitive)
                    {
                        paramTypeClazz = typeof(object);
                    }

                    var superClass = argType.BaseType;
                    while (superClass != null)
                    {
                        if (paramTypeClazz.Equals(superClass))
                        {
                            result     = result + 2;
                            superClass = null;
                        }
                        else if (ClassUtils.IsAssignable(paramTypeClazz, superClass))
                        {
                            result     = result + 2;
                            superClass = superClass.BaseType;
                        }
                        else
                        {
                            superClass = null;
                        }
                    }

                    if (paramTypeClazz.IsInterface)
                    {
                        result = result + 1;
                    }
                }
            }

            return(result);
        }
Example #24
0
        /// <summary>
        /// Handle double-clicking on a tree view
        /// Depending on the saved options, we either do nothing ("0"), open a file
        /// using a default Explorer file association ("1"), or open a file using a
        /// specified application ("2")
        /// </summary>
        private void TreeCommitsDoubleClick(object sender, MouseEventArgs e)
        {
            string file = GetSelectedFile();

            if (file != string.Empty)
            {
                file = Path.Combine(App.Repos.Current.Path, file); // Commits tree stores file paths relative to the repo root
                ClassUtils.FileDoubleClick(file);
            }
        }
Example #25
0
        /// <summary>
        /// Создание экземпляра класса <see cref="Square2D"/>.
        /// </summary>
        public Square2D(params bool[] dots)
        {
            if (dots.Length != SquareSideSize * SquareSideSize)
            {
                throw new ArgumentException(nameof(dots));
            }

            SquareIdent = string.Concat(dots.Select(item => item ? 1 : 0));
            ClassUtils.SetIndexValues(this, PropertyPrefix, dots);
        }
Example #26
0
        /// <summary>
        /// Handle double-clicking on a tree view
        /// Depending on the saved options, we either do nothing ("0"), open a file
        /// using a default Explorer file association ("1"), or open a file using a
        /// specified application ("2")
        /// </summary>
        private void TreeViewDoubleClick(object sender, EventArgs e)
        {
            string file = GetSelectedFile();

            if (file != string.Empty)
            {
                ClassUtils.FileDoubleClick(file);
                WatchAndRefresh(file);
            }
        }
Example #27
0
        /// <summary>
        /// Создание экземпляра класса <see cref="Square2D"/>.
        /// </summary>
        public Square2D(string dots)
        {
            if (dots.Length != SquareSideSize * SquareSideSize)
            {
                throw new ArgumentException(nameof(dots));
            }

            SquareIdent = dots;
            ClassUtils.SetIndexValues(this, PropertyPrefix, dots.Select(chr => chr > '0').Cast <object>().ToArray());
        }
Example #28
0
        /// <summary>
        /// Edit selected file using either the default editor (native OS file association,
        /// if the tag is null, or the editor program specified in the tag field.
        /// This is a handler for both the context menu and the edit tool bar button.
        /// </summary>
        private void MenuEditClick(object sender, EventArgs e)
        {
            string file = GetSelectedFile();

            if (file != string.Empty)
            {
                file = Path.Combine(App.Repos.Current.Path, file); // Commits tree stores file paths relative to the repo root
                App.PrintStatusMessage("Editing " + file, MessageType.General);
                ClassUtils.FileOpenFromMenu(sender, file);
            }
        }
Example #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static bool IsExcludeController(string name)
 {
     foreach (Type item in ExcludeControllerSecurity)
     {
         if (name.Equals(ClassUtils.getNameObject(item)))
         {
             return(true);
         }
     }
     return(false);
 }
Example #30
0
        /// <summary>
        /// Edit selected file using either the default editor (native OS file association,
        /// if the tag is null, or the editor program specified in the tag field.
        /// This is a handler for both the context menu and the edit tool bar button.
        /// </summary>
        private void MenuViewEditClick(object sender, EventArgs e)
        {
            string file = GetSelectedFile();

            if (file != string.Empty)
            {
                App.PrintStatusMessage("Editing " + file, MessageType.General);
                ClassUtils.FileOpenFromMenu(sender, file);
                WatchAndRefresh(file);
            }
        }