Beispiel #1
0
        public void Ctor_DeclareLogObjectWithNullOutput_ExceptionThrown()
        {
            ILogOutput         outLog         = null;
            ILogEntryFormatter entryFormatter = new FileFormatter();

            Assert.Throws <ArgumentNullException>(() => new Log(outLog, entryFormatter));
        }
Beispiel #2
0
        public static Stream ToFileStream(this IEnumerable <Tuple <IEmployer, string> > employers)
        {
            // Create the stream.

            var stream    = new MemoryStream();
            var formatter = new FileFormatter(new DelimitedFormatProvider(Delimiter.Comma));

            formatter.Format(employers.ToFileRecords(), stream);

            // Write it out.

            stream.Position = 0;
            return(stream);
        }
        FilePath CreateTemplateJsonFile(
            FilePath baseDirectory,
            TemplateInformation viewModel,
            PolicyBag policies)
        {
            var templateJsonFileCreator = new TemplateJsonFileCreator();

            templateJsonFileCreator.CreateInDirectory(baseDirectory, viewModel);

            FileFormatter.FormatFile(policies, templateJsonFileCreator.TemplateJsonFilePath);

            IdeApp.Workbench.OpenDocument(
                templateJsonFileCreator.TemplateJsonFilePath,
                null,
                true);

            return(templateJsonFileCreator.TemplateJsonFilePath);
        }
Beispiel #4
0
        public void TestFormatList()
        {
            var result1 = new TestCsvResult("name1", "recruiter1", false);
            var result2 = new TestCsvResult("name2", "recruiter2", false);
            var list    = new List <TestCsvResult> {
                result1, result2
            };

            using (var memoryStream = new MemoryStream())
            {
                var formatter = new FileFormatter(new DelimitedFormatProvider(Delimiter.Comma));
                formatter.Format(list, memoryStream);

                var streamReader = new StreamReader(memoryStream);
                memoryStream.Position = 0;
                var contents = streamReader.ReadToEnd();
                Assert.AreEqual(
                    "\"OrganisationName\",\"EmployerRole\",\"SendNewsletters\""
                    + System.Environment.NewLine
                    + "\"name1\",\"recruiter1\",\"False\""
                    + System.Environment.NewLine
                    + "\"name2\",\"recruiter2\",\"False\"", contents);
            }
        }
Beispiel #5
0
 public void Ctor_FileLogCreated_NoError()
 {
     ILogOutput         outLog         = new ConsoleOutput();
     ILogEntryFormatter entryFormatter = new FileFormatter();
     Log uut = new Log(outLog, entryFormatter);
 }
Beispiel #6
0
        public async Task <IActionResult> ClickStat(TechType techtype, DateTime?date1, DateTime?date2, string obj_type, string obj_id)
        {
            var partinfo = (PartnerInfo)GetUserInfo();

            if (!partinfo.IsApproved || partinfo.IsAnal)
            {
                return(StatusCode(403, new Dictionary <string, string>()
                {
                    ["method"] = "clickstat",
                    ["status"] = "Access denied",
                    ["errorMsg"] = "Нет доступа в раздел статистики кликов"
                }));
            }

            _cm.GetDates(date1, date2, out DateTime start_date, out DateTime end_date);

            var sqlparameters = new SqlParameters
            {
                { "start_date", start_date },
                { "end_date", end_date },
                { "p_service_type", (int)techtype },
                { "p_obj_type", obj_type },
                { "p_obj_id", obj_id },
                { "p_idp", partinfo.Idp }
            };

            var data = new List <Dictionary <string, object> >();

            try
            {
                data = (await _db.SQLSendQueryMySQLAsync("getdata", sqlparameters).ConfigureAwait(false))[0];
            }
            catch (Exception ex)
            {
                return(StatusCode(503, ex.Message));
            }

            var hashes = data.Select(item => new { hash = (string)item["hash"], service_type = (sbyte)item["service_type"] }).ToArray();

            using var hashdata = new DataTable();

            hashdata.Columns.Add("hash", typeof(string));
            hashdata.Columns.Add("service_type", typeof(int));
            foreach (var item in hashes)
            {
                hashdata.Rows.Add(item.hash, item.service_type);
            }

            var sqlcommand = new SqlCommand("GetClickStat")
            {
                CommandType = CommandType.StoredProcedure
            };
            SqlParameter tvpParam = sqlcommand.Parameters.AddWithValue("@hashes", hashdata);

            tvpParam.SqlDbType = SqlDbType.Structured;

            var statdata = new List <Dictionary <string, object> >();

            try
            {
                statdata = (await _db.SQLSendQueryFromCommandAsync(sqlcommand).ConfigureAwait(false))[0];
            }
            catch (Exception ex)
            {
                return(StatusCode(503, ex.Message));
            }

            var result = (from d in data
                          join s in statdata
                          on d["hash"] equals s["hash"]
                          select new Dictionary <string, object>
            {
                { "date", d["date"] },
                { "obj_type", d["obj_type"] },
                { "obj_id", d["obj_id"] },
                { "phone", d["phone"] },
                { "ip", d["ip"] },
                { "host", d["host"] },
                { "uri", d["uri"] },
                { "referer", d["referer"] },
                { "orderid", s["orderid"] },
                { "orderstat", s["orderstat"] }
            }).ToList();

            string fileDownloadName = $"{techtype}_clickstat_from_{start_date:yyyy-MM-dd}_to_{end_date:yyyy-MM-dd}.xlsx";

            byte[] fileContents = await FileFormatter.GetFile(FileType.xlsx, result);

            if (fileContents == null || fileContents.Length == 0)
            {
                return(NotFound());
            }

            return(File(
                       fileContents: fileContents,
                       contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                       fileDownloadName: fileDownloadName
                       ));
        }
        public async Task <IActionResult> GetFile(OrderType ordertype,
                                                  FileType format,
                                                  DateTime?date1,
                                                  DateTime?date2)
        {
            _cm.GetDates(date1, date2, out DateTime start_date, out DateTime end_date);

            var partinfo = (PartnerInfo)GetUserInfo();

            if (!partinfo.IsApproved || partinfo.IsAnal)
            {
                return(StatusCode(403, new Dictionary <string, string>()
                {
                    ["method"] = "files",
                    ["status"] = "Access denied",
                    ["errorMsg"] = "Нет доступа в раздел файлов"
                }));
            }

            var sqlparameters = new SqlParameters
            {
                { "part_id", partinfo.UserId },
                { "start_date", start_date },
                { "end_date", end_date }
            };

            string command = ordertype switch
            {
                OrderType.report_stat => $"EXEC dbo.GetReport {sqlparameters}",
                OrderType.cross_stat => $"EXEC dbo.GetCross {sqlparameters}",
                _ => null
            };

            var keys = ordertype switch
            {
                OrderType.report_stat => new string[] { "id", "name", "city", "status", "createddate" },
                OrderType.cross_stat => new string[] { "id", "name", "city", "phone", "address" },
                _ => null
            };

            List <Dictionary <string, object> > data;

            try
            {
                data = (await _db.SQLSendQueryAsync <QueryData>(command, sqlparameters).ConfigureAwait(false))[0];
            }
            catch (Exception ex)
            {
                return(StatusCode(503, ex.Message));
            }

            var contentType = format switch
            {
                FileType.xml => "application/xml",
                FileType.xlsx => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                _ => ""
            };

            string fileDownloadName = $"{ordertype}_from_{start_date:yyyy-MM-dd}_to_{end_date:yyyy-MM-dd}.{format}";

            byte[] fileContents = await FileFormatter.GetFile(format, data, keys);

            if (fileContents == null || fileContents.Length == 0)
            {
                return(NotFound());
            }

            return(File(
                       fileContents: fileContents,
                       contentType: contentType,
                       fileDownloadName: fileDownloadName
                       ));
        }
    }
}
        private PostFormatter load_post_data_str(string data, bool isop)
        {
            JsonObject post_data = JsonConvert.Import<JsonObject>(data);

            string[] keys = post_data.Names.Cast<string>().ToArray();

            PostFormatter pf = new PostFormatter();

            foreach (JsonMember member in post_data)
            {
                switch (member.Name)
                {
                    case "RawComment":
                        pf.Comment = Convert.ToString(member.Value);
                        continue;
                    case "Email":
                        pf.Email = Convert.ToString(member.Value);
                        continue;
                    case "Name":
                        pf.Name = Convert.ToString(member.Value);
                        continue;
                    case "PosterID":
                        pf.PosterID = Convert.ToString(member.Value);
                        continue;
                    case "Subject":
                        pf.Subject = Convert.ToString(member.Value);
                        continue;
                    case "Trip":
                        pf.Trip = Convert.ToString(member.Value);
                        continue;
                    case "ID":
                        pf.PostID = Convert.ToInt32(member.Value);
                        continue;
                    case "Time":
                        try
                        {
                            pf.Time = DateTime.Parse(member.Value.ToString());
                        }
                        catch
                        {

                        }
                        continue;
                    case "FileHash":
                        {
                            FileFormatter f = new FileFormatter();
                            f.PostID = pf.PostID;
                            f.FileName = Convert.ToString(post_data["FileName"]);
                            f.Hash = Convert.ToString(post_data["FileHash"]);
                            f.ThumbName = Convert.ToString(post_data["ThumbTime"]);
                            f.Height = Convert.ToInt32(post_data["FileHeight"]);
                            f.Width = Convert.ToInt32(post_data["FileWidth"]);
                            f.Size = Convert.ToInt32(post_data["FileSize"]);
                            pf.MyFile = f;
                            continue;
                        }
                    case "Sticky":
                        pf.IsSticky = Convert.ToBoolean(member.Value);
                        continue;
                    case "Closed":
                        pf.IsLocked = Convert.ToBoolean(member.Value);
                        continue;
                }
            }
            pf.Type = isop ? PostFormatter.PostType.OP : PostFormatter.PostType.Reply;
            return pf;
        }
Beispiel #9
0
        private PostFormatter load_post_data_str(string data, bool isop)
        {
            JsonObject post_data = JsonConvert.Import <JsonObject>(data);

            string[] keys = post_data.Names.Cast <string>().ToArray();

            PostFormatter pf = new PostFormatter();

            foreach (JsonMember member in post_data)
            {
                switch (member.Name)
                {
                case "RawComment":
                    pf.Comment = Convert.ToString(member.Value);
                    continue;

                case "Email":
                    pf.Email = Convert.ToString(member.Value);
                    continue;

                case "Name":
                    pf.Name = Convert.ToString(member.Value);
                    continue;

                case "PosterID":
                    pf.PosterID = Convert.ToString(member.Value);
                    continue;

                case "Subject":
                    pf.Subject = Convert.ToString(member.Value);
                    continue;

                case "Trip":
                    pf.Trip = Convert.ToString(member.Value);
                    continue;

                case "ID":
                    pf.PostID = Convert.ToInt32(member.Value);
                    continue;

                case "Time":
                    try
                    {
                        pf.Time = DateTime.Parse(member.Value.ToString());
                    }
                    catch
                    {
                    }
                    continue;

                case "FileHash":
                {
                    FileFormatter f = new FileFormatter();
                    f.PostID    = pf.PostID;
                    f.FileName  = Convert.ToString(post_data["FileName"]);
                    f.Hash      = Convert.ToString(post_data["FileHash"]);
                    f.ThumbName = Convert.ToString(post_data["ThumbTime"]);
                    f.Height    = Convert.ToInt32(post_data["FileHeight"]);
                    f.Width     = Convert.ToInt32(post_data["FileWidth"]);
                    f.Size      = Convert.ToInt32(post_data["FileSize"]);
                    pf.MyFile   = f;
                    continue;
                }

                case "Sticky":
                    pf.IsSticky = Convert.ToBoolean(member.Value);
                    continue;

                case "Closed":
                    pf.IsLocked = Convert.ToBoolean(member.Value);
                    continue;
                }
            }
            pf.Type = isop ? PostFormatter.PostType.OP : PostFormatter.PostType.Reply;
            return(pf);
        }