Ejemplo n.º 1
0
        /// <summary>
        /// Save the visual data.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="vpv">The VPV.</param>
        /// <param name="vovs">The vovs.</param>
        /// <param name="userName"></param>
        public void VisualizationDataSave(
            string operation,
            VPVVModels vpv,
            VOVVModel[] vovs, string userName)
        {
            var imageTypes = new string[] { "png", "jpg", "jpeg", "gif", "bpm" };

            IDBContext.Current.Operation = operation;
            //check if operation mapping is empty before call to save
            if (vpv.IsNotNull())
            {
                var business = new VisualizationBusinessContext();
                vpv.LocationTypeId       = MasterDefinitions.GetMaster("UNDEFINED").MasterId;
                business.VisualProjectId = vpv.VisualProjectId;
                business.Load(operation);
                business.ViewModel = vpv;
                if (vpv.VisualProjectMedia.IsNotNull())
                {
                    foreach (var media in vpv.VisualProjectMedia)
                    {
                        //Transform the sended media from base64 and send to sharepoint
                        media.MediaUrl = new SharepointProxy().AddMediaFile(
                            new Base64file(media.MediaFile64, media.MediaUrl));

                        //Get the media source from the sended name for each media
                        media.MediaSourceId = MasterDefinitions
                                              .GetMaster("MEDIA_SOURCE", media.MediaSource).MasterId;

                        //Set MediaTypeId depending of the media type sended
                        var mime = ImageHelper.URLGetMime(media.MediaUrl);
                        if (mime.StartsWith("image/"))
                        {
                            media.MediaTypeId = MasterDefinitions.GetMaster("MEDIA_TYPE", "IMAGE").MasterId;
                        }
                        else
                        {
                            media.MediaTypeId = MasterDefinitions.GetMaster("MEDIA_TYPE", "VIDEO").MasterId;
                        }
                    }
                }
                business.ViewModel = vpv;
                business.Execute("Visualization.VP.Save");
            }

            if (vovs.IsNotNull())
            {
                var business = new VisualizationBusinessContext();

                business.ViewModel = vpv;
                foreach (var vov in vovs)
                {
                    vov.LocationTypeId = MasterDefinitions.GetMaster("UNDEFINED").MasterId;
                    if (vov.VisualOutputId == -1)
                    {
                        business.OutputId = vov.OutputId.Value;
                    }
                    else
                    {
                        business.VisualOutputId = vov.VisualOutputId;
                        business.OutputId       = business
                                                  .VisualOutputGet(vov.VisualOutputId)
                                                  .VisualOutputVersions
                                                  .First()
                                                  .OutputYearPlan
                                                  .OutputId;
                    }
                    business.Load(IDBContext.Current.Operation);
                    vov.LocationTypeId   = MasterDefinitions.GetMasterByName("VO_LOCATION_TYPE", vov.LocationType).MasterId;
                    vov.DeliveryStatusId = MasterDefinitions.GetMasterByName("VO_DELIVERY_STATUS", vov.DeliveryStatus).MasterId;
                    business.ViewModel   = vov;

                    if (vov.VisualOutputMedia.IsNotNull())
                    {
                        foreach (var media in vov.VisualOutputMedia)
                        {
                            //Transform the sended media from base64 and send to sharepoint
                            media.MediaUrl = new SharepointProxy().AddMediaFile(
                                new Base64file(media.MediaFile64, media.MediaUrl));

                            //Get the media source from the sended name for each media
                            media.MediaSourceId = MasterDefinitions
                                                  .GetMaster("MEDIA_SOURCE", media.MediaSource).MasterId;
                            //get the history status from given information
                            media.MediaHistoryStatusId = MasterDefinitions.GetMasterByName(
                                "VO_DELIVERY_STATUS", media.MediaHistoryStatus).MasterId;

                            //Set MediaTypeId depending of the media type sended
                            var mime = ImageHelper.URLGetMime(media.MediaUrl);
                            if (mime.StartsWith("image/"))
                            {
                                media.MediaTypeId = MasterDefinitions.GetMaster("MEDIA_TYPE", "IMAGE").MasterId;
                            }
                            else
                            {
                                media.MediaTypeId = MasterDefinitions.GetMaster("MEDIA_TYPE", "VIDEO").MasterId;
                            }
                        }
                    }
                    business.Execute("Visualization.VO.Save");
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the visual outputs matrix.
        /// </summary>
        /// <param name="operationNumber">The operation number.</param>
        /// <returns></returns>
        public VisualizationDataResponse VisualOutputsMatrixGet(string operationNumber)
        {
            IDBContext.Current.Operation = operationNumber;
            var business = new VisualizationBusinessContext();

            business.Load(operationNumber);
            business.Execute("Visualization.Grid.Load");
            var matrix = business.ResultsMatrixContext.Current;
            var vosId  = business
                         .VisualOutputs
                         .Where(vo => vo.VisualOutputVersionsData.IsNotNull() &&
                                vo.VisualOutputVersionsData.OutputYearPlan.IsNotNull())
                         .Select(ou => ou.VisualOutputVersionsData.VisualOutputVersionId)
                         .ToList();
            var vosGelocation = business
                                .VisualizationRepository
                                .VisualOutputsLocationDataGet(vosId);
            var outputs = matrix.Components.SelectMany(cp => cp.Outputs);


            foreach (var visualOutput in business.VisualOutputs)
            {
                var geoData = vosGelocation.FirstOrDefault(geo =>
                                                           visualOutput.VisualOutputVersionsData.IsNotNull() &&
                                                           geo.FK_GEO_OBJECT_ID == visualOutput.VisualOutputVersionsData.VisualOutputVersionId);
                if (geoData.IsNotNull())
                {
                    visualOutput.VisualOutputVersionsData.GeolocationWNT = geoData.SHAPE;
                }
            }


            foreach (var visualOutput in business.VisualOutputs)
            {
                visualOutput.VisualOutputVersions = null;
            }

            if (!business.VisualProjects.Any())
            {
                business.Execute("Visualization.VP.Create");
            }
            if (business.VisualProjectVersionId != -1)
            {
                //Get vp geolocation data, only the first point
                var vPGelocation = business
                                   .VisualizationRepository
                                   .VisualProjectLocationDataGet(business.VisualProjectVersionId.Value);
                if (vPGelocation.Any())
                {
                    business.VisualProject.VisualProjectVersionsData.GeolocationWNT =
                        vPGelocation.First().SHAPE;
                }
            }
            matrix.OtherCosts = null;

            var components = new List <ComponentsResponse>();

            foreach (var component in matrix.Components)
            {
                var newComponent = new ComponentsResponse()
                {
                    Statement = component.Statement,
                };
                components.Add(newComponent);
                foreach (var output0 in component.Outputs)
                {
                    var visualOutputs = business
                                        .VisualOutputs
                                        .Where(vo => vo.VisualOutputVersionsData.IsNotNull() &&
                                               vo.VisualOutputVersionsData.OutputYearPlan.IsNotNull() &&
                                               vo.VisualOutputVersionsData.OutputYearPlan.OutputId == output0.OutputId)
                                        .ToList();
                    newComponent.Outputs.Add(new OutputResponse()
                    {
                        Definition      = output0.Definition,
                        OutputCategory  = output0.OutputCategory,
                        OutputYearPlans = output0.OutputYearPlans,
                        VisualOutputs   = visualOutputs
                    });
                }
            }

            return(new VisualizationDataResponse()
            {
                VisualProject = business.VisualProject,
                Components = components
            });
        }
Ejemplo n.º 3
0
        public string AddMediaFile(HttpPostedFileBase file)
        {
            var imageTypes = new string[] { "png", "jpg", "jpeg", "gif", "bpm" };
            var videoTypes = new string[] { "avi", "wmf", "mp4", "flv" };

            byte[] fileBytes;
            var    fileExtension = Path.GetExtension(file.FileName)
                                   .ToLower()
                                   .Trim('.');

            if (!videoTypes.Any(vt => vt == fileExtension) &&
                !imageTypes.Any(it => it == fileExtension))
            {
                throw new Exception("Invalid file type");
            }

            if (file.ContentLength > 0xf00000)
            {
                IDBContext.Current.ErrorMessage("Max allowed size is 15 MB");
            }

            var isImage = imageTypes.Any(it => it == fileExtension);

            if (isImage)
            {
                ImageHelper.ResizeImage(file.InputStream, out fileBytes, fileExtension);
            }
            else
            {
                fileBytes = new byte[file.InputStream.Length];
                file.InputStream.Read(fileBytes, 0, (int)file.InputStream.Length);
            }

            var business = new VisualizationBusinessContext();

            try
            {
                var fileName = file.FileName;

                var spUrl = string.Format("{0}/{1}/{2}",
                                          IntegrationHelper.SPOperationURL,
                                          Globals.GetSetting("SPMediaPath"),
                                          fileName);
                var servicePath = string.Format("{0}/_vti_bin/copy.asmx",
                                                IntegrationHelper.SPOperationURL);
                var endPoint = new EndpointAddress(servicePath);
                var binding  = GetSharepointBinding();

                string userWebConf = ConfigurationManager.AppSettings["CyberArk:SPServiceAccount_login"];
                string user        = userWebConf.Split('|')[0];
                string password    = PasswordStorage.GetPasswordStorage().GetPassword(userWebConf);

                using (var factory = new ChannelFactory <ListsSoap>(binding, endPoint))
                {
                    using (var proxy = new CopySoapClient(binding, endPoint))
                    {
                        proxy.Endpoint.Address = new EndpointAddress(servicePath);
                        proxy.ClientCredentials.Windows.ClientCredential          = CredentialCache.DefaultNetworkCredentials;
                        proxy.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
                        proxy.ClientCredentials.UserName.UserName = user;
                        proxy.ClientCredentials.UserName.Password = password;
                        proxy.Open();
                        FieldInformation myFieldInfo = new FieldInformation()
                        {
                            DisplayName  = string.Empty,
                            InternalName = string.Empty,
                            Type         = FieldType.Text,
                            Value        = fileName
                        };
                        CopyResult[] result;

                        proxy.CopyIntoItems(spUrl,
                                            new string[] { spUrl },
                                            new FieldInformation[] { myFieldInfo },
                                            fileBytes,
                                            out result);

                        if (result == null || result.Length == 0)
                        {
                            throw new Exception("Error calling copy.asmx service");
                        }

                        if (result[0].ErrorCode != CopyErrorCode.Success)
                        {
                            throw new Exception(string.Format("ErrorCode:{0}. ErrorMessage: {1}",
                                                              result[0].ErrorCode,
                                                              result[0].ErrorMessage));
                        }
                    }
                }

                return(spUrl);
            }
            catch (Exception ex)
            {
                Architecture.Logging.Logger.GetLogger()
                .WriteError(GetType().Name, ex.Message, ex);
                throw;
            }
        }