// Token: 0x0600020F RID: 527 RVA: 0x000081AC File Offset: 0x000063AC
        internal static DownloadResult SendRestRequest(string requestMethod, string requestUri, OwaIdentity identity, Stream requestStream, DataProviderCallLogEvent logEvent, string spCallName)
        {
            DownloadResult result;

            using (HttpClient httpClient = new HttpClient())
            {
                HttpSessionConfig httpSessionConfig = new HttpSessionConfig
                {
                    Method          = requestMethod,
                    Credentials     = OauthUtils.GetOauthCredential(identity.GetOWAMiniRecipient()),
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    RequestStream   = requestStream,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true
                };
                httpSessionConfig.Headers = OneDriveProUtilities.GetOAuthRequestHeaders();
                if (logEvent != null)
                {
                    logEvent.TrackSPCallBegin();
                }
                ICancelableAsyncResult cancelableAsyncResult = httpClient.BeginDownload(new Uri(requestUri), httpSessionConfig, null, null);
                cancelableAsyncResult.AsyncWaitHandle.WaitOne();
                DownloadResult downloadResult = httpClient.EndDownload(cancelableAsyncResult);
                if (logEvent != null)
                {
                    string correlationId = (downloadResult.ResponseHeaders == null) ? null : downloadResult.ResponseHeaders["SPRequestGuid"];
                    logEvent.TrackSPCallEnd(spCallName, correlationId);
                }
                result = downloadResult;
            }
            return(result);
        }
Exemplo n.º 2
0
        public void BizUserCreateAndDeleteStock()
        {
            var createStockRequest1 = new StockRequestModel
            {
                Id        = 0,
                Name      = "Розничный склад 1",
                IsMain    = false,
                StockType = 2
            };

            var createStockRequest2 = new StockRequestModel
            {
                Id        = 0,
                Name      = "Розничный склад 2",
                IsMain    = false,
                StockType = 2
            };

            string login = TesterUtils.CreateBizUserOooUsn15AndFillRequisites();

            TesterUtils.SwitchOnStock(login);
            string             token           = OauthUtils.GetAutorizationToken(login);
            StockResponseModel responseCreate1 = StockUtils.СreateStock(token, createStockRequest1);
            StockResponseModel responseCreate2 = StockUtils.СreateStock(token, createStockRequest2);

            StockUtils.DeleteStock(token, responseCreate1.Id);
            StockListResponseModel stockList = StockUtils.GetStockList(token, 1, 10);
            int count = stockList.ResourceList.Count;

            Assert.AreEqual(2, count);
        }
Exemplo n.º 3
0
        public void BizUserCreateUpdateAndGetStock()
        {
            var createStockRequest = new StockRequestModel
            {
                Id        = 0,
                Name      = "Розничный склад",
                IsMain    = false,
                StockType = 2
            };

            string login = TesterUtils.CreateBizUserOooUsn15AndFillRequisites();

            TesterUtils.SwitchOnStock(login);
            string             token          = OauthUtils.GetAutorizationToken(login);
            StockResponseModel responseCreate = StockUtils.СreateStock(token, createStockRequest);

            var updateStockRequest = new StockRequestModel
            {
                Id        = responseCreate.Id,
                Name      = "Отредактированный склад",
                IsMain    = true,
                StockType = 1
            };

            StockResponseModel responceUpdate = StockUtils.UpdateStock(token, responseCreate.Id, updateStockRequest);
            StockResponseModel responceGet    = StockUtils.GetStock(token, responseCreate.Id);

            Assert.AreEqual(updateStockRequest.Id, responceGet.Id);
            Assert.AreEqual(updateStockRequest.Name, responceGet.Name);
            Assert.AreEqual(updateStockRequest.IsMain, responceGet.IsMain);
            Assert.AreEqual(updateStockRequest.StockType, responceGet.StockType);
            Assert.AreEqual(responceUpdate.SubcontoId, responceGet.SubcontoId);
        }
 // Token: 0x0600020E RID: 526 RVA: 0x0000819D File Offset: 0x0000639D
 internal static ICredentials GetOneDriveProCredentials(OwaIdentity identity)
 {
     return(OauthUtils.GetOauthCredential(identity.GetOWAMiniRecipient()));
 }
        // Token: 0x06000211 RID: 529 RVA: 0x000082BC File Offset: 0x000064BC
        internal static string GetWacUrl(OwaIdentity identity, string endPointUrl, string documentUrl, bool isEdit)
        {
            string arg  = isEdit ? "2" : "4";
            string text = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
            string result;

            using (HttpClient httpClient = new HttpClient())
            {
                OWAMiniRecipient    owaminiRecipient    = identity.GetOWAMiniRecipient();
                ICredentials        oauthCredential     = OauthUtils.GetOauthCredential(owaminiRecipient);
                WebHeaderCollection oauthRequestHeaders = OneDriveProUtilities.GetOAuthRequestHeaders();
                HttpSessionConfig   sessionConfig       = new HttpSessionConfig
                {
                    Method          = "GET",
                    Credentials     = oauthCredential,
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true,
                    Headers         = oauthRequestHeaders
                };
                DownloadResult downloadResult;
                try
                {
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                catch (WebException ex)
                {
                    if (!OneDriveProUtilities.IsDurableUrlFormat(documentUrl))
                    {
                        throw ex;
                    }
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Exception while trying to get wac token using durable url. : {0}", ex.StackTrace);
                    documentUrl = documentUrl.Substring(0, documentUrl.LastIndexOf("?", StringComparison.InvariantCulture));
                    text        = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Fallback to canonical url format: {0}", text);
                    OwaServerTraceLogger.AppendToLog(new TraceLogEvent("SP.GWT", null, "GetWacToken", string.Format("Error getting WAC Token fallback to canonical format:{0}", text)));
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(downloadResult.ResponseStream);
                string namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices";
                string text2        = null;
                string text3        = null;
                string text4        = null;
                foreach (object obj in xmlDocument.GetElementsByTagName("*", namespaceURI))
                {
                    XmlNode xmlNode = (XmlNode)obj;
                    if (xmlNode is XmlElement)
                    {
                        if (text2 != null && text3 != null && text4 != null)
                        {
                            break;
                        }
                        if (string.CompareOrdinal(xmlNode.LocalName, "AppUrl") == 0)
                        {
                            text2 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessToken") == 0)
                        {
                            text3 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessTokenTtl") == 0)
                        {
                            text4 = xmlNode.InnerText;
                        }
                    }
                }
                if (text2 == null || text3 == null || text4 == null)
                {
                    throw new OwaException("SharePoint's GetWacToken response is not usable.");
                }
                string text5 = isEdit ? "OwaEdit" : "OwaView";
                result = string.Format("{0}&access_token={1}&access_token_ttl={2}&sc={3}", new object[]
                {
                    text2,
                    text3,
                    text4,
                    text5
                });
            }
            return(result);
        }
Exemplo n.º 6
0
        protected override MailboxSession CreateMailboxSession()
        {
            if (base.IsDisposed || this.isInProcessOfDisposing)
            {
                string message = string.Format(CultureInfo.InvariantCulture, "Cannot call UserContext.CreateMailboxSession when object is disposed. isDisposed={0}, isInProcessOfDisposing={1}.", new object[]
                {
                    base.IsDisposed,
                    this.isInProcessOfDisposing
                });
                throw new ObjectDisposedException("UserContext", message);
            }
            if (base.LogonIdentity == null)
            {
                throw new OwaInvalidOperationException("Cannot call CreateMailboxSession when logonIdentity is null");
            }
            MailboxSession result;

            try
            {
                if (base.ExchangePrincipal.RecipientTypeDetails == RecipientTypeDetails.TeamMailbox)
                {
                    Exception ex = null;
                    ExTraceGlobals.UserContextTracer.TraceDebug(0L, "Creating Mailbox session for TeamMailbox");
                    SharepointAccessManager.Instance.UpdateAccessTokenIfNeeded(base.ExchangePrincipal, OauthUtils.GetOauthCredential(base.LogonIdentity.GetOWAMiniRecipient()), base.LogonIdentity.ClientSecurityContext, out ex, false);
                    if (ex != null)
                    {
                        ExTraceGlobals.UserContextTracer.TraceDebug <Exception>(0L, "CreateMailboxSession for TeamMailbox hit exception while updating AccessToken: {0}", ex);
                    }
                }
                CultureInfo    cultureInfo = Culture.GetPreferredCultureInfo(base.ExchangePrincipal) ?? Thread.CurrentThread.CurrentCulture;
                MailboxSession mailboxSession;
                if (base.ExchangePrincipal.RecipientTypeDetails == RecipientTypeDetails.GroupMailbox)
                {
                    mailboxSession = base.LogonIdentity.CreateDelegateMailboxSession(base.ExchangePrincipal, cultureInfo);
                }
                else
                {
                    mailboxSession = base.LogonIdentity.CreateMailboxSession(base.ExchangePrincipal, cultureInfo);
                }
                if (mailboxSession == null)
                {
                    throw new OwaInvalidOperationException("CreateMailboxSession cannot create a mailbox session");
                }
                result = mailboxSession;
            }
            catch (AccessDeniedException innerException)
            {
                throw new OwaExplicitLogonException("user has no access rights to the mailbox", "errorexplicitlogonaccessdenied", innerException);
            }
            return(result);
        }