public object WaitForTask(ManagedObjectReference taskReference)
        {
            Task     view = (Task)this.GetView(taskReference, (string[])null);
            TaskInfo info;

            while (true)
            {
                info = view.Info;
                if (info.State != TaskInfoState.success)
                {
                    if (info.State != TaskInfoState.error)
                    {
                        Thread.Sleep(2000);
                        view.UpdateViewData();
                    }
                    else
                    {
                        goto label_4;
                    }
                }
                else
                {
                    break;
                }
            }
            return(info.Result);

label_4:
            MethodFault fault = info.Error.Fault;

            throw new VimException(info.Error.LocalizedMessage, fault);
        }
示例#2
0
        private static string EnrichErrorMessage(string message, MethodFault methodFault)
        {
            if (methodFault == null || methodFault.FaultMessage == null)
            {
                return(message);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(message.Trim());
            LocalizableMessage[] faultMessage = methodFault.FaultMessage;
            for (int i = 0; i < faultMessage.Length; i++)
            {
                LocalizableMessage localizableMessage = faultMessage[i];
                stringBuilder.Append((stringBuilder[stringBuilder.Length - 1] != '.') ? ". " : " ");
                if (!string.IsNullOrEmpty(localizableMessage.Message))
                {
                    stringBuilder.Append(localizableMessage.Message.Trim());
                }
            }
            return(stringBuilder.ToString());
        }
示例#3
0
 public VimException(string message, MethodFault methodFault, Exception inner) : base(VimException.EnrichErrorMessage(message, methodFault), inner)
 {
     this.methodFault = methodFault;
 }
示例#4
0
        public static VimException HandleFault(FaultException faultException)
        {
            MethodFault viServerFault = FaultUtility.GetVIServerFault(faultException);

            return(new VimException(faultException.Message, viServerFault, (Exception)faultException));
        }
 internal static void SetViewData(ViewBase currentObject, string currentPropertyPath, Dictionary<string, List<string>> allowedPropertyPath, Dictionary<string, ObjectContent> objectContentList, Dictionary<string, ViewBase> generatedManagedObjectList)
 {
     if (currentPropertyPath == null)
         currentPropertyPath = string.Empty;
     if (!objectContentList.ContainsKey(currentObject.MoRef.Value))
         return;
     if (!generatedManagedObjectList.ContainsKey(currentObject.MoRef.Value))
         generatedManagedObjectList.Add(currentObject.MoRef.Value, currentObject);
     ObjectContent objectContent = objectContentList[currentObject.MoRef.Value];
     if (allowedPropertyPath != null)
         ViewBase.ClearViewData(currentObject, currentPropertyPath, new List<string>((IEnumerable<string>)allowedPropertyPath.Keys));
     else
         ViewBase.ClearViewData(currentObject, currentPropertyPath, (List<string>)null);
     if (objectContent.PropSet != null)
     {
         foreach (DynamicProperty prop in objectContent.PropSet)
         {
             bool flag1 = false;
             string key1 = string.Empty;
             if (allowedPropertyPath != null)
             {
                 key1 = string.Format("{0}{1}{2}", (object)currentPropertyPath, currentPropertyPath != "" ? (object)"." : (object)"", (object)prop.Name.ToLower());
                 string str = string.Format("{0}{1}{2}", (object)currentPropertyPath, currentPropertyPath != "" ? (object)"." : (object)"", (object)"*");
                 bool flag2 = false;
                 bool flag3 = false;
                 foreach (string key2 in allowedPropertyPath.Keys)
                 {
                     if (key2.StartsWith(key1))
                         flag2 = true;
                     if (key2.Equals(str) && ViReflectionCache.GetTypeProperties(currentObject.GetType()).ContainsKey(prop.Name.ToLower()))
                     {
                         flag3 = true;
                         break;
                     }
                     if (key2.Equals(key1))
                         flag3 = true;
                     if (flag2 & flag3)
                         break;
                 }
                 if (!flag3 & flag2)
                     flag1 = true;
                 if (!flag3 && !flag2)
                     continue;
             }
             string[] strArray = prop.Name.Split('.');
             Type type = currentObject.GetType();
             object currentObject1 = (object)currentObject;
             for (int index = 0; index < strArray.Length - 1; ++index)
             {
                 string name = "_" + strArray[index];
                 FieldInfo field = type.GetTypeInfo().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
                 object obj = field.GetValue(currentObject1);
                 type = field.FieldType;
                 if (obj == null)
                 {
                     obj = type.GetConstructor(Type.EmptyTypes).Invoke((object[])null);
                     field.SetValue(currentObject1, obj);
                 }
                 currentObject1 = obj;
             }
             FieldInfo field1 = type.GetField("_" + strArray[strArray.Length - 1], BindingFlags.Instance | BindingFlags.NonPublic);
             if (!flag1)
             {
                 foreach (FieldInfo fieldInfo in ViewBase.GetAllFieldsWithName("_" + strArray[strArray.Length - 1], type))
                     fieldInfo.SetValue(currentObject1, prop.Val);
             }
             ManagedObjectReference[] moList = (ManagedObjectReference[])null;
             if (field1.FieldType == typeof(ManagedObjectReference))
                 moList = new ManagedObjectReference[1]
                 {
       (ManagedObjectReference) prop.Val
                 };
             else if (field1.FieldType == typeof(ManagedObjectReference[]))
             {
                 List<string> stringList = new List<string>();
                 if (allowedPropertyPath != null)
                 {
                     if (allowedPropertyPath.ContainsKey(key1) && allowedPropertyPath[key1] != null)
                         stringList.AddRange((IEnumerable<string>)allowedPropertyPath[key1]);
                     if (allowedPropertyPath.ContainsKey(key1 + "->") && allowedPropertyPath[key1 + "->"] != null)
                         stringList.AddRange((IEnumerable<string>)allowedPropertyPath[key1 + "->"]);
                 }
                 List<ManagedObjectReference> managedObjectReferenceList = new List<ManagedObjectReference>();
                 foreach (ManagedObjectReference managedObjectReference in (ManagedObjectReference[])prop.Val)
                 {
                     if (stringList.Count == 0 || stringList.Contains(managedObjectReference.Type))
                     {
                         managedObjectReferenceList.Add(managedObjectReference);
                     }
                     else
                     {
                         foreach (string typeName in stringList)
                         {
                             if (ViReflectionCache.GetTypeByRemoteTypeAndName(typeof(ManagedObjectReference), typeName).IsAssignableFrom(ViReflectionCache.GetTypeByRemoteTypeAndName(typeof(ManagedObjectReference), managedObjectReference.Type)))
                             {
                                 managedObjectReferenceList.Add(managedObjectReference);
                                 break;
                             }
                         }
                     }
                 }
                 moList = managedObjectReferenceList.ToArray();
             }
             if (moList != null)
             {
                 string str = string.Format("{0}{1}{2}", (object)currentPropertyPath, currentPropertyPath != "" ? (object)"." : (object)"", (object)prop.Name.ToLower());
                 if (ViewBase.IsNonTerminalPath(allowedPropertyPath, str))
                     ViewBase.SetExtView(currentObject1, field1.Name, currentObject._client, moList, objectContentList, generatedManagedObjectList, str, allowedPropertyPath);
             }
         }
     }
     else if (objectContent.MissingSet != null && objectContent.MissingSet.Length != 0)
     {
         MethodFault fault = objectContent.MissingSet[0].Fault.Fault;
         throw new VimException(objectContent.MissingSet[0].Fault.LocalizedMessage, fault);
     }
 }