Example #1
0
        public void Get(long cid, EventHandler<EventArgs> onSuccess, EventHandler<ExceptionEventArgs> onError)
        {
            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                MsnServiceState getObject = new MsnServiceState(PartnerScenario.Initial, "Get", true);
                DirectoryService dirService = (DirectoryService)CreateService(MsnServiceType.Directory, getObject);
                dirService.GetCompleted += delegate(object sender, GetCompletedEventArgs e)
                {
                    OnAfterCompleted(new ServiceOperationEventArgs(dirService, MsnServiceType.Directory, e));

                    if (NSMessageHandler.MSNTicket == MSNTicket.Empty)
                        return;

                    if (e.Cancelled)
                        return;

                    if (e.Error != null)
                    {
                        OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("Get", e.Error));

                        if (onError != null)
                            onError(sender, new ExceptionEventArgs(e.Error));
                        return;
                    }

                    if (e.Result.GetResult != null)
                    {
                        if (e.Result.GetResult.View != null)
                        {
                            FindContactByCidAndFireCoreProfileUpdated(cid, e.Result.GetResult.View);
                        }
                        else
                        {
                            //No profile yet.

                        }

                    }

                    if (onSuccess != null)
                    {
                        onSuccess(sender, e);
                    }
                };

                IdType id = new IdType();
                id.Ns1 = "Cid";
                id.V1 = cid;

                id.Ns2 = "Unspecified";
                id.V2 = null;

                GetRequestType request = new GetRequestType();
                request.request = new GetRequestTypeRequest();
                request.request.ViewName = "WLX.DC.CoreProfile";
                request.request.Id = id;

                RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(dirService, MsnServiceType.Directory, getObject, request));
            }
        }
Example #2
0
        public void GetMany(long[] cids, EventHandler<EventArgs> onSuccess, EventHandler<ExceptionEventArgs> onError)
        {
            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                MsnServiceState getManyObject = new MsnServiceState(PartnerScenario.Initial, "GetMany", true);
                DirectoryService dirService = (DirectoryService)CreateService(MsnServiceType.Directory, getManyObject);
                dirService.GetManyCompleted += delegate(object sender, GetManyCompletedEventArgs e)
                {
                    OnAfterCompleted(new ServiceOperationEventArgs(dirService, MsnServiceType.Directory, e));

                    if (NSMessageHandler.MSNTicket == MSNTicket.Empty)
                        return;

                    if (e.Cancelled)
                        return;

                    if (e.Error != null)
                    {
                        OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("Get", e.Error));
                        if (onError != null)
                            onError(sender, new ExceptionEventArgs(e.Error));
                        return;
                    }

                    if (e.Result.GetManyResult != null)
                    {
                        GetManyResultType r = e.Result.GetManyResult;
                        for (int i = 0; i < r.Ids.Length; i++)
                        {
                            IdType idType = r.Ids[i];
                            if (idType != null && idType.Ns1 == "Cid")
                            {
                                long cid;
                                if (long.TryParse(idType.V1.ToString(), out cid) && cid != 0)
                                {
                                    FindContactByCidAndFireCoreProfileUpdated(cid, r.Views[i]);
                                }
                            }
                        }
                    }

                    if (onSuccess != null)
                    {
                        onSuccess(sender, e);
                    }
                };

                List<IdType> ids = new List<IdType>(cids.Length);

                foreach (long cid in cids)
                {
                    IdType id = new IdType();
                    id.Ns1 = "Cid";
                    id.V1 = cid;

                    id.Ns2 = "Unspecified";
                    id.V2 = null;

                    ids.Add(id);
                }

                GetManyRequestType request = new GetManyRequestType();
                request.request = new GetManyRequestTypeRequest();
                request.request.ViewName = "WLX.DC.CoreProfile";
                request.request.Ids = ids.ToArray();

                RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(dirService, MsnServiceType.Directory, getManyObject, request));
            }
        }