コード例 #1
0
        public override void WriteText(MTextWriter writer)
        {
            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteString(Name);
                writer.WriteSpace();
            }

            if (TypeName.Contains("::"))
            {
                writer.WriteString($"\'{TypeName}\'");
            }
            else
            {
                writer.WriteString(TypeName);
            }

            writer.WriteOpenScope();

            foreach (var node in Child)
            {
                node.WriteText(writer);
            }

            writer.WriteEndScope();
        }
コード例 #2
0
 public void ConvertFromAttribute(KeyValuePair <string, object> a, int guidShift)
 {
     Key      = a.Key;
     TypeName = a.Value.GetType().ToString().ToLower();
     if (TypeName.Contains("guid"))
     {
         Value = Common.ShiftString(a.Value.ToString(), guidShift);
     }
     else if (TypeName.Contains("entityreference"))
     {
         var er = (EntityReference)a.Value;
         Value = Common.ShiftString(er.Id.ToString(), guidShift) + ":" + er.LogicalName;
     }
     else if (TypeName.Contains("string"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("int"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("double"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("float"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("decimal"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("datetime"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("optionsetvalue"))
     {
         Value = ((OptionSetValue)a.Value).Value.ToString();
     }
     else if (TypeName.Contains("money"))
     {
         Value = ((Money)a.Value).Value.ToString();
     }
     else if (TypeName.Contains("boolean"))
     {
         Value = a.Value.ToString();
     }
     else if (TypeName.Contains("entitycollection"))
     {
         Value = null;
     }
     else
     {
         throw new InvalidPluginExecutionException("Type not supported: " + TypeName);
     }
 }
コード例 #3
0
        public KeyValuePair<string, object> ConvertToAttribute()
        {
            if (Value == null) return new KeyValuePair<string, object>(Key, null);

            Object attributeValue = null;

            if (TypeName.Contains("guid"))
            {
                attributeValue = Guid.Parse(Value.ToString());
            }
            else if (TypeName.Contains("entityreference"))
            {
                string[] pair = ((string)Value).Split(':');
                attributeValue = new EntityReference(pair[1], Guid.Parse(pair[0]));
            }
            else if (TypeName.Contains("string"))
            {
                attributeValue = (string)Value;
            }
            else if (TypeName.Contains("int"))
            {
                attributeValue = long.Parse((string)Value);
            }
            else if (TypeName.Contains("double"))
            {
                attributeValue = double.Parse((string)Value);
            }
            else if (TypeName.Contains("float"))
            {
                attributeValue = float.Parse((string)Value);
            }
            else if (TypeName.Contains("decimal"))
            {
                attributeValue = decimal.Parse((string)Value);
            }
            else if (TypeName.Contains("datetime"))
            {
                attributeValue = DateTime.Parse((string)Value);
            }
            else if (TypeName.Contains("optionsetvalue"))
            {
                attributeValue = new OptionSetValue(int.Parse((string)Value));
            }
            else if (TypeName.Contains("money"))
            {
                attributeValue = new Money(decimal.Parse((string)Value));
            }
            else if (TypeName.Contains("boolean"))
            {
                attributeValue = bool.Parse((string)Value);
            }
           

            KeyValuePair<string, object> a = new KeyValuePair<string, object>(Key, attributeValue);
            return a;
        }
コード例 #4
0
 private int _sizeof()
 {
     if (TypeName.Contains("32"))
     {
         return(4);
     }
     else if (TypeName.Contains("16"))
     {
         return(2);
     }
     else if (TypeName.ToLower() == "byte")
     {
         return(1);
     }
     else
     {
         throw new Exception("Формат не поддерживается");
     }
 }
コード例 #5
0
        /// <summary>
        /// Performs execution of the command
        /// </summary>
        protected override void DoProcessRecord()
        {
            var provider = ParameterSetName == "Get by collection" ? this.GetCollection() : this.GetServer();

            Type clientType;

            if (TypeName.Contains(","))
            {
                // Fully qualified - use Type.GetType
                clientType = Type.GetType(TypeName);
            }
            else
            {
                // Not fully qualified - iterate over all loaded assemblies (may not find if assembly's not loaded yet)
                clientType = AppDomain.CurrentDomain.GetAssemblies().Select(asm => asm.GetType(TypeName)).FirstOrDefault();

                if (clientType == null)
                {
                    // Try to guess the assembly name from the class name
                    var assemblyName = TypeName.Substring(0, TypeName.LastIndexOf("."));

                    try
                    {
                        var asm = Assembly.LoadFrom(
                            $"{this.MyInvocation.MyCommand.Module.ModuleBase}/Lib/{EnvironmentUtil.PSEdition}/{assemblyName}.dll");
                        clientType = asm.GetType(TypeName);
                    }
                    finally {}
                }
            }

            if (clientType == null)
            {
                throw new Exception($"Invalid or non-existent type '{TypeName}'. " +
                                    "If the type name is correct, either provide the assembly name in the form of 'Type,Assembly' " +
                                    "or check whether its assembly has been previously loaded");
            }

            WriteObject(provider.GetClientFromType(clientType));
        }
コード例 #6
0
        //No need for buid backshift - the point is to have new guids
        public KeyValuePair <string, object> ConvertToAttribute(IOrganizationService service, string entityName, int guidShift)
        {
            if (Value == null)
            {
                return(new KeyValuePair <string, object>(Key, null));
            }

            Object attributeValue = null;

            TypeName = ReferenceResolution.GetAttributeCodeTypeName(service, entityName, Key).ToLower();
            if (TypeName == null)
            {
                throw new Exception("Cannot find type name for " + entityName + ":" + Key);
            }
            if (TypeName.Contains("guid"))
            {
                attributeValue = Guid.Parse(Value.ToString());
            }
            else if (TypeName.Contains("entityreference"))
            {
                string[] pair = ((string)Value).Split(':');
                attributeValue = new EntityReference(pair[1], Guid.Parse(pair[0]));
            }
            else if (TypeName.Contains("string"))
            {
                attributeValue = (string)Value;
            }
            else if (TypeName.Contains("int"))
            {
                attributeValue = int.Parse((string)Value);
            }
            else if (TypeName.Contains("double"))
            {
                attributeValue = double.Parse((string)Value);
            }
            else if (TypeName.Contains("float"))
            {
                attributeValue = float.Parse((string)Value);
            }
            else if (TypeName.Contains("decimal"))
            {
                attributeValue = decimal.Parse((string)Value);
            }
            else if (TypeName.Contains("datetime"))
            {
                attributeValue = DateTime.Parse((string)Value);
            }
            else if (TypeName.Contains("optionsetvalue"))
            {
                attributeValue = new OptionSetValue(int.Parse((string)Value));
            }
            else if (TypeName.Contains("money"))
            {
                attributeValue = new Money(decimal.Parse((string)Value));
            }
            else if (TypeName.Contains("boolean"))
            {
                attributeValue = bool.Parse((string)Value);
            }


            KeyValuePair <string, object> a = new KeyValuePair <string, object>(Key, attributeValue);

            return(a);
        }
コード例 #7
0
        public Arg(string opName = "", string argName = "", string typeString = "", string descString = "")
        {
            if (opName == "sgd_mom_update")
            {
            }
            if (argName == "src")
            {
                argName = "data";
            }
            this.OrginName   = argName;
            this.Name        = GetName(argName);
            this.Description = descString;
            if (argName != "dtype" && typeString.StartsWith("{"))
            {
                IsEnum   = true;
                Enum     = new EnumType(opName + "_" + argName, typeString);
                TypeName = Enum.Name;
            }
            else if (argName == "dtype")
            {
                TypeName = "Dtype";
            }
            else
            {
                string typename;
                if (_typeDict.TryGetValue(typeString.Split(',').First().Replace(",", ""), out typename))
                {
                    TypeName = typename;
                }
            }
            if (TypeName == null)
            {
                Console.WriteLine($"{opName} {argName}");
            }

            if (typeString.IndexOf("default=", StringComparison.Ordinal) != -1)
            {
                HasDefault    = true;
                DefaultString = typeString.Split(new string[] { "default=" }, StringSplitOptions.None)[1]
                                .Trim()
                                .Trim('\'');

                if (IsEnum)
                {
                    if (DefaultString == "None")
                    {
                        TypeName     += "?";
                        DefaultString = "null";
                    }
                    else
                    {
                        DefaultString = Enum.GetDefaultValueString(DefaultString);
                    }
                }
                else if (DefaultString == "False")
                {
                    DefaultString = "false";
                }
                else if (DefaultString == "True")
                {
                    DefaultString = "true";
                }
                else if (DefaultString == "None")
                {
                    DefaultString = "null";
                }
                else if (TypeName == "Shape")
                {
                    if (DefaultString != "()")
                    {
                        DefaultStringWithObject = $"if({Name}==null){{ {Name}= new Shape{DefaultString};}}\n";
                    }

                    DefaultString = "null";
                }
                else if (TypeName.StartsWith("Tuple"))
                {
                    if (DefaultString != "()")
                    {
                        if (TypeName.Contains("float"))
                        {
                            DefaultString = DefaultString.Replace(")", "f)").Replace(",", "f,");
                            DefaultString = DefaultString.Replace(",f)", ")");
                        }
                        DefaultStringWithObject = $"if({Name}==null){{ {Name}= new {TypeName}{DefaultString};}}\n";
                    }

                    DefaultString = "null";
                }

                if (TypeName == "float")
                {
                    DefaultString = DefaultString + "f";
                }
                if (TypeName == "string")
                {
                    DefaultString = "null";
                }
                if (TypeName == "bool")
                {
                    if (DefaultString == "0")
                    {
                        DefaultString = "false";
                    }
                    if (DefaultString == "1")
                    {
                        DefaultString = "true";
                    }
                }
                if (TypeName == "Dtype" && DefaultString != "null")
                {
                    DefaultStringWithObject = $"if({Name}==null){{ {Name}= {Dtype.GetCode(DefaultString)};}}\n";
                    DefaultString           = "null";
                }
                if (argName == "ctx")
                {
                    TypeName = "Context";
                }
            }
            if (argName == "weight" || argName == "bias")
            {
                HasDefault    = true;
                DefaultString = "null";
            }
        }