Example #1
0
        /// <summary>
        /// Invoke a network operation using the WebClient or the HttpWebRequest classes.
        /// </summary>
        /// <typeparam name="T">Type of the return value.</typeparam>
        /// <param name="action">Action to be performed.</param>
        /// <returns>Web response.</returns>
        public virtual T InvokeNetworkOperation <T>(Func <T> action) where T : class
        {
            int attempt = 1;

            while (true)
            {
                try
                {
                    return(action());
                }
                catch (WebException webExc)
                {
                    GraphException graphException = ErrorResolver.ParseWebException(webExc);

                    if (!this.graphSettings.IsRetryEnabled ||
                        this.graphSettings.TotalAttempts <= 0 ||
                        attempt == this.graphSettings.TotalAttempts ||
                        attempt == Constants.MaxRetryAttempts ||
                        !this.graphSettings.RetryOnExceptions.Contains(graphException.GetType().FullName))
                    {
                        throw graphException;
                    }

                    attempt++;
                    // TODO: Validate that we are not going to sleep for too long :-)
                    Thread.Sleep(this.graphSettings.WaitBeforeRetry);
                }
            }
        }
Example #2
0
        protected void RunButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (SessionManager.Instance.CurrentIndex == null)
                {
                    return;
                }

                CodeGenerator generator = new CodeGenerator();
                string        code      = generator.GetLinqCode(GetObjectType(), GetWhereClause(), GetTakeClause());
                var           result    = Compiler.CompileAndRun(code, GetSearchResultItemAssembly());
                int           timeTaken;
                if (!Int32.TryParse(result.Item1, out timeTaken))
                {
                    ErrorLabel.Text = result.Item1;
                }
                else
                {
                    ErrorLabel.Text = String.Empty;
                    //Unfortunately we can't really work on the entered searchResultClass type as it can't be passed to T
                    IEnumerable <SearchResultItem>      results    = result.Item2.Select(i => i as SearchResultItem);
                    LinqSearchResult <SearchResultItem> resultList = new LinqSearchResult <SearchResultItem>(results);
                    SessionManager.Instance.LinqSearchResults = resultList;
                    int numberOfHits = results.Count();
                    TotalHitsLabel.Text   = numberOfHits.ToString();
                    TimeElapsedLabel.Text = result.Item1 + "ms";
                }
            }
            catch (Exception ex)
            {
                ErrorResolver.ResolveError(ex, this);
            }
        }
Example #3
0
 protected void CancelButton_Click(object sender, EventArgs e)
 {
     try
     {
         Response.Write("<script language='javascript'>window.top.dialogClose();</script>");
     }
     catch (Exception ex)
     {
         ErrorResolver.ResolveError(ex, this);
     }
 }
Example #4
0
        private void FillIndexList()
        {
            string address       = GetAddress();
            string pathToService = "/sitecore/system/Modules/IndexViewer/Service/AvailableIndexes";
            Item   settingsItem  = Database.GetDatabase("master").GetItem(new ID(Constants.ItemIds.SettingsItemId));

            if (settingsItem == null)
            {
                throw new InvalidOperationException("Could not find settings item");
            }
            string    securityToken = settingsItem[Constants.FieldNames.SecurityToken];
            string    fullAddress   = address + pathToService + "?securityToken=" + securityToken;
            WebClient webClient     = new WebClient();
            XDocument indexList;

            try
            {
                string xmlResponse = webClient.DownloadString(fullAddress);
                indexList = XDocument.Parse(xmlResponse);
            }
            catch (Exception ex)
            {
                //Could handle this nicer
                ErrorResolver.ResolveError(ex, this);
                return;
            }

            IndexDropDown.Items.Clear();
            IndexDropDown.Enabled = true;

            IEnumerable <XElement> indexElements = indexList.Descendants("index");

            if (indexElements == null || indexElements.Count() == 0)
            {
                IndexDropDown.Items.Add("No index...");
            }
            else
            {
                IndexDropDown.Items.Add("Choose index...");
            }

            foreach (XElement indexElement in indexElements)
            {
                string indexName = indexElement.Attribute("name").Value;
                IndexDropDown.Items.Add(new ListItem(indexName, indexName));
            }
        }
Example #5
0
 public void SaveImportXSDJ(List <XSDJMXModel> ListXSDJandMX, ErrorResolver Errors)
 {
     try
     {
         try
         {
             for (int i = 0; i < ListXSDJandMX.Count; i++)
             {
                 XSDJMXModel model     = ListXSDJandMX[i];
                 string      str       = string.Format("销售单据编号: {0} ", model.BH);
                 string      errowInfo = this.AllowImport(model);
                 if (errowInfo != "0")
                 {
                     Errors.AddError(errowInfo, model.BH, 0, false);
                     Errors.AbandonCount++;
                 }
                 else
                 {
                     Dictionary <string, object> dictionary = new Dictionary <string, object>();
                     dictionary.Add("bh", model.BH);
                     if (this.baseDAO.queryValueSQL <int>("aisino.Fwkp.Wbjk.XSDJExist", dictionary) > 0)
                     {
                         int num3 = this.baseDAO.updateSQL("aisino.Fwkp.Wbjk.XSDJDeleteFast", dictionary);
                     }
                     switch (this.AddXSDJ(model))
                     {
                     case "0":
                         Errors.SaveCount++;
                         break;
                     }
                 }
             }
         }
         catch
         {
             throw;
         }
     }
     finally
     {
     }
 }
Example #6
0
        protected void RebuildButton_Click(object sender, EventArgs e)
        {
            string address       = GetAddress();
            string pathToService = "/sitecore/system/Modules/IndexViewer/Service/rebuildindex";
            Item   settingsItem  = Database.GetDatabase("master").GetItem(new ID(Constants.ItemIds.SettingsItemId));

            if (settingsItem == null)
            {
                throw new InvalidOperationException("Settings item could not be found");
            }
            string    securityToken = settingsItem[Constants.FieldNames.SecurityToken];
            string    indexName     = IndexDropDown.SelectedValue;
            string    fullAddress   = address + pathToService + "?indexName=" + indexName + @"&method=rebuildindex&SecurityToken=" + securityToken;
            WebClient webClient     = new WebClient();
            XDocument indexRebuildResult;

            try
            {
                string xmlResponse = webClient.DownloadString(fullAddress);
                indexRebuildResult = XDocument.Parse(xmlResponse);
            }
            catch (Exception ex)
            {
                ErrorResolver.ResolveError(ex, this);
                return;
            }
            XElement resultElement = indexRebuildResult.Descendants("rebuild").FirstOrDefault();

            if (resultElement == null)
            {
                //TODO: Do something nicer
                Response.Write("Something went wrong. I am truly sorry. However the truth is probably, that you didn't configure the module correctly");
                return;
            }
            string jobId = resultElement.Attribute("jobId").Value;
            string url   = address + pathToService + @"?method=status&jobName=" + jobId + @"&SecurityToken=" + securityToken;

            SessionManager.Instance.CurrentRebuildingJobUrl = Server.UrlEncode(url);
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.top.dialogClose();", true);
        }
Example #7
0
 public void SaveImport(XSDJ xsdj)
 {
     try
     {
         MessageHelper.MsgWait("正在导入单据,请稍候...");
         int count = xsdj.Dj.Count;
         this.FanSuan(xsdj);
         ErrorResolver      errorResolver = this.errorResolver;
         XSDJ               xsdjImport    = xsdj;
         List <XSDJMXModel> listXSDJandMX = this.ConvertImportXSDJ(xsdjImport);
         this.imsaveDAL.SaveImportXSDJ(listXSDJandMX, errorResolver);
     }
     catch (Exception exception)
     {
         HandleException.HandleError(exception);
     }
     finally
     {
         Thread.Sleep(100);
         MessageHelper.MsgWait();
     }
 }
 public ErrorHandlingMessageProcessor(MessageProcessor processor)
 {
     _processor = processor;
     _errorResolver = new ErrorResolver();
 }
Example #9
0
 public ResultForm(ErrorResolver ErrorResolver)
 {
     this.Initialize();
     this.ErrorsResolver = ErrorResolver;
 }
Example #10
0
        /// <summary>
        /// Deserialize a batch response into individual response items.
        /// </summary>
        /// <param name="contentTypeHeader">Content type header.</param>
        /// <param name="responseString">Response string.</param>
        /// <param name="batchRequestItems">Batch request items.</param>
        /// <returns>Batch response items.</returns>
        public static List <BatchResponseItem> DeserializeBatchResponse(
            string contentTypeHeader, string responseString, IList <BatchRequestItem> batchRequestItems)
        {
            List <BatchResponseItem> batchResponseItems = new List <BatchResponseItem>();

            Utils.ThrowIfNullOrEmpty(contentTypeHeader, "contentTypeHeader");

            string[] splitContentTypeTokens = contentTypeHeader.Split(";".ToCharArray());
            string   boundaryMarker         = String.Empty;

            foreach (string contentTypeToken in splitContentTypeTokens)
            {
                if (contentTypeToken.Trim().StartsWith("boundary="))
                {
                    boundaryMarker = contentTypeToken.Trim().Substring("boundary=".Length);
                    break;
                }
            }

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(responseString)))
            {
                bool isCurrentBatchItemAFailure = false;
                int  itemIndex = 0;
                using (StreamReader sr = new StreamReader(ms))
                {
                    WebHeaderCollection headers = null;

                    while (!sr.EndOfStream)
                    {
                        string currentLine = sr.ReadLine();

                        if (String.IsNullOrWhiteSpace(currentLine))
                        {
                            continue;
                        }

                        if (currentLine.StartsWith("HTTP/1.1 "))
                        {
                            // In a batch item, the http status code for successful changesets is also 200 OK.
                            isCurrentBatchItemAFailure = !currentLine.Contains("200 OK");
                            continue;
                        }

                        if (currentLine.StartsWith("{\"odata.metadata"))
                        {
                            PagedResults <GraphObject> pagedResults = SerializationHelper.DeserializeJsonResponse <GraphObject>(
                                currentLine, batchRequestItems[itemIndex].RequestUri);
                            itemIndex++;
                            BatchResponseItem batchResponseItem = new BatchResponseItem();
                            batchResponseItem.Failed    = isCurrentBatchItemAFailure;
                            batchResponseItem.ResultSet = pagedResults;
                            batchResponseItems.Add(batchResponseItem);

                            // Add the response headers from the current batch to the response.
                            if (headers != null)
                            {
                                batchResponseItem.BatchHeaders.Add(headers);
                                headers = null;
                            }

                            continue;
                        }

                        if (currentLine.StartsWith("{\"odata.error"))
                        {
                            BatchResponseItem batchResponseItem = new BatchResponseItem();
                            batchResponseItem.Failed    = isCurrentBatchItemAFailure;
                            batchResponseItem.Exception = ErrorResolver.ParseErrorMessageString(
                                HttpStatusCode.BadRequest, currentLine);
                            batchResponseItem.Exception.ResponseUri = batchRequestItems[itemIndex].RequestUri.ToString();
                            batchResponseItems.Add(batchResponseItem);

                            if (headers != null)
                            {
                                batchResponseItem.BatchHeaders.Add(headers);
                                headers = null;
                            }
                        }

                        string[] tokens = currentLine.Split(":".ToCharArray());
                        if (tokens != null && tokens.Length == 2)
                        {
                            if (headers == null)
                            {
                                headers = new WebHeaderCollection();
                            }

                            headers[tokens[0]] = tokens[1];
                        }
                    }
                }
            }

            return(batchResponseItems);
        }
Example #11
0
 public Maintenance(IServiceProvider services, ErrorResolver errorResolver)
 {
     resolver         = errorResolver;
     lazyIssueTracker = new LazyDisposable <IssueTracker>(() => services.GetRequiredService <IssueTracker>());
     prefix           = services.GetScoppedSettings <AppSettings>().Settings.DefaultCommandPrefix;
 }