Tile.cs :  » GUI » LongBar » TileLib » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » LongBar 
LongBar » TileLib » Tile.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
using System.Windows;
using System.IO;

namespace TileLib{
  public class TileInfo : Attribute
  {
    public readonly string Name;
    public readonly bool hasflyout;
    public readonly bool hasOptions;

    public TileInfo(string name, bool hasflyout, bool hasOptions)
    {
      this.Name = name;
      this.hasflyout = hasflyout;
      this.hasOptions = hasOptions;
    }
  }

  public abstract class BaseTile
  {
    #region Events
    public delegate void CaptionChangedEventHandler(string value);
    public delegate void IconChangedEventHandler(BitmapImage image);
    public delegate void ShowFlyoutEventHandler();
    public delegate void ShowOptionsEventHandler();
    public delegate void HeightChangedEventHandler(double height);

    public event CaptionChangedEventHandler CaptionChanged;
    public event IconChangedEventHandler IconChanged;
    public event ShowFlyoutEventHandler ShowFlyoutEvent;
    public event ShowOptionsEventHandler ShowOptionsEvent;
    public event HeightChangedEventHandler HeightChangedEvent;
    #endregion

    private string _caption;
    private BitmapImage _icon;
    private bool _isMinimized;
    private bool _isPinned;
    private UserControl _flyoutContent;
    private UserControl _optionsContent;
    private double _height;
    public string _path;

    public string Caption
    {
      get { return _caption;}
      set
      {
        _caption = value;
        CaptionChanged(value);
      }
    }

    public bool IsMinimized
    {
      get { return _isMinimized; }
      set { _isMinimized = value; }
    }

    public bool IsPinned
    {
        get { return _isPinned; }
        set { _isPinned = value; }
    }

    public BitmapImage Icon
    {
      get { return _icon; }
      set
      {
        _icon = value;
        IconChanged(value);
      }
    }

    public double Height
    {
        get { return _height; }
        set
        {
            _height = value;
            if (HeightChangedEvent != null)
                HeightChangedEvent(value);
        }
    }

    public UserControl FlyoutContent
    {
      get { return _flyoutContent; }
      set { _flyoutContent = value; }
    }

    public UserControl OptionsContent
    {
      get { return _optionsContent; }
      set { _optionsContent = value; }
    }

    public abstract UserControl Load();

    public virtual void Unload() { }
    public virtual void ChangeSide(int side) { }
    public virtual void ChangeLocale(string locale) { }
    public virtual void ChangeTheme(string theme) { }
    public virtual void Minimized() { }
    public virtual void Unminimized() { }
    
    public virtual void ShowFlyout()
    {
      ShowFlyoutEvent();
    }

    public virtual void ShowOptions()
    {
      ShowOptionsEvent();
    }

    public void WriteSetting(string tileName, string setting, string value)
    {
        bool exit = false;
        if (File.Exists(_path + "\\Library\\" + tileName + "\\" + "Settings.ini"))
        {
            string[] lines = File.ReadAllLines(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(setting))
                {
                    lines[i] = setting + "=" + value;
                    exit = true;
                }
            }
            File.WriteAllLines(_path + "\\Library\\" + tileName + "\\" + "Settings.ini", lines);
            if (exit)
                return;
        }
            StreamWriter writer = File.AppendText(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
            writer.WriteLine(setting + "=" + value);
            writer.Flush();
            writer.Close();
        /*RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree);
        key = key.OpenSubKey(tileName, RegistryKeyPermissionCheck.ReadWriteSubTree);
        if (key == null)
            key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree).CreateSubKey(tileName,RegistryKeyPermissionCheck.ReadWriteSubTree);
        key.SetValue(setting, value, RegistryValueKind.String);
        key.Close();*/
    }

    public void WriteSetting(string tileName, string setting, int value)
    {
        bool exit = false;
        if (File.Exists(_path + "\\Library\\" + tileName + "\\" + "Settings.ini"))
        {
            string[] lines = File.ReadAllLines(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(setting))
                {
                    lines[i] = setting + "=" + value.ToString();
                    exit = true;
                }
            }
            File.WriteAllLines(_path + "\\Library\\" + tileName + "\\" + "Settings.ini", lines);
            if (exit)
                return;
        }
        StreamWriter writer = File.AppendText(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
        writer.WriteLine(setting + "=" + value.ToString());
        writer.Flush();
        writer.Close();
        /*RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree);
        key = key.OpenSubKey(tileName, RegistryKeyPermissionCheck.ReadWriteSubTree);
        if (key == null)
            key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree).CreateSubKey(tileName, RegistryKeyPermissionCheck.ReadWriteSubTree);
        key.SetValue(setting, value, RegistryValueKind.DWord);
        key.Close();*/
    }

    public void WriteSetting(string tileName, string setting, string[] value)
    {
        bool exit = false;
        if (File.Exists(_path + "\\Library\\" + tileName + "\\" + "Settings.ini"))
        {
            string[] lines = File.ReadAllLines(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(setting + ":"))
                {
                    lines[i] = setting + ": ";
                    for (int n = 0; i < value.Length; i++)
                    {
                        lines[i] += value[n] + ";";
                    }
                    exit = true;
                }
            }
            File.WriteAllLines(_path + "\\Library\\" + tileName + "\\" + "Settings.ini", lines);
            if (exit)
                return;
        }
        StreamWriter writer = File.AppendText(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
        writer.Write(setting + ": ");
        for (int i = 0; i < value.Length; i++)
        {
            writer.Write(value[i] + ";");
        }
        writer.WriteLine();
        writer.Flush();
        writer.Close();
        /*RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree);
        key = key.OpenSubKey(tileName, RegistryKeyPermissionCheck.ReadWriteSubTree);
        if (key == null)
            key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree).CreateSubKey(tileName, RegistryKeyPermissionCheck.ReadWriteSubTree);
        key.SetValue(setting, value, RegistryValueKind.MultiString);
        key.Close();*/
    }

    public object ReadSetting(string tileName, string setting)
    {
        if (File.Exists(_path + "\\Library\\" + tileName + "\\" + "Settings.ini"))
        {
          string line = "";
          StreamReader reader = System.IO.File.OpenText(_path + "\\Library\\" + tileName + "\\" + "Settings.ini");
          while (!reader.EndOfStream)
          {
              line = reader.ReadLine();
              if (line.StartsWith(setting + ":"))
              {
                  string s = line.Substring(line.IndexOf(":") + 2, line.Length - line.IndexOf(":") - 2);
                  return (object)s.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
              }
              else if (line.StartsWith(setting))
              {
                  return (object)line.Split('=')[1];
              }
          }
          return null;
        }
        else
            return null;
        /*RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)
            .OpenSubKey("LongBar", RegistryKeyPermissionCheck.ReadWriteSubTree);
        key = key.OpenSubKey(tileName, RegistryKeyPermissionCheck.ReadWriteSubTree);
        if (key == null)
        {
            return null;
        }
        else
        {
            return key.GetValue(setting);
        }*/
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.