小编aza*_*arp的帖子

在App.config文件控制台应用程序中保护部分

我试图加密控制台应用程序的App.config文件中的appSettingsconnectionStrings部分.由于某种原因section.SectionInformation.IsProtected总是返回真实.

static void Main(string[] args)
{
    EncryptSection("connectionStrings", "DataProtectionConfigurationProvider"); 
}

private static void EncryptSection(string sectionName, string providerName)
{
    string assemblyPath = Assembly.GetExecutingAssembly().Location;
    Configuration config = ConfigurationManager.OpenExeConfiguration(assemblyPath);

    ConfigurationSection section = config.GetSection(sectionName);

    if (section != null && !section.SectionInformation.IsProtected)
    {
        section.SectionInformation.ProtectSection(providerName);
        config.Save(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

不知道为什么它总是回归真实.

.net c# encryption configuration

6
推荐指数
1
解决办法
3620
查看次数

RichTextBox和插入位置

这是交易:我有一个RichTextBox控件,它工作正常.问题是有一个"插入当前日期时间"按钮,它将当前日期时间添加/注入RichTextBox.用户可以在插入符指向的任何地方输入日期时间.这涉及复杂的字符串操作和东西.

任何想法如何获得当前的插入位置.每当我得到RichTextBox.CaretPositon时,它似乎指向RichTextBox的开头而不是实际插入符的位置.

更新1:

日期时间按钮单击代码:

 private void DateTimeStampButton_Click(object sender, RoutedEventArgs e)
        {
            //TextRange tr = new TextRange(textBox.Selection.Start, textBox.Selection.End);
            var tr = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd);

            if(tr.Text.Length == 2)
            {
                if(tr.Text == "\r\n")
                {
                    tr.Text = tr.Text.TrimStart(new[] { '\r', '\n' }); 
                }
            }

            textBox.CaretPosition.InsertTextInRun(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ":  ");

            DateTimeStampButton.Focusable = false;
        }

 private void SharpRichTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            SetValue(TextProperty, Text);

            var binding = BindingOperations.GetBinding(this, TextProperty);

            if (binding == null) return;

            if (binding.UpdateSourceTrigger == UpdateSourceTrigger.Default || binding.UpdateSourceTrigger == UpdateSourceTrigger.LostFocus) …
Run Code Online (Sandbox Code Playgroud)

wpf richtextbox

6
推荐指数
1
解决办法
1万
查看次数

如何在洞穴中编程时消耗阳光?

我在地牢/洞穴里工作.它是地下室.气氛很好,但我确实错过了阳光.你在这样的环境中做了什么?我发现一些产生人造阳光的设备,但我认为它们会造成很多问题.

想法?

development-environment

6
推荐指数
1
解决办法
275
查看次数

从iOS应用程序向SOAP ASMX服务发送参数

我想从iOS应用程序调用.NET ASMX服务.我创建了这样的SOAP消息:

    -(IBAction)submitButtonClicked:(id)sender
{
       NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/NotificationService.asmx"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
    [request setRequestMethod:@"POST"];
    [request addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];
    [request addRequestHeader:@"SOAPAction" value:@"http://tempuri.org/HelloWorld"];


    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"

 "<soap:Envelope 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" 
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                             "<soap:Body>"
                             "<Greet xmlns=\"http://tempuri.org/\">"
                             "<deviceToken>some device token</deviceToken>"
                             "<userName>azamsharp</userName>"
                             "</Greet>"
                             "</soap:Body>"
                             "</soap:Envelope>"];

    NSString *messageLength = [NSString stringWithFormat:@"%d",[soapMessage length]];

    [request addRequestHeader:@"Content-Length" value:messageLength];

    [request appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

    [request setDelegate:self]; 
    [request startAsynchronous]; 


}
Run Code Online (Sandbox Code Playgroud)

上面的代码可以正常工作,但正如您所看到的,我必须手动创建SOAP消息.有没有办法只传入参数和方法名称,并自动创建soap正文/消息.StackOverFlow上有一个示例用于相同的场景,但我无法找到它.

web-services ios

6
推荐指数
1
解决办法
6553
查看次数

使用Microsoft Chart控件在图表上标记

我正在使用Microsoft Chart控件创建一个3d图表.这是图像:

替代文字http://www.highoncoding.com/articleimages/bar_graph.png

我想在每个条形图的顶部显示该点.对于条形图顶部的考试1,它应该显示2(如2分)等.

这是代码:

private void BindData() {

            var exams = new List<Exam>()
            {
                new Exam() { Name = "Exam 1", Point = 10 }, 
                new Exam() { Name = "Exam 2", Point = 12 }, 
                new Exam() { Name = "Exam 3", Point = 15 }, 
                new Exam() { Name = "Exam 4", Point = 2 }
            };

            var series = ExamsChart.Series["ExamSeries"];         



            series.YValueMembers = "Point"; 
            series.XValueMember = "Name"; 

            //series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle;
            //series.MarkerSize = 20;
            //series.LegendText = "hellow";
            //series.Label …
Run Code Online (Sandbox Code Playgroud)

asp.net mschart

5
推荐指数
1
解决办法
7394
查看次数

Cocos2d CCSprite类获取图像文件的名称

我可以使用以下代码初始化或创建新的CCSprite对象:

NSString *fileName = [[imagesPath objectAtIndex:i] lastPathComponent];
        CCSprite *sprite = [CCSprite spriteWithFile:fileName];
Run Code Online (Sandbox Code Playgroud)

现在,无论如何要找到用于特定CCSprite对象的图像文件的名称?

更新1:

userData属性看起来很有趣!

iphone cocos2d-iphone

5
推荐指数
1
解决办法
4145
查看次数

Rake Gems安装错误

我在尝试安装gem时遇到以下错误:

Mohammad-Azams-MacBook-Pro:awesomecats azamsharp$ sudo rake gems:install
Password:
(in /Projects/awesomecats)
rake aborted!
Don't know how to build task 'gems:install'

(See full trace by running task with --trace)
Mohammad-Azams-MacBook-Pro:awesomecats azamsharp$ 
Run Code Online (Sandbox Code Playgroud)

rake ruby-on-rails

5
推荐指数
1
解决办法
2617
查看次数

在Cocos2d中替换场景时不会触发dealloc

出于某种原因,在更换场景时不会触发我的CCLayer的dealloc.这是替换场景的代码:

[[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:2.0f scene:[HelloWorld scene]]];
Run Code Online (Sandbox Code Playgroud)

按下按钮时会触发上面的代码.

我已经在dealloc方法中放置了一个永远不会触发的NSLog.

更新1:

我最后通过在更换场景之前手动释放内存来解决问题.

cocos2d-iphone

5
推荐指数
1
解决办法
2140
查看次数

NUnit,WatiN SpecFlow和STA线程错误

当我尝试运行SpecFlow测试时,我收到以下异常:

CurrentThread需要将它的ApartmentState设置为ApartmentState.STA才能自动化Internet Explorer.

我已经在App.config中添加了以下代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="NUnit">
      <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
  </configSections>
  <NUnit>
    <TestRunner>
      <!-- Valid values are STA,MTA. Others ignored. -->
      <add key="ApartmentState" value="STA" />
    </TestRunner>
  </NUnit>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我正在使用VS 2010并强制我的应用程序以3.5版本运行.

我也在使用nUnit工具的GUI显示!

nunit watin unit-testing

5
推荐指数
2
解决办法
2495
查看次数

Apple推送通知错误(aps-environment)

我在iTunes connect上注册了该应用程序.当我在设备上运行应用程序时,我收到以下APNS错误.

Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x19e890 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}
Run Code Online (Sandbox Code Playgroud)

我在xCode项目中使用了相同的AppID和包标识符以及iTunes连接.

此外,我忘了提到该应用程序是在Enterprise开发人员配置文件下注册的,我在我的个人开发人员配置文件下运行它.

apple-push-notifications ios

5
推荐指数
1
解决办法
6419
查看次数