Ejemplo n.º 1
0
        public static IEnumerable <TwitterStatus> GetFromCache(TwitterResource resource)
        {
            string fileName   = GetCacheName(resource);
            var    serializer = new SharpSerializer(SerializerSettings);

            IEnumerable <TwitterStatus> statuses = null;

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                try
                {
                    using (var stream = FileAbstractor.GetFileStream(fileName))
                    {
                        if (stream.Length != 0)
                        {
                            statuses = serializer.Deserialize(stream) as IEnumerable <TwitterStatus>;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            });

            return(statuses ?? new List <TwitterStatus>());
        }
Ejemplo n.º 2
0
 public static void ClearAll()
 {
     MutexUtil.DoWork(mutexName, () =>
     {
         IsolatedStorageSettings.ApplicationSettings.Clear();
     });
 }
Ejemplo n.º 3
0
        private static T GenericGetFromConfig <T>(string key, ref T element)
        {
            if (element != null)
            {
                return(element);
            }

            T copy = default(T);

            MutexUtil.DoWork(mutexName, () =>
            {
                IsolatedStorageSettings config = IsolatedStorageSettings.ApplicationSettings;

                try
                {
                    if (!config.TryGetValue <T>(key, out copy))
                    {
                        if (DefaultValues.ContainsKey(key))
                        {
                            copy = (T)DefaultValues[key];
                        }
                        else
                        {
                            copy = CreateDefault <T>();
                        }

                        config.Add(key, copy);
                        config.Save();
                    }
                }
                catch (InvalidCastException)
                {
                    copy = CreateDefault <T>();
                    config.Remove(key);
                    config.Save();
                }
            });

            element = copy;

            if (element == null)
            {
                element = CreateDefault <T>();
            }

            return(element);
        }
Ejemplo n.º 4
0
        public static void WriteContentsToFile(string contents, string fileName)
        {
            IsolatedStorageFile       storage = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream file;

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                using (file = storage.OpenFile(fileName, System.IO.FileMode.Create))
                {
                    using (var writer = new StreamWriter(file))
                    {
                        writer.Write(contents);
                        writer.Close();
                    }
                    file.Close();
                }
            });
        }
Ejemplo n.º 5
0
        public static string ReadContentsOfFile(string fileName)
        {
            var    storage  = IsolatedStorageFile.GetUserStoreForApplication();
            string contents = "";

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                using (var file = storage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate))
                {
                    using (var reader = new StreamReader(file))
                    {
                        contents = reader.ReadToEnd();
                        reader.Close();
                    }
                    file.Close();
                }
            });

            return(contents);
        }
Ejemplo n.º 6
0
        public static void WriteLinesToFile(IEnumerable <string> lines, string fileName)
        {
            IsolatedStorageFile       storage = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream file;

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                using (file = storage.OpenFile(fileName, System.IO.FileMode.Create))
                {
                    using (var writer = new StreamWriter(file))
                    {
                        foreach (var line in lines)
                        {
                            writer.WriteLine(line);
                        }
                        writer.Close();
                    }
                    file.Close();
                }
            });
        }
Ejemplo n.º 7
0
        public static void SaveToCache(TwitterResource resource, IEnumerable <TwitterStatus> list)
        {
            string fileName = GetCacheName(resource);

            var serializer = new SharpSerializer(SerializerSettings);

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                try
                {
                    using (var stream = FileAbstractor.GetFileStream(fileName))
                    {
                        serializer.Serialize(list.Distinct().OfType <TwitterStatus>().ToList(), stream);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            });
        }
Ejemplo n.º 8
0
        public static void Main()
        {
            MutexUtil.WrapSingleInstance(() =>
            {
                var p = new OptionSet()
                {
                    { "p|port=", "ProPresenter network port number", (int _port) => AppConfig.port = _port },
                    { "r|password="******"ProPresenter network remote control password", (string _password) => AppConfig.password = _password }
                };

                try
                {
                    p.Parse(Environment.GetCommandLineArgs());
                }
                catch (OptionException e)
                {
                    var stringBuilder = new StringBuilder();

                    using (TextWriter writer = new StringWriter(stringBuilder))
                    {
                        p.WriteOptionDescriptions(writer);
                    }

                    MessageBox.Show("Command line arguments failed to parse. Error:\n" + e.Message);

                    MessageBox.Show("ClickerFixer command line arguments usage:\n" + stringBuilder.ToString());

                    return;
                }

                Application.ApplicationExit += new EventHandler((s, e) => {
                    if (_clickerListener != null)
                    {
                        _clickerListener.Abort();
                    }
                });

                Application.Run(new SysTrayApp());
            });
        }
Ejemplo n.º 9
0
        private static void GenericSaveToConfig <T>(string Key, ref T element, T value)
        {
            if (value == null)
            {
                return;
            }

            element = value;

            MutexUtil.DoWork(mutexName, () =>
            {
                IsolatedStorageSettings conf = IsolatedStorageSettings.ApplicationSettings;

                if (conf.Contains(Key))
                {
                    conf[Key] = value;
                }
                else
                {
                    conf.Add(Key, value);
                }
                conf.Save();
            });
        }
Ejemplo n.º 10
0
        public static IEnumerable <string> ReadLinesOfFile(string fileName)
        {
            List <string> lines = new List <string>();

            var storage = IsolatedStorageFile.GetUserStoreForApplication();

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                using (var file = storage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate))
                {
                    using (var reader = new StreamReader(file))
                    {
                        while (!reader.EndOfStream)
                        {
                            lines.Add(reader.ReadLine());
                        }
                        reader.Close();
                    }
                    file.Close();
                }
            });

            return(lines);
        }