コード例 #1
0
        public void PostManyMarketShareToRest()
        {
            for (int i = 0; i < 1000; i++)
            {
                string result = string.Empty;
                requestPost                       = (HttpWebRequest)WebRequest.Create("http://localhost/BIdataApi/api/marketshare");
                requestPost.Method                = "POST";
                requestPost.ContentType           = "application/json";
                requestPost.UseDefaultCredentials = true;

                MarketShareDataType msdt = new MarketShareDataType {
                    BitMaskId = 4, TypeId = 3, DomainId = i, Value = "Go Daddy", SampleDate = "02/07/2013"
                };

                string requestData = new JavaScriptSerializer().Serialize(msdt);

                byte[] data = Encoding.UTF8.GetBytes(requestData);

                using (Stream dataStream = requestPost.GetRequestStream())
                    dataStream.Write(data, 0, data.Length);

                HttpWebResponse response = requestPost.GetResponse() as HttpWebResponse;
                result = new StreamReader(response.GetResponseStream()).ReadToEnd();

                Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
            }
        }
コード例 #2
0
ファイル: WebHost.cs プロジェクト: sawyerit/drone
        private void GetAllWebHosts()
        {
            MarketShareDataSource mds = DroneDataSource as MarketShareDataSource;

            if (!Object.Equals(null, mds))
            {
                using (Dig dig = new Dig())
                {
                    int maxParallel = XMLUtility.GetTextFromAccountNode(Xml, ProcessorName + "/maxparallel").ConvertStringToInt(1);

                    Parallel.ForEach(mds.GetAllCompanies(MarketShareTypeBitMaskEnum.WebHost, XMLUtility.GetIntFromAccountNode(Xml, ProcessorName + "/recordcount"))
                                     , new ParallelOptions {
                        MaxDegreeOfParallelism = maxParallel
                    }
                                     , (company, state) =>
                    {
                        try
                        {
                            if (Context.ShuttingDown)
                            {
                                state.Break();
                            }

                            MarketShareDataType marketType = new MarketShareDataType();
                            string url = Utility.CleanUrl(company.Uri.ToString());

                            if (!String.IsNullOrWhiteSpace(url))
                            {
                                WriteToUsageLogFile("Domain:" + url, string.Format("Executing {0}.{1}", ComponentTypeName, MethodInfo.GetCurrentMethod().Name), true);

                                marketType.Value      = dig.GetWebHostName(url);
                                marketType.DomainId   = company.DomainId;
                                marketType.SampleDate = company.DomainAttributes["SampleDate"];
                                marketType.TypeId     = (int)MarketShareDataTypeEnum.WebHost;
                                marketType.BitMaskId  = (int)MarketShareTypeBitMaskEnum.WebHost;
                                marketType.UniqueID   = g;

                                if (!string.IsNullOrWhiteSpace(marketType.Value))
                                {
                                    MarketShareDataComponent dc = new MarketShareDataComponent();
                                    dc.MarketShareType          = marketType;
                                    DroneDataSource.Process(dc);
                                }
                                else
                                {
                                    Utility.WriteToLogFile(String.Format("SmallBiz_NoWebHost_{0:M_d_yyyy}", DateTime.Today) + ".log", string.Format("Domain: ,{0}", url));
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            ExceptionExtensions.LogError(e, "WebHost.GetAllWebHostsParallel", "Domain: " + company.Uri.ToString());
                        }
                    });
                }
            }
        }
コード例 #3
0
        private static string BuildMarketShareMessage(MarketShareDataType marketShareDataType)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("Domain ID: " + marketShareDataType.DomainId);
            sb.Append(", TypeID:" + marketShareDataType.TypeId);
            sb.Append(", value: " + marketShareDataType.Value);
            sb.Append(", " + DateTime.Now);

            return(sb.ToString());
        }
コード例 #4
0
        public MarketShareDataType Create(MarketShareDataType value)
        {
            try
            {
                value.Value = Regex.Replace(value.Value, "[^\x20-\x7E]", String.Empty);
                _queueManager.AddToQueue(Utility.SerializeToXMLString <MarketShareDataType>(value), "MarketShare BitMaskID " + value.BitMaskId.ToString());
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "MarketShareService.Create", "Domainid: " + value.DomainId);
            }

            return(value);
        }
コード例 #5
0
ファイル: EmailHost.cs プロジェクト: sawyerit/drone
        /// <summary>
        /// Gets registrars for all companies in our database
        /// </summary>
        internal void GetAllEmailHosts()
        {
            MarketShareDataSource mds = DroneDataSource as MarketShareDataSource;

            if (!Object.Equals(null, mds))
            {
                using (Dig dig = new Dig())
                {
                    var list = mds.GetAllCompanies(MarketShareTypeBitMaskEnum.EmailHost, XMLUtility.GetIntFromAccountNode(Xml, "emailhost/recordcount"));

                    foreach (var company in list)
                    {
                        try
                        {
                            MarketShareDataType marketType = new MarketShareDataType();
                            string url = Utility.CleanUrl(company.Uri.ToString());

                            if (!String.IsNullOrWhiteSpace(url))
                            {
                                WriteToUsageLogFile("Domain:" + url, string.Format("Executing {0}.{1}", ComponentTypeName, MethodInfo.GetCurrentMethod().Name), true);

                                marketType.Value      = dig.GetEmailHostName(url);
                                marketType.DomainId   = company.DomainId;
                                marketType.SampleDate = company.DomainAttributes["SampleDate"];
                                marketType.TypeId     = (int)MarketShareDataTypeEnum.EmailHost;
                                marketType.BitMaskId  = (int)MarketShareTypeBitMaskEnum.EmailHost;

                                if (!string.IsNullOrWhiteSpace(marketType.Value))
                                {
                                    MarketShareDataComponent dc = new MarketShareDataComponent();
                                    dc.MarketShareType = marketType;
                                    DroneDataSource.Process(dc);
                                }
                                else
                                {
                                    Utility.WriteToLogFile(String.Format("SmallBiz_NoEmailHost_{0:M_d_yyyy}", DateTime.Today) + ".log", string.Format("Domain: ,{0}", url));
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            ExceptionExtensions.LogError(e, "EmailHost.GetAllEmailHosts", "Domain: " + company.Uri.ToString());
                        }
                    }
                }
            }
        }
コード例 #6
0
        private static void SaveMarketShare(MarketShareDataType msType)
        {
            try
            {
                DateTime sampleDate = DateTime.Now;
                if (!DateTime.TryParse(msType.SampleDate, out sampleDate))
                {
                    sampleDate = DateTime.Now;
                }

                List <KeyValuePair <string, object> > paramList = new List <KeyValuePair <string, object> >();
                paramList.Add(new KeyValuePair <string, object>("@DomainId", msType.DomainId));
                paramList.Add(new KeyValuePair <string, object>("@TypeId", msType.TypeId));
                paramList.Add(new KeyValuePair <string, object>("@BitMask", msType.BitMaskId));
                paramList.Add(new KeyValuePair <string, object>("@SampleDate", sampleDate));
                if (msType.Value != "None")
                {
                    paramList.Add(new KeyValuePair <string, object>("@Value", msType.Value));
                }

                DataFactory.ExecuteNonQuery("MarketShareInsUp", paramList);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("deadlocked"))
                {
                    SaveMarketShare(msType);
                    ExceptionExtensions.LogInformation("MarketShareDataSource.SaveMarketShare", "Deadlock encountered, trying again");
                }
                else if (e.Message.Contains("Timeout expired"))
                {
                    Thread.Sleep(5000);
                    SaveMarketShare(msType);
                }
                else
                {
                    ExceptionExtensions.LogError(e, "MarketShareDataSource.SaveMarketShare", "Name: " + msType.Value);

                    //if tempdb full or other critical db error, re-throw
                    if (Utility.IsCriticalDBError(e))
                    {
                        throw;
                    }
                }
            }
        }
コード例 #7
0
        private void SendDomainData(MarketShareDataType msType)
        {
            //CreatePostRequest
            Uri apiuri = new Uri(XMLUtility.GetTextFromAccountNode(Xml, "apiuri"));

            //send
            try
            {
                HttpStatusCode code = SendRequest(apiuri, msType, true);
                if (code != HttpStatusCode.Created)
                {
                    ExceptionExtensions.LogInformation("MarketShareDataSource.SendDomainData", "Send failed with status code: " + code + ". Trying again.");
                    SendDomainData(msType);
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "MarketShareDataSource.SendRequest()", "DomainID: " + msType.DomainId);
            }
        }
コード例 #8
0
ファイル: QueueMarketShare.cs プロジェクト: sawyerit/drone
        public override void ProcessMessage(object sender, MessageEventArgs args)
        {
            bool handled = false;

            try
            {
                string msg             = Encoding.UTF8.GetString(args.Message.BodyStream.ToByteArray());
                MarketShareDataType ms = Utility.DeserializeXMLString <MarketShareDataType>(msg);

                if (!Object.Equals(ms, null))
                {
                    WriteToUsageLogFile("MarketShareDataType:" + ms.ToString(), string.Format("Executing {0}.{1}", ProcessorName, MethodInfo.GetCurrentMethod().Name), true);
                    MarketShareDataComponent dc = new MarketShareDataComponent();
                    dc.MarketShareType = ms;

                    handled = true;
                    FireMessageProcessingEvent();
                    QueueComponentDataSource.Process(dc);
                    FireMessageProcessedEvent();
                }

                ms = null;
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "QueueMarketShare.ProcessMessage");

                if (Utility.IsCriticalDBError(e))
                {
                    FireShuttingDownEvent();
                }

                if (handled)
                {
                    FireMessageProcessedEvent();
                }
            }
        }
コード例 #9
0
        internal void AddMarketShareToBulk(MarketShareDataType msType)
        {
            DateTime sampleDate = DateTime.Now;

            if (!DateTime.TryParse(msType.SampleDate, out sampleDate))
            {
                sampleDate = DateTime.Now;
            }

            lock (_lockObj)
            {
                lock (_bulkTableDict)
                {
                    //check if it exists, if not, add table then add row
                    if (!_bulkTableDict.ContainsKey(msType.TypeId))
                    {
                        DataTable bulkTable = new DataTable("DomainMarketShareType");
                        bulkTable.Columns.Add("DomainID", typeof(int));
                        bulkTable.Columns.Add("TypeID", typeof(int));
                        bulkTable.Columns.Add("Value", typeof(string));
                        bulkTable.Columns.Add("SampleDate", typeof(DateTime));
                        bulkTable.Columns.Add("BitMask", typeof(int));

                        _bulkTableDict.Add(msType.TypeId, new MarketShareBulkData {
                            LastCount = 0, BulkTable = bulkTable
                        });
                    }

                    //Make sure row doesn't exist, then add it
                    if (!_bulkTableDict[msType.TypeId].BulkTable.AsEnumerable().Any(row => row.Field <int>("DomainID") == msType.DomainId && row.Field <int>("TypeID") == msType.TypeId))
                    {
                        _bulkTableDict[msType.TypeId].BulkTable.Rows.Add(msType.DomainId, msType.TypeId, (msType.Value != "None" ? msType.Value : null), sampleDate, msType.BitMaskId);
                    }
                }

                CheckBulkData(msType.TypeId);
            }
        }
コード例 #10
0
        // POST api/marketshare
        public HttpResponseMessage Post([FromBody] MarketShareDataType value)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            if (!Object.Equals(null, value))
            {
                try
                {
                    MarketShareDataType cr = _marketService.Create(value);
                    response = Request.CreateResponse(HttpStatusCode.Created);
                    response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = cr.DomainId }));
                }
                catch (Exception e)
                {
                    ExceptionExtensions.LogError(e, "MarketShareController.Post(msdatatype)", "Error creating marketshare type from posted value");
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            return(response);
        }