コード例 #1
0
        public static IHtmlString GetPreviewColumn(this HtmlHelper helper, FileDataViewModel viewModel)
        {
            var html     = "";
            var outerDiv = new TagBuilder("img");

            if (Constants.imageString.Contains(viewModel.Extension))
            {
                outerDiv.AddCssClass("img-responsive img-gridCss");
                outerDiv.MergeAttribute("src", viewModel.AbsoluteUri);
                outerDiv.MergeAttribute("width", Constants.ImageWidth);
                outerDiv.MergeAttribute("height", Constants.ImageHeight);
            }
            else if (Constants.TextString.Contains(viewModel.Extension))
            {
                outerDiv = new TagBuilder("p");
                outerDiv.AddCssClass("CssFileTableTd");
                var text       = FilesData.GetTextFromUrl(viewModel.AbsoluteUri);
                var textToShow = text.Substring(0, Math.Min(text.Length, 15)) + "...";
                outerDiv.SetInnerText(text);
            }
            else
            {
                outerDiv.SetInnerText("Invalid format to preview");
            }
            html = outerDiv.ToString(TagRenderMode.Normal);
            return(MvcHtmlString.Create(html));
        }
コード例 #2
0
ファイル: FileService.cs プロジェクト: mmckn/GenomicsApp
        public async Task <FileDataViewModel> GetGenome(string contributorId)
        {
            string blobstorageconnection = configuration.GetValue <string>("blobstorage");

            // Retrieve storage account from connection string.
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);

            //Create the blob client
            CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();

            //get access to the container where genome files are stored
            CloudBlobContainer container = blobClient.GetContainerReference("genomecontainer");

            FileDataViewModel file = new FileDataViewModel();

            var found = container.GetBlobReference(contributorId);

            // If file exists.
            if (await found.ExistsAsync())
            {
                file.FileName = found.Name;

                return(file);
            }

            return(null);
        }
コード例 #3
0
        public async void ReadFileCommandAction_WhenFileExist_EnsureTheModelContainsNumbersDivisableByZero()
        {
            //Arrange            
            var stubFileRepo = new StubIFileRepository();
            var model = new FileDataViewModel(stubFileRepo);
            model.SelectedFileItem = new FileItem("code", "name");

            //Act
            await model.ReadFileCommandAction();

            //Assert             
            Assert.True(model.OutputText.Equals("fake string"));
        }        
コード例 #4
0
        public FileDataViewModel Report(int portId, User user, OptimalPortfolio opPort)
        {
            var           port = managePortfolios.GetFullPortfolio(portId, user.Currency.CurrencyId, user.Licence.Stocks.Select(x => x.id).ToList());
            StringBuilder csv  = new StringBuilder();

            csv.AppendLine("Report optimization:");
            csv.AppendLine("");
            csv.AppendLine("Portfolio name,,Date today");
            csv.AppendLine(port.Details[0].Name + ",," + DateTime.Today.ToString("yyyy/MM/dd"));
            csv.AppendLine("");
            csv.AppendLine("Optimizations results:");
            csv.AppendLine("");

            // cOptimalPort optimal_portf = optimz_res.Portfolios[optimz_res.PortNumA];
            csv.AppendLine("Risk level,Investment,Portfolio value,Profit");
            // TODO: Alex: bug-fix: remove formatting
            //csv.AppendLine(port.Details[0].PreferedRisk.RiskType.ToString() + ",\"" + String.Format("{0:C}", port.Details[0].Equity) + "\",\"" + String.Format("{0:C}", port.Details[0].CurrEquity) + "\",\"" + String.Format("{0:C}", port.Details[0].Profit)+ "\"");
            csv.AppendLine(port.Details[0].PreferedRisk.RiskType.ToString() + ",\"" + port.Details[0].Equity + "\",\"" + port.Details[0].CurrEquity + "\",\"" + port.Details[0].Profit + "\"");
            csv.AppendLine("");
            csv.AppendLine("Risk,Return,Return-to-risk ratio,Diversification");
            csv.AppendLine(cGeneralFunctions.getFormatPercentFromDbl(opPort.Risk, 2) + "," + cGeneralFunctions.getFormatPercentFromDbl(opPort.Return, 3) + "," + cGeneralFunctions.getDoubleFormat(opPort.RateToRisk, 3) + "," +
                           cGeneralFunctions.getFormatPercentFromDbl(opPort.Diversification, 1));
            csv.AppendLine(",,Num of secs");
            csv.AppendLine(",," + port.Details[0].SecsNum.ToString());

            csv.AppendLine("");
            csv.AppendLine("Securities results:");
            csv.AppendLine("");
            csv.AppendLine("Name,Symbol,Sector,Quantity,Value,Last price");
            for (int isec = 0; isec < port.Details[0].SecurityData.Count; isec++)
            {
                //DataRow sec = optimz_res.SecuritiesTable.Rows[isec];
                //if (Convert.ToDouble(sec["dWeight"]) != 0.0)
                //{

                var sec     = port.Details[0].SecurityData[isec];
                var secRate = pricesBL.GetPrices(sec.idSecurity, sec.idCurrency).Where(x => x.Date <= DateTime.Today.AddDays(-1)).FirstOrDefault();
                csv.AppendLine(sec.strName + "," + sec.strSymbol + "," + sec.sectorName + "," +
                               sec.flQuantity.ToString() + "," + (sec.portSecWeight * port.Details[0].CurrEquity).ToString() + "," + secRate.RateVal.ToString());
                // }
            }

            var vm = new FileDataViewModel();

            vm.Name = "Portfolio_" + port.Details[0].Name + "_" + DateTime.Today.ToString("yyyy-MM-dd") + ".csv";
            vm.Data = Encoding.GetEncoding("Windows-1255").GetBytes(csv.ToString());
            return(vm);
        }
        public void CalculateCommand_WhenValidDataValueExists_ReturnsExpectedTotal()
        {
            //Arrange            
            var stubFileRepo = new StubFileRepository();
            string fileContent = "3, 5";
            string expectedTotal = "8";

            var model = new FileDataViewModel(stubFileRepo) { FileContent = fileContent };
            var command = new CalculateCommand();

            //Act
            command.Execute(model);

            //Assert             
            Assert.AreEqual(expectedTotal, model.TotalValue);
        }
コード例 #6
0
        public string Post(FileDataViewModel data)
        {
            //var remoteFile = "newTest/testing.txt";

            ftpCont ftp = new ftpCont(@"ftp://q.ti-kc.com/", "Anonymous", "");
            //ftp.createDirectory("test");
            //ftp.createDirectory(data.remoteFile.Substring(0, index));
            List <string> folders     = data.remoteFile.Split('/').ToList();
            int           removeIndex = folders.Count() - 1;

            folders.RemoveAt(removeIndex);
            string checkPath = "";

            foreach (string f in folders)
            {
                checkPath += f + '/';
                ftp.createDirectory(checkPath);
            }

            ftp.upload(data.remoteFile, @"" + data.localFile);

            return(checkPath);
        }
コード例 #7
0
 internal FileDataUserControl(FileDataViewModel dataContext)
 {
     DataContext = Arguments.NotNull(dataContext, nameof(dataContext));
     InitializeComponent();
 }
コード例 #8
0
        public async Task <bool> Save(TransmittalViewModel vm, bool UpdateToIssued)
        {
            if (UpdateToIssued)
            {
                TransmittalStatus = TransmittalStatus.Issued;
                SentDate          = DateTime.Today;
            }

            using (SqlConnection connection = new SqlConnection(TransmitalManager.connString))
            {
                Task       cmd = connection.OpenAsync();
                Task <int> t;


                if (IsLoadedFromDb)///update
                {
                    string updates = "";
                    if (vm.IssueToWorkshop != IssueToWorkshop)
                    {
                        updates += $"ToWorkShop = {Convert.ToInt32(vm.IssueToWorkshop)}";
                    }
                    if (vm.IssueType != IssueType)
                    {
                        updates += $"IssueType = {vm.IssueType}";
                    }
                    if (vm.TransmittalStatus != TransmittalStatus)
                    {
                        updates += $"Status = {vm.TransmittalStatus}";
                    }
                    if (vm.Comments != Comments)
                    {
                        updates += $"Comments = {vm.Comments}";
                    }
                    if (vm.Project.Number != Project.Number)
                    {
                        updates += $"ProjectNo = {vm.Project.Number}";
                    }
                    if (vm.IssueBy?.Id != IssueBy.Id)
                    {
                        updates += $"IssuedBy = {vm.IssueBy}";
                    }
                    if (vm.CreatedBy?.Id != CreatedBy.Id)
                    {
                        updates += $"CreatedBy= {vm.CreatedBy.Id}";
                    }


                    string     query   = string.Format(SqlScripts.UpdateTransmittal, Id, updates);
                    SqlCommand command = new SqlCommand(query, connection);
                    await      cmd;
                    t = command.ExecuteNonQueryAsync();


                    ///**** Update Transmittal Recipients *****

                    //TODO Not remove all recipients, check if they need to be removed to stop thrashing.
                    query = string.Format(SqlScripts.DeleteTransmitalRecipients, Id);  //Remove all recipients
                    Task <int> rr = new SqlCommand(query, connection).ExecuteNonQueryAsync();
                    await      rr;
                    //Add them
                    Parallel.ForEach(Recipients, async rec => await new SqlCommand(string.Format(SqlScripts.AddTransmitalRecipients, Id, rec.Id), connection).ExecuteNonQueryAsync());

                    //**** Update Files Lists ****
                    List <Document>          toRemove = Files.ToArray().ToList();
                    List <FileDataViewModel> toAdd    = new List <FileDataViewModel>();

                    //Files to add
                    foreach (FileDataViewModel fileVm in vm.Files)
                    {
                        Document fnd = Files.FirstOrDefault(a => fileVm.Id == a.Id);
                        if (fnd == null)
                        {
                            toAdd.Add(fileVm);
                        }
                    }
                    //Files to remove
                    foreach (Document file in Files)
                    {
                        FileDataViewModel fnd = vm.Files.FirstOrDefault(a => file.Id == a.Id);
                        if (fnd == null)
                        {
                            toRemove.Remove(file);
                        }
                    }

                    //remove files
                    string removeId = "";
                    toRemove.ForEach(r => removeId += (r.Id + ","));
                    string     remove = string.Format(SqlScripts.RemoveFiles, removeId.TrimEnd(','));
                    Task <int> t4     = new SqlCommand(remove, connection).ExecuteNonQueryAsync();

                    //Add files
                    Parallel.ForEach(toAdd, async doc => await doc.Model.dbQueryInsert(connection));
                    return(true);
                }
                else //add new
                {
                    try
                    {
                        Dictionary <string, string> updates = new Dictionary <string, string>();


                        updates.Add("ToWorkShop", Convert.ToInt32(vm.IssueToWorkshop).ToString());
                        updates.Add("IssueType", ((int)vm.IssueType).ToString());
                        updates.Add("Status", ((int)vm.TransmittalStatus).ToString());
                        if (!string.IsNullOrEmpty(vm.Comments))
                        {
                            updates.Add("Comments", "'" + vm.Comments + "'");
                        }
                        if (vm.Project != null)
                        {
                            updates.Add("ProjectNo", vm.Project.Number.ToString());
                        }
                        if (vm.IssueBy != null)
                        {
                            updates.Add("IssueBy", "'" + vm.IssueBy + "'");
                        }
                        if (vm.CreatedBy?.Id != CreatedBy.Id)
                        {
                            updates.Add("CreatedBy", vm.CreatedBy?.Id.ToString() ?? User.ActiveUser.Id.ToString());
                        }



                        string header = "", values = "";
                        foreach (KeyValuePair <string, string> v in updates)
                        {
                            header += v.Key + ",";
                            values += v.Value + ",";
                        }

                        header = header.Trim(',');
                        values = values.Trim(',');

                        string     query   = string.Format(SqlScripts.NewTransmittal, header, values);
                        SqlCommand command = new SqlCommand(query, connection);
                        await      cmd;

                        //Get id from new added record
                        object id = await command.ExecuteScalarAsync();

                        if (id is decimal d)
                        {
                            Id = Convert.ToInt32(d);
                        }
                        else if (id is int i)
                        {
                            Id = i;
                        }

                        if (Id != null)
                        {
                            ///**** Add Transmittal Recipients *****
                            Parallel.ForEach(Recipients, async rec => await new SqlCommand(string.Format(SqlScripts.AddTransmitalRecipients, Id, rec.Id), connection).ExecuteNonQueryAsync());

                            //**** Update Files Lists ****
                            foreach (var doc in vm.Files)
                            {
                                doc.Model.TransmittalId = Id ?? 1;
                                await doc.Model.dbQueryInsert(connection);
                            }

                            //Add files
                            //    Parallel.ForEach(vm.Files, doc =>
                            //{
                            //    doc.Model.TransmittalId = Id ?? 1;
                            //    doc.Model.dbQueryInsert(connection);
                            //    //    string header2 = "TransId, FileName, FileId, Version, Revision";
                            //    //    string values2 = $"{Id}, {doc.Name}, {doc.Id}, {doc.Version}, {doc.Revision}";
                            //    //    string query2 = string.Format(SqlScripts.AddFilesToTransmittal, header2, values2);
                            //    //    SqlCommand command2 = new SqlCommand(query2, connection);
                            //    //    command2.ExecuteNonQueryAsync();
                            //});
                        }

                        return(true);
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        Debugger.Break();
#endif
                        return(false);
                    }
                }
            }
        }