public virtual Stream AllURIs()
 {
     try
     {
         string requestName = $"{nameof(AllURIs)}";
         AuditRequest(requestName, null);
         string        allHeadersFullString = GetAllHeadersFullString();
         StringBuilder message         = new StringBuilder();
         string        applicationName = string.IsNullOrEmpty(GOCWindows.Instance.ApplicationName) ? "REST Web Service" : GOCWindows.Instance.ApplicationName;
         message.AppendLine(applicationName);
         message.AppendLine();
         message.AppendLine("HTTP Headers:");
         message.AppendLine();
         message.AppendLine(allHeadersFullString);
         message.AppendLine();
         string responseMessage = message.ToString();
         Stream result          = StreamHelper.GetStreamFromString(responseMessage, GOCWindows.Instance.Encoding);
         AuditResponse(requestName, responseMessage);
         return(result);
     }
     catch (Exception ex)
     {
         if (_handleExceptions)
         {
             ExceptionHandlerWindows.HandleException(ex, null);
         }
         UpdateHttpStatusOnException(ex);
         throw ex;
     }
 }
 public virtual Stream FileUploadCompleted(string fileName)
 {
     try
     {
         string requestName = $"{nameof(FileUploadCompleted)} : File Name = {fileName}";
         AuditRequest(requestName, null);
         ValidateRequestMethod(HttpVerb.POST);
         FileStream fs = null;
         lock (FileUploadSessions.Instance.FileStreams)
         {
             FileUploadSessions.Instance.FileStreams.TryGetValue(fileName, out fs);
             if (fs == null)
             {
                 throw new Exception(string.Format("Could not find {0} to closse for file {1}", typeof(FileStream).Name, fileName));
             }
             fs.Close();
             fs.Dispose();
             FileUploadSessions.Instance.FileStreams.Remove(fileName);
         }
         string responseMessage = string.Format("{0} for {1} closed.", typeof(FileStream).Name, fileName);
         Stream result          = StreamHelper.GetStreamFromString(responseMessage, GOCWindows.Instance.Encoding);
         AuditResponse(requestName, responseMessage);
         return(result);
     }
     catch (Exception ex)
     {
         if (_handleExceptions)
         {
             ExceptionHandlerWindows.HandleException(ex, null);
         }
         UpdateHttpStatusOnException(ex);
         throw;
     }
 }
示例#3
0
 /// <summary>
 /// Indicates that the user wants to cancel the property sheet.
 /// Default implementation allows cancel operation.
 /// </summary>
 protected override void OnCancel()
 {
     try
     {
         _childSettingControl.RefreshData(this.ParentSheet.SelectionObject);
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
     }
 }
示例#4
0
 /// <summary>
 /// Sent to every page in the property sheet to indicate that the user has clicked the OK
 /// or Close button and wants all changes to take effect.
 /// </summary>
 protected override bool OnOK()
 {
     try
     {
         return(this.OnApply());
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
     }
     return(false);
 }
        public virtual Stream PostEntity(string entityName, Stream inputStream)
        {
            LinqEntityContextWindows context = null;

            try
            {
                string requestName = $"{nameof(PostEntity)} : Entity Name = {entityName}";
                ValidateRequestMethod(HttpVerb.POST);
                context = GetEntityContext();
                Nullable <Guid> userId     = null;
                string          userName   = null;
                Type            entityType = GetEntityType(entityName);
                GetUserDetails(context, out userId, out userName);
                object inputEntity = GetObjectFromStream(entityType, inputStream, GOCWindows.Instance.JsonSerializer, out string serializedText);
                AuditRequest(requestName, serializedText);
                if (OnBeforePost != null)
                {
                    OnBeforePost(this, new RestServicePostEntityEventArgsWindows(
                                     entityName, userId, userName, context, entityType, inputEntity));
                }
                context.Insert(
                    entityType,
                    new List <object>()
                {
                    inputEntity
                },
                    userId,
                    userName,
                    false);
                if (OnAfterPost != null)
                {
                    OnAfterPost(this, new RestServicePostEntityEventArgsWindows(
                                    entityName, userId, userName, context, entityType, inputEntity));
                }
                string responseMessage = string.Format("{0} saved successfully.", entityName);
                Stream result          = StreamHelper.GetStreamFromString(responseMessage, GOCWindows.Instance.Encoding);
                AuditResponse(requestName, responseMessage);
                return(result);
            }
            catch (Exception ex)
            {
                if (_handleExceptions)
                {
                    ExceptionHandlerWindows.HandleException(ex, null);
                }
                UpdateHttpStatusOnException(ex);
                throw ex;
            }
            finally
            {
                DisposeEntityContext(context);
            }
        }
        public virtual Stream DeleteEntity(string entityName, string entityId)
        {
            LinqEntityContextWindows context = null;

            try
            {
                string requestName = $"{nameof(DeleteEntity)} : Entity Name = {entityName} : Entity ID = {entityId}";
                AuditRequest(requestName, null);
                ValidateRequestMethod(HttpVerb.DELETE);
                context = GetEntityContext();
                Nullable <Guid> userId   = null;
                string          userName = null;
                GetUserDetails(context, out userId, out userName);
                Type entityType = GetEntityType(entityName);
                if (OnBeforeDelete != null)
                {
                    OnBeforeDelete(this, new RestServiceDeleteEntityEventArgsWindows(
                                       entityName, userId, userName, context, entityType, entityId));
                }
                context.DeleteBySurrogateKey(
                    entityType,
                    new List <object>()
                {
                    entityId
                },
                    userId,
                    userName);
                if (OnAfterDelete != null)
                {
                    OnAfterDelete(this, new RestServiceDeleteEntityEventArgsWindows(
                                      entityName, userId, userName, context, entityType, entityId));
                }
                string responseMessage = string.Format("{0} deleted successfully.", entityName);
                Stream result          = StreamHelper.GetStreamFromString(responseMessage, GOCWindows.Instance.Encoding);
                AuditResponse(requestName, responseMessage);
                return(result);
            }
            catch (Exception ex)
            {
                if (_handleExceptions)
                {
                    ExceptionHandlerWindows.HandleException(ex, null);
                }
                UpdateHttpStatusOnException(ex);
                throw ex;
            }
            finally
            {
                DisposeEntityContext(context);
            }
        }
        public virtual Stream GetEntitiesByField(string entityName, string fieldName, string fieldValue)
        {
            LinqEntityContextWindows context = null;

            try
            {
                string requestName = $"{nameof(GetEntitiesByField)} : Entity Name = {entityName} : Field Name = {fieldName} : Field Value = {fieldValue}";
                AuditRequest(requestName, null);
                ValidateRequestMethod(HttpVerb.GET);
                context = GetEntityContext();
                Nullable <Guid> userId   = null;
                string          userName = null;
                GetUserDetails(context, out userId, out userName);
                Type entityType = GetEntityType(entityName);
                if (OnBeforeGetEntitiesByField != null)
                {
                    OnBeforeGetEntitiesByField(this, new RestServiceGetEntitiesByFieldEventArgsWindows(
                                                   entityName, userId, userName, context, entityType, fieldName, fieldValue, null));
                }
                List <object> outputEntities = context.GetEntitiesByField(
                    entityType,
                    fieldName,
                    fieldValue,
                    false,
                    userId,
                    userName).Contents;
                if (OnAfterGetEntitiesByField != null)
                {
                    OnAfterGetEntitiesByField(this, new RestServiceGetEntitiesByFieldEventArgsWindows(
                                                  entityName, userId, userName, context, entityType, fieldName, fieldValue, outputEntities));
                }
                Stream result = GetStreamFromObject(outputEntities, out string serializedText);
                AuditResponse(requestName, serializedText);
                return(result);
            }
            catch (Exception ex)
            {
                if (_handleExceptions)
                {
                    ExceptionHandlerWindows.HandleException(ex, null);
                }
                UpdateHttpStatusOnException(ex);
                throw ex;
            }
            finally
            {
                DisposeEntityContext(context);
            }
        }
示例#8
0
 /// <summary>
 /// OnAddPropertyPages is used to get the property pages to show.
 /// (triggered by SelectionData.ShowPropertySheet)
 /// </summary>
 /// <param name="propertyPageCollection">property pages</param>
 protected override void OnAddPropertyPages(PropertyPageCollection propertyPageCollection)
 {
     try
     {
         if (_settingsControl.ListView.SelectedItems.Count < 1)
         {
             throw new Exception("there should be at least one selection");
         }
         propertyPageCollection.Add(new EditSettingPage(this.SelectionData.SelectionObject));
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
     }
 }
示例#9
0
 /// <summary>
 /// Sent to every page in the property sheet to indicate that the user has clicked
 /// the Apply button and wants all changes to take effect.
 /// </summary>
 protected override bool OnApply()
 {
     try
     {
         if (this.Dirty && _childSettingControl.CanApplyChanges())
         {
             _childSettingControl.UpdateData(this.ParentSheet.SelectionObject); //Save changes.
             return(true);
         }
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
     }
     return(false); //Something invalid was entered.
 }
示例#10
0
 public virtual ActionResult InformationDialog(string message)
 {
     try
     {
         InformationModel model = new InformationModel();
         model.PostBackControllerAction = GetCurrentActionName();
         model.PostBackControllerName   = GetCurrentControllerName();
         model.DialogDivId        = INFORMATION_DIALOG_DIV_ID;
         model.InformationMessage = message == null ? string.Empty : message;
         PartialViewResult result = PartialView(INFORMATION_DIALOG_PARTIAL_VIEW_NAME, model);
         return(result);
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
         return(GetJsonResult(false, ex.Message));
     }
 }
示例#11
0
 protected override void TimerElapsed(object state)
 {
     StopJob();
     try
     {
         BeginExecution(this);
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
     }
     finally
     {
         if (!this.IsEnabled)
         {
             StartJob();
         }
     }
 }
示例#12
0
 protected override void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     StopJob();
     try
     {
         BeginExecution(this);
     }
     catch (Exception ex)
     {
         ExceptionHandlerWindows.HandleException(ex);
     }
     finally
     {
         if (!this.IsEnabled())
         {
             StartJob();
         }
     }
 }
示例#13
0
        /// <summary>
        /// Handle triggered action
        /// </summary>
        /// <param name="action">triggered action</param>
        /// <param name="status">asynchronous status to update console</param>
        protected override void OnSelectionAction(Microsoft.ManagementConsole.Action action, AsyncStatus status)
        {
            try
            {
                SnapInActionWindows settingAction = (SnapInActionWindows)action.Tag;
                switch (settingAction)
                {
                case SnapInActionWindows.Edit:
                    this.SelectionData.ShowPropertySheet("Setting");
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                ExceptionHandlerWindows.HandleException(ex);
            }
        }
 public virtual Stream FileDownload(string fileName)
 {
     try
     {
         string requestName = $"{nameof(FileDownload)}: File Name = {fileName}";
         AuditRequest(requestName, null);
         FileSystemHelper.ValidateDirectoryExists(fileName);
         Stream result = File.OpenRead(fileName);
         AuditResponse(requestName, null);
         return(result);
     }
     catch (Exception ex)
     {
         if (_handleExceptions)
         {
             ExceptionHandlerWindows.HandleException(ex, null);
         }
         UpdateHttpStatusOnException(ex);
         throw;
     }
 }
 //http://blogs.msdn.com/b/webapps/archive/2012/09/06/wcf-chunking.aspx
 public virtual Stream FileUpload(string fileName, Stream inputStream)
 {
     try
     {
         string requestName = $"{nameof(FileUpload)} : File Name = {fileName}";
         AuditRequest(requestName, null);
         ValidateRequestMethod(HttpVerb.POST);
         byte[]     fileBytes = StreamHelper.GetBytesFromStream(inputStream);
         FileStream fs        = null;
         lock (FileUploadSessions.Instance.FileStreams)
         {
             FileUploadSessions.Instance.FileStreams.TryGetValue(fileName, out fs);
             if (fs == null)
             {
                 fs = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
                 FileUploadSessions.Instance.FileStreams.Add(fileName, fs);
             }
             fs.Write(fileBytes, 0, fileBytes.Length);
             fs.Flush();
         }
         string responseMessage = string.Format("{0} bytes written to {1}", fileBytes.Length, fileName);
         Stream result          = StreamHelper.GetStreamFromString(
             responseMessage,
             GOCWindows.Instance.Encoding);
         AuditResponse(requestName, responseMessage);
         return(result);
     }
     catch (Exception ex)
     {
         FileUploadCompleted(fileName);
         if (_handleExceptions)
         {
             ExceptionHandlerWindows.HandleException(ex, null);
         }
         UpdateHttpStatusOnException(ex);
         throw ex;
     }
 }