Friday, June 29, 2012

List of TPC ports

list .

CuteFTP - use pro for interops!

I wasn't using pro and was knocking my head out why the dll wasn't working

Interop excel

I went through hell getting the right saveas format
until I started using
XlFileFormat.xlXMLSpreadsheet

thus:


workBook.SaveAs(path,
                 XlFileFormat.xlXMLSpreadsheet,
                Type.Missing, Type.Missing,
                false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

CLR Errors - crashing without actually running

are usually caused by invalid references

to a windows program you can add the following for error handling in program.cs

  [STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException +=
            new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //CheckForShortcut();
            Application.Run(new Invoice());
        }

        static void CurrentDomain_UnhandledException
  (object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;

                MessageBox.Show(ex.Message + ex.StackTrace,
                      "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            finally
            {
                Application.Exit();
            }
        }

Tuesday, June 26, 2012

setting reporting service identity

having big problems with that , as the text box was greyed out. First I changed the apppool. After that I had to restart the services (otherwise got bizarre error) :
System.Runtime.InteropServices.COMException (0x800706B3)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Management.ManagementObject.Get()
   at ReportServicesConfigUI.WMIProvider.RSReportServerAdmin.SetWebServiceIdentity(String applicationPool)

Could not load file errors

Could not load file or assembly 'blah' or one of its dependencies. An attempt was made to load a program with an incorrect format.

could just mean  the apppool is not configured for 32 bit apps

In my case I converted a .net 2.0 asp.net project to 4.0. 

Surrogate Keys

in OLAP

Tuesday, June 19, 2012

Monday, June 18, 2012

cannot debug error message

may mean an invalid web.config

web extensions

in asp.net 4 do not need an explicit reference - when you upgrade old apps there may be issues

503 error

can be caused when the password for the identity for the apppool changed. I would of thought that IIS would have used the new password in my case but it didnt

Friday, June 15, 2012

xp_cmdshell

to get sp to run xp_cmdshell
you need major permissions

also need this

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

flush

if you cant resolve a computer on the network you may have to flush

Thursday, June 14, 2012

WCF Custom behaviours


To add custom behavior to your calls to WCF services the way to go is with message inspectors

A behavior extension element HttpBlahBehaviorExtensionElement
Will be configured thus:


<client>
      <endpoint address="http://localhost/blah/blah.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReportingService" contract="IBlah" name="BasicHttpBinding_IBlah" behaviorConfiguration=" BlahServiceBehavior">
       </endpoint>
    </client>

<extensions>
      <behaviorExtensions>
        <add name="httpBlah" type="HttpBlahBehaviorExtensionElement” />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="BlahServiceBehavior">
          < httpBlah />
        </behavior>
      </endpointBehaviors>
    </behaviors>


The code for HttpBlahBehaviorExtensionElement
namespace Blah.MessageInspectors
{
    public class HttpBlahBehaviorExtensionElement: BehaviorExtensionElement
    {
        public override Type BehaviorType
        {
            get
            {
                return typeof(HttpBlahEndpointBehavior);
            }
        }

        protected override object CreateBehavior()
        {
            return new HttpBlahEndpointBehavior();
        }

    }
}

This references the following behavior HttpBlahEndpointBehavior which implements IEndpointBehavior
 Code thus:

  public class HttpBlahEndpointBehavior: IEndpointBehavior
    {

        public HttpBlahEndpointBehavior ()
        {
        }

        #region IEndpointBehavior Members

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
  HttpBlahMessageInspector inspector = new       HttpBlahMessageInspector ();
            clientRuntime.MessageInspectors.Add(inspector);
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }

        #endregion
    }

In this case we only care about applying a behavior in this case an inspector
Here is the HttpBlahMessageInspector which implements IClientMessageInspector



public class HttpBlahMessageInspector: IClientMessageInspector
    {

        #region IClientMessageInspector Members

        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
        }

        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {

             //do something
            return null;
        }

        #endregion
    }

Function to clean string for folder creation


public static string stripIllegal(string str)
       {
           string regex = String.Format("[{0}]", Regex.Escape(new string(Path.GetInvalidFileNameChars())));
      return Regex.Replace(str,regex,"-");
       }

in this case I exchange invalid char with -

root relative paths

Good article about root relative paths

Tuesday, June 12, 2012

Asp.net updatepanel

I kinda agree with a comment I found that updatepanels are useless if they lose css formatting on postbacks 

More WCF errors

if you get
System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding
try to navigate to the  service on the server - things like invalid config files can do this.

This happened again and the reason was iis_usrs lost permission to read config

Thursday, June 7, 2012

Logging idea

good idea to log time to see how long a process is taking


//logging proc
public static void Write(string message, DateTime beginTimeStamp)
        {
            double elapsedMS = DateTime.Now.Subtract(beginTimeStamp).TotalMilliseconds;
            _logger. Write (message + " (" + elapsedMS + ")");
        }

//client
public string GetBlah()
         {
             Logger.Debug("GetBlah Begin");
             DateTime beginTimeStamp = DateTime.Now;
             Logger.Debug("GetBlah End", beginTimeStamp);
             return “”;
         }

Adding your own security policy to WCF


<behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceAuthorization principalPermissionMode="Custom">
            <authorizationPolicies>
              <add policyType="blah" />

Blah will have to implement  IAuthorizationPolicy
Issuer can be disregarded thus:
public System.IdentityModel.Claims.ClaimSet Issuer
        {
            get { throw new NotImplementedException(); }
        }
But at least evaluate should be implemented
public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {

At this point you can add information to the authorization policy thus
evaluationContext.Properties["Principal"] = new ReportingPrincipal(identity);

later this information can be derived thus
var principal = ServiceSecurityContext.Current.AuthorizationContext.Properties["Principal"] as ReportingPrincipal;