public void ProcessRequest(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (_blobAddress == null)
            {
                context.Response.StatusCode  = 404;
                context.Response.ContentType = "text/plain";
                context.Response.Write(ResourceManager.GetString("Not_Found_Exception"));

                return;
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(PortalName, context.Request.RequestContext);

            CloudStorageAccount storageAccount;

            if (!TryGetCloudStorageAccount(context, out storageAccount))
            {
                context.Response.StatusCode  = 404;
                context.Response.ContentType = "text/plain";
                context.Response.Write(ResourceManager.GetString("Failed_To_Configure_Cloud_Storage_Account"));

                return;
            }

            if (_enableTracking)
            {
                var log = new Entity("adx_webfilelog");

                log["adx_name"]      = _blobAddress;
                log["adx_date"]      = DateTime.UtcNow;
                log["adx_ipaddress"] = context.Request.UserHostAddress;
                log["adx_webfileid"] = _entity;

                var user = dataAdapterDependencies.GetPortalUser();

                if (user != null && user.LogicalName == "contact")
                {
                    log["adx_contactid"] = user;
                }

                var serviceContext = dataAdapterDependencies.GetServiceContextForWrite();

                serviceContext.AddObject(log);
                serviceContext.SaveChanges();
            }

            var blobClient = storageAccount.CreateCloudBlobClient();
            var blob       = blobClient.GetBlobReferenceFromServer(new Uri(_blobAddress));

            var accessSignature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions            = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(55)
            });

            context.Response.Redirect(blob.Uri + accessSignature);
        }
Пример #2
0
        public ActionResult AddPortalComment(string regardingEntityLogicalName, string regardingEntityId, string text,
                                             HttpPostedFileBase file = null, string attachmentSettings = null)
        {
            if (string.IsNullOrWhiteSpace(text) || string.IsNullOrWhiteSpace(StringHelper.StripHtml(text)))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed, ResourceManager.GetString("Required_Field_Error").FormatWith(ResourceManager.GetString("Comment_DefaultText"))));
            }

            Guid regardingId;

            Guid.TryParse(regardingEntityId, out regardingId);
            var regarding = new EntityReference(regardingEntityLogicalName, regardingId);

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext);
            var serviceContext          = dataAdapterDependencies.GetServiceContext();

            var dataAdapter = new ActivityDataAdapter(dataAdapterDependencies);
            var settings    = EntityNotesController.GetAnnotationSettings(serviceContext, attachmentSettings);
            var crmUser     = dataAdapter.GetCRMUserActivityParty(regarding, "ownerid");
            var portalUser  = new Entity("activityparty");

            portalUser["partyid"] = dataAdapterDependencies.GetPortalUser();

            var portalComment = new PortalComment
            {
                Description        = text,
                From               = portalUser,
                To                 = crmUser,
                Regarding          = regarding,
                AttachmentSettings = settings,
                StateCode          = StateCode.Completed,
                StatusCode         = StatusCode.Received,
                DirectionCode      = PortalCommentDirectionCode.Incoming
            };

            if (file != null && file.ContentLength > 0)
            {
                // Soon we will change the UI/controller to accept multiple attachments during the create dialog, so the data adapter takes in a list of attachments
                portalComment.FileAttachments = new IAnnotationFile[]
                { AnnotationDataAdapter.CreateFileAttachment(file, settings.StorageLocation) };
            }

            var result = dataAdapter.CreatePortalComment(portalComment);

            if (!result.PermissionsExist)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden,
                                                ResourceManager.GetString("Entity_Permissions_Have_Not_Been_Defined_Message")));
            }

            if (!result.CanCreate)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden,
                                                ResourceManager.GetString("No_Permissions_To_Create_Notes")));
            }

            if (!result.CanAppendTo)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden,
                                                ResourceManager.GetString("No_Permissions_To_Append_Record")));
            }

            if (!result.CanAppend)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden,
                                                ResourceManager.GetString("No_Permissions_To_Append_Notes")));
            }

            if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage))
            {
                PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Comments, this.HttpContext, "create_comment_" + regardingEntityLogicalName, 1, regarding, "create");
            }

            return(new HttpStatusCodeResult(HttpStatusCode.Created));
        }
Пример #3
0
        public ActionResult AddNote(string regardingEntityLogicalName, string regardingEntityId, string text, bool isPrivate = false, HttpPostedFileBase file = null, string attachmentSettings = null)
        {
            Guid regardingId;

            Guid.TryParse(regardingEntityId, out regardingId);
            var    regarding           = new EntityReference(regardingEntityLogicalName, regardingId);
            string portalName          = null;
            var    portalContext       = PortalCrmConfigurationManager.CreatePortalContext();
            var    languageCodeSetting = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "Language Code");

            if (!string.IsNullOrWhiteSpace(languageCodeSetting))
            {
                int languageCode;
                if (int.TryParse(languageCodeSetting, out languageCode))
                {
                    portalName = languageCode.ToString(CultureInfo.InvariantCulture);
                }
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: portalName);
            var serviceContext          = dataAdapterDependencies.GetServiceContext();

            var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies);
            var settings    = JsonConvert.DeserializeObject <AnnotationSettings>(attachmentSettings) ??
                              new AnnotationSettings(serviceContext, true);

            var annotation = new Annotation
            {
                NoteText  = string.Format("{0}{1}", AnnotationHelper.WebAnnotationPrefix, text),
                Subject   = AnnotationHelper.BuildNoteSubject(serviceContext, dataAdapterDependencies.GetPortalUser(), isPrivate),
                Regarding = regarding
            };

            if (file != null && file.ContentLength > 0)
            {
                annotation.FileAttachment = AnnotationDataAdapter.CreateFileAttachment(file, settings.StorageLocation);
            }

            var result = dataAdapter.CreateAnnotation(annotation, settings);

            if (!result.PermissionsExist)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Entity Permissions have not been defined. Your request could not be completed."));
            }

            if (!result.CanCreate)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to create notes."));
            }

            if (!result.CanAppendTo)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to append to record."));
            }

            if (!result.CanAppend)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Permission Denied. You do not have the appropriate Entity Permissions to append notes."));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }