Example #1
0
        public void PopulateFields()
        {
            // fill hashTable
            Fields.Clear();
            Aspose.Word.Document doc;
            string filePath = this.SavedPath == "" ? this.FilePath : this.SavedPath;

            if (File.Exists(filePath) == false)
            {
                return;
            }

            using (FileStreamManager fs = new FileStreamManager(filePath, true))
            {
                fs.OpenFileStream();
                if (fs.Abort == true)
                {
                    TemplateValid = false;
                    return;
                }

                doc = null;
                try
                {
                    doc = new Aspose.Word.Document(fs.FileStream);
                }
                catch (Exception ex)
                {
                    ErrorManager.WriteTraceInfo("TemplateStruct.PopulateFields().openDocument", ex, true, String.Format("The following document failed to open...\n{0}", filePath));
                    TemplateValid = false;
                    return;
                }
            }

            using (JetTask t = new JetTask())
            {
                object str;
                foreach (DocumentProperty property in doc.CustomDocumentProperties)
                {
                    if (property.Name.StartsWith("pA_"))
                    {
                        t.CommandText = "SELECT [Default] FROM FieldNames WHERE FieldKey = '" + property.Name + "'";
                        str           = t.ExecuteScalar();
                        if (str == null)
                        {
                            str = "";
                        }

                        this.Fields.Add(property.Name, str);
                    }
                }
            }

            // sync dataTable
            if (this.DataTable != null)
            {
                Hashtable ht = new Hashtable();
                foreach (DictionaryEntry entry in this.Fields)
                {
                    ht.Add(entry.Key, entry.Value);

                    // check to see if its already in the datatable
                    if (this.DataTable != null && this.DataTable.IsInitialized)
                    {
                        if (this.DataTable.FindByKey(entry.Key.ToString()) == null)
                        {
                            this.DataTable.AddChildKeyValueRow(entry.Key.ToString(), DatabaseOptimizer.GetKeyName(entry.Key.ToString()), true, "", true);
                        }
                    }
                }

                // update visibility
                if (this.DataTable.Count > 0)
                {
                    foreach (MasterDS.ChildKeyValueRow row in DataTable)
                    {
                        row.IsVisible = ht.ContainsKey(row.Key);
                        row.KeyName   = DatabaseOptimizer.GetKeyName(row.Key);
                    }
                }
            }
        }
Example #2
0
        public void FilterAndRecord(Session oSession)
        {
            Debug.Log("oSession.host.ToLower: " + oSession.host.ToLower() + ", Global.sRosinDomain:" + Global.sRosinDomain);
            Debug.Log("oSession.fullUrl:" + oSession.fullUrl);
            Debug.Log("rosin target url:" + ("http://" + oSession.host + "/?__rosin__"));
            // 支持https的请求
            // 由于https的请求需要服务器的配合,单凭fiddler没办法模拟,所以这里使用一个到页面所在https的请求,带上标识,拦截掉
            if (oSession.host.ToLower() == Global.sRosinDomain || oSession.fullUrl == ("https://" + oSession.host + "/?__rosin__"))
            {
                string sRequestBodyString = oSession.GetRequestBodyAsString();
                if (sRequestBodyString != "")
                {
                    List <LogItem> logList = JsonConvert.DeserializeObject <List <LogItem> >(sRequestBodyString);

                    if (logList.Count > 0)
                    {
                        bool   isNew     = false;
                        string sFileName = logList[0].key + ".txt";
                        string sFileDir  = FiddlerPath.RosinLogDir + @"\" + sFileName;
                        string sContent  = "";

                        if (!File.Exists(sFileDir))
                        {
                            isNew = true;
                        }

                        if (isNew)
                        {
                            sContent += "Page URL: " + oSession.oRequest.headers["Referer"] + "\r\n";
                            sContent += "Create Date: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
                            sContent += "\r\n";
                        }

                        foreach (LogItem item in logList)
                        {
                            sContent += "[" + TimeFormat.GetTime(item.time).ToString("yyyy-MM-dd HH:mm:ss") + "] [" + item.level + "]" + item.content.ToString() + "\r\n";
                        }

                        FileStreamManager.Instance().Write(logList[0].key, sFileDir, sContent);

                        // 先写日志,在去记录,避免出现读数据空的情况
                        if (isNew)
                        {
                            this.RecordPageUrl(logList[0].key, oSession);
                        }

                        // dispatch event
                        RosinWrite(this, new EventArgs());
                    }
                }

                //if (oSession.port == 443)
                //{
                //    oSession["x-replywithfile"] = "rosinhttps.dat";
                //}
                //else
                //{
                oSession["x-replywithfile"] = "rosinpost.dat";
                //}

                oSession["ui-hide"] = "true";

                // 这个接口在低版本没有,会报错
                // Fiddler Web Debugger (v2.4.5.0) Built: 2013年8月15日
                // oSession.Ignore(); // 忽略该次请求,fiddler中将看不到这个请求,但是实际上该次请求还是发出去了,所以要自己模拟一个响应
                return;
            }
        }