Ejemplo n.º 1
0
        public object ExecuteMethod(ProxyMethodInfo pmi, object[] args)
        {
            object obj;

            if (pmi.FakeType == typeof(fakeUnknown))
            {
                obj = new fakeUnknown(pmi.TypeName, this);
            }
            else
            {
                obj = Activator.CreateInstance(pmi.FakeType, this);
            }

            object[] methodArgs = new object[pmi.FakeMethod.GetParameters().Length];
            for (int i = 0; i < methodArgs.Length; i++)
            {
                methodArgs[i] = args[i];
            }

            switch (pmi.FakeMethodType)
            {
            case MethodType.Sync:
                return(pmi.FakeMethod.Invoke(obj, methodArgs));

            case MethodType.Async:
                Response <string> response = (Response <string>)pmi.FakeMethod.Invoke(obj, methodArgs);
                if (response.Status == ResponseTypes.SUCCESS)
                {
                    return(new Response <string>(CreateTask(DbProxy.TaskStatus.success, response.Value)));
                }
                else
                {
                    return(new Response <string>(CreateTask(DbProxy.TaskStatus.failure, response.ErrorDescription)));
                }
            }

            return(new Response <String>(true, new String[] { Failure.INTERNAL_ERROR }));
        }
Ejemplo n.º 2
0
        public object Invoke(string proxyMethodName, string returnType, params object[] args)
        {
            VerifyVersion(proxyMethodName);

            ProxyMethodInfo pmi = ProxyMethodNameParser.Parse(proxyMethodName);

            OnInvoking(new DbProxyInvokingEventArgs(pmi));

            if (pmi.FakeType != null)
            {
                return(ExecuteMethod(pmi, args));
            }

            if (pmi.MethodName.StartsWith("set_"))
            {
                string fieldname = pmi.MethodName.Substring(4);

                // Special case: set_memory_limits is not just editing a "memory_limits" field
                if (fieldname == "memory_limits")
                {
                    EditObject(pmi.TypeName, (string)args[1], "memory_static_min", args[2]);
                    EditObject(pmi.TypeName, (string)args[1], "memory_static_max", args[3]);
                    EditObject(pmi.TypeName, (string)args[1], "memory_dynamic_min", args[4]);
                    EditObject(pmi.TypeName, (string)args[1], "memory_dynamic_max", args[5]);
                }
                else
                {
                    EditObject(pmi.TypeName, (string)args[1], fieldname, args[2]);
                }

                return(new Response <string>(""));
            }

            switch (pmi.MethodName)
            {
            case "Url":
                return(url);   // "http://XenCenter.Simulator/";

            case "get_record":
            {
                string uuid = (string)args[1];
                if (uuid.StartsWith("task"))          // tasks are kept track of separately
                {
                    return(new Response <Proxy_Task>(task_get_record(uuid)));
                }
                return(get_record(pmi.TypeName, uuid, true));
            }

            case "destroy":
            {
                string uuid = (string)args[1];
                if (uuid.StartsWith("task"))
                {
                    task_destroy(uuid);
                    return(new Response <string>(""));
                }
                break;
            }

            case "add_to_other_config":
            {
                string uuid = (string)args[1];
                if (!uuid.StartsWith("task"))          // ignore other_config for tasks (used to keep track of meddling actions)
                {
                    AddToDictionary(pmi.TypeName, (string)args[1], "other_config", args[2], args[3]);
                }
                return(new Response <string>(""));
            }

            case "remove_from_other_config":
                RemoveFromDictionary(pmi.TypeName, (string)args[1], "other_config", args[2]);
                return(new Response <string>(""));

            case "add_to_gui_config":
                AddToDictionary(pmi.TypeName, (string)args[1], "gui_config", args[2], args[3]);
                return(new Response <string>(""));

            case "remove_from_gui_config":
                RemoveFromDictionary(pmi.TypeName, (string)args[1], "gui_config", args[2]);
                return(new Response <string>(""));

            case "add_tags":
                AddToArray(pmi.TypeName, (string)args[1], "tags", args[2]);
                return(new Response <string>(""));

            case "remove_tags":
                RemoveFromArray(pmi.TypeName, (string)args[1], "tags", args[2]);
                return(new Response <string>(""));

            case "get_subject_information_from_identifier":
                Hashtable subjectInfo = new Hashtable();
                if ((string)args[1] == "SID1")
                {
                    subjectInfo["subject-name"]        = @"citrix\tu_one";
                    subjectInfo["subject-displayname"] = "Test User 1";
                    subjectInfo["subject-is-group"]    = "false";
                }
                else if ((string)args[1] == "SID2")
                {
                    subjectInfo["subject-name"]        = @"citrix\tu_two";
                    subjectInfo["subject-displayname"] = "Test User 2";
                    subjectInfo["subject-is-group"]    = "false";
                }
                else if ((string)args[1] == "SID3")
                {
                    subjectInfo["subject-name"]        = @"citrix\tg";
                    subjectInfo["subject-displayname"] = "Test Group";
                    subjectInfo["subject-is-group"]    = "true";
                }
                return(new Response <Object>(subjectInfo));

            // For VBDEditPage.CalculateDevicePositions()
            case "get_allowed_vbd_devices":
                return(new Response <String[]>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7" }));

            case "retrieve_wlb_recommendations":
            case "retrieve_wlb_evacuate_recommendations":
            case "retrieve_wlb_configuration":
                Hashtable tbl = new Hashtable();
                return(new Response <object>(tbl));

            case "get_uncooperative_resident_vms":
                return(new Response <string[]>(new string[0]));

            // For HAWizard_Pages.AssignPriorities
            case "ha_compute_hypothetical_max_host_failures_to_tolerate":
                return(new Response <string>("1"));

            case "get_ha_host_failures_to_tolerate":
                return(new Response <string>("1"));

            // For EvacuateHostDialog and RollingUpgradeWizard
            case "get_vms_which_prevent_evacuation":
                return(new Response <object>(new Hashtable()));

            // For RollingUpgradeWizard
            case "get_live":
                return(new Response <bool>(true));

            case "get_allowed_operations":
                return(new Response <string[]>(new string[0]));

            case "get_health_check_config":
                string uuid1 = (string)args[1];
                return(new Response <object>(get_health_check_config(pmi.TypeName, uuid1, true)));
            }

            return(new Response <String>(true, new String[] { Failure.INTERNAL_ERROR }));
        }
Ejemplo n.º 3
0
 public DbProxyInvokingEventArgs(ProxyMethodInfo proxyMethodInfo)
 {
     Util.ThrowIfParameterNull(proxyMethodInfo, "proxyMethodInfo");
     ProxyMethodInfo = proxyMethodInfo;
 }
Ejemplo n.º 4
0
        public object ExecuteMethod(ProxyMethodInfo pmi, object[] args)
        {
            object obj;

            if (pmi.FakeType == typeof(fakeUnknown))
            {
                obj = new fakeUnknown(pmi.TypeName, this);
            }
            else
            {
                obj = Activator.CreateInstance(pmi.FakeType, this);
            }

            object[] methodArgs = new object[pmi.FakeMethod.GetParameters().Length];
            for (int i = 0; i < methodArgs.Length; i++)
            {
                methodArgs[i] = args[i];
            }

            switch (pmi.FakeMethodType)
            {
                case MethodType.Sync:
                    return pmi.FakeMethod.Invoke(obj, methodArgs);

                case MethodType.Async:
                    Response<string> response = (Response<string>)pmi.FakeMethod.Invoke(obj, methodArgs);
                    if (response.Status == ResponseTypes.SUCCESS)
                    {
                        return new Response<string>(CreateTask(DbProxy.TaskStatus.success, response.Value));
                    }
                    else
                    {
                        return new Response<string>(CreateTask(DbProxy.TaskStatus.failure, response.ErrorDescription));
                    }

            }

            return new Response<String>(true, new String[] { Failure.INTERNAL_ERROR });
        }
Ejemplo n.º 5
0
 public DbProxyInvokingEventArgs(ProxyMethodInfo proxyMethodInfo)
 {
     Util.ThrowIfParameterNull(proxyMethodInfo, "proxyMethodInfo");
     ProxyMethodInfo = proxyMethodInfo;
 }