예제 #1
0
        /// <summary>
        /// Save on database Log
        /// </summary>
        /// <param name="value"></param>
        /// <param name="mode"></param>
        /// <param name="source"></param>
        public static Boolean DataBaseEntry(String value, StatisticMode mode = StatisticMode.Information, String source = "")
        {
            var model = new MtnLog {
                CreatedType = DateTime.Now, LogId = Guid.NewGuid().ToString(), ModeType = mode.ToString(), Source = source.Replace("'", "\""), Value = value.Replace("'", "\"")
            };
            var strQuery =
                Configuration.Config.GetConnectionString("Mtn.Library.Statistics.InsertQuery");

            strQuery = strQuery.IsNullOrWhiteSpaceMtn() ? m_query : strQuery;
            strQuery = strQuery.FormatByPropertyMtn(model);
            var useDbContext =
                Configuration.Config.GetNullableBoolean("Mtn.Library.Statistics.UseDbContext").HasValue;

            var assemblyLoad =
                Configuration.Config.GetString("Mtn.Library.Statistics.EntityAssembly");
            var cnnsStr = Mtn.Library.Configuration.Config.GetConnectionString("Mtn.Library.Statistics.ConnectionString");
            //System.Data.Entity.DbContext            DbConte
            //var db = new ObjectContext();

            //return db.ExecuteStoreCommand(strQuery) > 0;

            var objDb = Assembly.Load(assemblyLoad);

            if (objDb != null)
            {
                var     objList = new object[] { cnnsStr };
                dynamic db;
                if (useDbContext)
                {
                    db = objDb.CreateInstance("System.Data.Entity.DbContext", false, BindingFlags.CreateInstance, null, objList, null, null);
                    if (db != null)
                    {
                        int ret = db.Database.ExecuteSqlCommand(strQuery);
                        return(ret > 0);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    db = objDb.CreateInstance("System.Data.Objects.ObjectContext", false, BindingFlags.CreateInstance, null, objList, null, null);
                    if (db != null)
                    {
                        int ret = db.ExecuteStoreCommand(strQuery);
                        return(ret > 0);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                throw new ArgumentNullException("Cannot instance the object : " + assemblyLoad);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="mode"></param>
        /// <param name="source"></param>
        /// <param name="logName"></param>
        /// <param name="eventId"></param>
        /// <param name="category"></param>
        public static void EventLogEntry(String value, StatisticMode mode = StatisticMode.Information, String source = "", String logName = "", Int32 eventId = 1, Int16 category = 1)
        {
            if (Core.Parameter.DisableEventLogStatisticOnLowPermission)
            {
                try
                {
                    if (Core.Parameter.IsFulltrust)
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }

            lock (m_lock)
            {
                if (source.IsNullOrWhiteSpaceMtn())
                {
                    source = Utils.Parameter.EventSource;
                }
                if (logName.IsNullOrWhiteSpaceMtn())
                {
                    logName = Utils.Parameter.EventLogName;
                }

                EventLogEntryType eventType;
                switch (mode)
                {
                case StatisticMode.Log:
                    eventType = EventLogEntryType.SuccessAudit;
                    break;

                case StatisticMode.Information:
                    eventType = EventLogEntryType.Information;
                    break;

                case StatisticMode.Warn:
                    eventType = EventLogEntryType.Warning;
                    break;

                case StatisticMode.Error:
                    eventType = EventLogEntryType.Error;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mode");
                }
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, logName);
                }

                EventLog.WriteEntry(source, value, eventType, eventId, category);
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="mode"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool FileEntry(String value, StatisticMode mode = StatisticMode.Information, String fileName = "")
        {
            if (fileName.IsNullOrWhiteSpaceMtn())
            {
                fileName = Utils.Parameter.StatisticsFileName;
            }

            return(value.ToFileMtn(fileName, writeline: true));
        }
        private void ClientSumSupplyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int currIndex = UnsetOptions();

            SetOptions();
            _Mode = StatisticMode.ClientSumSupply;
            cbxOptions.SelectedIndex = currIndex;

            btnReport.Visible  = false;
            cbxOptions.Visible = true;

            ShowClientSumSupply();
        }
        private void EmploymentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int currIndex = UnsetOptions();

            SetOptions();
            _Mode = StatisticMode.Employment;
            cbxOptions.SelectedIndex = currIndex;

            btnReport.Visible  = false;
            cbxOptions.Visible = false;

            ShowEmployment();
        }
        private void GoodProfitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int currIndex = UnsetOptions();

            SetOptions();
            _Mode = StatisticMode.GoodProfit;
            cbxOptions.SelectedIndex = currIndex;

            btnReport.Visible  = true;
            cbxOptions.Visible = true;

            ShowGoodProfit();
        }
예제 #7
0
        /// <summary>
        /// Builds the statistic.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        private ObservableCollection <ObservablePoint <DateTime, int> > BuildStatistic(StatisticMode mode)
        {
            TicketService service = null;

            Dispatcher.Invoke((Action) delegate() { service = Service; });

            if (service == null)
            {
                return(null);
            }

            ObservableCollection <ObservablePoint <DateTime, int> > data = new ObservableCollection <ObservablePoint <DateTime, int> >();

            ObservableCollection <ITicket> tickets = service.TicketSource.ActiveTickets;

            ITicket ticket = (from t in tickets
                              where t.IsRedeemed && t.RedeemDate.HasValue
                              orderby t.RedeemDate ascending
                              select t).FirstOrDefault();

            DateTime firstRedeemed;

            if (ticket == null)
            {
                firstRedeemed = DateTime.Now;
            }
            else
            {
                firstRedeemed = ticket.RedeemDate.Value;
            }

            int offset   = 0;
            int interval = 60;

            Dispatcher.Invoke((Action) delegate() { interval = Convert.ToInt32((comboBoxStatisticResolution.SelectedItem as ComboBoxItem).Tag); });
            DateTime time = new DateTime();

            do
            {
                DateTime last = time;
                time = (new DateTime(firstRedeemed.Year, firstRedeemed.Month, firstRedeemed.Day, firstRedeemed.Hour, 0, 0)).AddMinutes(interval * offset++);
                int ticketsRedeemed;
                switch (mode)
                {
                case StatisticMode.PerUnit:
                    ticketsRedeemed = GetRedeemdCount(tickets, last, time);
                    break;

                case StatisticMode.Total:
                default:
                    ticketsRedeemed = GetRedeemdCount(tickets, time);
                    break;
                }
                data.Add(new ObservablePoint <DateTime, int>(time, ticketsRedeemed));
            }while (time < DateTime.Now);

            return(data);
        }
예제 #8
0
 //public static Dictionary<string,double> Statistic(IFeatureClass featureClass,string labelName,IGeometry geometry = null)
 //{
 //    var dict = new Dictionary<string, double>();
 //    var index = featureClass.Fields.FindField(labelName);
 //    if (index != -1)
 //    {
 //        var field = featureClass.Fields.get_Field(index);
 //        var valList = GetUniqueValue(featureClass, labelName);
 //        var whereClause = string.Empty;
 //        foreach(var val in valList)
 //        {
 //            if (!dict.ContainsKey(val) && !string.IsNullOrEmpty(val))
 //            {
 //                if (field.Type == esriFieldType.esriFieldTypeString)
 //                {
 //                    whereClause = string.Format("{0} = '{1}'", labelName, val);
 //                }
 //                else
 //                {
 //                    whereClause = string.Format("{0} = {1}", labelName, val);
 //                }
 //            }
 //        }
 //    }
 //    return dict;
 //}
 public static Dictionary<string, double> Statistic(IFeatureClass FeatureClass, StatisticMode Mode)
 {
     if (Mode == StatisticMode.Region)
     {
         return Statistic(FeatureClass, "SIX");
     }
     else if (Mode == StatisticMode.Restrict)
     {
         return Statistic(FeatureClass, "CF");
     }
     var dict = new Dictionary<string, double>();
     var list = LayerInfoHelper.GetStatistic(Mode.GetDescription());
     foreach (var item in list)
     {
         if (!dict.ContainsKey(item) && !string.IsNullOrEmpty(item))
         {
             dict.Add(item, Statistic2(FeatureClass,  "DISTRICT='" + item + "' AND RANK <> '匝道' AND RANK <> '连杆道路' AND RANK <> '步行街'", "LENGTH", "DISTRICT='" + item + "' AND RANK='快速路'"));
         }
     }
     return dict;
 }
예제 #9
0
 public double Statistic(string datasourceName, string datasetName, string fieldName, StatisticMode statisticMode)
 {
     if (string.IsNullOrEmpty(datasourceName)) throw new ArgumentNullException("datasourceName", Resources.ArgumentIsNotNull);
     if (string.IsNullOrEmpty(datasetName)) throw new ArgumentNullException("datasetName", Resources.ArgumentIsNotNull);
     if (string.IsNullOrEmpty(fieldName)) throw new ArgumentNullException("fieldName", Resources.ArgumentIsNotNull);
     string uri = string.Format("{0}/data/datasources/{1}/datasets/{2}/fields/{3}/{4}.json?", this._serviceUrl,
         HttpUtility.UrlEncode(datasourceName), HttpUtility.UrlEncode(datasetName), HttpUtility.UrlEncode(fieldName), statisticMode.ToString());
     string result = SynchHttpRequest.GetRequestString(uri);
     Dictionary<string, object> hasResult = JsonConvert.DeserializeObject<Dictionary<string, object>>(result);
     double statisticResult = -9999;
     if (hasResult != null && hasResult.ContainsKey("result") && hasResult["result"] != null)
     {
         double.TryParse(hasResult["result"].ToString(), out statisticResult);
     }
     return statisticResult;
 }
예제 #10
0
 /// <summary>
 /// 在指定的数据集中,根据指定的统计方法对指定字段进行统计计算。
 /// </summary>
 /// <param name="datasourceName">数据源名称,必设参数。</param>
 /// <param name="datasetName">数据集名称,必设参数。</param>
 /// <param name="fieldName">字段名称,必设参数。</param>
 /// <param name="statisticMode">统计方法。</param>
 /// <returns>统计结果。</returns>
 /// <exception cref="ArgumentNullException">参数 datasourceName、datasetName、fieldName 为空时抛出异常。</exception>
 /// <exception cref="SuperMap.Connector.Utility.ServiceException">服务端处理错误时抛出异常。</exception>
 public double Statistic(string datasourceName, string datasetName, string fieldName, StatisticMode statisticMode)
 {
     return _dataProvider.Statistic(datasourceName, datasetName, fieldName, statisticMode);
 }
예제 #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 /// <param name="mode"></param>
 public static void MemoryEntry(String value, StatisticMode mode = StatisticMode.Information)
 {
     memoryEntry.Add(mode.ToString(), value);
 }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="store"></param>
        /// <param name="mode"></param>
        /// <param name="sourceOrFile"></param>
        /// <returns></returns>
        public static Boolean Add(String value, StatisticStore store = StatisticStore.EventLog, StatisticMode mode = StatisticMode.Information, String sourceOrFile = "")
        {
            try
            {
                var storeType = Configuration.Config.GetString("Mtn.Library.ForceStatisticStore");
                if (!storeType.IsNullOrWhiteSpaceMtn())
                {
                    store = storeType.ToEnumMtn <StatisticStore>();
                }
            }
            catch
            {
            }
            try
            {
                switch (store)
                {
                case StatisticStore.EventLog:
                    EventLogEntry(value, mode, sourceOrFile);
                    break;

                case StatisticStore.File:
                    return(FileEntry(value, mode, sourceOrFile));

                case StatisticStore.DataBase:
                    return(DataBaseEntry(value, mode, sourceOrFile));

                case StatisticStore.Memory:
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mode");
                }
            }
            catch (Exception exp)
            {
                //ignored
                var msg = "Statistics Error (See target error) :{0} \r\n\r\n Source:{1}\r\nTarget Error:{2}".FormatMtn(exp.GetAllMessagesMtn().ToSafeStringMtn(),
                                                                                                                       sourceOrFile.ToSafeStringMtn(), value.ToSafeStringMtn());
                throw new Exception(msg);
            }
            return(true);
        }