示例#1
0
        /// <summary>
        /// Code to initialize the language etc during design time
        /// </summary>
        protected void InitializeForDesigner()
        {
            if (DesignMode)
            {
                designTimeControls       = new Dictionary <string, Control>();
                designTimeToolStripItems = new Dictionary <string, ToolStripItem>();
                try {
                    ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;

                    // Add a hard-path if you are using SharpDevelop
                    // Language.AddLanguageFilePath(@"C:\Greenshot\Greenshot\Languages");

                    // this "type"
                    Assembly currentAssembly   = GetType().Assembly;
                    string   assemblyPath      = typeResService.GetPathOfAssembly(currentAssembly.GetName());
                    string   assemblyDirectory = Path.GetDirectoryName(assemblyPath);
                    if (!Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Greenshot\Languages\")))
                    {
                        Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Greenshot\Languages\"));
                    }
                    if (!Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Languages\")))
                    {
                        Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Languages\"));
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }
 /// <summary>
 /// Code to initialize the language etc during design time
 /// </summary>
 protected void InitializeForDesigner()
 {
     if (this.DesignMode)
     {
         designTimeControls       = new Dictionary <string, Control>();
         designTimeToolStripItems = new Dictionary <string, ToolStripItem>();
         try
         {
             ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
             Assembly currentAssembly = this.GetType().Assembly;
             string   assemblyPath    = typeResService.GetPathOfAssembly(currentAssembly.GetName());
             if (!Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\Greenshot\Languages\")))
             {
                 Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\..\Greenshot\Languages\"));
             }
             if (!Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\Languages\")))
             {
                 Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\..\Languages\"));
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }
示例#3
0
        /// <summary>
        ///    <para>Gets a license for the instance of the component and determines if it is valid.</para>
        /// </summary>
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            LicFileLicense lic = null;

            Debug.Assert(context != null, "No context provided!");
            if (context != null)
            {
                if (context.UsageMode == LicenseUsageMode.Runtime)
                {
                    string key = context.GetSavedLicenseKey(type, null);
                    if (key != null && IsKeyValid(key, type))
                    {
                        lic = new LicFileLicense(this, key);
                    }
                }

                if (lic == null)
                {
                    string modulePath = null;

                    if (context != null)
                    {
                        ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService));
                        if (resolver != null)
                        {
                            modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName());
                        }
                    }

                    if (modulePath == null)
                    {
                        modulePath = type.Module.FullyQualifiedName;
                    }

                    string moduleDir   = Path.GetDirectoryName(modulePath);
                    string licenseFile = moduleDir + "\\" + type.FullName + ".lic";

                    Debug.WriteLine($"Looking for license in: {licenseFile}");
                    if (File.Exists(licenseFile))
                    {
                        Stream       licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                        StreamReader sr        = new StreamReader(licStream);
                        string       s         = sr.ReadLine();
                        sr.Close();
                        if (IsKeyValid(s, type))
                        {
                            lic = new LicFileLicense(this, GetKey(type));
                        }
                    }

                    if (lic != null)
                    {
                        context.SetSavedLicenseKey(type, lic.LicenseKey);
                    }
                }
            }
            return(lic);
        }
示例#4
0
        public void Compile()
        {
            List <IFileNode> localCompileList;
            bool             recompileAll;

            lock (compileList)
            {
                if (typeResolverContext == null)
                {
                    Action itr = () =>
                    {
                        typeResolverContext = GlobalServices.TypeService.GetContextTypeResolver(projectManager);
                        typeResolver        = GlobalServices.TypeService.GetTypeResolutionService(projectManager);
                        //hack to ensure that necessary internal state gets initialized
                        typeResolver.GetPathOfAssembly(new AssemblyName("mscorlib.dll"));
                    };
                    Application.Current.Dispatcher.Invoke(itr);
                }
                localCompileList = new List <IFileNode>(compileList);
                compileList.Clear();
                if (localCompileList.Count == 0 && !referencesDirty)
                {
                    return;
                }
                recompileAll    = referencesDirty;
                referencesDirty = false;
            }

            var results = new Dictionary <IFileNode, CompileResults>();

            foreach (var file in BooProjectNode.GetFileEnumerator(projectManager))
            {
                if (recompileAll || localCompileList.Contains(file))
                {
                    // this seemingly redundant variable ensures that each closure below has its own copy of
                    // the file reference. Without it they share the same copy decalred in the loop statemenet
                    // essentially all of them will point to the last element in the loop
                    var localfile = file;
                    results.Add(file, new CompileResults(() => localfile.Url, localfile.GetCompilerInput, () => GlobalServices.LanguageService.GetLanguagePreferences().TabSize));
                }
                else
                {
                    results.Add(file, file.GetCompileResults());
                }
            }

            Boo.ASTMapper.CompilerManager.Compile(
                GlobalServices.LanguageService.GetLanguagePreferences().TabSize,
                references.Values.Select(ae => ae.GetAssembly(typeResolver.GetAssembly)).Where(a => a != null),
                results.Values);

            foreach (var result in results)
            {
                result.Key.SetCompilerResults(result.Value);
            }
        }
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            LicFileLicense license = null;

            if (context != null)
            {
                if (context.UsageMode == LicenseUsageMode.Runtime)
                {
                    string savedLicenseKey = context.GetSavedLicenseKey(type, null);
                    if ((savedLicenseKey != null) && this.IsKeyValid(savedLicenseKey, type))
                    {
                        license = new LicFileLicense(this, savedLicenseKey);
                    }
                }
                if (license != null)
                {
                    return(license);
                }
                string path = null;
                if (context != null)
                {
                    ITypeResolutionService service = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService));
                    if (service != null)
                    {
                        path = service.GetPathOfAssembly(type.Assembly.GetName());
                    }
                }
                if (path == null)
                {
                    path = type.Module.FullyQualifiedName;
                }
                string str4 = Path.GetDirectoryName(path) + @"\" + type.FullName + ".lic";
                if (File.Exists(str4))
                {
                    Stream       stream = new FileStream(str4, FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader reader = new StreamReader(stream);
                    string       key    = reader.ReadLine();
                    reader.Close();
                    if (this.IsKeyValid(key, type))
                    {
                        license = new LicFileLicense(this, this.GetKey(type));
                    }
                }
                if (license != null)
                {
                    context.SetSavedLicenseKey(type, license.LicenseKey);
                }
            }
            return(license);
        }
示例#6
0
        public override License GetLicense(LicenseContext licenseContext_0, Type type_0, object object_0, bool bool_0)
        {
            License aELicense;

            if (licenseContext_0 == null)
            {
                throw new LicenseException(type_0, object_0, "License context is null.");
            }
            string savedLicenseKey = licenseContext_0.GetSavedLicenseKey(type_0, null);

            if ((savedLicenseKey == null ? true : !this.IsKeyValid(type_0, savedLicenseKey)))
            {
                switch (licenseContext_0.UsageMode)
                {
                case LicenseUsageMode.Runtime:
                {
                    savedLicenseKey =
                        this.GetLicenseFromFile(string.Concat(Application.StartupPath, "\\licences.lic"),
                                                type_0.FullName);
                    if (savedLicenseKey == null || !this.IsKeyValid(type_0, savedLicenseKey))
                    {
                        aELicense = null;
                        break;
                    }
                    else
                    {
                        licenseContext_0.SetSavedLicenseKey(type_0, savedLicenseKey);
                        aELicense = new AELicense("Runtime");
                        break;
                    }
                }

                case LicenseUsageMode.Designtime:
                {
                    ITypeResolutionService service =
                        (ITypeResolutionService)licenseContext_0.GetService(typeof(ITypeResolutionService));
                    if (service != null)
                    {
                        if (service.GetPathOfAssembly(type_0.Assembly.GetName()) == null)
                        {
                            string fullyQualifiedName = type_0.Module.FullyQualifiedName;
                        }
                        savedLicenseKey = "受限许可";
                    }
                    aELicense = new AELicense(savedLicenseKey);
                    break;
                }

                default:
                {
                    aELicense = null;
                    break;
                }
                }
            }
            else
            {
                aELicense = new AELicense(savedLicenseKey);
            }
            return(aELicense);
        }
示例#7
0
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            ChartLicense chartLicense = null;

            if (context != null)
            {
                if (context.UsageMode == LicenseUsageMode.Designtime)
                {
                    chartLicense = new ChartLicense(this, "Dundas Chart. Design-Time License");
                }
                if (chartLicense == null)
                {
                    string savedLicenseKey = context.GetSavedLicenseKey(type, null);
                    if (savedLicenseKey != null && this.IsKeyValid(savedLicenseKey, type))
                    {
                        chartLicense = new ChartLicense(this, savedLicenseKey);
                    }
                }
                if (chartLicense == null)
                {
                    string text = null;
                    if (context != null)
                    {
                        ITypeResolutionService typeResolutionService = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService));
                        if (typeResolutionService != null)
                        {
                            text = typeResolutionService.GetPathOfAssembly(type.Assembly.GetName());
                        }
                    }
                    if (text == null)
                    {
                        text = type.Module.FullyQualifiedName;
                    }
                    string directoryName = Path.GetDirectoryName(text);
                    string path          = directoryName + "\\" + type.FullName + ".lic";
                    bool   flag          = File.Exists(path);
                    if (!flag)
                    {
                        string path2 = directoryName + "\\__AssemblyInfo__.ini";
                        if (File.Exists(path2))
                        {
                            string       text2        = null;
                            Stream       stream       = new FileStream(path2, FileMode.Open, FileAccess.Read, FileShare.Read);
                            StreamReader streamReader = new StreamReader(stream);
                            do
                            {
                                text2 = streamReader.ReadLine();
                                text2 = text2.ToUpper(CultureInfo.InvariantCulture);
                                if (text2 != null && text2.StartsWith("URL=", StringComparison.Ordinal))
                                {
                                    directoryName = text2.Substring(4);
                                    if (directoryName.StartsWith("FILE:///", StringComparison.Ordinal))
                                    {
                                        directoryName = directoryName.Substring(8);
                                    }
                                    directoryName = directoryName.Replace('/', '\\');
                                    int num = directoryName.LastIndexOf('\\');
                                    if (num >= 0)
                                    {
                                        directoryName = directoryName.Substring(0, num);
                                    }
                                    path  = directoryName + "\\" + type.FullName + ".lic";
                                    flag  = File.Exists(path);
                                    text2 = null;
                                }
                            }while (text2 != null);
                            streamReader.Close();
                        }
                    }
                    if (flag)
                    {
                        Stream       stream2       = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                        StreamReader streamReader2 = new StreamReader(stream2);
                        string       key           = streamReader2.ReadLine();
                        streamReader2.Close();
                        if (this.IsKeyValid(key, type))
                        {
                            chartLicense = new ChartLicense(this, key);
                        }
                    }
                    if (chartLicense != null)
                    {
                        context.SetSavedLicenseKey(type, chartLicense.LicenseKey);
                    }
                }
            }
            return(chartLicense);
        }
        // InvokeMethods the currently selected method, if any, when
        // the InvokeMethod button is pressed.
        private void InvokeMethod(object sender, EventArgs e)
        {
            // If the GetAssembly or GetPathofAssembly radio button
            // is selected.
            if (this.radioButton1.Checked || this.radioButton2.Checked || this.radioButton4.Checked)
            {
                if (this.entryBox.Text.Length == 0)
                {
                    // If there is no assembly name specified, display status message.
                    this.infoBox.Text = "You must enter the name of the assembly to retrieve.";
                }
                else if (rs != null)
                {
                    // Create a System.Reflection.AssemblyName
                    // for the entered text.
                    AssemblyName name = new AssemblyName();
                    name.Name = this.entryBox.Text.Trim();

                    // If the GetAssembly radio button is checked...
                    if (this.radioButton1.Checked)
                    {
                        // Use the ITypeResolutionService to attempt to
                        // resolve an assembly reference.
                        Assembly a = rs.GetAssembly(name, false);
                        // If an assembly matching the specified name was not
                        // located in the GAC or local project references,
                        // display a message.
                        if (a == null)
                        {
                            this.infoBox.Text = "The " + this.entryBox.Text + " assembly could not be located.";
                        }
                        else
                        {
                            // An assembly matching the specified name was located.
                            // Builds a list of types.
                            Type[]        types = a.GetTypes();
                            StringBuilder sb    = new StringBuilder();
                            for (int i = 0; i < types.Length; i++)
                            {
                                sb.Append(types[i].FullName + "\r\n");
                            }
                            string path = rs.GetPathOfAssembly(name);
                            // Displays assembly information and a list of types contained in the assembly.
                            this.infoBox.Text = "Assembly located:\r\n\r\n" + a.FullName + "\r\n  at: " + path + "\r\n\r\nAssembly types:\r\n\r\n" + sb.ToString();
                        }
                    }
                    else if (this.radioButton2.Checked)
                    {
                        string path = rs.GetPathOfAssembly(name);
                        if (path != null)
                        {
                            this.infoBox.Text = "Assembly located at:\r\n" + path;
                        }
                        else
                        {
                            this.infoBox.Text = "Assembly was not located.";
                        }
                    }
                    else if (this.radioButton4.Checked)
                    {
                        Assembly a = null;
                        try
                        {
                            // Add a reference to the assembly to the
                            // current project.
                            rs.ReferenceAssembly(name);
                            // Use the ITypeResolutionService to attempt
                            // to resolve an assembly reference.
                            a = rs.GetAssembly(name, false);
                        }
                        catch
                        {
                            // Catch this exception so that the exception
                            // does not interrupt control behavior.
                        }
                        // If an assembly matching the specified name was not
                        // located in the GAC or local project references,
                        // display a message.
                        if (a == null)
                        {
                            this.infoBox.Text = "The " + this.entryBox.Text + " assembly could not be located.";
                        }
                        else
                        {
                            this.infoBox.Text = "A reference to the " + a.FullName + " assembly has been added to the project's referenced assemblies.";
                        }
                    }
                }
            }
            else if (this.radioButton3.Checked)
            {
                if (this.entryBox.Text.Length == 0)
                {
                    // If there is no type name specified, display a
                    // status message.
                    this.infoBox.Text = "You must enter the name of the type to retrieve.";
                }
                else if (rs != null)
                {
                    Type type = null;
                    try
                    {
                        type = rs.GetType(this.entryBox.Text, false, true);
                    }
                    catch
                    {
                        // Consume exceptions raised during GetType call
                    }
                    if (type != null)
                    {
                        // Display type information.
                        this.infoBox.Text = "Type: " + type.FullName + " located.\r\n  Namespace: " + type.Namespace + "\r\n" + type.AssemblyQualifiedName;
                    }
                    else
                    {
                        this.infoBox.Text = "Type not located.";
                    }
                }
            }
        }
        /// <include file='doc\LicFileLicenseProvider.uex' path='docs/doc[@for="LicFileLicenseProvider.GetLicense"]/*' />
        /// <devdoc>
        ///    <para>Gets a license for the instance of the component and determines if it is valid.</para>
        /// </devdoc>
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            ProcCountLicense lic = null;

            Debug.Assert(context != null, "No context provided!");
            //if no context is provided, do nothing
            if (context != null)
            {
                //if this control is in runtime mode
                if (context.UsageMode == LicenseUsageMode.Runtime)
                {
                    //retreive the stored license key
                    string key = context.GetSavedLicenseKey(type, null);

                    //check if the stored license key is null
                    // and call IsKeyValid to make sure its valid
                    if (key != null && IsKeyValid(key, type))
                    {
                        //if the key is valid create a new license
                        lic = new ProcCountLicense(this, key);
                    }
                }

                //if we're in design mode or
                //a suitable license key wasn't found in
                //the runtime context.
                //attempt to look for a .LIC file
                if (lic == null)
                {
                    //build up the path where the .LIC file
                    //should be
                    string modulePath = null;

                    // try and locate the file for the assembly
                    if (context != null)
                    {
                        ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService));
                        if (resolver != null)
                        {
                            modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName());
                        }
                    }


                    if (modulePath == null)
                    {
                        modulePath = type.Module.FullyQualifiedName;
                    }

                    //get the path from the file location
                    string moduleDir = Path.GetDirectoryName(modulePath);

                    //build the path of the .LIC file
                    string licenseFile = moduleDir + "\\" + type.FullName + ".lic";

                    Debug.WriteLine("Path of license file: " + licenseFile);

                    //if the .LIC file exists, dig into it
                    if (File.Exists(licenseFile))
                    {
                        //crack the file and get the first line
                        Stream       licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                        StreamReader sr        = new StreamReader(licStream);
                        string       s         = sr.ReadLine();
                        sr.Close();

                        Debug.WriteLine("Contents of license file: " + s);

                        //check if the key is valid
                        if (IsKeyValid(s, type))
                        {
                            //valid key so create a new License
                            lic = new ProcCountLicense(this, s);
                        }
                    }

                    //if we managed to create a license, stuff it into the context
                    if (lic != null)
                    {
                        context.SetSavedLicenseKey(type, lic.LicenseKey);
                    }
                }
            }
            return(lic);
        }
示例#10
0
 /// <summary>
 /// See <see cref="ITypeResolutionService.GetPathOfAssembly"/>.
 /// </summary>
 public override string GetPathOfAssembly(AssemblyName name)
 {
     return(parentLoader.GetPathOfAssembly(name));
 }