Exemple #1
0
 ///<summary>This now also gets a new list of sheet defs from the server.  But it's only called after testing that the web service exists.</summary>
 private void FillGrid()
 {
     try{
         if (!WebForms_SheetDefs.TryDownloadSheetDefs(out _listWebFormSheetDefs))
         {
             MsgBox.Show(this, "Failed to download sheet definitions.");
             _listWebFormSheetDefs = new List <WebForms_SheetDef>();
         }
         gridMain.ListGridColumns.Clear();
         GridColumn col = new GridColumn(Lan.g(this, "Description"), 200);
         gridMain.ListGridColumns.Add(col);
         gridMain.ListGridRows.Clear();
         foreach (WebForms_SheetDef sheetDef in _listWebFormSheetDefs)
         {
             GridRow row = new GridRow();
             row.Tag = sheetDef;
             row.Cells.Add(sheetDef.Description);
             gridMain.ListGridRows.Add(row);
         }
         gridMain.EndUpdate();
     }
     catch (Exception ex) {
         Cursor = Cursors.Default;
         MessageBox.Show(ex.Message);
     }
 }
Exemple #2
0
        private void butDelete_Click(object sender, EventArgs e)
        {
            if (gridMain.GetSelectedIndex() == -1)
            {
                MsgBox.Show(this, "Please select an item from the grid first.");
                return;
            }
            Cursor = Cursors.WaitCursor;
            int failures = 0;

            foreach (WebForms_SheetDef wf_sheetDef in gridMain.SelectedTags <WebForms_SheetDef>())
            {
                if (!WebForms_SheetDefs.DeleteSheetDef(wf_sheetDef.WebSheetDefID))
                {
                    failures++;
                }
            }
            if (failures > 0)
            {
                Cursor = Cursors.Default;
                MessageBox.Show(this, Lan.g(this, "Error deleting ") + POut.Int(failures) + Lan.g(this, " web form(s). Either the web service is not available or "
                                                                                                  + "the Host Server Address cannot be found."));
            }
            FillGrid();
            Cursor = Cursors.Default;
        }
Exemple #3
0
 ///<summary>Attempts to add or update the passed in sheet def. If the add or update fails because of a request being too large, then the content
 ///will be split and sent in pieces. This method returns whether the add or update was successful.</summary>
 ///<param name="currentForm">The form calling this method. Used to modify the cursor.</param>
 ///<param name="sheetDef">The SheetDef object being addeds or updated.</param>
 ///<param name="isNew">Indicates whether the object is new. If this is false, the object will be updated.</param>
 ///<param name="listWebFormSheetDefs">A list of webforms correlated to the passed in sheetDef. This should be set when updating a sheetdef.</param>
 public static bool TryAddOrUpdateSheetDef(Form currentForm, SheetDef sheetDef, bool isNew, List <WebForms_SheetDef> listWebFormSheetDefs = null)
 {
     try {
         SheetsSynchProxy.TimeoutOverride = 300000;              //for slow connections more timeout is provided. The  default is 100 seconds i.e 100000
         if (!isNew)
         {
             if (listWebFormSheetDefs == null)                   //This should be set when isNew is not true, but will check here just in case.
             {
                 return(false);
             }
             foreach (WebForms_SheetDef webSheetDef in listWebFormSheetDefs)
             {
                 WebForms_SheetDefs.UpdateSheetDef(webSheetDef.WebSheetDefID, sheetDef, doCatchExceptions: false);
             }
         }
         else
         {
             WebForms_SheetDefs.TryUploadSheetDef(sheetDef);
         }
         return(true);
     }
     catch (WebException wex) {
         if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.RequestEntityTooLarge)
         {
             int  chunkSize         = 1024 * 1024;          //Start with 1 MB chunk size if package needs to be broken up in size.
             bool isTooLargeRequest = true;
             while (isTooLargeRequest && chunkSize >= 1024) //loop until successful request transfer or chunk sizes get smaller than 1 KB
             {
                 try {
                     if (!isNew)
                     {
                         foreach (WebForms_SheetDef webSheetDef in listWebFormSheetDefs)
                         {
                             WebForms_SheetDefs.UpdateSheetDefChunked(webSheetDef.WebSheetDefID, sheetDef, chunkSize);
                         }
                     }
                     else
                     {
                         WebForms_SheetDefs.TryUploadSheetDefChunked(sheetDef, chunkSize);
                     }
                 }
                 catch (WebException wex2) {
                     if (((HttpWebResponse)wex2.Response).StatusCode == HttpStatusCode.RequestEntityTooLarge)
                     {
                         chunkSize /= 2;                           //Chunksize is divided by two each iteration after the first
                         continue;                                 //if still too large, continue to while loop
                     }
                     else
                     {
                         FriendlyException.Show(wex.Message, wex);
                         return(false);
                     }
                 }
                 catch (Exception ex) {
                     currentForm.Cursor = Cursors.Default;
                     FriendlyException.Show(ex.Message, ex);
                     return(false);
                 }
                 isTooLargeRequest = false;
             }
             if (isTooLargeRequest)                     //If breaking from loop due to chunksize getting too small, send error message
             {
                 currentForm.Cursor = Cursors.Default;
                 MsgBox.Show("The sheet you are trying to upload failed after attempts were made to resize the request.");
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
         else
         {
             FriendlyException.Show(wex.Message, wex);
             return(false);
         }
     }
     catch (Exception ex) {
         currentForm.Cursor = Cursors.Default;
         FriendlyException.Show(ex.Message, ex);
         return(false);
     }
 }